Skip to content

Commit ffa3382

Browse files
chu11mergify[bot]
authored andcommitted
job-list: support 'all' job-list attr
Problem: As the number of attributes grows in `job-list`, it is becoming inconvenient for users to get "all" (or most) attributes for a job. Solution: Support a special case attribute "all" which will return all attributes for a job. Fixes #4313
1 parent d8d8109 commit ffa3382

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/bindings/python/flux/job/list.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"expiration",
4343
"annotations",
4444
"dependencies",
45+
"all",
4546
]
4647

4748

src/modules/job-list/job_util.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
#include <jansson.h>
1717
#include <stdarg.h>
1818
#include <flux/core.h>
19+
#include <assert.h>
1920

2021
#include "src/common/libutil/errno_safe.h"
2122

23+
#include "job-list.h"
2224
#include "job_util.h"
2325
#include "job_state.h"
2426

@@ -180,6 +182,21 @@ static int store_attr (struct job *job,
180182
return 0;
181183
}
182184

185+
int store_all_attr (struct job *job, json_t *o, job_list_error_t *errp)
186+
{
187+
const char **ptr = job_attrs ();
188+
189+
assert (ptr);
190+
191+
while (*ptr) {
192+
if (store_attr (job, *ptr, o, errp) < 0)
193+
return -1;
194+
ptr++;
195+
}
196+
197+
return 0;
198+
}
199+
183200
/* For a given job, create a JSON object containing the jobid and any
184201
* additional requested attributes and their values. Returns JSON
185202
* object which the caller must free. On error, return NULL with
@@ -212,8 +229,14 @@ json_t *job_to_json (struct job *job, json_t *attrs, job_list_error_t *errp)
212229
errno = EINVAL;
213230
goto error;
214231
}
215-
if (store_attr (job, attr, o, errp) < 0)
216-
goto error;
232+
if (strcmp (attr, "all") == 0) {
233+
if (store_all_attr (job, o, errp) < 0)
234+
goto error;
235+
}
236+
else {
237+
if (store_attr (job, attr, o, errp) < 0)
238+
goto error;
239+
}
217240
}
218241
return o;
219242
error_nomem:

src/modules/job-list/list.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ void list_attrs_cb (flux_t *h, flux_msg_handler_t *mh,
574574
goto error;
575575
}
576576

577+
if (list_attrs_append (a, "all") < 0)
578+
goto error;
579+
577580
if (flux_respond_pack (h, msg, "{s:O}", "attrs", a) < 0)
578581
flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__);
579582

0 commit comments

Comments
 (0)