Exemple #1
0
void rpctest_begin_cb (flux_t h, flux_msg_watcher_t *w,
                       const flux_msg_t *msg, void *arg)
{
    const char *json_str;
    flux_rpc_t *r;

    errno = 0;
    ok (!(r = flux_rpc (h, NULL, NULL, FLUX_NODEID_ANY, 0))
        && errno == EINVAL,
        "flux_rpc with NULL topic fails with EINVAL");

    /* working no-payload RPC */
    ok ((r = flux_rpc (h, "rpctest.hello", NULL, FLUX_NODEID_ANY, 0)) != NULL,
        "flux_rpc with no payload when none is expected works");
    ok (flux_rpc_check (r) == false,
        "flux_rpc_check says get would block");
    ok (flux_rpc_get (r, NULL, NULL) == 0,
        "flux_rpc_get works");
    flux_rpc_destroy (r);

    /* cause remote EPROTO (unexpected payload) - will be picked up in _get() */
    ok ((r = flux_rpc (h, "rpctest.hello", "foo", FLUX_NODEID_ANY, 0)) != NULL,
        "flux_rpc with payload when none is expected works, at first");
    ok (flux_rpc_check (r) == false,
        "flux_rpc_check says get would block");
    errno = 0;
    ok (flux_rpc_get (r, NULL, NULL) < 0
        && errno == EPROTO,
        "flux_rpc_get fails with EPROTO");
    flux_rpc_destroy (r);

    /* cause remote EPROTO (missing payload) - will be picked up in _get() */
    errno = 0;
    ok ((r = flux_rpc (h, "rpctest.echo", NULL, FLUX_NODEID_ANY, 0)) != NULL,
        "flux_rpc with no payload when payload is expected works, at first");
    ok (flux_rpc_check (r) == false,
        "flux_rpc_check says get would block");
    errno = 0;
    ok (flux_rpc_get (r, NULL, NULL) < 0
        && errno == EPROTO,
        "flux_rpc_get fails with EPROTO");
    flux_rpc_destroy (r);

    /* working with-payload RPC */
    ok ((r = flux_rpc (h, "rpctest.echo", "foo", FLUX_NODEID_ANY, 0)) != NULL,
        "flux_rpc with payload when payload is expected works");
    ok (flux_rpc_check (r) == false,
        "flux_rpc_check says get would block");
    json_str = NULL;
    ok (flux_rpc_get (r, NULL, &json_str) == 0
        && json_str && !strcmp (json_str, "foo"),
        "flux_rpc_get works and returned expected payload");
    flux_rpc_destroy (r);

    flux_reactor_stop (h);
}
Exemple #2
0
void test_nsrc (flux_t *h, uint32_t nodeid)
{
    flux_future_t *f;
    const int count = 10000;
    json_object *in = Jnew ();
    const char *json_str;
    json_object *out = NULL;
    int i, seq;

    Jadd_int (in, "count", count);
    if (!(f = flux_rpc (h, "req.nsrc", Jtostr (in), FLUX_NODEID_ANY,
                                                      FLUX_RPC_NORESPONSE)))
        log_err_exit ("%s", __FUNCTION__);
    flux_future_destroy (f);
    for (i = 0; i < count; i++) {
        flux_msg_t *msg = flux_recv (h, FLUX_MATCH_ANY, 0);
        if (!msg)
            log_err_exit ("%s", __FUNCTION__);
        if (flux_response_decode (msg, NULL, &json_str) < 0)
            log_msg_exit ("%s: decode %d", __FUNCTION__, i);
        if (!json_str
            || !(out = Jfromstr (json_str))
            || !Jget_int (out, "seq", &seq))
            log_msg_exit ("%s: decode %d payload", __FUNCTION__, i);
        if (seq != i)
            log_msg_exit ("%s: decode %d - seq mismatch %d", __FUNCTION__, i, seq);
        Jput (out);
        flux_msg_destroy (msg);
    }
    Jput (in);
}
Exemple #3
0
zlist_t * kvs_jobid_list (plugin_ctx_t *p)
{
    zlist_t *zl = NULL;
    json_object_iter i;
    json_object *val = NULL;
    json_object *reply = NULL;
    json_object *request = util_json_object_new_object ();

    json_object_object_add (request, "lwj.id-list", NULL);

    reply = flux_rpc (p, request, "kvs.get.dir");
    if (!reply) {
        err ("kvs_job_list: plugin request failed!");
        goto done;
    }
    if (!(val = json_object_object_get (reply, "lwj.ids"))) {
        errno = ENOENT;
        err ("kvs_job_list: %s", strerror (errno));
        goto done;
    }
    if (!(zl = zlist_new ())) {
        errno = ENOMEM;
        goto done;
    }

    json_object_object_foreachC (val, i) {
        json_object *co;
        if ((co = json_object_object_get (i.val, "FILEVAL"))) {
            zlist_append (zl,
                strdup (json_object_to_json_string_ext (co,
                            JSON_C_TO_STRING_PLAIN)));
        }
    }
Exemple #4
0
void send_ping (struct ping_ctx *ctx)
{
    struct timespec t0;
    json_object *in = Jnew ();
    flux_rpc_t *rpc;
    struct ping_data *pdata = xzmalloc (sizeof (*pdata));

    pdata->tstat = xzmalloc (sizeof (*(pdata->tstat)));
    pdata->seq = 0;
    pdata->route = NULL;
    pdata->rpc_count = 0;

    Jadd_int (in, "seq", ctx->send_count);
    monotime (&t0);
    Jadd_int64 (in, "time.tv_sec", t0.tv_sec);
    Jadd_int64 (in, "time.tv_nsec", t0.tv_nsec);
    Jadd_str (in, "pad", ctx->pad);

    if (ctx->rank)
        rpc = flux_rpc_multi (ctx->h, ctx->topic, Jtostr (in), ctx->rank, 0);
    else
        rpc = flux_rpc (ctx->h, ctx->topic, Jtostr (in), ctx->nodeid, 0);
    if (!rpc)
        log_err_exit ("flux_rpc");
    flux_rpc_aux_set (rpc, pdata, ping_data_free);
    if (flux_rpc_then (rpc, ping_continuation, ctx) < 0)
        log_err_exit ("flux_rpc_then");

    Jput (in);

    ctx->send_count++;
}
Exemple #5
0
// builds the trigger request and sends it to "mod_name"
// converts sim_state to JSON, formats request tag based on "mod_name"
static int send_trigger (flux_t *h, const char *mod_name, sim_state_t *sim_state)
{
    int rc = 0;
    flux_future_t *future = NULL;
    json_t *o = NULL;
    char *topic = NULL;

    // Reset the next timer for "mod_name" to -1 before we trigger
    double *next_time = zhash_lookup (sim_state->timers, mod_name);
    *next_time = -1;

    o = sim_state_to_json (sim_state);

    topic = xasprintf ("%s.trigger", mod_name);
    future = flux_rpc (h, topic, Jtostr (o), FLUX_NODEID_ANY, FLUX_RPC_NORESPONSE);
    if (!future) {
        flux_log (h, LOG_ERR, "failed to send trigger to %s", mod_name);
        rc = -1;
    }

    Jput (o);
    free (topic);
    flux_future_destroy (future);
    return rc;
}
Exemple #6
0
static int attr_list_rpc (attr_ctx_t *ctx)
{
    flux_future_t *f;
    json_t *array, *value;
    size_t index;
    int rc = -1;

    if (!(f = flux_rpc (ctx->h, "attr.list", NULL, FLUX_NODEID_ANY, 0)))
        goto done;
    if (flux_rpc_get_unpack (f, "{s:o}", "names", &array) < 0)
        goto done;
    zlist_destroy (&ctx->names);
    if (!(ctx->names = zlist_new ()))
        goto done;
    json_array_foreach (array, index, value) {
        const char *name = json_string_value (value);
        if (!name) {
            errno = EPROTO;
            goto done;
        }
        if (zlist_append (ctx->names, strdup (name)) < 0) {
            errno = ENOMEM;
            goto done;
        }
    }
    zlist_sort (ctx->names, (zlist_compare_fn *)attr_strcmp);
    rc = 0;
done:
    flux_future_destroy (f);
    return rc;
}
Exemple #7
0
static int64_t next_jobid (flux_t h)
{
    int64_t ret = (int64_t) -1;
    const char *json_str;
    json_object *req, *resp;
    flux_rpc_t *rpc;

    req = Jnew ();
    Jadd_str (req, "name", "lwj");
    Jadd_int64 (req, "preincrement", 1);
    Jadd_int64 (req, "postincrement", 0);
    Jadd_bool (req, "create", true);
    rpc = flux_rpc (h, "cmb.seq.fetch",
                    json_object_to_json_string (req), 0, 0);
    json_object_put (req);

    if ((flux_rpc_get (rpc, NULL, &json_str) < 0)
        || !(resp = json_tokener_parse (json_str))) {
        flux_log_error (h, "rpc_get");
        goto out;
    }

    Jget_int64 (resp, "value", &ret);
    json_object_put (resp);
out:
    flux_rpc_destroy (rpc);
    return ret;
}
Exemple #8
0
void test_clog (flux_t *h, uint32_t nodeid)
{
    flux_future_t *f;
    if (!(f = flux_rpc (h, "req.clog", NULL, nodeid, 0))
             || flux_rpc_get (f, NULL) < 0)
        log_err_exit ("req.clog");
    flux_future_destroy (f);
}
Exemple #9
0
static flux_rpc_t *dmesg_rpc (flux_t h, int seq, bool follow)
{
    flux_rpc_t *rpc;
    JSON o = Jnew ();
    Jadd_int (o, "seq", seq);
    Jadd_bool (o, "follow", follow);
    rpc = flux_rpc (h, "cmb.dmesg", Jtostr (o), FLUX_NODEID_ANY, 0);
    Jput (o);
    return rpc;
}
Exemple #10
0
/* This test is to make sure that deferred responses are handled in order.
 * Arrange for module to source 10K sequenced responses.  Messages 5000-5499
 * are "put back" on the handle using flux_putmsg().  We ensure that
 * the 10K messages are nonetheless received in order.
 */
void test_putmsg (flux_t *h, uint32_t nodeid)
{
    flux_future_t *f;
    const char *json_str;
    const int count = 10000;
    const int defer_start = 5000;
    const int defer_count = 500;
    json_object *in = Jnew ();
    json_object *out = NULL;
    int seq, myseq = 0;
    zlist_t *defer = zlist_new ();
    bool popped = false;
    flux_msg_t *z;

    if (!defer)
        oom ();

    Jadd_int (in, "count", count);
    if (!(f = flux_rpc (h, "req.nsrc", Jtostr (in), FLUX_NODEID_ANY,
                                                      FLUX_RPC_NORESPONSE)))
        log_err_exit ("%s", __FUNCTION__);
    flux_future_destroy (f);
    do {
        flux_msg_t *msg = flux_recv (h, FLUX_MATCH_ANY, 0);
        if (!msg)
            log_err_exit ("%s", __FUNCTION__);
        if (flux_response_decode (msg, NULL, &json_str) < 0)
            log_msg_exit ("%s: decode", __FUNCTION__);
        if (!json_str
            || !(out = Jfromstr (json_str))
            || !Jget_int (out, "seq", &seq))
            log_msg_exit ("%s: decode - payload", __FUNCTION__);
        Jput (out);
        if (seq >= defer_start && seq < defer_start + defer_count && !popped) {
            if (zlist_append (defer, msg) < 0)
                oom ();
            if (seq == defer_start + defer_count - 1) {
                while ((z = zlist_pop (defer))) {
                    if (flux_requeue (h, z, FLUX_RQ_TAIL) < 0)
                        log_err_exit ("%s: flux_requeue", __FUNCTION__);
                    flux_msg_destroy (z);
                }
                popped = true;
            }
            continue;
        }
        if (seq != myseq)
            log_msg_exit ("%s: expected %d got %d", __FUNCTION__, myseq, seq);
        myseq++;
        flux_msg_destroy (msg);
    } while (myseq < count);
    zlist_destroy (&defer);
    Jput (in);
}
Exemple #11
0
void test_sink (flux_t *h, uint32_t nodeid)
{
    flux_future_t *f;
    json_object *in = Jnew();

    Jadd_double (in, "pi", 3.14);
    if (!(f = flux_rpc (h, "req.sink", Jtostr (in), nodeid, 0))
             || flux_future_get (f, NULL) < 0)
        log_err_exit ("%s", __FUNCTION__);
    Jput (in);
    flux_future_destroy (f);
}
Exemple #12
0
void test_src (flux_t *h, uint32_t nodeid)
{
    flux_future_t *f;
    int i;

    if (!(f = flux_rpc (h, "req.src", NULL, nodeid, 0))
             || flux_rpc_get_unpack (f, "{s:i}", "wormz", &i) < 0)
        log_err_exit ("%s", __FUNCTION__);
    if (i != 42)
        log_msg_exit ("%s: didn't get expected payload", __FUNCTION__);
    flux_future_destroy (f);
}
Exemple #13
0
void test_err (flux_t *h, uint32_t nodeid)
{
    flux_future_t *f;

    if (!(f = flux_rpc (h, "req.err", NULL, nodeid, 0)))
        log_err_exit ("error sending request");
    if (flux_future_get (f, NULL) == 0)
        log_msg_exit ("%s: succeeded when should've failed", __FUNCTION__);
    if (errno != 42)
        log_msg_exit ("%s: got errno %d instead of 42", __FUNCTION__, errno);
    flux_future_destroy (f);
}
Exemple #14
0
/* Proxy ping.
 */
void xping_request_cb (flux_t h, flux_msg_handler_t *w,
                       const flux_msg_t *msg, void *arg)
{
    ctx_t *ctx = arg;
    const char *json_str;
    int saved_errno;
    int rank, seq = ctx->ping_seq++;
    const char *service;
    char *hashkey = NULL;
    JSON in = Jnew ();
    JSON o = NULL;
    flux_msg_t *cpy;

    if (flux_request_decode (msg, NULL, &json_str) < 0) {
        saved_errno = errno;
        goto error;
    }
    if (!(o = Jfromstr (json_str)) || !Jget_int (o, "rank", &rank)
                                   || !Jget_str (o, "service", &service)) {
        saved_errno = errno = EPROTO;
        goto error;
    }
    flux_log (h, LOG_DEBUG, "Rxping rank=%d service=%s", rank, service);

    Jadd_int (in, "seq", seq);
    flux_log (h, LOG_DEBUG, "Tping seq=%d %d!%s", seq, rank, service);

    flux_rpc_t *rpc;
    if (!(rpc = flux_rpc (h, service, Jtostr (in), rank,
                                            FLUX_RPC_NORESPONSE))) {
        saved_errno = errno;
        goto error;
    }
    flux_rpc_destroy (rpc);
    if (!(cpy = flux_msg_copy (msg, true))) {
        saved_errno = errno;
        goto error;
    }
    hashkey = xasprintf ("%d", seq);
    zhash_update (ctx->ping_requests, hashkey, cpy);
    zhash_freefn (ctx->ping_requests, hashkey, (zhash_free_fn *)flux_msg_destroy);
    Jput (o);
    Jput (in);
    if (hashkey)
        free (hashkey);
    return;
error:
    if (flux_respond (h, msg, saved_errno, NULL) < 0)
        flux_log_error (h, "%s: flux_respond", __FUNCTION__);
    Jput (o);
    Jput (in);
}
Exemple #15
0
// Send an event to all modules that the simulation has completed
int send_complete_event (flux_t *h)
{
    int rc = 0;
    flux_future_t *future = NULL;

    future = flux_rpc (h, "sim.complete", NULL, FLUX_NODEID_ANY, FLUX_RPC_NORESPONSE);
    if (!future) {
        rc = -1;
    }

    flux_future_destroy (future);
    return rc;
}
Exemple #16
0
int main (int argc, char **argv)
{
    flux_t h;
    flux_rpc_t *rpc;

    if (!(h = flux_open (NULL, 0)))
        err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, "cmb.info", NULL, FLUX_NODEID_ANY, 0)))
        err_exit ("flux_rpc");
    get_rank (rpc);
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
Exemple #17
0
/*
 * Gather concatenated hwloc xml topo file with resource-hwloc.topo RPC
 *  and save results until destroyed by hwloc_topo_destroy ().
 */
