Skip to content

Commit cb9fa72

Browse files
committed
job-info: support reading/watching updated jobspec
Problem: It is inconvenient that lookup w/ the CURRENT flag and update-watch support reading/watching a current/updated R but not a current/updated jobspec. Support returning a current/updated jobspec.
1 parent 54ae474 commit cb9fa72

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

src/common/libjob/job.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ enum job_lookup_flags {
3737
FLUX_JOB_LOOKUP_JSON_DECODE = 1,
3838
/* get current value of special fields by applying eventlog
3939
* updates for those fields
40-
* - currently works for R
40+
* - currently works for jobspec and R
4141
*/
4242
FLUX_JOB_LOOKUP_CURRENT = 2,
4343
};

src/modules/job-info/lookup.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ static int lookup_current (struct lookup_ctx *l,
173173

174174
if (streq (key, "R"))
175175
update_event_name = "resource-update";
176+
else if (streq (key, "jobspec"))
177+
update_event_name = "jobspec-update";
176178

177179
if (!(value_object = json_loads (value, 0, NULL))) {
178180
errno = EINVAL;
@@ -205,6 +207,12 @@ static int lookup_current (struct lookup_ctx *l,
205207
if (streq (name, update_event_name)) {
206208
if (streq (key, "R"))
207209
apply_updates_R (l->ctx->h, l->id, key, value_object, context);
210+
else if (streq (key, "jobspec"))
211+
apply_updates_jobspec (l->ctx->h,
212+
l->id,
213+
key,
214+
value_object,
215+
context);
208216
}
209217
}
210218

@@ -288,7 +296,8 @@ static void info_lookup_continuation (flux_future_t *fall, void *arg)
288296
}
289297

290298
if ((l->flags & FLUX_JOB_LOOKUP_CURRENT)
291-
&& streq (keystr, "R")) {
299+
&& (streq (keystr, "R")
300+
|| streq (keystr, "jobspec"))) {
292301
if (lookup_current (l, fall, keystr, s, &current_value) < 0)
293302
goto error;
294303
s = current_value;
@@ -442,7 +451,7 @@ static int lookup_cached (struct lookup_ctx *l)
442451

443452
key_str = json_string_value (key);
444453

445-
if (!streq (key_str, "R"))
454+
if (!streq (key_str, "R") && !streq (key_str, "jobspec"))
446455
return 0;
447456

448457
if ((ret = update_watch_get_cached (l->ctx,

src/modules/job-info/update.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static struct update_ctx *update_ctx_create (struct info_ctx *ctx,
8383
goto error;
8484
if (streq (key, "R"))
8585
uc->update_name = "resource-update";
86+
else if (streq (key, "jobspec"))
87+
uc->update_name = "jobspec-update";
8688
else {
8789
errno = EINVAL;
8890
goto error;
@@ -180,6 +182,12 @@ static void eventlog_continuation (flux_future_t *f, void *arg)
180182
uc->key,
181183
uc->update_object,
182184
context);
185+
else if (streq (uc->key, "jobspec"))
186+
apply_updates_jobspec (uc->ctx->h,
187+
uc->id,
188+
uc->key,
189+
uc->update_object,
190+
context);
183191

184192
msg = flux_msglist_first (uc->msglist);
185193
while (msg) {
@@ -315,6 +323,12 @@ static void lookup_continuation (flux_future_t *f, void *arg)
315323
uc->key,
316324
uc->update_object,
317325
context);
326+
else if (streq (uc->key, "jobspec"))
327+
apply_updates_jobspec (uc->ctx->h,
328+
uc->id,
329+
uc->key,
330+
uc->update_object,
331+
context);
318332
uc->initial_update_count++;
319333
}
320334
else if (streq (name, "clean"))
@@ -474,7 +488,7 @@ void update_watch_cb (flux_t *h, flux_msg_handler_t *mh,
474488
errmsg = "update-watch request rejected without streaming RPC flag";
475489
goto error;
476490
}
477-
if (!streq (key, "R")) {
491+
if (!streq (key, "R") && !streq (key, "jobspec")) {
478492
errno = EINVAL;
479493
errmsg = "update-watch unsupported key specified";
480494
goto error;

src/modules/job-info/util.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ void apply_updates_R (flux_t *h,
125125
}
126126
}
127127

128+
void apply_updates_jobspec (flux_t *h,
129+
flux_jobid_t id,
130+
const char *key,
131+
json_t *jobspec,
132+
json_t *context)
133+
{
134+
const char *ckey;
135+
json_t *value;
136+
137+
json_object_foreach (context, ckey, value) {
138+
if (jpath_set (jobspec,
139+
ckey,
140+
value) < 0)
141+
flux_log (h, LOG_INFO,
142+
"%s: failed to update job %s %s",
143+
__FUNCTION__, idf58 (id), key);
144+
}
145+
}
146+
128147
/*
129148
* vi:tabstop=4 shiftwidth=4 expandtab
130149
*/

src/modules/job-info/util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ void apply_updates_R (flux_t *h,
4242
json_t *R,
4343
json_t *context);
4444

45+
/* apply context updates to the jobspec object */
46+
void apply_updates_jobspec (flux_t *h,
47+
flux_jobid_t id,
48+
const char *key,
49+
json_t *jobspec,
50+
json_t *context);
51+
4552
#endif /* ! _FLUX_JOB_INFO_UTIL_H */
4653

4754
/*

0 commit comments

Comments
 (0)