static int update_jcb_obj (flux_t *h, int64_t jobid, const char *key, json_object *jcb) { int rc = -1; json_object *o = NULL; if (!jcb) return -1; if (jobid_exist (h, jobid) != 0) return -1; if (is_jobid (key)) { flux_log (h, LOG_ERR, "jobid attr cannot be updated"); } else if (is_state_pair (key)) { if (Jget_obj (jcb, JSC_STATE_PAIR, &o)) rc = update_state (h, jobid, o); } else if (is_rdesc (key)) { if (Jget_obj (jcb, JSC_RDESC, &o)) rc = update_rdesc (h, jobid, o); } else if (is_rdl (key)) { const char *s = NULL; if (Jget_str (jcb, JSC_RDL, &s)) rc = update_rdl (h, jobid, s); } else if (is_rdl_alloc (key)) { if (Jget_obj (jcb, JSC_RDL_ALLOC, &o)) rc = update_rdl_alloc (h, jobid, o); } else if (is_pdesc (key)) { if (Jget_obj (jcb, JSC_PDESC, &o)) rc = update_pdesc (h, jobid, o); } else flux_log (h, LOG_ERR, "key (%s) not understood", key); return rc; }
static int update_pdesc (flux_t h, int64_t j, JSON o) { int i = 0; int rc = -1; int64_t size = 0; JSON h_arr = NULL, e_arr = NULL, pd_arr = NULL, pde = NULL; if (!Jget_int64 (o, JSC_PDESC_SIZE, &size)) return -1; if (!Jget_obj (o, JSC_PDESC_PDARRAY, &pd_arr)) return -1; if (!Jget_obj (o, JSC_PDESC_HOSTNAMES, &h_arr)) return -1; if (!Jget_obj (o, JSC_PDESC_EXECS, &e_arr)) return -1; for (i=0; i < (int) size; ++i) { if (!Jget_ar_obj (pd_arr, i, &pde)) goto done; if ( (rc = update_1pdesc (h, i, j, pde, h_arr, e_arr)) < 0) goto done; } if (kvs_commit (h) < 0) { flux_log (h, LOG_ERR, "update_pdesc commit failed"); goto done; } rc = 0; done: return rc; }
static inline void get_states (JSON jcb, int64_t *os, int64_t *ns) { JSON o = NULL; Jget_obj (jcb, JSC_STATE_PAIR, &o); Jget_int64 (o, JSC_STATE_PAIR_OSTATE, os); Jget_int64 (o, JSC_STATE_PAIR_NSTATE, ns); }
static inline void get_states (json_object *jcb, int64_t *os, int64_t *ns) { json_object *o = NULL; Jget_obj (jcb, JSC_STATE_PAIR, &o); Jget_int64 (o, JSC_STATE_PAIR_OSTATE, os); Jget_int64 (o, JSC_STATE_PAIR_NSTATE, ns); }
const char * kvs_path_json_get (json_object *o) { const char *p; json_object *ar; if (!Jget_obj (o, "paths", &ar) || !Jget_ar_str (ar, 0, &p)) return (NULL); return (p); }
static int update_pdesc (flux_t *h, int64_t j, json_object *o) { int i = 0; int rc = -1; int64_t size = 0; json_object *h_arr = NULL; json_object *e_arr = NULL; json_object *pd_arr = NULL; json_object *pde = NULL; flux_kvs_txn_t *txn = NULL; flux_future_t *f = NULL; if (!Jget_int64 (o, JSC_PDESC_SIZE, &size)) goto done; if (!Jget_obj (o, JSC_PDESC_PDARRAY, &pd_arr)) goto done; if (!Jget_obj (o, JSC_PDESC_HOSTNAMES, &h_arr)) goto done; if (!Jget_obj (o, JSC_PDESC_EXECS, &e_arr)) goto done; if (!(txn = flux_kvs_txn_create ())) { flux_log_error (h, "txn_create"); goto done; } for (i=0; i < (int) size; ++i) { if (!Jget_ar_obj (pd_arr, i, &pde)) goto done; if ( (rc = update_1pdesc (h, txn, i, j, pde, h_arr, e_arr)) < 0) goto done; } if (!(f = flux_kvs_commit (h, 0, txn)) || flux_future_get (f, NULL) < 0) { flux_log (h, LOG_ERR, "update_pdesc commit failed"); goto done; } rc = 0; done: flux_kvs_txn_destroy (txn); flux_future_destroy (f); return rc; }
static int update_1ra (flux_t h, int r, int64_t j, JSON o) { int rc = 0; int64_t ncores = 0; char key[20] = {'\0'}; JSON c = NULL; if (!Jget_obj (o, JSC_RDL_ALLOC_CONTAINED, &c)) return -1; if (!Jget_int64 (c, JSC_RDL_ALLOC_CONTAINED_NCORES, &ncores)) return -1; snprintf (key, 20, "lwj.%ld.rank.%d.cores", j, r); if ( (rc = kvs_put_int64 (h, key, ncores)) < 0) { flux_log (h, LOG_ERR, "put %s: %s", key, strerror (errno)); } return rc; }
int kp_tsetroot_dec (JSON o, int *rootseq, const char **rootdir, JSON *root, const char **fence) { int rc = -1; if (!o || !rootseq || !rootdir || !root || !fence) { errno = EINVAL; goto done; } if (!Jget_int (o, "rootseq", rootseq) || !Jget_str (o, "rootdir", rootdir)){ errno = EPROTO; goto done; } *fence = NULL; (void)Jget_str (o, "fence", fence); *root = NULL; (void)Jget_obj (o, "rootdirval", root); rc = 0; done: return rc; }
static bool complete_job (wjctx_t *ctx) { JSON jcb = NULL; JSON o = NULL; bool rc = false; char *json_str = NULL; int64_t state = J_NULL; if (jsc_query_jcb (ctx->h, ctx->jobid, JSC_STATE_PAIR, &json_str) == 0) { jcb = Jfromstr (json_str); Jget_obj (jcb, JSC_STATE_PAIR, &o); Jget_int64 (o, JSC_STATE_PAIR_NSTATE, &state); Jput (jcb); free (json_str); flux_log (ctx->h, LOG_INFO, "%"PRId64" already started (%s)", ctx->jobid, jsc_job_num2state (state)); if (state == J_COMPLETE) { flux_log (ctx->h, LOG_INFO, "%"PRId64" already completed", ctx->jobid); rc = true; } } return rc; }
static int update_hash_1ra (flux_t *h, int64_t j, json_object *o, zhash_t *rtab) { int rc = 0; int64_t ncores = 0; int64_t rank = 0; int64_t *curcnt; char *key; json_object *c = NULL; if (!Jget_obj (o, JSC_RDL_ALLOC_CONTAINED, &c)) return -1; if (!Jget_int64 (c, JSC_RDL_ALLOC_CONTAINING_RANK, &rank)) return -1; if (!Jget_int64 (c, JSC_RDL_ALLOC_CONTAINED_NCORES, &ncores)) return -1; key = lwj_key (h, j, ".rank.%ju.cores", rank); if (!(curcnt = zhash_lookup (rtab, key))) { curcnt = xzmalloc (sizeof (*curcnt)); *curcnt = ncores; zhash_insert (rtab, key, curcnt); zhash_freefn (rtab, key, free); } else *curcnt = *curcnt + ncores; free (key); return rc; }
int kp_tcommit_dec (JSON o, const char **sender, JSON *ops, const char **fence, int *nprocs) { int rc = -1; if (!sender || !ops || !fence || !nprocs) { errno = EINVAL; goto done; } *ops = NULL; (void)Jget_obj (o, "ops", ops); if (*ops) Jget (*ops); *sender = NULL; (void)Jget_str (o, ".arg_sender", sender); *fence = NULL; (void)Jget_str (o, ".arg_fence", fence); *nprocs = 1; (void)Jget_int (o, ".arg_nprocs", nprocs); rc = 0; done: return rc; }