-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add utility for posting job events manually if required #5848
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,8 @@ dist_fluxcmd_SCRIPTS = \ | |
flux-update.py \ | ||
flux-imp-exec-helper \ | ||
py-runner.py \ | ||
flux-hostlist.py | ||
flux-hostlist.py \ | ||
flux-post-job-event.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo in commit "finidh" |
||
|
||
fluxcmd_PROGRAMS = \ | ||
flux-terminus \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/false | ||
############################################################## | ||
# Copyright 2024 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 | ||
############################################################## | ||
|
||
import argparse | ||
import logging | ||
|
||
import flux | ||
from flux.job import JobID | ||
from flux.util import TreedictAction | ||
|
||
|
||
def post_event(args): | ||
"""Post an event to the job-manager.post-event.post service""" | ||
|
||
req = {"id": JobID(args.id), "name": args.name} | ||
if args.context: | ||
req["context"] = args.context | ||
|
||
try: | ||
flux.Flux().rpc("job-manager.post-event.post", req).get() | ||
except FileNotFoundError: | ||
raise ValueError(f"No such job {args.id}") | ||
|
||
|
||
LOGGER = logging.getLogger("flux-job-post-event") | ||
|
||
|
||
@flux.util.CLIMain(LOGGER) | ||
def main(): | ||
parser = argparse.ArgumentParser(prog="flux-job-post-event") | ||
parser.add_argument("id", help="jobid to which event shall be posted") | ||
parser.add_argument("name", help="name of event to post") | ||
parser.add_argument( | ||
"context", | ||
help="List of key=value pairs to set as event context", | ||
action=TreedictAction, | ||
nargs=argparse.REMAINDER, | ||
) | ||
parser.set_defaults(func=post_event) | ||
args = parser.parse_args() | ||
args.func(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
# vi: ts=4 sw=4 expandtab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/************************************************************\ | ||
* Copyright 2024 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 | ||
\************************************************************/ | ||
|
||
/* post-event.c - post manual events to job eventlog | ||
*/ | ||
|
||
#if HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include <jansson.h> | ||
#include <flux/core.h> | ||
#include <flux/jobtap.h> | ||
|
||
static void post_event_cb (flux_t *h, | ||
flux_msg_handler_t *mh, | ||
const flux_msg_t *msg, | ||
void *arg) | ||
{ | ||
flux_plugin_t *p = arg; | ||
flux_jobid_t id; | ||
const char *name; | ||
json_t *context = NULL; | ||
|
||
if (flux_msg_unpack (msg, | ||
"{s:I s:s s?o}", | ||
"id", &id, | ||
"name", &name, | ||
"context", &context) < 0) | ||
goto error; | ||
if (context) { | ||
if (flux_jobtap_event_post_pack (p, id, name, "O", context) < 0) | ||
goto error; | ||
} | ||
else if (flux_jobtap_event_post_pack (p, id, name, NULL) < 0) | ||
goto error; | ||
if (flux_respond (h, msg, NULL) < 0) | ||
flux_log_error (h, "error responding to job-manager.post-event"); | ||
error: | ||
if (flux_respond_error (h, msg, errno, NULL) < 0) | ||
flux_log_error (h, "error responding to job-manager.post-event"); | ||
} | ||
|
||
|
||
int post_event_init (flux_plugin_t *p) | ||
{ | ||
if (flux_jobtap_service_register_ex (p, "post", 0, post_event_cb, p) < 0) | ||
return -1; | ||
return 0; | ||
} | ||
|
||
// vi:ts=4 sw=4 expandtab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/sh | ||
|
||
test_description='Test flux post-job-event command' | ||
|
||
. $(dirname $0)/sharness.sh | ||
|
||
test_under_flux 1 | ||
|
||
test_expect_success 'run a test job' ' | ||
JOBID=$(flux submit --wait-event=start sleep inf) | ||
' | ||
test_expect_success 'flux-post-job-event --help works' ' | ||
flux post-job-event --help >help.out && | ||
test_debug "cat help.out" && | ||
grep "name of event to post" help.out | ||
' | ||
test_expect_success 'flux-post-job-event can post a simple event' ' | ||
flux post-job-event $JOBID test && | ||
flux job wait-event -t15 $JOBID test | ||
' | ||
test_expect_success 'flux-post-job-event can post an event with context' ' | ||
flux post-job-event $JOBID test note=testing && | ||
flux job wait-event -m note=testing -t15 $JOBID test | ||
' | ||
test_expect_success 'flux-post-job-event can post multiple context keys' ' | ||
flux post-job-event $JOBID test note=test2 status=0 && | ||
flux job wait-event -m note=test2 -t15 $JOBID test && | ||
flux job wait-event -m status=0 -t15 $JOBID test | ||
' | ||
test_expect_success 'flux-post-job-event fails for invalid job' ' | ||
test_must_fail flux post-job-event f123 test note="test event" | ||
' | ||
test_expect_success 'flux-post-job-event fails for inactive job' ' | ||
flux cancel $JOBID && | ||
flux job wait-event $JOBID clean && | ||
test_must_fail flux post-job-event $JOBID test note="test event" | ||
' | ||
test_expect_success 'flux-post-job-event fails with invalid id' ' | ||
test_must_fail flux post-job-event baz test | ||
' | ||
test_done |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit message typo "aarond"