Skip to content

Commit cb1ea82

Browse files
committed
WIP (DIO-911) Include job_id in ABS --json output
Prior to this commit, when using --service=abs and --json the job_id value is not included in the JSON blob, which makes it difficult for calling code to grab both the job_id and the hosts without text processing the log messages printed to standard error.
1 parent 9a44cc4 commit cb1ea82

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/vmfloaty/abs.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def self.retrieve(verbose, os_types, token, url, user, options, _ondemand = nil)
233233

234234
(1..retries).each do |i|
235235
queue_place, res_body = check_queue(conn, saved_job_id, req_obj, verbose)
236-
return translated(res_body) if res_body
236+
return translated(res_body, saved_job_id) if res_body
237237

238238
sleep_seconds = 10 if i >= 10
239239
sleep_seconds = i if i < 10
@@ -247,8 +247,8 @@ def self.retrieve(verbose, os_types, token, url, user, options, _ondemand = nil)
247247
#
248248
# We should fix the ABS API to be more like the vmpooler or nspooler api, but for now
249249
#
250-
def self.translated(res_body)
251-
vmpooler_formatted_body = {}
250+
def self.translated(res_body, job_id)
251+
vmpooler_formatted_body = {'job_id' => job_id}
252252

253253
res_body.each do |host|
254254
if vmpooler_formatted_body[host['type']] && vmpooler_formatted_body[host['type']]['hostname'].class == Array

lib/vmfloaty/utils.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def self.standardize_hostnames(response_body)
4545

4646
result = {}
4747

48+
# ABS has a job_id associated with hosts so pass that along
49+
abs_job_id = response_body.delete('job_id')
50+
result['job_id'] = abs_job_id unless abs_job_id.nil?
51+
4852
filtered_response_body = response_body.reject { |key, _| key == 'request_id' || key == 'ready' }
4953
filtered_response_body.each do |os, value|
5054
hostnames = Array(value['hostname'])
@@ -57,7 +61,8 @@ def self.standardize_hostnames(response_body)
5761

5862
def self.format_host_output(hosts)
5963
hosts.flat_map do |os, names|
60-
names.map { |name| "- #{name} (#{os})" }
64+
# Assume hosts are stored in Arrays and ignore everything else
65+
names.map { |name| "- #{name} (#{os})" } if names.is_a? Array
6166
end.join("\n")
6267
end
6368

0 commit comments

Comments
 (0)