Skip to content

Commit 36b93c6

Browse files
committed
service discovery stop/start
1 parent d058ebe commit 36b93c6

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

app/lib/routes/resources.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ def self.registered(app)
7878
end
7979

8080
app.post '/infra/ecs/redeploy/*' do |service|
81+
java_service_send_stop_start(service, STOP_ENDPOINT) if %w[inventory audit replic].include?(service)
82+
8183
UC3Resources::ServicesClient.new.redeploy_service(service)
8284
redirect '/infra/ecs/services/state'
8385
end
8486

8587
app.post '/infra/ecs/retag-redeploy/*' do |service|
88+
java_service_send_stop_start(service, STOP_ENDPOINT) if %w[inventory audit replic].include?(service)
89+
8690
UC3Resources::ServicesClient.new.retag_and_redeploy_service(service)
8791
redirect '/infra/ecs/services/state'
8892
end

app/lib/routes/services.rb

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,17 @@ def self.registered(app)
9191
end
9292

9393
app.post '/json/inventory/start' do
94-
java_service_send_stop_start(inventory_host, 'inventory', START_ENDPOINT)
94+
resp = java_service_send_stop_start('inventory', START_ENDPOINT)
95+
return post_url("#{inventory_host}/#{START_ENDPOINT}") if resp.empty?
96+
97+
resp.to_json
9598
end
9699

97100
app.post '/json/inventory/stop' do
98-
java_service_send_stop_start(inventory_host, 'inventory', STOP_ENDPOINT)
101+
resp = java_service_send_stop_start('inventory', STOP_ENDPOINT)
102+
return post_url("#{inventory_host}/#{STOP_ENDPOINT}") if resp.empty?
103+
104+
resp.to_json
99105
end
100106

101107
app.post '/json/inventory/admin-init' do
@@ -119,11 +125,17 @@ def self.registered(app)
119125
end
120126

121127
app.post '/json/audit/start' do
122-
java_service_send_stop_start(audit_host, 'audit', START_ENDPOINT)
128+
resp = java_service_send_stop_start('audit', START_ENDPOINT)
129+
return post_url("#{audit_host}/#{START_ENDPOINT}") if resp.empty?
130+
131+
resp.to_json
123132
end
124133

125134
app.post '/json/audit/stop' do
126-
java_service_send_stop_start(audit_host, 'audit', STOP_ENDPOINT)
135+
resp = java_service_send_stop_start('audit', STOP_ENDPOINT)
136+
return post_url("#{audit_host}/#{STOP_ENDPOINT}") if resp.empty?
137+
138+
resp.to_json
127139
end
128140

129141
app.get '/json/replic/state' do
@@ -136,11 +148,17 @@ def self.registered(app)
136148
end
137149

138150
app.post '/json/replic/start' do
139-
java_service_send_stop_start(replic_host, 'replic', START_ENDPOINT)
151+
resp = java_service_send_stop_start('replic', START_ENDPOINT)
152+
return post_url("#{replic_host}/#{START_ENDPOINT}") if resp.empty?
153+
154+
resp.to_json
140155
end
141156

142157
app.post '/json/replic/pause' do
143-
java_service_send_stop_start(replic_host, 'replic', 'service/pause?t=json')
158+
resp = java_service_send_stop_start('replic', STOP_ENDPOINT)
159+
return post_url("#{replic_host}/#{STOP_ENDPOINT}") if resp.empty?
160+
161+
resp.to_json
144162
end
145163

146164
app.get '/json/replic/nodes' do
@@ -579,7 +597,7 @@ def self.registered(app)
579597
end
580598
end
581599

582-
def java_service_send_stop_start(host, service, endpoint)
600+
def java_service_send_stop_start(service, endpoint)
583601
resp = []
584602
Aws::ServiceDiscovery::Client.new(region: UC3::UC3Client.region)
585603
.discover_instances(
@@ -590,11 +608,9 @@ def java_service_send_stop_start(host, service, endpoint)
590608
hostip = instance.attributes.fetch('AWS_INSTANCE_IPV4', '')
591609
resp << JSON.parse(post_url("http://#{hostip}:8080/#{service}/#{endpoint}")) unless hostip.empty?
592610
end
593-
# if service is not yet in ECS, use ALB address to send request to one host
594-
return post_url("#{host}/#{endpoint}") if resp.empty?
595-
resp.to_json
611+
resp
596612
rescue StandardError
597-
post_url("#{host}/#{endpoint}")
613+
[]
598614
end
599615

600616
def admin_state

0 commit comments

Comments
 (0)