From efc43796a7353ec7500f2414c2f2beed95deff5d Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Sat, 25 Nov 2023 12:05:24 -0800 Subject: [PATCH] flux-job: remove manual jobspec reconstruction Problem: flux job info manually reconstructs a current jobspec from the jobspec and eventlog. However the job-info.lookup service w/ the CURRENT flag could be used instead. Update code to use the lookup service w/ current flag instead of manually reconstructing the current jobspec. --- src/cmd/flux-job.c | 64 +++------------------------------------------- 1 file changed, 3 insertions(+), 61 deletions(-) diff --git a/src/cmd/flux-job.c b/src/cmd/flux-job.c index 56c44895290d..d02fb9c2c6c2 100644 --- a/src/cmd/flux-job.c +++ b/src/cmd/flux-job.c @@ -3308,42 +3308,6 @@ int cmd_wait_event (optparse_t *p, int argc, char **argv) return (0); } -char *reconstruct_current_jobspec (const char *jobspec_str, - const char *eventlog_str) -{ - json_t *jobspec; - json_t *eventlog; - size_t index; - json_t *entry; - char *result; - - if (!(jobspec = json_loads (jobspec_str, 0, NULL))) - log_msg_exit ("error decoding jobspec"); - if (!(eventlog = eventlog_decode (eventlog_str))) - log_msg_exit ("error decoding eventlog"); - json_array_foreach (eventlog, index, entry) { - const char *name; - json_t *context; - - if (eventlog_entry_parse (entry, NULL, &name, &context) < 0) - log_msg_exit ("error decoding eventlog entry"); - if (streq (name, "jobspec-update")) { - const char *path; - json_t *value; - - json_object_foreach (context, path, value) { - if (jpath_set (jobspec, path, value) < 0) - log_err_exit ("failed to update jobspec"); - } - } - } - if (!(result = json_dumps (jobspec, JSON_COMPACT))) - log_msg_exit ("failed to encode jobspec object"); - json_decref (jobspec); - json_decref (eventlog); - return result; -} - void info_usage (void) { fprintf (stderr, @@ -3403,33 +3367,11 @@ int cmd_info (optparse_t *p, int argc, char **argv) log_msg_exit ("Failed to unwrap J to get jobspec: %s", error.text); val = new_val; } - /* The current (non --base) jobspec has to be reconstructed by fetching - * the jobspec and the eventlog and updating the former with the latter. - */ - else if (!optparse_hasopt (p, "base") && streq (key, "jobspec")) { - const char *jobspec; - const char *eventlog; - - // fetch the two keys in parallel - if (!(f = flux_rpc_pack (h, - "job-info.lookup", - FLUX_NODEID_ANY, - 0, - "{s:I s:[ss] s:i}", - "id", id, - "keys", "jobspec", "eventlog", - "flags", 0)) - || flux_rpc_get_unpack (f, - "{s:s s:s}", - "jobspec", &jobspec, - "eventlog", &eventlog) < 0) - log_msg_exit ("%s", future_strerror (f, errno )); - val = new_val = reconstruct_current_jobspec (jobspec, eventlog); - } - /* The current (non --base) R is obtained through the + /* The current (non --base) R and jobspec are obtained through the * job-info.lookup RPC w/ the CURRENT flag. */ - else if (!optparse_hasopt (p, "base") && streq (key, "R")) { + else if (!optparse_hasopt (p, "base") + && (streq (key, "R") || streq (key, "jobspec"))) { if (!(f = flux_rpc_pack (h, "job-info.lookup", FLUX_NODEID_ANY,