resrc_flow_t *resrc_flow_deserialize (json_t *o, resrc_flow_t *parent) { json_t *ca = NULL; /* array of child json objects */ json_t *co = NULL; /* child json object */ resrc_t *resrc = NULL; resrc_flow_t *resrc_flow = NULL; resrc = resrc_new_from_json (o, NULL, false); if (resrc) { resrc_flow = resrc_flow_new (parent, resrc, NULL); if ((ca = Jobj_get (o, "children"))) { int i, nchildren = 0; if (Jget_ar_len (ca, &nchildren)) { for (i=0; i < nchildren; i++) { Jget_ar_obj (ca, i, &co); (void) resrc_flow_deserialize (co, resrc_flow); } } } } return resrc_flow; }
resrc_reqst_t *resrc_reqst_from_json (JSON o, resrc_reqst_t *parent) { bool exclusive = false; JSON ca = NULL; /* array of child json objects */ JSON co = NULL; /* child json object */ JSON ga = NULL; /* array of graph json objects */ int64_t endtime; int64_t qty = 0; int64_t size = 0; int64_t starttime; resrc_reqst_t *child_reqst = NULL; resrc_reqst_t *resrc_reqst = NULL; resrc_t *resrc = NULL; if (!Jget_int64 (o, "req_qty", &qty) && (qty < 1)) goto ret; /* * If the size has not been specified, leave it at zero. A size * of zero means that this job request will not consume any part * of the resource. This allows multiple jobs to share the same * resource. */ if (Jget_int64 (o, "req_size", &size) && (size < 0)) goto ret; /* * If exclusivity has not been specified, leave it at false. */ Jget_bool (o, "exclusive", &exclusive); /* * We use the request's start time to determine whether to request * resources that are available now or in the future. A zero * starttime conveys a request for resources that are available * now. */ if (parent) starttime = parent->starttime; else if (!(Jget_int64 (o, "starttime", &starttime))) starttime = 0; if (parent) endtime = parent->endtime; else if (!(Jget_int64 (o, "endtime", &endtime))) endtime = TIME_MAX; resrc = resrc_new_from_json (o, NULL, false); if (resrc) { resrc_reqst = resrc_reqst_new (resrc, qty, size, starttime, endtime, exclusive); if ((ga = Jobj_get (o, "graphs"))) resrc_reqst->g_reqs = resrc_graph_req_from_json (ga); if ((co = Jobj_get (o, "req_child"))) { child_reqst = resrc_reqst_from_json (co, resrc_reqst); if (child_reqst) resrc_reqst_add_child (resrc_reqst, child_reqst); } else if ((ca = Jobj_get (o, "req_children"))) { int i, nchildren = 0; if (Jget_ar_len (ca, &nchildren)) { for (i=0; i < nchildren; i++) { Jget_ar_obj (ca, i, &co); child_reqst = resrc_reqst_from_json (co, resrc_reqst); if (child_reqst) resrc_reqst_add_child (resrc_reqst, child_reqst); } } } } ret: return resrc_reqst; }