Skip to content

Commit d9dbb22

Browse files
committed
resource: add set_status rpc
Problem: there is no way for a service external to Fluxion to mark a vertex as down. Rabbit nodes are monitored by an external service, and Fluxion needs to be informed of their status. Add a 'sched-fluxion-resource.set_status' RPC for marking a vertex as up/down.
1 parent 0b70113 commit d9dbb22

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
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
* *

0 commit comments

Comments
 (0)