Skip to content

Commit d0a4c01

Browse files
committed
state command lists
1 parent 4e79d27 commit d0a4c01

2 files changed

Lines changed: 77 additions & 39 deletions

File tree

app/lib/routes/services.rb

Lines changed: 76 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ def ui_host
2525
host =~ /^http/ ? host : "http://#{host}"
2626
end
2727

28+
def ui_hosts
29+
hosts = ENV.fetch('HOSTS_UI', '').split(',').map do |host|
30+
"http://#{host}"
31+
end
32+
return service_urls('ui') if hosts.empty?
33+
34+
hosts
35+
end
36+
2837
def ingest_host
2938
"http://#{ENV.fetch('SVC_INGEST', 'ingest:8080/ingest')}"
3039
end
@@ -105,23 +114,43 @@ def inventory_hosts
105114

106115
def self.registered(app)
107116
app.get '/json/ui/state' do
108-
get_url("#{ui_host}/state.json")
117+
resp = []
118+
ui_hosts.each do |host|
119+
resp << get_url_json("#{host}/state.json")
120+
end
121+
resp = get_url("#{ui_host}/state.json") if resp.empty?
122+
resp.to_json
109123
end
110124

111125
app.get '/json/ui/audit-replic' do
112-
get_url("#{ui_host}/state-audit-replic.json")
126+
resp = []
127+
ui_hosts.each do |host|
128+
resp << get_url_json("#{host}/state-audit-replic.json")
129+
end
130+
resp = get_url("#{ui_host}/state-audit-replic.json") if resp.empty?
131+
resp.to_json
113132
end
114133

115134
app.get '/json/ingest/state' do
116-
get_url("#{ingest_host}/state?t=json")
135+
resp = []
136+
ingest_hosts.each do |host|
137+
resp << get_url_json("#{host}/state?t=json")
138+
end
139+
resp = get_url("#{ingest_host}/state?t=json") if resp.empty?
140+
resp.to_json
117141
end
118142

119143
app.get '/json/ingest/tag' do
120144
get_url("#{ingest_host}/#{BUILD_TAG_ENDPOINT}")
121145
end
122146

123147
app.get '/json/store/state' do
124-
get_url("#{store_host}/state?t=json")
148+
resp = []
149+
store_hosts.each do |host|
150+
resp << get_url_json("#{host}/state?t=json")
151+
end
152+
resp = get_url("#{store_host}/state?t=json") if resp.empty?
153+
resp.to_json
125154
end
126155

127156
app.get '/json/store/jsonstatus' do
@@ -141,18 +170,21 @@ def self.registered(app)
141170
end
142171

143172
app.get '/json/inventory/state' do
144-
get_url("#{inventory_host}/state?t=json")
173+
resp = []
174+
inventory_hosts.each do |host|
175+
resp << get_url_json("#{host}/state?t=json")
176+
end
177+
resp = get_url("#{inventory_host}/state?t=json") if resp.empty?
178+
resp.to_json
145179
end
146180

147181
app.post '/json/inventory/start' do
148182
resp = java_service_send_stop_start('inventory', START_ENDPOINT)
149183
if resp.empty?
150184
inventory_hosts.each do |host|
151-
begin
152-
resp << post_url("#{host}/#{START_ENDPOINT}")
153-
rescue StandardError => e
154-
logger.error("Error sending start to inventory host #{host}: #{e}")
155-
end
185+
resp << post_url("#{host}/#{START_ENDPOINT}")
186+
rescue StandardError => e
187+
logger.error("Error sending start to inventory host #{host}: #{e}")
156188
end
157189
end
158190
return post_url("#{inventory_host}/#{START_ENDPOINT}") if resp.empty?
@@ -164,11 +196,9 @@ def self.registered(app)
164196
resp = java_service_send_stop_start('inventory', STOP_ENDPOINT)
165197
if resp.empty?
166198
inventory_hosts.each do |host|
167-
begin
168-
resp << post_url("#{host}/#{STOP_ENDPOINT}")
169-
rescue StandardError => e
170-
logger.error("Error sending stop to inventory host #{host}: #{e}")
171-
end
199+
resp << post_url("#{host}/#{STOP_ENDPOINT}")
200+
rescue StandardError => e
201+
logger.error("Error sending stop to inventory host #{host}: #{e}")
172202
end
173203
end
174204
return post_url("#{inventory_host}/#{STOP_ENDPOINT}") if resp.empty?
@@ -185,7 +215,12 @@ def self.registered(app)
185215
end
186216

