Esempio n. 1
0
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;
}
Esempio n. 2
0
static resrc_graph_req_t *resrc_graph_req_from_json (JSON ga)
{
    JSON go = NULL;     /* graph json object */
    const char *name = NULL;
    int i, ngraphs = 0;
    int64_t ssize;
    resrc_graph_req_t *resrc_graph_req = NULL;

    if (Jget_ar_len (ga, &ngraphs)) {
        resrc_graph_req = xzmalloc ((ngraphs + 1) * sizeof (resrc_graph_req_t));
        for (i=0; i < ngraphs; i++) {
            Jget_ar_obj (ga, i, &go);
            if (Jget_str (go, "name", &name))
                resrc_graph_req[i].name = xstrdup (name);
            else
                goto fail;
            if (Jget_int64 (go, "size", &ssize))
                resrc_graph_req[i].size = (size_t) ssize;
            else
                goto fail;
        }
        /* end of the line */
        resrc_graph_req[i].name = NULL;
    }

    return resrc_graph_req;
fail:
    free (resrc_graph_req);
    return NULL;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
static int update_rdl_alloc (flux_t *h, int64_t j, json_object *o)
{
    int i = 0;
    int rc = -1;
    int size = 0;
    json_object *ra_e = NULL;
    const char *key = NULL;
    zhash_t *rtab = NULL;
    int64_t *ncores = NULL;
    flux_kvs_txn_t *txn = NULL;
    flux_future_t *f = NULL;

    if (!(rtab = zhash_new ()))
        oom ();
    if (!Jget_ar_len (o, &size))
        goto done;

    for (i=0; i < (int) size; ++i) {
        if (!Jget_ar_obj (o, i, &ra_e))
            goto done;
        /* 'o' represents an array of per-node core count to use.
         * However, becasue the same rank can appear multiple times
         * in this array in emulation mode, update_hash_1ra is
         * used to determine the total core count per rank.
         */
        if ( (rc = update_hash_1ra (h, j, ra_e, rtab)) < 0)
            goto done;
    }

    if (!(txn = flux_kvs_txn_create ())) {
        flux_log_error (h, "txn_create");
        goto done;
    }
    FOREACH_ZHASH (rtab, key, ncores) {
        if ( (rc = flux_kvs_txn_pack (txn, 0, key, "I", *ncores)) < 0) {
            flux_log_error (h, "put %s", key);
            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_future_destroy (f);
    flux_kvs_txn_destroy (txn);
    zhash_destroy (&rtab);
    return rc;
}
Esempio n. 5
0
static int update_rdl_alloc (flux_t h, int64_t j, JSON o)
{
    int i = 0;
    int rc = -1;
    int size = 0;
    JSON ra_e = NULL;
    const char *key = NULL;
    zhash_t *rtab = NULL;
    int64_t *ncores = NULL;

    if (!(rtab = zhash_new ()))
        oom ();
    if (!Jget_ar_len (o, &size))
        goto done;

    for (i=0; i < (int) size; ++i) {
        if (!Jget_ar_obj (o, i, &ra_e))
            goto done;
        /* 'o' represents an array of per-node core count to use.
         * However, becasue the same rank can appear multiple times
         * in this array in emulation mode, update_hash_1ra is
         * used to determine the total core count per rank.
         */
        if ( (rc = update_hash_1ra (h, j, ra_e, rtab)) < 0)
            goto done;
    }

    FOREACH_ZHASH (rtab, key, ncores) {
        if ( (rc = kvs_put_int64 (h, key, *ncores)) < 0) {
            flux_log_error (h, "put %s", key);
            goto done;
        }
    }
    if (kvs_commit (h) < 0) {
        flux_log (h, LOG_ERR, "update_pdesc commit failed");
        goto done;
    }
    rc = 0;

done:
    zhash_destroy (&rtab);
    return rc;
}
Esempio n. 6
0
resrc_flow_list_t *resrc_flow_list_deserialize (json_t *o)
{
    json_t *ca = NULL;     /* array of child json objects */
    int i, nchildren = 0;
    resrc_flow_t *rf = NULL;
    resrc_flow_list_t *rfl = resrc_flow_list_new ();

    if (o && rfl) {
        if (Jget_ar_len (o, &nchildren)) {
            for (i=0; i < nchildren; i++) {
                Jget_ar_obj (o, i, &ca);
                rf = resrc_flow_deserialize (ca, NULL);
                if (!rf || resrc_flow_list_append (rfl, rf))
                    break;
            }
        }
    }

    return rfl;
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
static int update_rdl_alloc (flux_t h, int64_t j, JSON o) 
{
    int i = 0;
    int rc = -1;
    int size = 0;
    JSON ra_e = NULL;

    if (!Jget_ar_len (o, &size)) return -1;

    for (i=0; i < (int) size; ++i) {
        if (!Jget_ar_obj (o, i, &ra_e))
            goto done;
        if ( (rc = update_1ra (h, i, j, ra_e)) < 0)
            goto done; 
    } 
    if (kvs_commit (h) < 0) {
        flux_log (h, LOG_ERR, "update_pdesc commit failed"); 
        goto done;
    }
    rc = 0;

done:
    return rc;
}
Esempio n. 9
0
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;
}