예제 #1
0
파일: rpc.c 프로젝트: surajpkn/flux-core
static int rpc_request_send (flux_rpc_t *rpc, int n, const char *topic,
                             const char *json_str, uint32_t nodeid)
{
    flux_msg_t *msg;
    int flags = 0;
    int rc = -1;

    if (!(msg = flux_request_encode (topic, json_str)))
        goto done;
    if (flux_msg_set_matchtag (msg, rpc->m.matchtag + n) < 0)
        goto done;
    if (nodeid == FLUX_NODEID_UPSTREAM) {
        flags |= FLUX_MSGFLAG_UPSTREAM;
        if (flux_get_rank (rpc->h, &nodeid) < 0)
            goto done;
    }
    if (flux_msg_set_nodeid (msg, nodeid, flags) < 0)
        goto done;
    if (flux_send (rpc->h, msg, 0) < 0)
        goto done;
    rc = 0;
done:
    if (msg)
        flux_msg_destroy (msg);
    return rc;
}
예제 #2
0
static int send_request (flux_t h, const char *topic)
{
    int rc = -1;
    flux_msg_t *msg = flux_request_encode (topic, NULL);
    if (!msg || flux_send (h, msg, 0) < 0) {
        fprintf (stderr, "%s: flux_send failed: %s",
                 __FUNCTION__, strerror (errno));
        goto done;
    }
    rc = 0;
done:
    flux_msg_destroy (msg);
    return rc;
}
예제 #3
0
int main (int argc, char *argv[])
{
    flux_msg_t *msg;
    flux_t h;
    flux_reactor_t *reactor;

    plan (35);

    (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0);
    ok ((h = flux_open ("loop://", FLUX_O_COPROC)) != NULL,
        "opened loop connector");
    if (!h)
        BAIL_OUT ("can't continue without loop handle");
    ok ((reactor = flux_get_reactor (h)) != NULL,
        "obtained reactor");
    if (!reactor)
        BAIL_OUT ("can't continue without reactor");

    flux_fatal_set (h, fatal_err, NULL);
    flux_fatal_error (h, __FUNCTION__, "Foo");
    ok (fatal_tested == true,
        "flux_fatal function is called on fatal error");

    /* create nodeset for last _then test */
    ok ((then_ns = nodeset_create ()) != NULL,
        "nodeset created ok");

    ok (flux_msghandler_addvec (h, htab, htablen, NULL) == 0,
        "registered message handlers");
    /* test continues in rpctest_begin_cb() so that rpc calls
     * can sleep while we answer them
     */
    ok ((msg = flux_request_encode ("rpctest.begin", NULL)) != NULL
        && flux_send (h, msg, 0) == 0,
        "sent message to initiate test");
    ok (flux_reactor_run (reactor, 0) == 0,
        "reactor completed normally");
    flux_msg_destroy (msg);

    /* Check result of last _then test */
    ok (nodeset_count (then_ns) == 128,
        "then callback worked with correct nodemap");
    nodeset_destroy (then_ns);
    flux_rpc_destroy (then_r);

    flux_close (h);

    done_testing();
    return (0);
}
예제 #4
0
/* Send sched.free request for job.
 * Update flags.
 */