187217
app.get '/json/audit/state' do
188-
get_url("#{audit_host}/state?t=json")
218+
resp = []
219+
audit_hosts.each do |host|
220+
resp << get_url_json("#{host}/state?t=json")
221+
end
222+
resp = get_url("#{audit_host}/state?t=json") if resp.empty?
223+
resp.to_json
189224
end
190225

191226
app.get '/json/audit/tag' do
@@ -200,11 +235,9 @@ def self.registered(app)
200235
resp = java_service_send_stop_start('audit', START_ENDPOINT)
201236
if resp.empty?
202237
audit_hosts.each do |host|
203-
begin
204-
resp << post_url("#{host}/#{START_ENDPOINT}")
205-
rescue StandardError => e
206-
logger.error("Error sending start to audit host #{host}: #{e}")
207-
end
238+
resp << post_url("#{host}/#{START_ENDPOINT}")
239+
rescue StandardError => e
240+
logger.error("Error sending start to audit host #{host}: #{e}")
208241
end
209242
end
210243
return post_url("#{audit_host}/#{START_ENDPOINT}") if resp.empty?
@@ -216,11 +249,9 @@ def self.registered(app)
216249
resp = java_service_send_stop_start('audit', STOP_ENDPOINT)
217250
if resp.empty?
218251
audit_hosts.each do |host|
219-
begin
220-
resp << post_url("#{host}/#{STOP_ENDPOINT}")
221-
rescue StandardError => e
222-
logger.error("Error sending stop to audit host #{host}: #{e}")
223-
end
252+
resp << post_url("#{host}/#{STOP_ENDPOINT}")
253+
rescue StandardError => e
254+
logger.error("Error sending stop to audit host #{host}: #{e}")
224255
end
225256
end
226257
return post_url("#{audit_host}/#{STOP_ENDPOINT}") if resp.empty?
@@ -230,8 +261,13 @@ def self.registered(app)
230261

231262
app.get '/json/replic/state' do
232263
# Per David, replic uses status instead of state
233-
get_url("#{replic_host}/status?t=json")
234-
end
264+
resp = []
265+
replic_hosts.each do |host|
266+
resp << get_url_json("#{host}/status=json")
267+
end
268+
resp = get_url("#{replic_host}/status=json") if resp.empty?
269+
resp.to_json
270+
end
235271

236272
app.get '/json/replic/tag' do
237273
get_url("#{replic_host}/#{BUILD_TAG_ENDPOINT}")
@@ -241,11 +277,9 @@ def self.registered(app)
241277
resp = java_service_send_stop_start('replic', START_ENDPOINT)
242278
if resp.empty?
243279
replic_hosts.each do |host|
244-
begin
245-
resp << post_url("#{host}/#{START_ENDPOINT}")
246-
rescue StandardError => e
247-
logger.error("Error sending start to replic host #{host}: #{e}")
248-
end
280+
resp << post_url("#{host}/#{START_ENDPOINT}")
281+
rescue StandardError => e
282+
logger.error("Error sending start to replic host #{host}: #{e}")
249283
end
250284
end
251285
return post_url("#{replic_host}/#{START_ENDPOINT}") if resp.empty?
@@ -257,11 +291,9 @@ def self.registered(app)
257291
resp = java_service_send_stop_start('replic', 'service/pause?t=json')
258292
if resp.empty?
259293
replic_hosts.each do |host|
260-
begin
261-
resp << post_url("#{host}/service/pause?t=json")
262-
rescue StandardError => e
263-
logger.error("Error sending pause to replic host #{host}: #{e}")
264-
end
294+
resp << post_url("#{host}/service/pause?t=json")
295+
rescue StandardError => e
296+
logger.error("Error sending pause to replic host #{host}: #{e}")
265297
end
266298
end
267299
return post_url("#{replic_host}/service/pause?t=json") if resp.empty?
@@ -274,7 +306,12 @@ def self.registered(app)
274306
end
275307

276308
app.get '/json/access/state' do
277-
get_url("#{access_host}/state?t=json")
309+
resp = []
310+
access_hosts.each do |host|
311+
resp << get_url_json("#{host}/state?t=json")
312+
end
313+
resp = get_url("#{access_host}/state?t=json") if resp.empty?
314+
resp.to_json
278315
end
279316

280317
app.get '/json/access/tag' do

app/public/mrt/custom.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ td.profile {
6464
td.nodedata {
6565
min-width: 300px;
6666
white-space: pre;
67+
text-wrap-mode: wrap;
6768
}
6869

6970
span.env {

0 commit comments

Comments
 (0)