Skip to content

Commit

Permalink
job-list: add R update helper function
Browse files Browse the repository at this point in the history
Problem: In the near future we would like to update R
with new information.

Add a new helper function job_R_update() to update R.

Add unit tests.
  • Loading branch information
chu11 authored and grondo committed Oct 26, 2023
1 parent 47e83de commit bbe7ba0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/modules/job-list/job_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,29 @@ int job_jobspec_update (struct job *job, json_t *updates)
return parse_jobspec (job, false);
}

int job_R_update (struct job *job, json_t *updates)
{
const char *key;
json_t *value;

if (!updates)
return 0;

json_object_foreach (updates, key, value) {
/* RFC 21 resource-update event only allows update
* to:
* - expiration
*/
if (streq (key, "expiration"))
if (jpath_set (job->R, "execution.expiration", value) < 0)
flux_log (job->h, LOG_INFO,
"%s: job %s failed to update R key %s",
__FUNCTION__, idf58 (job->id), key);
}

return parse_R (job, false);
}

/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
5 changes: 5 additions & 0 deletions src/modules/job-list/job_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ int job_parse_R (struct job *job, const char *s);
*/
int job_parse_R_fatal (struct job *job, const char *s);

/* Update R with RFC21 defined keys
* (i.e. "expiration") and value.
*/
int job_R_update (struct job *job, json_t *updates);

#endif /* ! _FLUX_JOB_LIST_JOB_DATA_H */

/*
Expand Down
56 changes: 56 additions & 0 deletions src/modules/job-list/test/job_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,61 @@ static void test_jobspec_update (void)
free (data);
}

static void test_R_update (void)
{
struct job *job = job_create (NULL, FLUX_JOBID_ANY);
const char *filename = TEST_SRCDIR "/R/1node_1core.R";
char *data;
int ret;
double expiration;
const char *tmp = NULL;
json_t *o;

if (!job)
BAIL_OUT ("job_create failed");

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

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

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");

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,
"dummy", "dummy")))
BAIL_OUT ("json_pack failed");
ret = job_R_update (job, o);
ok (ret == 0, "job_R_update");
json_decref (o);

ret = json_unpack (job->R,
"{s:{s:F}}",
"execution",
"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");

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

ok (tmp == NULL, "R not updated with illegal update key");

free (data);
}

int main (int argc, char *argv[])
{
plan (NO_PLAN);
Expand All @@ -823,6 +878,7 @@ int main (int argc, char *argv[])
test_ntasks ();
test_ncores ();
test_jobspec_update ();
test_R_update ();

done_testing ();
}
Expand Down

0 comments on commit bbe7ba0

Please sign in to comment.