Skip to content

Commit 159c660

Browse files
authored
Merge pull request #7058 from garlick/issue#7034
flux-job: remove cancel[all] subcommands
2 parents a29d29d + 316d221 commit 159c660

File tree

4 files changed

+7
-269
lines changed

4 files changed

+7
-269
lines changed

src/cmd/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ flux_job_SOURCES = \
160160
job/id.c \
161161
job/namespace.c \
162162
job/urgency.c \
163-
job/cancel.c \
163+
job/kill.c \
164164
job/eventlog.c \
165165
job/info.c \
166166
job/stats.c \
Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* SPDX-License-Identifier: LGPL-3.0
99
\************************************************************/
1010

11-
/* flux-job raise/cancel/kill */
11+
/* flux-job raise/kill */
1212

1313
#if HAVE_CONFIG_H
1414
#include "config.h"
@@ -26,30 +26,6 @@
2626
#include "ccan/str/str.h"
2727
#include "common.h"
2828

29-
struct optparse_option cancel_opts[] = {
30-
{ .name = "message", .key = 'm', .has_arg = 1, .arginfo = "NOTE",
31-
.usage = "Set cancel exception note",
32-
},
33-
OPTPARSE_TABLE_END
34-
};
35-
36-
struct optparse_option cancelall_opts[] = {
37-
{ .name = "user", .key = 'u', .has_arg = 1, .arginfo = "USER",
38-
.usage = "Set target user or 'all' (instance owner only)",
39-
},
40-
{ .name = "states", .key = 'S', .has_arg = 1, .arginfo = "STATES",
41-
.flags = OPTPARSE_OPT_AUTOSPLIT,
42-
.usage = "Set target job states (default=ACTIVE)",
43-
},
44-
{ .name = "force", .key = 'f', .has_arg = 0,
45-
.usage = "Confirm the command",
46-
},
47-
{ .name = "quiet", .key = 'q', .has_arg = 0,
48-
.usage = "Suppress output if no jobs match",
49-
},
50-
OPTPARSE_TABLE_END
51-
};
52-
5329
struct optparse_option raise_opts[] = {
5430
{ .name = "severity", .key = 's', .has_arg = 1, .arginfo = "N",
5531
.usage = "Set exception severity [0-7] (default=0)",
@@ -449,98 +425,5 @@ int cmd_killall (optparse_t *p, int argc, char **argv)
449425
return 0;
450426
}
451427

452-
int cmd_cancel (optparse_t *p, int argc, char **argv)
453-
{
454-
int optindex = optparse_option_index (p);
455-
flux_t *h;
456-
char *note = NULL;
457-
zlistx_t *args;
458-
struct jobid_arg *arg;
459-
flux_future_t *f;
460-
int rc = 0;
461-
462-
if (argc - optindex < 1) {
463-
optparse_print_usage (p);
464-
exit (1);
465-
}
466-
467-
parse_jobids_and_note (p, argv + optindex, &args, &note);
468-
469-
fprintf (stderr,
470-
"WARNING: this command is deprecated. Use flux-cancel(1).\n");
471-
472-
if (!(h = flux_open (NULL, 0)))
473-
log_err_exit ("flux_open");
474-
475-
if (!(f = flux_future_wait_all_create ()))
476-
log_err_exit ("flux_future_wait_all_create");
477-
flux_future_set_flux (f, h);
478-
479-
arg = zlistx_first (args);
480-
while (arg) {
481-
flux_future_t *rf = flux_job_cancel (h, arg->id, note);
482-
if (!rf || flux_future_push (f, arg->arg, rf) < 0)
483-
log_err_exit ("flux_job_cancel");
484-
arg = zlistx_next (args);
485-
}
486-
rc = wait_all_check (f, "cancel");
487-
488-
zlistx_destroy (&args);
489-
flux_future_destroy (f);
490-
flux_close (h);
491-
free (note);
492-
return rc;
493-
}
494-
495-
int cmd_cancelall (optparse_t *p, int argc, char **argv)
496-
{
497-
int optindex = optparse_option_index (p);
498-
uint32_t userid;
499-
int state_mask;
500-
flux_t *h;
501-
char *note = NULL;
502-
int dry_run = 1;
503-
int count;
504-
int errors;
505-
506-
if (optindex < argc)
507-
note = parse_arg_message (argv + optindex, "message");
508-
if (optparse_hasopt (p, "states")) {
509-
state_mask = parse_arg_states (p, "states");
510-
if ((state_mask & FLUX_JOB_STATE_INACTIVE))
511-
log_msg_exit ("Inactive jobs cannot be canceled");
512-
}
513-
else
514-
state_mask = FLUX_JOB_STATE_ACTIVE;
515-
if (optparse_hasopt (p, "user"))
516-
userid = parse_arg_userid (p, "user");
517-
else
518-
userid = getuid ();
519-
if (optparse_hasopt (p, "force"))
520-
dry_run = 0;
521-
fprintf (stderr,
522-
"WARNING: this command is deprecated. Use flux-cancel(1).\n");
523-
if (!(h = flux_open (NULL, 0)))
524-
log_err_exit ("flux_open");
525-
count = raiseall (h,
526-
dry_run,
527-
userid,
528-
state_mask,
529-
0,
530-
"cancel",
531-
note,
532-
&errors);
533-
if (count > 0 && dry_run)
534-
log_msg ("Command matched %d jobs (-f to confirm)", count);
535-
else if (count > 0 && !dry_run)
536-
log_msg ("Canceled %d jobs (%d errors)", count, errors);
537-
else if (!optparse_hasopt (p, "quiet"))
538-
log_msg ("Command matched 0 jobs");
539-
flux_close (h);
540-
free (note);
541-
return 0;
542-
}
543-
544-
545428
/* vi: ts=4 sw=4 expandtab
546429
*/

src/cmd/job/main.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ extern int cmd_namespace (optparse_t *p, int argc, char **argv);
4646
extern int cmd_urgency (optparse_t *p, int argc, char **argv);
4747
extern struct optparse_option urgency_opts[];
4848

49-
extern int cmd_cancel (optparse_t *p, int argc, char **argv);
50-
extern struct optparse_option cancel_opts[];
51-
52-
extern int cmd_cancelall (optparse_t *p, int argc, char **argv);
53-
extern struct optparse_option cancelall_opts[];
54-
5549
extern int cmd_raise (optparse_t *p, int argc, char **argv);
5650
extern struct optparse_option raise_opts[];
5751

@@ -128,20 +122,6 @@ static struct optparse_subcommand subcommands[] = {
128122
0,
129123
urgency_opts,
130124
},
131-
{ "cancel",
132-
"[OPTIONS] ids... [--] [message ...]",
133-
"Cancel one or more jobs",
134-
cmd_cancel,
135-
OPTPARSE_SUBCMD_HIDDEN,
136-
cancel_opts,
137-
},
138-
{ "cancelall",
139-
"[OPTIONS] [message ...]",
140-
"Cancel multiple jobs",
141-
cmd_cancelall,
142-
OPTPARSE_SUBCMD_HIDDEN,
143-
cancelall_opts,
144-
},
145125
{ "raise",
146126
"[OPTIONS] ids... [--] [message ...]",
147127
"Raise exception on one or more jobs",

t/t2201-job-cmd.t

Lines changed: 5 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ test_expect_success 'flux-job: raise --severity works' '
286286
flux job raise --severity=5 ${id} &&
287287
flux job wait-event -t 30 ${id} exception >raise3.out &&
288288
grep "severity\=5" raise3.out &&
289-
flux job cancel ${id}
289+
flux cancel ${id}
290290
'
291291

292292
test_expect_success 'flux-job: raise --message works' '
@@ -303,56 +303,6 @@ test_expect_success ' flux-job: raise message works (cmdline)' '
303303
grep "eep ork ook" raise5.out
304304
'
305305

306-
test_expect_success 'flux-job: cancel fails with bad FLUX_URI' '
307-
(FLUX_URI=/wrong test_must_fail flux job cancel ${validjob})
308-
'
309-
310-
test_expect_success 'flux-job: cancel fails with unknown job id' '
311-
test_must_fail flux job cancel 0
312-
'
313-
314-
test_expect_success 'flux-job: cancel fails with unknown job ids' '
315-
test_must_fail flux job cancel 0 f123
316-
'
317-
318-
test_expect_success 'flux-job: cancel fails if note set twice' '
319-
test_must_fail flux job cancel --message=hi ${validjob} -- hello
320-
'
321-
322-
test_expect_success 'flux-job: cancel fails with no args' '
323-
test_must_fail flux job cancel
324-
'
325-
326-
test_expect_success 'flux-job: cancel fails with invalid jobid' '
327-
test_must_fail flux job cancel foo
328-
'
329-
330-
test_expect_success 'flux-job: cancel fails with invalid option' '
331-
test_must_fail flux job cancel --meep foo
332-
'
333-
334-
test_expect_success 'flux-job: cancel basic works' '
335-
id=$(flux submit sleep 100) &&
336-
flux job cancel ${id} &&
337-
flux job wait-event -t 30 ${id} exception >cancel1.out &&
338-
grep "cancel" cancel1.out &&
339-
grep "severity\=0" cancel1.out
340-
'
341-
342-
test_expect_success 'flux-job: cancel --message works' '
343-
id=$(flux submit sleep 100) &&
344-
flux job cancel --message=meepmessage ${id} &&
345-
flux job wait-event -t 30 ${id} exception >cancel2.out &&
346-
grep "meepmessage" cancel2.out
347-
'
348-
349-
test_expect_success ' flux-job: cancel message works (cmdline)' '
350-
id=$(flux submit sleep 100) &&
351-
flux job cancel ${id} -- foo loo moo &&
352-
flux job wait-event -t 30 ${id} exception >cancel3.out &&
353-
grep "foo loo moo" cancel3.out
354-
'
355-
356306
test_expect_success 'flux-job: list fails with bad FLUX_URI' '
357307
(FLUX_URI=/wrong test_must_fail flux job list)
358308
'
@@ -499,65 +449,11 @@ test_expect_success 'flux job: the queue contains active jobs' '
499449
test ${count} -gt 0
500450
'
501451

502-
test_expect_success 'flux job: cancelall with no args works' '
503-
count=$(flux job list | wc -l) &&
504-
flux job cancelall 2>cancelall.tmp &&
505-
grep -v WARNING cancelall.tmp >cancelall.err &&
506-
cat <<-EOT >cancelall.exp &&
507-
flux-job: Command matched ${count} jobs (-f to confirm)
508-
EOT
509-
test_cmp cancelall.exp cancelall.err
510-
'
511-
512-
test_expect_success 'flux-job: cancelall with bad broker connection fails' '
513-
(FLUX_URI=/wrong test_must_fail flux job cancelall)
514-
'
515-
516-
test_expect_success 'flux job: cancelall with reason works' '
517-
flux job cancelall this is a reason 2>cancelall_reason.tmp &&
518-
grep -v WARNING cancelall_reason.tmp >cancelall_reason.err &&
519-
test_cmp cancelall.exp cancelall_reason.err
520-
'
521-
522-
test_expect_success 'flux job: cancelall --force works' '
523-
count=$(flux job list | wc -l) &&
524-
flux job cancelall --force 2>cancelall_f.tmp &&
525-
grep -v WARNING cancelall_f.tmp >cancelall_f.err &&
526-
cat <<-EOT >cancelall_f.exp &&
527-
flux-job: Canceled ${count} jobs (0 errors)
528-
EOT
529-
test_cmp cancelall_f.exp cancelall_f.err
530-
'
531-
532-
test_expect_success 'flux job: the queue is empty' '
452+
test_expect_success 'clear out the queue' '
453+
flux cancel --all &&
533454
run_timeout 60 flux queue drain
534455
'
535456

536-
test_expect_success 'flux-job: cancelall --user all fails for guest' '
537-
id=$(($(id -u)+1)) &&
538-
test_must_fail runas ${id} \
539-
flux job cancelall --user all 2> cancelall_all_guest.tmp &&
540-
grep -v WARNING cancelall_all_guest.tmp >cancelall_all_guest.err &&
541-
cat <<-EOF >cancelall_all_guest.exp &&
542-
flux-job: raiseall: guests can only raise exceptions on their own jobs
543-
EOF
544-
test_cmp cancelall_all_guest.exp cancelall_all_guest.err
545-
'
546-
547-
test_expect_success 'flux-job: cancelall --user <guest uid> works for guest' '
548-
id=$(($(id -u)+1)) &&
549-
runas ${id} \
550-
flux job cancelall --user ${id} 2> cancelall_guest.err
551-
'
552-
553-
test_expect_success 'flux job: cancelall with unknown state fails' '
554-
test_must_fail flux job cancelall --states=FOO 2>cancelall_bs.err &&
555-
cat <<-EOT >cancelall_bs.exp &&
556-
flux-job: error parsing --states: FOO is unknown
557-
EOT
558-
test_cmp cancelall_bs.exp cancelall_bs.err
559-
'
560-
561457
test_expect_success 'flux job: raiseall with no args prints Usage' '
562458
test_must_fail flux job raiseall 2>raiseall_na.err &&
563459
grep Usage: raiseall_na.err
@@ -667,16 +563,8 @@ test_expect_success 'flux-job: raiseall -f returns correct count' '
667563
test_cmp raiseall_testf.exp raiseall_testf.err
668564
'
669565

670-
test_expect_success 'flux-job: cancelall -f returns correct count' '
671-
flux job cancelall -f 2>cancelall_testf.tmp &&
672-
grep -v WARNING cancelall_testf.tmp >cancelall_testf.err &&
673-
cat <<-EOT >cancelall_testf.exp &&
674-
flux-job: Canceled 3 jobs (0 errors)
675-
EOT
676-
test_cmp cancelall_testf.exp cancelall_testf.err
677-
'
678-
679-
test_expect_success 'flux job: the queue is empty' '
566+
test_expect_success 'empty the queue' '
567+
flux cancel --all &&
680568
run_timeout 60 flux queue drain
681569
'
682570
test_expect_success 'flux job: retrieve eventlogs' '
@@ -727,19 +615,6 @@ test_expect_success 'flux job: killall -f kills one job' '
727615
run_timeout 60 flux queue drain
728616
'
729617

730-
test_expect_success 'flux job: cancel can operate on multiple jobs' '
731-
ids=$(flux submit --bcc=1-3 sleep 600) &&
732-
for id in ${ids}; do
733-
flux job wait-event \
734-
-vt 30 -p exec $id shell.init
735-
done &&
736-
flux job cancel ${ids} cancel multiple jobs &&
737-
for id in ${ids}; do
738-
flux job wait-event -t 30 ${id} exception >exception.out &&
739-
grep multiple exception.out
740-
done
741-
'
742-
743618
test_expect_success 'flux job: raise can operate on multiple jobs' '
744619
ids=$(flux submit --bcc=1-3 sleep 600) &&
745620
flux job raise ${ids} raise multiple jobs &&

0 commit comments

Comments
 (0)