int free_request (struct alloc_ctx *ctx, struct job *job)
{
    flux_msg_t *msg;

    if (!(msg = flux_request_encode ("sched.free", NULL)))
        return -1;
    if (flux_msg_pack (msg, "{s:I}", "id", job->id) < 0)
        goto error;
    if (flux_send (ctx->h, msg, 0) < 0)
        goto error;
    flux_msg_destroy (msg);
    return 0;
error:
    flux_msg_destroy (msg);
    return -1;
}
예제 #5
0
파일: rpc.c 프로젝트: SteVwonder/flux-core
static int rpc_request_send (flux_rpc_t *rpc, const char *topic,
                             uint32_t nodeid, const char *json_str)
{
    flux_msg_t *msg;
    int rc = -1;

    if (!(msg = flux_request_encode (topic, json_str)))
        goto done;
    if (rpc_request_prepare (rpc, msg, nodeid) < 0)
        goto done;
    if (flux_send (rpc->h, msg, 0) < 0)
        goto done;
    rc = 0;
done:
    flux_msg_destroy (msg);
    return rc;
}
예제 #6
0
파일: hello.c 프로젝트: cigolabs/flux-core
flux_msg_t *hello_encode (int rank)
{
    flux_msg_t *msg = NULL;
    JSON out = Jnew ();

    Jadd_int (out, "rank", rank);
    if (!(msg = flux_request_encode ("cmb.hello", Jtostr (out))))
        goto error;
    if (flux_msg_set_nodeid (msg, 0, 0) < 0)
        goto error;
    Jput (out);
    return msg;
error:
    flux_msg_destroy (msg);
    Jput (out);
    return NULL;
}
예제 #7
0
파일: rpc.c 프로젝트: SteVwonder/flux-core
static int rpc_request_vsendf (flux_rpc_t *rpc, const char *topic,
                               uint32_t nodeid, const char *fmt, va_list ap)
{
    flux_msg_t *msg;
    int rc = -1;

    if (!(msg = flux_request_encode (topic, NULL)))
        goto done;
    if (flux_msg_vset_jsonf (msg, fmt, ap) < 0)
        goto done;
    if (rpc_request_prepare (rpc, msg, nodeid) < 0)
        goto done;
    if (flux_send (rpc->h, msg, 0) < 0)
        goto done;
    rc = 0;
done:
    flux_msg_destroy (msg);
    return rc;
}
예제 #8
0
/* Send sched.alloc request for job.
 * Update flags.
 */
