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_flow_t *resrc_flow_new_from_json (json_t *o, resrc_flow_t *parent) { json_t *jhierarchyo = NULL; /* json hierarchy object */ const char *basename = NULL; const char *name = NULL; const char *hierarchy = NULL; const char *path = NULL; const char *hierarchy_path = NULL; const char *tmp = NULL; const char *type = NULL; int64_t id; int64_t ssize; resrc_flow_t *resrc_flow = NULL; resrc_t *flow_resrc; resrc_t *resrc = NULL; size_t size = 1; uuid_t uuid; if (!Jget_str (o, "type", &type)) goto ret; Jget_str (o, "basename", &basename); Jget_str (o, "name", &name); if (!(Jget_int64 (o, "id", &id))) id = -1; if (Jget_str (o, "uuid", &tmp)) uuid_parse (tmp, uuid); else uuid_clear(uuid); if (Jget_int64 (o, "size", &ssize)) size = (size_t) ssize; if ((jhierarchyo = Jobj_get (o, "hierarchy"))) { /* Get first key and value from hierarchy object */ const char *key = json_object_iter_key (json_object_iter (jhierarchyo)); if (key) { hierarchy = key; Jget_str (jhierarchyo, key, &hierarchy_path); } } if (!Jget_str (o, "path", &path)) { if (hierarchy_path) path = xstrdup (hierarchy_path); } if (!path) { if (parent) path = xasprintf ("%s/%s", resrc_path (parent->flow_resrc), name); else path = xasprintf ("/%s", name); } if (!(flow_resrc = resrc_new_resource (type, path, basename, name, NULL, id, uuid, size))) goto ret; if (!strncmp (type, "node", 5)) { resrc = resrc_lookup (name); } if ((resrc_flow = resrc_flow_new (parent, flow_resrc, resrc))) { /* add time window if we are given a start time */ int64_t starttime; if (Jget_int64 (o, "starttime", &starttime)) { json_t * w = Jnew (); char *json_str; int64_t endtime; int64_t wall_time; Jadd_int64 (w, "starttime", starttime); if (!Jget_int64 (o, "endtime", &endtime)) { if (Jget_int64 (o, "walltime", &wall_time)) endtime = starttime + wall_time; else endtime = TIME_MAX; } Jadd_int64 (w, "endtime", endtime); json_str = xstrdup (Jtostr (w)); resrc_twindow_insert (resrc_flow->flow_resrc, "0", (void *) json_str); Jput (w); } } if (resrc) resrc_graph_insert (resrc, hierarchy, resrc_flow); ret: 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; }