/* sched-ready: * Scheduler indicates what style of alloc concurrency is requires, * and tells job-manager to start allocations. job-manager tells * scheduler how many jobs are in the queue. */ static void ready_cb (flux_t *h, flux_msg_handler_t *mh, const flux_msg_t *msg, void *arg) { struct alloc_ctx *ctx = arg; const char *mode; int count; if (flux_request_unpack (msg, NULL, "{s:s}", "mode", &mode) < 0) goto error; if (!strcmp (mode, "single")) ctx->mode = SCHED_SINGLE; else if (!strcmp (mode, "unlimited")) ctx->mode = SCHED_UNLIMITED; else { errno = EPROTO; goto error; } ctx->ready = true; flux_log (h, LOG_DEBUG, "scheduler: ready %s", mode); count = queue_size (ctx->inqueue); if (flux_respond_pack (h, msg, "{s:i}", "count", count) < 0) flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__); return; error: if (flux_respond_error (h, msg, errno, NULL) < 0) flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); }
static void lsmod_request_cb (flux_t *h, flux_msg_handler_t *mh, const flux_msg_t *msg, void *arg) { json_t *mods = NULL; if (flux_request_decode (msg, NULL, NULL) < 0) goto error; mods = module_list (); if (flux_respond_pack (h, msg, "{s:O}", "mods", mods) < 0) flux_log_error (h, "%s: flux_respond", __FUNCTION__); json_decref (mods); return; error: if (flux_respond_error (h, msg, errno, NULL) < 0) flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); }
/* sched-hello: * Scheduler obtains a list of jobs that have resources allocated. */ static void hello_cb (flux_t *h, flux_msg_handler_t *mh, const flux_msg_t *msg, void *arg) { struct alloc_ctx *ctx = arg; struct job *job; json_t *o = NULL; json_t *jobid; if (flux_request_decode (msg, NULL, NULL) < 0) goto error; flux_log (h, LOG_DEBUG, "scheduler: hello"); if (!(o = json_array ())) goto nomem; job = queue_first (ctx->queue); while (job) { if (job->has_resources) { if (!(jobid = json_integer (job->id))) goto nomem; if (json_array_append_new (o, jobid) < 0) { json_decref (jobid); goto nomem; } } job = queue_next (ctx->queue); } if (flux_respond_pack (h, msg, "{s:O}", "alloc", o) < 0) flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__); /* Restart any free requests that might have been interrupted * when scheduler was last unloaded. */ job = queue_first (ctx->queue); while (job) { if (event_job_action (ctx->event_ctx, job) < 0) flux_log_error (h, "%s: event_job_action", __FUNCTION__); job = queue_next (ctx->queue); } json_decref (o); return; nomem: errno = ENOMEM; error: if (flux_respond_error (h, msg, errno, NULL) < 0) flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); json_decref (o); }
void list_handle_request (flux_t *h, struct queue *queue, const flux_msg_t *msg) { int max_entries; json_t *jobs; json_t *attrs; if (flux_request_unpack (msg, NULL, "{s:i s:o}", "max_entries", &max_entries, "attrs", &attrs) < 0) goto error; if (!(jobs = list_job_array (queue, max_entries, attrs))) goto error; if (flux_respond_pack (h, msg, "{s:O}", "jobs", jobs) < 0) flux_log_error (h, "%s: flux_respond_pack", __FUNCTION__); json_decref (jobs); return; error: if (flux_respond_error (h, msg, errno, NULL) < 0) flux_log_error (h, "%s: flux_respond_error", __FUNCTION__); }
void pub_cb (flux_t *h, flux_msg_handler_t *mh, const flux_msg_t *msg, void *arg) { struct publisher *pub = arg; const char *topic; const char *payload = NULL; // optional int flags; uint32_t rolemask, userid; flux_msg_t *event = NULL; if (flux_request_unpack (msg, NULL, "{s:s s:i s?:s}", "topic", &topic, "flags", &flags, "payload", &payload) < 0) goto error; if ((flags & ~(FLUX_MSGFLAG_PRIVATE)) != 0) { errno = EPROTO; goto error; } if (flux_msg_get_rolemask (msg, &rolemask) < 0) goto error; if (flux_msg_get_userid (msg, &userid) < 0) goto error; if (!(event = encode_event (topic, flags, rolemask, userid, ++pub->seq, payload))) goto error_restore_seq; send_event (pub, event); if (flux_respond_pack (h, msg, "{s:i}", "seq", pub->seq) < 0) flux_log_error (h, "%s: flux_respond", __FUNCTION__); flux_msg_destroy (event); return; error_restore_seq: pub->seq--; error: if (flux_respond (h, msg, errno, NULL) < 0) flux_log_error (h, "%s: flux_respond", __FUNCTION__); flux_msg_destroy (event); }