Skip to content

Commit

Permalink
job-list: add updates object to job_parse_R()
Browse files Browse the repository at this point in the history
Problem: The job_parse_jobspec() function takes an optional "updates"
object to update the parsed jobspec with contents in "updates".  It would
be convenient if the same functionality existed with job_parse_R().

Solution: Add an updates object to job_parse_R().  Update unit tests
and callers accordingly.
  • Loading branch information
chu11 authored and grondo committed Oct 26, 2023
1 parent bbe7ba0 commit f25c1aa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
12 changes: 8 additions & 4 deletions src/modules/job-list/job_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,22 @@ static int parse_R (struct job *job, bool allow_nonfatal)
return rc;
}

int job_parse_R (struct job *job, const char *s)
int job_parse_R (struct job *job, const char *s, json_t *updates)
{
if (load_R (job, s, true) < 0)
return -1;
return parse_R (job, true);
if (parse_R (job, true) < 0)
return -1;
return job_R_update (job, updates);
}

int job_parse_R_fatal (struct job *job, const char *s)
int job_parse_R_fatal (struct job *job, const char *s, json_t *updates)
{
if (load_R (job, s, false) < 0)
return -1;
return parse_R (job, false);
if (parse_R (job, false) < 0)
return -1;
return job_R_update (job, updates);
}

int job_jobspec_update (struct job *job, json_t *updates)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/job-list/job_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ int job_jobspec_update (struct job *job, json_t *updates);
* - ncores
* - ntasks (if necessary)
*/
int job_parse_R (struct job *job, const char *s);
int job_parse_R (struct job *job, const char *s, json_t *updates);

/* identical to above, but all nonfatal errors will return error.
* Primarily used for testing.
*/
int job_parse_R_fatal (struct job *job, const char *s);
int job_parse_R_fatal (struct job *job, const char *s, json_t *updates);

/* Update R with RFC21 defined keys
* (i.e. "expiration") and value.
Expand Down
4 changes: 2 additions & 2 deletions src/modules/job-list/job_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static void state_run_lookup_continuation (flux_future_t *f, void *arg)
goto out;
}

if (job_parse_R (job, s) < 0)
if (job_parse_R (job, s, NULL) < 0)
goto out;

updt = zlist_head (job->updates);
Expand Down Expand Up @@ -852,7 +852,7 @@ static int depthfirst_map_one (struct job_state_ctx *jsctx,
if (flux_kvs_lookup_get (f3, &R) < 0)
goto done;

if (job_parse_R (job, R) < 0)
if (job_parse_R (job, R, NULL) < 0)
goto done;
}

Expand Down
19 changes: 12 additions & 7 deletions src/modules/job-list/test/job_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ static int parse_R (struct job *job, const char *filename)

read_file (filename, (void **)&data);

ret = job_parse_R_fatal (job, data);
ret = job_parse_R_fatal (job, data, NULL);

free (data);
return ret;
Expand Down Expand Up @@ -821,23 +821,28 @@ static void test_R_update (void)

read_file (filename, (void **)&data);

if (job_parse_R (job, data) < 0)
if (!(o = json_pack ("{s:f}", "expiration", 100.0)))
BAIL_OUT ("json_pack failed");

if (job_parse_R (job, data, o) < 0)
BAIL_OUT ("cannot load basic R");

json_decref (o);

ret = json_unpack (job->R,
"{s:{s:F}}",
"execution",
"expiration", &expiration);
ok (ret == 0, "parsed initial R expiration");

ok (expiration == 0.0, "initial R expiration == 0.0");
ok (job->expiration == 0.0, "initial job->expiration == 0.0");
ok (expiration == 100.0, "initial R expiration == 100.0");
ok (job->expiration == 100.0, "initial job->expiration == 100.0");

ret = job_R_update (job, NULL);
ok (ret == 0, "job_R_update success with no update");

if (!(o = json_pack ("{s:f s:s}",
"expiration", 100.0,
"expiration", 200.0,
"dummy", "dummy")))
BAIL_OUT ("json_pack failed");
ret = job_R_update (job, o);
Expand All @@ -850,8 +855,8 @@ static void test_R_update (void)
"expiration", &expiration);
ok (ret == 0, "parsed updated R expiration");

ok (expiration == 100.0, "R expiration == 100.0");
ok (job->expiration == 100.0, "job->expiration == 100.0");
ok (expiration == 200.0, "R expiration == 200.0");
ok (job->expiration == 200.0, "job->expiration == 200.0");

ret = json_unpack (job->R, "{s?s}", "dummy", &tmp);
ok (ret == 0, "parsed updated R dummy");
Expand Down

0 comments on commit f25c1aa

Please sign in to comment.