int alloc_request (struct alloc_ctx *ctx, struct job *job)
{
    flux_msg_t *msg;

    if (!(msg = flux_request_encode ("sched.alloc", NULL)))
        return -1;
    if (flux_msg_pack (msg, "{s:I s:i s:i s:f}",
                            "id", job->id,
                            "priority", job->priority,
                            "userid", job->userid,
                            "t_submit", job->t_submit) < 0)
        goto error;
    if (flux_send (ctx->h, msg, 0) < 0)
        goto error;
    flux_msg_destroy (msg);
    return 0;
error:
    flux_msg_destroy (msg);
    return -1;
}
예제 #9
0
int main (int argc, char *argv[])
{
    flux_msg_t *msg;
    flux_t h;

    plan (33);

    (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0);
    ok ((h = flux_open ("loop://", FLUX_O_COPROC)) != NULL,
        "opened loop connector");
    if (!h)
        BAIL_OUT ("can't continue without loop handle");
    flux_fatal_set (h, fatal_err, NULL);

    ok (flux_msg_watcher_addvec (h, htab, NULL) == 0,
        "registered message handlers");
    /* test continues in rpctest_begin_cb() so that rpc calls
     * can sleep while we answer them
     */
    ok ((msg = flux_request_encode ("rpctest.begin", NULL)) != NULL,
        "encoded rpctest.begin request OK");
    ok (flux_send (h, msg, 0) == 0,
        "sent rpctest.begin request");
    ok (flux_reactor_start (h) == 0,
        "reactor completed normally");
    flux_msg_destroy (msg);

    /* test _then:  Slightly tricky.
     * Send request.  We're not in a coproc ctx here in main(), so there
     * will be no response, therefore, check will be false.  Register
     * continuation, start reactor.  Response will be received, continuation
     * will be invoked. Continuation stops the reactor.
    */
    flux_rpc_t *r;
    ok ((r = flux_rpc (h, "rpctest.echo", "xxx", 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");
    /* reg/unreg _then a couple times for fun */
    ok (flux_rpc_then (r, NULL, 0) == 0,
        "flux_rpc_then with NULL cb works");
    ok (flux_rpc_then (r, then_cb, h) == 0,
        "flux_rpc_then works after NULL");
    ok (flux_rpc_then (r, NULL, 0) == 0,
        "flux_rpc_then with NULL cb after non-NULL works");
    ok (flux_rpc_then (r, then_cb, h) == 0,
        "flux_rpc_then works");
    /* enough of that */
    ok (flux_reactor_start (h) == 0,
        "reactor completed normally");
    flux_rpc_destroy (r);

    /* Test a _then corner case:
     * If _check() is called before _then(), a message may have been cached
     * in the flux_rpc_t.  rpctest_thenbug_cb creates this condition.
     * Next, _then continuation is installed, but will reactor call it?
     * This will hang if rpc implementation doesn't return a cached message
     * back to the handle in _then().  Else, continuation will stop reactor.
     */
    ok ((thenbug_r = flux_rpc (h, "rpctest.echo", "xxx",
        FLUX_NODEID_ANY, 0)) != NULL,
        "thenbug: sent echo request");
    do {
        if (!(msg = flux_request_encode ("rpctest.thenbug", NULL))
                  || flux_send (h, msg, 0) < 0
                  || flux_reactor_start (h) < 0) {
            flux_msg_destroy (msg);
            break;
        }
        flux_msg_destroy (msg);
    } while (!flux_rpc_check (thenbug_r));
    ok (true,
        "thenbug: check says message ready");
    ok (flux_rpc_then (thenbug_r, then_cb, h) == 0,
        "thenbug: registered then - hangs on failure");
    ok (flux_reactor_start (h) == 0,
        "reactor completed normally");
    flux_rpc_destroy (thenbug_r);

    flux_msg_watcher_delvec (h, htab);
    flux_close (h);
    done_testing();
    return (0);
}
예제 #10
0
파일: request.c 프로젝트: trws/flux-core
int main (int argc, char *argv[])
{
    flux_msg_t *msg;
    const char *topic, *s;
    const char *json_str = "{\"a\":42}";
    const void *d;
    const char data[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    int i, l, len = strlen (data);

    plan (NO_PLAN);

    /* no topic is an error */
    errno = 0;
    ok ((msg = flux_request_encode (NULL, json_str)) == NULL
        && errno == EINVAL,
        "flux_request_encode returns EINVAL with no topic string");
    ok ((msg = flux_request_encode_raw (NULL, data, strlen (data))) == NULL
        && errno == EINVAL,
        "flux_request_encode_raw returns EINVAL with no topic string");

    /* without payload */
    ok ((msg = flux_request_encode ("foo.bar", NULL)) != NULL,
        "flux_request_encode works with NULL payload");
    topic = NULL;
    ok (flux_request_decode (msg, &topic, NULL) == 0
        && topic != NULL && !strcmp (topic, "foo.bar"),
        "flux_request_decode returns encoded topic");
    ok (flux_request_decode (msg, NULL, NULL) == 0,
        "flux_request_decode topic is optional");
    errno = 0;
    ok (flux_request_decode (msg, NULL, &s) == 0 && s == NULL,
        "flux_request_decode returns s = NULL when expected payload is missing");
    flux_msg_destroy(msg);

    /* with JSON payload */
    ok ((msg = flux_request_encode ("foo.bar", json_str)) != NULL,
        "flux_request_encode works with payload");

    s = NULL;
    ok (flux_request_decode (msg, NULL, &s) == 0
        && s != NULL && !strcmp (s, json_str),
        "flux_request_decode returns encoded payload");
    topic = NULL;
    i = 0;
    ok (flux_request_unpack (msg, &topic, "{s:i}", "a", &i) == 0
        && i == 42 && topic != NULL && !strcmp (topic, "foo.bar"),
        "flux_request_unpack returns encoded payload");

    errno = 0;
    ok (flux_request_decode (msg, NULL, NULL) == 0,
        "flux_request_decode works with payload but don't want the payload");
    flux_msg_destroy(msg);

    /* without payload (raw) */
    ok ((msg = flux_request_encode_raw ("foo.bar", NULL, 0)) != NULL,
        "flux_request_encode_raw works with NULL payload");
    topic = NULL;
    ok (flux_request_decode_raw (msg, &topic, &d, &l) == 0
        && topic != NULL && !strcmp (topic, "foo.bar"),
        "flux_request_decode_raw returns encoded topic");
    ok (flux_request_decode_raw (msg, NULL, &d, &l) == 0,
        "flux_request_decode_raw topic is optional");
    d = (char *)&d;
    l = 1;
    ok (flux_request_decode_raw (msg, NULL, &d, &l) == 0 && l == 0 && d == NULL,
        "flux_request_decode_raw returned NULL payload");
    flux_msg_destroy(msg);

    /* with raw payload */
    ok ((msg = flux_request_encode_raw ("foo.bar", data, len)) != NULL,
        "flux_request_encode_raw works with payload");

    d = NULL;
    l = 0;
    ok (flux_request_decode_raw (msg, NULL, &d, &l) == 0
        && d != NULL && l == len && memcmp (d, data, len) == 0,
        "flux_request_decode_raw returns encoded payload");
    flux_msg_destroy(msg);

    done_testing();
    return (0);
}