Skip to content

Commit

Permalink
plugin: add jobspec-update of project name
Browse files Browse the repository at this point in the history
Problem: The priority plugin has no way to update jobspec with the
project used for the job in the case where an association submits a job
under a default project.

Add a helper function to the plugin that adds the project name for
an association's job to jobspec via jobspec-update under
attributes.system.project.

Add a jobspec-update of the association's default project name when the
job is in the job.new callback.

In the event where an association submits a job before any information
is loaded to the priority plugin and their job is held in PRIORITY
state, add a jobspec-update of the association's default project name in
job.state.priority if they are submitting under a default project.
  • Loading branch information
cmoussa1 committed Sep 10, 2024
1 parent 1a85cd6 commit f145f1a
Showing 1 changed file with 59 additions and 4 deletions.
63 changes: 59 additions & 4 deletions src/plugins/mf_priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@ static int update_jobspec_bank (flux_plugin_t *p, int userid)
}


/*
* Update the jobspec with the default project the association used to
* submit their job under.
*/
static int update_jobspec_project (flux_plugin_t *p, int userid, char *bank)
{
Association *a = get_association (userid, bank, users, users_def_bank);
if (a == nullptr)
// association could not be found
return -1;

// get association's default project
std::string project = a->def_project;

if (!project.empty ()) {
// post jobspec-update event
if (flux_jobtap_jobspec_update_pack (p,
"{s:s}",
"attributes.system.project",
project.c_str ()) < 0)
return -1;
}

return 0;
}


/*
* Create a special Association object for an association's job while the
* plugin waits for flux-accounting data to be loaded.
Expand Down Expand Up @@ -451,17 +478,19 @@ static int priority_cb (flux_plugin_t *p,
int urgency, userid;
char *bank = NULL;
char *queue = NULL;
const char *project = NULL;
int64_t priority;
Association *b;

flux_t *h = flux_jobtap_get_flux (p);
if (flux_plugin_arg_unpack (args,
FLUX_PLUGIN_ARG_IN,
"{s:i, s:i, s{s{s{s?s, s?s}}}}",
"{s:i, s:i, s{s{s{s?s, s?s, s?s}}}}",
"urgency", &urgency,
"userid", &userid,
"jobspec", "attributes", "system",
"bank", &bank, "queue", &queue) < 0) {
"bank", &bank, "queue", &queue,
"project", &project) < 0) {
flux_log (h,
LOG_ERR,
"flux_plugin_arg_unpack: %s",
Expand Down Expand Up @@ -542,6 +571,18 @@ static int priority_cb (flux_plugin_t *p,
"with bank name");
return -1;
}

if (project == NULL) {
// we also need to update the jobspec with the default project
// used to submit this job under
if (update_jobspec_project (p, userid, bank) < 0) {
flux_jobtap_raise_exception (p, FLUX_JOBTAP_CURRENT_JOB,
"mf_priority", 0,
"failed to update jobspec "
"with project name");
return -1;
}
}
}
}

Expand Down Expand Up @@ -683,16 +724,18 @@ static int new_cb (flux_plugin_t *p,
int userid;
char *bank = NULL;
char *queue = NULL;
const char *project = NULL;
int max_run_jobs, cur_active_jobs, max_active_jobs = 0;
Association *b;

flux_t *h = flux_jobtap_get_flux (p);
if (flux_plugin_arg_unpack (args,
FLUX_PLUGIN_ARG_IN,
"{s:i, s{s{s{s?s, s?s}}}}",
"{s:i, s{s{s{s?s, s?s, s?s}}}}",
"userid", &userid,
"jobspec", "attributes", "system",
"bank", &bank, "queue", &queue) < 0) {
"bank", &bank, "queue", &queue,
"project", &project) < 0) {
return flux_jobtap_reject_job (p, args, "unable to unpack bank arg");
}

Expand Down Expand Up @@ -750,6 +793,18 @@ static int new_cb (flux_plugin_t *p,
return 0;
}

if (project == NULL) {
// this job is meant to run under a default project, so update
// the jobspec with the project name
if (update_jobspec_project (p, userid, bank) < 0) {
flux_jobtap_raise_exception (p, FLUX_JOBTAP_CURRENT_JOB,
"mf_priority", 0,
"failed to update jobspec with "
"project name");
return -1;
}
}

if (flux_jobtap_job_aux_set (p,
FLUX_JOBTAP_CURRENT_JOB,
"mf_priority:bank_info",
Expand Down

0 comments on commit f145f1a

Please sign in to comment.