zlist_t * kvs_jobid_list (plugin_ctx_t *p) { zlist_t *zl = NULL; json_object_iter i; json_object *val = NULL; json_object *reply = NULL; json_object *request = util_json_object_new_object (); json_object_object_add (request, "lwj.id-list", NULL); reply = flux_rpc (p, request, "kvs.get.dir"); if (!reply) { err ("kvs_job_list: plugin request failed!"); goto done; } if (!(val = json_object_object_get (reply, "lwj.ids"))) { errno = ENOENT; err ("kvs_job_list: %s", strerror (errno)); goto done; } if (!(zl = zlist_new ())) { errno = ENOMEM; goto done; } json_object_object_foreachC (val, i) { json_object *co; if ((co = json_object_object_get (i.val, "FILEVAL"))) { zlist_append (zl, strdup (json_object_to_json_string_ext (co, JSON_C_TO_STRING_PLAIN))); } }
static int exit_event_send (flux_t h, const char *name, int errnum) { json_object *o = util_json_object_new_object (); int rc; util_json_object_add_string (o, "name", name); util_json_object_add_int (o, "errnum", errnum); rc = flux_event_send (h, o, "xbarrier.exit"); json_object_put (o); return rc; }
static void send_enter_request (ctx_t *ctx, barrier_t *b) { json_object *o = util_json_object_new_object (); util_json_object_add_string (o, "name", b->name); util_json_object_add_int (o, "count", b->count); util_json_object_add_int (o, "nprocs", b->nprocs); util_json_object_add_int (o, "hopcount", 1); flux_request_send (ctx->h, o, "xbarrier.enter"); json_object_put (o); }
void util_json_object_add_tstat (json_object *o, const char *name, tstat_t *ts, double scale) { json_object *to = util_json_object_new_object (); util_json_object_add_int (to, "count", tstat_count (ts)); util_json_object_add_double (to, "min", tstat_min (ts)*scale); util_json_object_add_double (to, "mean", tstat_mean (ts)*scale); util_json_object_add_double (to, "stddev", tstat_stddev (ts)*scale); util_json_object_add_double (to, "max", tstat_max (ts)*scale); json_object_object_add (o, name, to); }
static void send_enter_request (ctx_t *ctx, barrier_t *b) { json_object *o = util_json_object_new_object (); util_json_object_add_string (o, "name", b->name); util_json_object_add_int (o, "count", b->count); util_json_object_add_int (o, "nprocs", b->nprocs); util_json_object_add_int (o, "hopcount", 1); if (flux_json_request (ctx->h, FLUX_NODEID_UPSTREAM, FLUX_MATCHTAG_NONE, "barrier.enter", o) < 0) flux_log (ctx->h, LOG_ERR, "%s: flux_json_request: %s", __FUNCTION__, strerror (errno)); json_object_put (o); }
static int wait_for_lwj_watch_init (flux_t h, int64_t id) { int rc; json_object *rpc_o; json_object *rpc_resp; rpc_o = util_json_object_new_object (); util_json_object_add_string (rpc_o, "key", "lwj.next-id"); util_json_object_add_int64 (rpc_o, "val", id); rc = flux_json_rpc (h, FLUX_NODEID_ANY, "sim_sched.lwj-watch", rpc_o, &rpc_resp); if (rc >= 0) { util_json_object_get_int (rpc_resp, "rc", &rc); json_object_put (rpc_resp); } json_object_put (rpc_o); return rc; }
static int job_request_cb (flux_t h, int typemask, zmsg_t **zmsg, void *arg) { const char *json_str; json_object *o = NULL; const char *topic; if (flux_msg_get_topic (*zmsg, &topic) < 0) goto out; if (flux_msg_get_payload_json (*zmsg, &json_str) < 0) goto out; if (json_str && !(o = json_tokener_parse (json_str))) goto out; if (strcmp (topic, "job.shutdown") == 0) { flux_reactor_stop (h); } if (strcmp (topic, "job.next-id") == 0) { if (flux_rank (h) == 0) { unsigned long id = lwj_next_id (h); json_object *ox = json_id (id); flux_json_respond (h, ox, zmsg); json_object_put (o); } else { fprintf (stderr, "%s: forwarding request\n", topic); flux_json_request (h, FLUX_NODEID_ANY, FLUX_MATCHTAG_NONE, topic, o); } } if (strcmp (topic, "job.create") == 0) { json_object *jobinfo = NULL; unsigned long id = lwj_next_id (h); bool should_workaround = false; //"Fix" for Race Condition if (util_json_object_get_boolean (o, "race_workaround", &should_workaround) < 0) { should_workaround = false; } else if (should_workaround) { if (wait_for_lwj_watch_init (h, id) < 0) { flux_err_respond (h, errno, zmsg); goto out; } } int rc = kvs_job_new (h, id); if (rc < 0) { flux_err_respond (h, errno, zmsg); goto out; } add_jobinfo (h, id, o); kvs_commit (h); /* Generate reply with new jobid */ jobinfo = util_json_object_new_object (); util_json_object_add_int64 (jobinfo, "jobid", id); flux_json_respond (h, jobinfo, zmsg); json_object_put (jobinfo); } out: if (o) json_object_put (o); zmsg_destroy (zmsg); return 0; }