static struct hwloc_topo * hwloc_topo_create (optparse_t *p)
{
    const char *json_str;
    struct hwloc_topo *t = xzmalloc (sizeof (*t));

    if (!(t->h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");

    t->rpc = flux_rpc (t->h, "resource-hwloc.topo", NULL, 0, 0);
    if (!t->rpc || (flux_rpc_get (t->rpc, NULL, &json_str) < 0))
        log_err_exit ("flux_rpc");

    if (!(t->o = Jfromstr (json_str)) || !Jget_str (t->o, "topology", &t->topo))
        log_msg_exit ("failed to parse json topology");

    return (t);
}
Exemple #18
0
static int internal_heaptrace_stop (optparse_t *p, int ac, char *av[])
{
    flux_t *h;
    flux_rpc_t *rpc;

    if (optparse_optind (p) != ac) {
        optparse_print_usage (p);
        exit (1);
    }
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, "cmb.heaptrace.stop", NULL, FLUX_NODEID_ANY, 0))
            || flux_rpc_get (rpc, NULL) < 0)
        log_err_exit ("cmb.heaptrace.stop");
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
Exemple #19
0
static int op_event_unsubscribe (void *impl, const char *topic)
{
    ctx_t *c = impl;
    assert (c->magic == CTX_MAGIC);
    flux_rpc_t *rpc = NULL;
    JSON in = Jnew ();
    int rc = 0;

    Jadd_str (in, "topic", topic);
    if (!(rpc = flux_rpc (c->h, "local.unsub", Jtostr (in), FLUX_NODEID_ANY, 0))
                || flux_rpc_get (rpc, NULL, NULL) < 0)
        goto done;
    rc = 0;
done:
    flux_rpc_destroy (rpc);
    Jput (in);
    return rc;
}
Exemple #20
0
void test_src (flux_t *h, uint32_t nodeid)
{
    flux_future_t *f;
    const char *json_str;
    json_object *out = NULL;
    int i;

    if (!(f = flux_rpc (h, "req.src", NULL, nodeid, 0))
             || flux_rpc_get (f, &json_str) < 0)
        log_err_exit ("%s", __FUNCTION__);
    if (!json_str
        || !(out = Jfromstr (json_str))
        || !Jget_int (out, "wormz", &i)
        || i != 42)
        log_msg_exit ("%s: didn't get expected payload", __FUNCTION__);
    Jput (out);
    flux_future_destroy (f);
}
Exemple #21
0
static int dmesg_clear (flux_t h, int seq)
{
    flux_rpc_t *rpc;
    JSON o = Jnew ();
    int rc = -1;

    Jadd_int (o, "seq", seq);
    if (!(rpc = flux_rpc (h, "cmb.dmesg.clear", Jtostr (o),
                          FLUX_NODEID_ANY, 0)))
        goto done;
    if (flux_rpc_get (rpc, NULL, NULL) < 0)
        goto done;
    rc = 0;
done:
    flux_rpc_destroy (rpc);
    Jput (o);
    return rc;
}
Exemple #22
0
static void send_enter_request (ctx_t *ctx, barrier_t *b)
{
    json_object *o = Jnew ();
    flux_rpc_t *rpc;

    Jadd_str (o, "name", b->name);
    Jadd_int (o, "count", b->count);
    Jadd_int (o, "nprocs", b->nprocs);
    Jadd_int (o, "hopcount", 1);

    if (!(rpc = flux_rpc (ctx->h, "barrier.enter", Jtostr (o),
                          FLUX_NODEID_UPSTREAM, FLUX_RPC_NORESPONSE))) {
        flux_log_error (ctx->h, "sending barrier.enter request");
        goto done;
    }
done:
    if (rpc)
        flux_rpc_destroy (rpc);
    json_object_put (o);
}
Exemple #23
0
static int internal_content_dropcache (optparse_t *p, int ac, char *av[])
{
    flux_t *h;
    flux_rpc_t *rpc = NULL;
    const char *topic = "content.dropcache";

    if (optparse_optind (p) != ac) {
        optparse_print_usage (p);
        exit (1);
    }
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, topic, NULL, FLUX_NODEID_ANY, 0)))
        log_err_exit ("%s", topic);
    if (flux_rpc_get (rpc, NULL) < 0)
        log_err_exit ("%s", topic);
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
Exemple #24
0
static int op_event_unsubscribe (void *impl, const char *topic)
{
    ctx_t *ctx = impl;
    assert (ctx->magic == MODHANDLE_MAGIC);
    JSON in = Jnew ();
    flux_rpc_t *rpc = NULL;
    int rc = -1;

    if (connect_socket (ctx) < 0)
        goto done;
    Jadd_str (in, "topic", topic);
    if (!(rpc = flux_rpc (ctx->h, "cmb.unsub", Jtostr (in), FLUX_NODEID_ANY, 0))
                || flux_rpc_get (rpc, NULL, NULL) < 0)
        goto done;
    rc = 0;
done:
    Jput (in);
    flux_rpc_destroy (rpc);
    return rc;
}
Exemple #25
0
static int internal_heaptrace_dump (optparse_t *p, int ac, char *av[])
{
    flux_t *h;
    flux_rpc_t *rpc;
    json_object *in = Jnew ();

    if (optparse_optind (p) != ac - 1) {
        optparse_print_usage (p);
        exit (1);
    }
    Jadd_str (in, "reason", av[ac - 1]);
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, "cmb.heaptrace.dump", Jtostr (in),
                          FLUX_NODEID_ANY, 0))
            || flux_rpc_get (rpc, NULL) < 0)
        log_err_exit ("cmb.heaptrace.dump");
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
Exemple #26
0
void test_echo (flux_t *h, uint32_t nodeid)
{
    json_object *in = Jnew ();
    json_object *out = NULL;
    const char *json_str;
    const char *s;
    flux_future_t *f;

    Jadd_str (in, "mumble", "burble");
    if (!(f = flux_rpc (h, "req.echo", Jtostr (in), nodeid, 0))
             || flux_rpc_get (f, &json_str) < 0)
        log_err_exit ("%s", __FUNCTION__);
    if (!json_str
        || !(out = Jfromstr (json_str))
        || !Jget_str (out, "mumble", &s)
        || strcmp (s, "burble") != 0)
        log_msg_exit ("%s: returned payload wasn't an echo", __FUNCTION__);
    Jput (in);
    Jput (out);
    flux_future_destroy (f);
}
Exemple #27
0
int get_watch_stats (flux_t *h, int *count)
{
    flux_rpc_t *rpc;
    const char *json_str;
    json_object *o = NULL;
    int rc = -1;

    if (!(rpc = flux_rpc (h, "kvs.stats.get", NULL, FLUX_NODEID_ANY, 0)))
        goto done;
    if (flux_rpc_get (rpc, &json_str) < 0)
        goto done;
    if (!(o = Jfromstr (json_str)) || !Jget_int (o, "#watchers", count)) {
        errno = EPROTO;
        goto done;
    }
    rc = 0;
done:
    flux_rpc_destroy (rpc);
    Jput (o);
    return rc;
}
Exemple #28
0
static void xping (flux_t *h, uint32_t nodeid, uint32_t xnodeid, const char *svc)
{
    flux_future_t *f;
    const char *json_str;
    json_object *in = Jnew ();
    json_object *out = NULL;
    const char *route;

    Jadd_int (in, "rank", xnodeid);
    Jadd_str (in, "service", svc);
    if (!(f = flux_rpc (h, "req.xping", Jtostr (in), nodeid, 0))
            || flux_rpc_get (f, &json_str) < 0)
        log_err_exit ("req.xping");
    if (!json_str
        || !(out = Jfromstr (json_str))
        || !Jget_str (out, "route", &route))
        log_errn_exit (EPROTO, "req.xping");
    printf ("hops=%d\n", count_hops (route));
    Jput (out);
    Jput (in);
    flux_future_destroy (f);
}
Exemple #29
0
static int lwj_kvs_path (flux_t *h, int64_t id, char **pathp)
{
    int rc = -1;
    const char *path;
    const char *json_str;
    flux_future_t *f;
    uint32_t nodeid = FLUX_NODEID_ANY;
    json_object *o = kvspath_request_json (id);

    if (!(f = flux_rpc (h, "job.kvspath", Jtostr (o), nodeid, 0))
        ||  (flux_rpc_get (f, &json_str) < 0)) {
        flux_log_error (h, "flux_rpc (job.kvspath)");
        goto out;
    }
    Jput (o);
    o = NULL;
    if (!json_str) {
        flux_log (h, LOG_ERR, "flux_rpc (job.kvspath): empty payload");
        goto out;
    }
    if (!(o = Jfromstr (json_str))) {
        flux_log_error (h, "flux_rpc (job.kvspath): failed to parse json");
        goto out;
    }
    if (!(path = kvs_path_json_get (o))) {
        flux_log_error (h, "flux_rpc (job.kvspath): failed to get path");
        goto out;
    }
    if (!(*pathp = strdup (path))) {
        flux_log_error (h, "flux_rpc (job.kvspath): strdup");
        goto out;
    }
    rc = 0;
out:
    flux_future_destroy (f);
    Jput (o);
    return (rc);
}
Exemple #30
-1
static flux_msg_t *op_recv (void *impl, int flags)
{
    ctx_t *ctx = impl;
    assert (ctx->magic == MODHANDLE_MAGIC);
    zmq_pollitem_t zp = {
        .events = ZMQ_POLLIN, .socket = ctx->sock, .revents = 0, .fd = -1,
    };
    flux_msg_t *msg = NULL;

    if (connect_socket (ctx) < 0)
        goto done;
    if ((flags & FLUX_O_NONBLOCK)) {
        int n;
        if ((n = zmq_poll (&zp, 1, 0L)) <= 0) {
            if (n == 0)
                errno = EWOULDBLOCK;
            goto done;
        }
    }
    msg = flux_msg_recvzsock (ctx->sock);
done:
    return msg;
}

static int op_event_subscribe (void *impl, const char *topic)
{
    ctx_t *ctx = impl;
    assert (ctx->magic == MODHANDLE_MAGIC);
    json_object *in = Jnew ();
    flux_rpc_t *rpc = NULL;
    int rc = -1;

    if (connect_socket (ctx) < 0)
        goto done;
    Jadd_str (in, "topic", topic);
    if (!(rpc = flux_rpc (ctx->h, "cmb.sub", Jtostr (in), FLUX_NODEID_ANY, 0))
            || flux_rpc_get (rpc, NULL) < 0)
        goto done;
    rc = 0;
done:
    Jput (in);
    flux_rpc_destroy (rpc);
    return rc;
}