Ejemplo n.º 1
0
static int extract_raw_rdl_alloc (flux_t *h, int64_t j, json_object *jcb)
{
    int i;
    json_object *ra = Jnew_ar ();
    bool processing = true;

    for (i=0; processing; ++i) {
        char *key = lwj_key (h, j, ".rank.%d.cores", i);
        flux_future_t *f = NULL;
        int64_t cores = 0;
        if (!key || !(f = flux_kvs_lookup (h, 0, key))
                 || flux_kvs_lookup_get_unpack (f, "I", &cores) < 0) {
            if (errno != EINVAL)
                flux_log_error (h, "extract %s", key);
            processing = false;
        } else {
            json_object *elem = Jnew ();
            json_object *o = Jnew ();
            Jadd_int64 (o, JSC_RDL_ALLOC_CONTAINED_NCORES, cores);
            json_object_object_add (elem, JSC_RDL_ALLOC_CONTAINED, o);
            json_object_array_add (ra, elem);
        }
        free (key);
        flux_future_destroy (f);
    }
    json_object_object_add (jcb, JSC_RDL_ALLOC, ra);
    return 0;
}
Ejemplo n.º 2
0
int main (int argc, char *argv[])
{
    flux_t *h;
    const char *key;
    flux_future_t *f;

    if (argc != 2) {
        fprintf (stderr, "Usage: waitcreate_cancel key\n");
        return (1);
    }
    key = argv[1];
    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");

    if (!(f = flux_kvs_lookup (h, NULL, FLUX_KVS_WAITCREATE, key)))
        log_err_exit ("flux_kvs_lookup");

    if (flux_kvs_lookup_cancel (f) < 0)
        log_err_exit ("flux_kvs_lookup_cancel");

    if (flux_kvs_lookup_get (f, NULL) < 0) {
        if (errno != ENODATA)
            log_err_exit ("flux_kvs_lookup_get");
        flux_future_destroy (f);
    }
    else
        log_msg_exit ("flux_kvs_lookup_get returned success");

    flux_close (h);
    return (0);
}
Ejemplo n.º 3
0
static int depthfirst_map_one (flux_t *h, const char *key, int dirskip,
                               restart_map_f cb, void *arg)
{
    flux_jobid_t id;
    flux_future_t *f;
    const char *eventlog;
    struct job *job = NULL;
    char path[64];
    int rc = -1;

    if (strlen (key) <= dirskip) {
        errno = EINVAL;
        return -1;
    }
    if (fluid_decode (key + dirskip + 1, &id, FLUID_STRING_DOTHEX) < 0)
        return -1;
    if (flux_job_kvs_key (path, sizeof (path), id, "eventlog") < 0) {
        errno = EINVAL;
        return -1;
    }
    if (!(f = flux_kvs_lookup (h, NULL, 0, path)))
        goto done;
    if (flux_kvs_lookup_get (f, &eventlog) < 0)
        goto done;
    if (!(job = job_create_from_eventlog (id, eventlog)))
        goto done;
    if (cb (job, arg) < 0)
        goto done;
    rc = 1;
done:
    flux_future_destroy (f);
    job_decref (job);
    return rc;
}
Ejemplo n.º 4
0
static int update_1pdesc (flux_t *h, flux_kvs_txn_t *txn,
              int r, int64_t j, json_object *o,
			  json_object *ha, json_object *ea)
{
    flux_future_t *f = NULL;
    int rc = -1;
    json_object *d = NULL;
    char *key;
    const char *json_str;
    const char *hn = NULL, *en = NULL;
    int64_t pid = 0, hindx = 0, eindx = 0, hrank = 0;

    if (!Jget_int64 (o, JSC_PDESC_RANK_PDARRAY_PID, &pid)) return -1;
    if (!Jget_int64 (o, JSC_PDESC_RANK_PDARRAY_HINDX, &hindx)) return -1;
    if (!Jget_int64 (o, JSC_PDESC_RANK_PDARRAY_EINDX, &eindx)) return -1;
    if (!Jget_ar_str (ha, (int)hindx, &hn)) return -1;
    if (!Jget_ar_str (ea, (int)eindx, &en)) return -1;

    key = lwj_key (h, j, ".%d.procdesc", r);

    if (!key || !(f = flux_kvs_lookup (h, 0, key))
             || flux_kvs_lookup_get (f, &json_str) < 0
            || !(d = Jfromstr (json_str))) {
        flux_log_error (h, "extract %s", key);
        goto done;
    }

    Jadd_str (d, "command", en);
    Jadd_int64 (d, "pid", pid);
    errno = 0;
    if ( (hrank = strtoul (hn, NULL, 10)) && errno != 0) {
        flux_log (h, LOG_ERR, "invalid hostname %s", hn);
        goto done;
    }
    Jadd_int64 (d, "nodeid", (int64_t)hrank);
    if (flux_kvs_txn_put (txn, 0, key, Jtostr (d)) < 0) {
        flux_log_error (h, "put %s", key);
        goto done;
    }
    rc = 0;

done:
    flux_future_destroy (f);
    free (key);
    if (d)
        Jput (d);
    return rc;
}
Ejemplo n.º 5
0
static int depthfirst_map (flux_t *h, const char *key,
                           int dirskip, restart_map_f cb, void *arg)
{
    flux_future_t *f;
    const flux_kvsdir_t *dir;
    flux_kvsitr_t *itr;
    const char *name;
    int path_level;
    int count = 0;
    int rc = -1;

    path_level = restart_count_char (key + dirskip, '.');
    if (!(f = flux_kvs_lookup (h, NULL, FLUX_KVS_READDIR, key)))
        return -1;
    if (flux_kvs_lookup_get_dir (f, &dir) < 0) {
        if (errno == ENOENT && path_level == 0)
            rc = 0;
        goto done;
    }
    if (!(itr = flux_kvsitr_create (dir)))
        goto done;
    while ((name = flux_kvsitr_next (itr))) {
        char *nkey;
        int n;
        if (!flux_kvsdir_isdir (dir, name))
            continue;
        if (!(nkey = flux_kvsdir_key_at (dir, name)))
            goto done_destroyitr;
        if (path_level == 3) // orig 'key' = .A.B.C, thus 'nkey' is complete
            n = depthfirst_map_one (h, nkey, dirskip, cb, arg);
        else
            n = depthfirst_map (h, nkey, dirskip, cb, arg);
        if (n < 0) {
            int saved_errno = errno;
            free (nkey);
            errno = saved_errno;
            goto done_destroyitr;
        }
        count += n;
        free (nkey);
    }
    rc = count;
done_destroyitr:
    flux_kvsitr_destroy (itr);
done:
    flux_future_destroy (f);
    return rc;
}
Ejemplo n.º 6
0
static int extract_raw_walltime (flux_t *h, int64_t j, int64_t *walltime)
{
    int rc = 0;
    char *key = lwj_key (h, j, ".walltime");
    flux_future_t *f = NULL;

    if (!key || !(f = flux_kvs_lookup (h, 0, key))
             || flux_kvs_lookup_get_unpack (f, "I", walltime) < 0) {
        flux_log_error (h, "extract %s", key);
        rc = -1;
    }
    else
        flux_log (h, LOG_DEBUG, "extract %s: %"PRId64"", key, *walltime);
    free (key);
    flux_future_destroy (f);
    return rc;
}
Ejemplo n.º 7
0
void errors (void)
{
    flux_future_t *f;
    /* check simple error cases */

    errno = 0;
    ok (flux_kvs_lookup (NULL, NULL, 0, NULL) == NULL && errno == EINVAL,
        "flux_kvs_lookup fails on bad input");

    errno = 0;
    ok (flux_kvs_lookupat (NULL, 0, NULL, NULL) == NULL && errno == EINVAL,
        "flux_kvs_lookupat fails on bad input");

    errno = 0;
    ok (flux_kvs_lookup_get (NULL, NULL) < 0 && errno == EINVAL,
        "flux_kvs_lookup_get fails on bad input");

    errno = 0;
    ok (flux_kvs_lookup_get_unpack (NULL, NULL) < 0 && errno == EINVAL,
        "flux_kvs_lookup_get_unpack fails on bad input");

    errno = 0;
    ok (flux_kvs_lookup_get_raw (NULL, NULL, NULL) < 0 && errno == EINVAL,
        "flux_kvs_lookup_get_raw fails on bad input");

    errno = 0;
    ok (flux_kvs_lookup_get_key (NULL) == NULL && errno == EINVAL,
        "flux_kvs_lookup_get_key future=NULL fails with EINVAL");

    errno = 0;
    ok (flux_kvs_lookup_cancel (NULL) == -1 && errno == EINVAL,
        "flux_kvs_lookup_cancel future=NULL fails with EINVAL");

    if (!(f = flux_future_create (NULL, NULL)))
        BAIL_OUT ("flux_future_create failed");

    errno = 0;
    ok (flux_kvs_lookup_get_key (f) == NULL && errno == EINVAL,
        "flux_kvs_lookup_get_key future=(wrong type) fails with EINVAL");

    errno = 0;
    ok (flux_kvs_lookup_cancel (f) == -1 && errno == EINVAL,
        "flux_kvs_lookup_cancel future=(wrong type) fails with EINVAL");

    flux_future_destroy (f);
}
Ejemplo n.º 8
0
static int extract_raw_pdesc (flux_t *h, int64_t j, int64_t i, json_object **o)
{
    flux_future_t *f = NULL;
    const char *json_str;
    char *key = lwj_key (h, j, ".%ju.procdesc", i);
    int rc = -1;

    if (!key || !(f = flux_kvs_lookup (h, 0, key))
             || flux_kvs_lookup_get (f, &json_str) < 0
             || !(*o = Jfromstr (json_str))) {
        flux_log_error (h, "extract %s", key);
        goto done;
    }
    rc = 0;
done:
    flux_future_destroy (f);
    free (key);
    return rc;
}
Ejemplo n.º 9
0
static int extract_raw_state (flux_t *h, int64_t j, int64_t *s)
{
    int rc = 0;
    char *key = lwj_key (h, j, ".state");
    const char *state;
    flux_future_t *f = NULL;

    if (!key || !(f = flux_kvs_lookup (h, 0, key))
             || flux_kvs_lookup_get_unpack (f, "s", &state) < 0) {
        flux_log_error (h, "extract %s", key);
        rc = -1;
    }
    else {
        *s = jsc_job_state2num (state);
        flux_log (h, LOG_DEBUG, "extract %s: %s", key, state);
    }
    free (key);
    flux_future_destroy (f);
    return rc;
}
Ejemplo n.º 10
0
static int extract_raw_rdl (flux_t *h, int64_t j, char **rdlstr)
{
    int rc = 0;
    char *key = lwj_key (h, j, ".rdl");
    const char *s;
    flux_future_t *f = NULL;

    if (!key || !(f = flux_kvs_lookup (h, 0, key))
             || flux_kvs_lookup_get_unpack (f, "s", &s) < 0) {
        flux_log_error (h, "extract %s", key);
        rc = -1;
    }
    else {
        *rdlstr = xstrdup (s);
        flux_log (h, LOG_DEBUG, "rdl under %s extracted", key);
    }
    free (key);
    flux_future_destroy (f);
    return rc;
}
Ejemplo n.º 11
0
static int jobid_exist (flux_t *h, int64_t j)
{
    flux_future_t *f = NULL;
    jscctx_t *ctx = getctx (h);
    const char *path = jscctx_jobid_path (ctx, j);
    int rc = -1;

    if (path == NULL)
        goto done;
    if (!(f = flux_kvs_lookup (h, FLUX_KVS_READDIR, path))
                                || flux_kvs_lookup_get_dir (f, NULL) < 0) {
        flux_log (h, LOG_DEBUG, "flux_kvs_lookup(%s): %s",
                     path, flux_strerror (errno));
        goto done;
    }
    rc = 0;
done:
    flux_future_destroy (f);
    return rc;
}
Ejemplo n.º 12
0
void errors (void)
{
    /* check simple error cases */

    errno = 0;
    ok (flux_kvs_lookup (NULL, 0, NULL) == NULL && errno == EINVAL,
        "flux_kvs_lookup fails on bad input");

    errno = 0;
    ok (flux_kvs_lookupat (NULL, 0, NULL, NULL) == NULL && errno == EINVAL,
        "flux_kvs_lookupat fails on bad input");

    errno = 0;
    ok (flux_kvs_lookup_get (NULL, NULL) < 0 && errno == EINVAL,
        "flux_kvs_lookup_get fails on bad input");

    errno = 0;
    ok (flux_kvs_lookup_get_unpack (NULL, NULL) < 0 && errno == EINVAL,
        "flux_kvs_lookup_get_unpack fails on bad input");

    errno = 0;
    ok (flux_kvs_lookup_get_raw (NULL, NULL, NULL) < 0 && errno == EINVAL,
        "flux_kvs_lookup_get_raw fails on bad input");
}
Ejemplo n.º 13
0
int main (int argc, char *argv[])
{
    flux_t *h;
    const char *key;
    int i;

    if (argc != 2) {
        fprintf (stderr, "Usage: watch_cancel_loop key\n");
        return (1);
    }
    key = argv[1];
    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");

    for (i = 0; i < 1000; i++) {
        flux_future_t *f;

        log_msg ("loop=%d", i);

        if (!(f = flux_kvs_lookup (h, NULL, FLUX_KVS_WATCH
                                   | FLUX_KVS_WAITCREATE, key)))
            log_err_exit ("flux_kvs_lookup");
        if (flux_kvs_lookup_cancel (f) < 0)
            log_err_exit ("flux_kvs_lookup_cancel");
        /* Consume responses until ENODATA from cancel appears
         */
        while (flux_kvs_lookup_get (f, NULL) == 0)
            ;
        if (errno != ENODATA)
            log_err_exit ("flux_kvs_lookup_get");
        flux_future_destroy (f);
    }

    flux_close (h);
    return (0);
}
Ejemplo n.º 14
0
int main (int argc, char *argv[])
{
    flux_t *h;
    flux_reactor_t *r;
    int last = -1;
    int ch;
    flux_future_t *f;

    log_init ("commit_order");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 'v': /* --verbose */
                verbose = true;
                break;
            case 'c': /* --count N */
                totcount = strtoul (optarg, NULL, 10);
                break;
            case 'f': /* --fanout N */
                max_queue_depth = strtoul (optarg, NULL, 10);
                break;
            case 'n': /* --namespace=NAME */
                if (!(ns = strdup (optarg)))
                    log_err_exit ("out of memory");
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind != argc - 1)
        usage ();
    key = argv[optind++];
    if (totcount < 1 || max_queue_depth < 1)
        usage ();

    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");
    if (!(r = flux_get_reactor (h)))
        log_err_exit ("flux_get_reactor");
    /* One synchronous put before watch request, so that
     * watch request doesn't fail with ENOENT.
     */
    f = commit_int (h, key, txcount++);
    commit_continuation (f, NULL); // destroys f, increments rxcount

    /* Configure watcher
     * Wait for one response before unleashing async puts, to ensure
     * that first value is captured.
     */
    if (!(f = flux_kvs_lookup (h, ns, FLUX_KVS_WATCH, key)))
        log_err_exit ("flux_kvs_lookup");
    watch_continuation (f, &last); // resets f, increments wrxcount
    if (flux_future_then (f, -1., watch_continuation, &last) < 0)
        log_err_exit ("flux_future_then");

    /* Configure mechanism to keep max_queue_depth (--fanout) put RPCs
     * outstanding until totcount (--count) reached.
     */
    if (!(w_prep = flux_prepare_watcher_create (r, prep, NULL)))
        log_err_exit ("flux_prepare_watcher_create");
    if (!(w_check = flux_check_watcher_create (r, check, h)))
        log_err_exit ("flux_check_watcher_create");
    if (!(w_idle = flux_idle_watcher_create (r, NULL, NULL)))
        log_err_exit ("flux_idle_watcher_create");
    flux_watcher_start (w_prep);
    flux_watcher_start (w_check);

    /* Run until work is exhausted.
     */
    if (flux_reactor_run (r, 0) < 0)
        log_err_exit ("flux_reactor_run");

    flux_watcher_destroy (w_prep);
    flux_watcher_destroy (w_check);
    flux_watcher_destroy (w_idle);

    free (ns);
    flux_close (h);
    log_fini ();
    return 0;
}