(maint) Fix for ABS PR#306 that includes json responses

Before this change ABS sometiimes returned a string of JSON with escaped
quotes, that had to be parsed again
With this change, floaty should accept both the legacy and the new
full JSON responses.
This commit is contained in:
Samuel Beaulieu 2020-09-21 14:39:10 -05:00
parent f3cd540455
commit 4df970b21f
2 changed files with 26 additions and 8 deletions

View file

@ -77,8 +77,10 @@ class ABS
requests.each do |req|
next if req == 'null'
if valid_json?(req)
if valid_json?(req) # legacy ABS had another JSON string always-be-scheduling/pull/306
req_hash = JSON.parse(req)
elsif req.is_a?(Hash)
req_hash = req
else
FloatyLogger.warn "Warning: couldn't parse request returned from abs/status/queue"
next
@ -170,7 +172,11 @@ class ABS
res_body = JSON.parse(res.body)
if res_body.key?('vmpooler_platforms')
os_list << '*** VMPOOLER Pools ***'
os_list += JSON.parse(res_body['vmpooler_platforms'])
if res_body['vmpooler_platforms'].is_a?(Hash)
os_list += res_body['vmpooler_platforms']
else
os_list += JSON.parse(res_body['vmpooler_platforms']) # legacy ABS had another JSON string always-be-scheduling/pull/306
end
end
end
@ -180,7 +186,11 @@ class ABS
if res_body.key?('ondemand_vmpooler_platforms') && res_body['ondemand_vmpooler_platforms'] != '[]'
os_list << ''
os_list << '*** VMPOOLER ONDEMAND Pools ***'
os_list += JSON.parse(res_body['ondemand_vmpooler_platforms'])
if res_body['ondemand_vmpooler_platforms'].is_a?(Hash)
os_list += res_body['ondemand_vmpooler_platforms']
else
os_list += JSON.parse(res_body['ondemand_vmpooler_platforms']) # legacy ABS had another JSON string always-be-scheduling/pull/306
end
end
end
@ -190,7 +200,11 @@ class ABS
if res_body.key?('nspooler_platforms')
os_list << ''
os_list << '*** NSPOOLER Pools ***'
os_list += JSON.parse(res_body['nspooler_platforms'])
if res_body['nspooler_platforms'].is_a?(Hash)
os_list += res_body['nspooler_platforms']
else
os_list += JSON.parse(res_body['nspooler_platforms']) # legacy ABS had another JSON string always-be-scheduling/pull/306
end
end
end
@ -200,7 +214,11 @@ class ABS
if res_body.key?('aws_platforms')
os_list << ''
os_list << '*** AWS Pools ***'
os_list += JSON.parse(res_body['aws_platforms'])
if res_body['aws_platforms'].is_a?(Hash)
os_list += res_body['aws_platforms']
else
os_list += JSON.parse(res_body['aws_platforms']) # legacy ABS had another JSON string always-be-scheduling/pull/306
end
end
end