Skip to content

Commit

Permalink
job-manager: add update-duration builtin plugin
Browse files Browse the repository at this point in the history
Problem: Once a job is submitted the duration cannot be updated.

Add an update-duration plugin that adds a

 job.update.attributes.system.duration

callback so that jobspec duration updates are supported for pending
jobs. By default, users can update the duration of their own jobs
up to the currently configured limit, and instance owners can update
duration to any value.

The ability of the instance owner to bypass limits can be disabled
by reloading the plugin with the config parameter owner-allow-any=0.
  • Loading branch information
grondo committed Aug 24, 2023
1 parent d4d96f3 commit fa173d8
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/modules/job-manager/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ libjob_manager_la_SOURCES = \
plugins/limit-duration.c \
plugins/dependency-after.c \
plugins/begin-time.c \
plugins/update-duration.c \
plugins/validate-duration.c \
plugins/history.c

Expand Down
88 changes: 88 additions & 0 deletions src/modules/job-manager/plugins/update-duration.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/************************************************************\
* Copyright 2023 Lawrence Livermore National Security, LLC
* (c.f. AUTHORS, NOTICE.LLNS, COPYING)
*
* This file is part of the Flux resource manager framework.
* For details, see https://github.com/flux-framework.
*
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

/* update-duration.c - allow updates of attributes.system.duration for jobs
*
* This plugin implements a 'job.update.attributes.system.duration'
* callback to enable duration updates for pending jobs.
*/

#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <jansson.h>
#include <flux/core.h>
#include <flux/jobtap.h>

/*
* Allow instance owner to update duration to any value, even if it
* exceeds a configured duration limit. By default, this is true, to
* disable this behavior, reload the `.update-duration` plugin with
* owner-allow-any=0.
*/
static int owner_allow_any = 1;

static int duration_update_cb (flux_plugin_t *p,
const char *topic,
flux_plugin_arg_t *args,
void *arg)
{
struct flux_msg_cred cred;
flux_job_state_t state;
double duration;

if (flux_plugin_arg_unpack (args,
FLUX_PLUGIN_ARG_IN,
"{s:F s:i s:{s:i s:i}}",
"value", &duration,
"state", &state,
"cred",
"userid", &cred.userid,
"rolemask", &cred.rolemask) < 0) {
flux_jobtap_error (p, args, "plugin args unpack failed");
return -1;
}
if (duration < 0.) {
flux_jobtap_error (p, args, "duration must not be negative");
return -1;
}
if (state == FLUX_JOB_STATE_RUN
|| state == FLUX_JOB_STATE_CLEANUP) {
flux_jobtap_error (p,
args,
"update of duration for running job not supported");
return -1;
}
if ((cred.rolemask & FLUX_ROLE_OWNER) && owner_allow_any) {
/* If owner is allowed to make any urgency adjustment, then
* report that value is validated via out arguments:
*/
flux_plugin_arg_pack (args,
FLUX_PLUGIN_ARG_OUT,
"{s:i}",
"validated", 1);
}
return 0;
}

int update_duration_plugin_init (flux_plugin_t *p)
{
flux_plugin_conf_unpack (p,
"{s:i}",
"owner-allow-any",
&owner_allow_any);
return flux_plugin_add_handler (p,
"job.update.attributes.system.duration",
duration_update_cb,
NULL);
}

// vi:ts=4 sw=4 expandtab

0 comments on commit fa173d8

Please sign in to comment.