Skip to content

Commit 0278c61

Browse files
authored
Merge pull request #1110 from jameshcorbett/set-status-rpc
Add a set-status RPC for marking vertices up or down
2 parents 0b70113 + 1658f88 commit 0278c61

File tree

6 files changed

+171
-3
lines changed

6 files changed

+171
-3
lines changed

resource/modules/resource_match.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ static void satisfiability_request_cb (flux_t *h, flux_msg_handler_t *w,
255255
static void params_request_cb (flux_t *h, flux_msg_handler_t *w,
256256
const flux_msg_t *msg, void *arg);
257257

258+
static void set_status_request_cb (flux_t *h, flux_msg_handler_t *w,
259+
const flux_msg_t *msg, void *arg);
260+
258261
static const struct flux_msg_handler_spec htab[] = {
259262
{ FLUX_MSGTYPE_REQUEST,
260263
"sched-fluxion-resource.match", match_request_cb, 0 },
@@ -288,6 +291,8 @@ static const struct flux_msg_handler_spec htab[] = {
288291
"sched-fluxion-resource.satisfiability", satisfiability_request_cb, 0 },
289292
{ FLUX_MSGTYPE_REQUEST,
290293
"sched-fluxion-resource.params", params_request_cb, 0 },
294+
{ FLUX_MSGTYPE_REQUEST,
295+
"sched-fluxion-resource.set_status", set_status_request_cb, 0 },
291296
FLUX_MSGHANDLER_TABLE_END
292297
};
293298

@@ -2633,6 +2638,57 @@ static void params_request_cb (flux_t *h, flux_msg_handler_t *w,
26332638
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
26342639
}
26352640

2641+
/*
2642+
* Mark a vertex as up or down
2643+
*/
2644+
static void set_status_request_cb (flux_t *h, flux_msg_handler_t *w,
2645+
const flux_msg_t *msg, void *arg)
2646+
{
2647+
const char *rp = NULL, *st = NULL;
2648+
std::string resource_path = "", status = "", errmsg = "";
2649+
std::shared_ptr<resource_ctx_t> ctx = getctx ((flux_t *)arg);
2650+
resource_pool_t::string_to_status sts = resource_pool_t::str_to_status;
2651+
std::map<std::string, std::vector<vtx_t>>::const_iterator it {};
2652+
resource_pool_t::string_to_status::iterator status_it {};
2653+
2654+
if (flux_request_unpack (msg, NULL, "{s:s, s:s}",
2655+
"resource_path", &rp,
2656+
"status", &st) < 0){
2657+
errmsg = "malformed RPC";
2658+
goto error;
2659+
}
2660+
resource_path = rp;
2661+
status = st;
2662+
// check that the path/vertex exists
2663+
it = ctx->db->metadata.by_path.find (resource_path);
2664+
if (it == ctx->db->metadata.by_path.end ()) {
2665+
errmsg = "could not find path '" + resource_path + "' in resource graph";
2666+
goto error;
2667+
}
2668+
// check that the status given is valid ('up' or 'down')
2669+
status_it = sts.find (status);
2670+
if (status_it == sts.end ()) {
2671+
errmsg = "unrecognized status '" + status + "'";
2672+
goto error;
2673+
}
2674+
// mark the vertex
2675+
if (ctx->traverser->mark (resource_path, status_it->second) < 0) {
2676+
flux_log_error (h, "%s: traverser::mark: %s", __FUNCTION__,
2677+
ctx->traverser->err_message ().c_str ());
2678+
ctx->traverser->clear_err_message ();
2679+
errmsg = "Failed to set status of resource vertex";
2680+
goto error;
2681+
}
2682+
if (flux_respond (h, msg, NULL) < 0) {
2683+
flux_log_error (h, "%s: flux_respond", __FUNCTION__);
2684+
}
2685+
return;
2686+
2687+
error:
2688+
if (flux_respond_error (h, msg, EINVAL, errmsg.c_str ()) < 0)
2689+
flux_log_error (h, "%s: flux_respond_error", __FUNCTION__);
2690+
return;
2691+
}
26362692

26372693
/******************************************************************************
26382694
* *

t/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ set(ALL_TESTS
7777
t4009-match-update.t
7878
t4010-match-conf.t
7979
t4011-match-duration.t
80+
t4012-set-status.t
8081
t5000-valgrind.t
8182
t6000-graph-size.t
8283
t6001-match-formats.t

t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ TESTS = \
9595
t4009-match-update.t \
9696
t4010-match-conf.t \
9797
t4011-match-duration.t \
98+
t4012-set-status.t \
9899
t5000-valgrind.t \
99100
t5100-issues-test-driver.t \
100101
t6000-graph-size.t \

t/scripts/flux-ion-resource.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# FLUX_EXEC_PATH or `flux python flux-ion-resource` if not to
55
# avoid python version mismatch
66
#
7-
from __future__ import print_function
87
import argparse
98
import errno
109
import yaml
@@ -94,6 +93,10 @@ def rpc_find(self, criteria, find_format=None):
9493
def rpc_status(self):
9594
return self.f.rpc("sched-fluxion-resource.status").get()
9695

96+
def rpc_set_status(self, resource_path, status):
97+
payload = {"resource_path": resource_path, "status": status}
98+
return self.f.rpc("sched-fluxion-resource.set_status", payload).get()
99+
97100
def rpc_namespace_info(self, rank, type_name, identity):
98101
payload = {"rank": rank, "type-name": type_name, "id": identity}
99102
return self.f.rpc("sched-fluxion-resource.ns-info", payload).get()
@@ -288,6 +291,16 @@ def status_action(args):
288291
print(json.dumps(resp))
289292

290293

294+
"""
295+
Action for set-status sub-command
296+
"""
297+
298+
299+
def set_status_action(args):
300+
r = ResourceModuleInterface()
301+
r.rpc_set_status(args.resource_path, args.status)
302+
303+
291304
"""
292305
Action for ns-info sub-command
293306
"""
@@ -339,8 +352,9 @@ def main():
339352
istr = "Print info on a single job."
340353
sstr = "Print overall performance statistics."
341354
cstr = "Cancel an allocated or reserved job."
342-
fstr = "Find resources matching with a crieria."
355+
fstr = "Find resources matching with a criteria."
343356
ststr = "Display resource status."
357+
ssstr = "Set up/down status of a resource vertex."
344358
pstr = "Set property-key=value for specified resource."
345359
gstr = "Get value for specified resource and property-key."
346360
nstr = "Get remapped ID given raw ID seen by the reader."
@@ -352,6 +366,7 @@ def main():
352366
parser_c = subpar.add_parser("cancel", help=cstr, description=cstr)
353367
parser_f = subpar.add_parser("find", help=fstr, description=fstr)
354368
parser_st = subpar.add_parser("status", help=ststr, description=ststr)
369+
parser_ss = subpar.add_parser("set-status", help=ssstr, description=ssstr)
355370
parser_sp = subpar.add_parser("set-property", help=pstr, description=pstr)
356371
parser_gp = subpar.add_parser("get-property", help=gstr, description=gstr)
357372
parser_n = subpar.add_parser("ns-info", help=nstr, description=nstr)
@@ -419,6 +434,18 @@ def main():
419434
st_help = "Resource status"
420435
parser_st.set_defaults(func=status_action)
421436

437+
# Positional argument for set-status sub-command
438+
#
439+
parser_ss.add_argument(
440+
"resource_path",
441+
help="path to vertex",
442+
)
443+
parser_ss.add_argument(
444+
"status",
445+
help="status of vertex",
446+
)
447+
parser_ss.set_defaults(func=set_status_action)
448+
422449
#
423450
# Positional argument for match allocate sub-command
424451
#

t/scripts/flux-jsonschemalint.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# FLUX_EXEC_PATH or `flux python flux-jsonschemalint` if not to
55
# avoid python version mismatch
66
#
7-
from __future__ import print_function
87

98
import argparse
109
import errno

t/t4012-set-status.t

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/sh
2+
#set -x
3+
4+
test_description='Test the basic functionality of properties (get/set) within resource
5+
'
6+
7+
. `dirname $0`/sharness.sh
8+
9+
grug="${SHARNESS_TEST_SRCDIR}/data/resource/grugs/tiny.graphml"
10+
jobspec="${SHARNESS_TEST_SRCDIR}/data/resource/jobspecs/basics/test008.yaml"
11+
12+
#
13+
# test_under_flux is under sharness.d/
14+
#
15+
test_under_flux 1
16+
17+
#
18+
# print only with --debug
19+
#
20+
21+
test_debug '
22+
echo ${grug}
23+
'
24+
25+
test_expect_success 'loading resource module with a tiny machine config works' '
26+
load_resource \
27+
load-file=${grug} load-format=grug \
28+
prune-filters=ALL:core subsystems=containment policy=high
29+
'
30+
31+
test_expect_success 'set-status basic test works' '
32+
flux ion-resource find status=down | grep null &&
33+
flux ion-resource set-status /tiny0/rack0/node0 down &&
34+
flux ion-resource find status=down | grep node0 &&
35+
flux ion-resource set-status /tiny0/rack0/node0 up &&
36+
flux ion-resource find status=down | grep null
37+
'
38+
39+
test_expect_success 'bad resource path produces an error' '
40+
test_must_fail flux ion-resource set-status /foobar/not/a/vertex down
41+
'
42+
43+
test_expect_success 'bad status produces an error' '
44+
test_must_fail flux ion-resource set-status /tiny0/rack0/node0 foobar
45+
'
46+
47+
test_expect_success 'set-status not-so-basic test works' '
48+
flux ion-resource find status=down | grep null &&
49+
flux ion-resource set-status /tiny0/rack0/node0 down &&
50+
flux ion-resource find status=down | grep node0 &&
51+
flux ion-resource set-status /tiny0/rack0/node1 down &&
52+
flux ion-resource find status=down | grep "node\[0-1\]" &&
53+
flux ion-resource set-status /tiny0/rack0/node0 up &&
54+
flux ion-resource find status=down | grep node1 &&
55+
flux ion-resource set-status /tiny0/rack0/node1 up &&
56+
flux ion-resource find status=down | grep null
57+
'
58+
59+
test_expect_success 'jobs fail when all nodes are marked down' '
60+
flux ion-resource set-status /tiny0/rack0/node0 down &&
61+
flux ion-resource set-status /tiny0/rack0/node1 down &&
62+
flux ion-resource find status=up | grep null &&
63+
flux ion-resource match satisfiability $jobspec &&
64+
test_must_fail flux ion-resource match allocate $jobspec &&
65+
flux ion-resource set-status /tiny0/rack0/node0 up &&
66+
flux ion-resource set-status /tiny0/rack0/node1 up &&
67+
flux ion-resource find status=down | grep null
68+
'
69+
70+
test_expect_success 'jobs fail when all racks are marked down' '
71+
flux ion-resource find status=down | grep null &&
72+
flux ion-resource set-status /tiny0/rack0 down &&
73+
flux ion-resource find status=up | grep null &&
74+
flux ion-resource match satisfiability $jobspec &&
75+
test_must_fail flux ion-resource match allocate $jobspec &&
76+
flux ion-resource set-status /tiny0/rack0 up &&
77+
flux ion-resource find status=down | grep null
78+
'
79+
80+
test_expect_success 'removing resource works' '
81+
remove_resource
82+
'
83+
84+
test_done

0 commit comments

Comments
 (0)