Skip to content

Commit c976d26

Browse files
committed
state command lists
1 parent 678f425 commit c976d26

1 file changed

Lines changed: 32 additions & 18 deletions

File tree

app/lib/routes/services.rb

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,25 @@ def inventory_hosts
115115
def self.registered(app)
116116
app.get '/json/ui/state' do
117117
resp = ui_hosts.map do |host|
118-
get_url("#{host}/state.json")
118+
get_url_json("#{host}/state.json")
119119
end
120-
resp = get_url("#{ui_host}/state.json") if resp.empty?
120+
resp = get_url_json("#{ui_host}/state.json") if resp.empty?
121121
resp.to_json
122122
end
123123

124124
app.get '/json/ui/audit-replic' do
125125
resp = ui_hosts.map do |host|
126-
get_url("#{host}/state-audit-replic.json")
126+
get_url_json("#{host}/state-audit-replic.json")
127127
end
128-
resp = get_url("#{ui_host}/state-audit-replic.json") if resp.empty?
128+
resp = get_url_json("#{ui_host}/state-audit-replic.json") if resp.empty?
129129
resp.to_json
130130
end
131131

132132
app.get '/json/ingest/state' do
133133
resp = ingest_hosts.map do |host|
134-
get_url("#{host}/state?t=json")
134+
get_url_json("#{host}/state.json")
135135
end
136-
resp = get_url("#{ingest_host}/state?t=json") if resp.empty?
136+
resp = get_url_json("#{ingest_host}/state.json") if resp.empty?
137137
resp.to_json
138138
end
139139

@@ -143,9 +143,9 @@ def self.registered(app)
143143

144144
app.get '/json/store/state' do
145145
resp = store_hosts.map do |host|
146-
get_url("#{host}/state?t=json")
146+
get_url_json("#{host}/state.json")
147147
end
148-
resp = get_url("#{store_host}/state?t=json") if resp.empty?
148+
resp = get_url_json("#{store_host}/state.json") if resp.empty?
149149
resp.to_json
150150
end
151151

@@ -167,9 +167,9 @@ def self.registered(app)
167167

168168
app.get '/json/inventory/state' do
169169
resp = inventory_hosts.map do |host|
170-
get_url("#{host}/state?t=json")
170+
get_url_json("#{host}/state.json")
171171
end
172-
resp = get_url("#{inventory_host}/state?t=json") if resp.empty?
172+
resp = get_url_json("#{inventory_host}/state.json") if resp.empty?
173173
resp.to_json
174174
end
175175

@@ -211,9 +211,9 @@ def self.registered(app)
211211

212212
app.get '/json/audit/state' do
213213
resp = audit_hosts.map do |host|
214-
get_url("#{host}/state?t=json")
214+
get_url_json("#{host}/state.json")
215215
end
216-
resp = get_url("#{audit_host}/state?t=json") if resp.empty?
216+
resp = get_url_json("#{audit_host}/state.json") if resp.empty?
217217
resp.to_json
218218
end
219219

@@ -256,9 +256,9 @@ def self.registered(app)
256256
app.get '/json/replic/state' do
257257
# Per David, replic uses status instead of state
258258
resp = replic_hosts.map do |host|
259-
get_url("#{host}/status?t=json")
259+
get_url_json("#{host}/status.json")
260260
end
261-
resp = get_url("#{replic_host}/status?t=json") if resp.empty?
261+
resp = get_url_json("#{replic_host}/status.json") if resp.empty?
262262
resp.to_json
263263
end
264264

@@ -300,9 +300,9 @@ def self.registered(app)
300300

301301
app.get '/json/access/state' do
302302
resp = access_hosts.map do |host|
303-
get_url("#{host}/state?t=json")
303+
get_url_json("#{host}/state.json")
304304
end
305-
resp = get_url("#{access_host}/state?t=json") if resp.empty?
305+
resp = get_url_json("#{access_host}/state.json") if resp.empty?
306306
resp.to_json
307307
end
308308

@@ -814,7 +814,14 @@ def java_service_send_stop_start(service, endpoint)
814814

815815
def service_urls(service)
816816
urls = []
817-
svcsuff = service == 'access' ? 'store' : service
817+
svcsuff = case service
818+
when 'ui'
819+
''
820+
when 'access'
821+
'/store'
822+
else
823+
"/#{service}"
824+
end
818825
Aws::ServiceDiscovery::Client.new(region: UC3::UC3Client.region)
819826
.discover_instances(
820827
service_name: service,
@@ -824,7 +831,7 @@ def service_urls(service)
824831
hostip = instance.attributes.fetch('AWS_INSTANCE_IPV4', '')
825832
next if hostip.empty?
826833

827-
url = "http://#{hostip}:8080/#{svcsuff}"
834+
url = "http://#{hostip}:8080#{svcsuff}"
828835
urls << url
829836
end
830837
logger.info("Monitor #{urls}")
@@ -1304,6 +1311,13 @@ def get_url(url, ctype: :json)
13041311
{ uri: uri, error: e.to_s }.to_json
13051312
end
13061313

1314+
def get_url_json(url)
1315+
body = get_url(url)
1316+
::JSON.parse(body)
1317+
rescue StandardError => e
1318+
{ uri: url, error: e.to_s }
1319+
end
1320+
13071321
# this method may be over-customized for EZID. Consider refactoring.
13081322
def post_url_body(url, body: nil, user: nil, password: nil)
13091323
logger.info("URI: #{url}, body: #{body}, user: #{user}, password: #{'****' if password}")

0 commit comments

Comments
 (0)