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);
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
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);
}
Esempio n. 5
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;
}
Esempio n. 6
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");
}
Esempio n. 7
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);
}