コード例 #1
0
ファイル: barrier.c プロジェクト: surajpkn/flux-core
static void send_enter_request (ctx_t *ctx, barrier_t *b)
{
    json_object *o = util_json_object_new_object ();

    util_json_object_add_string (o, "name", b->name);
    util_json_object_add_int (o, "count", b->count);
    util_json_object_add_int (o, "nprocs", b->nprocs);
    util_json_object_add_int (o, "hopcount", 1);
    if (flux_json_request (ctx->h, FLUX_NODEID_UPSTREAM,
                                   FLUX_MATCHTAG_NONE, "barrier.enter", o) < 0)
        flux_log (ctx->h, LOG_ERR, "%s: flux_json_request: %s",
                  __FUNCTION__, strerror (errno));
    json_object_put (o);
}
コード例 #2
0
ファイル: req.c プロジェクト: dinesh121991/flux-core
/* Proxy ping.
 */
static int xping_request_cb (flux_t h, int typemask, zmsg_t **zmsg, void *arg)
{
    ctx_t *ctx = arg;
    int rank, seq = ctx->ping_seq++;
    const char *service;
    char *hashkey = NULL;
    JSON in = Jnew ();
    JSON o = NULL;

    if (flux_json_request_decode (*zmsg, &o) < 0) {
        if (flux_err_respond (h, errno, zmsg) < 0)
            flux_log (h, LOG_ERR, "%s: flux_err_respond: %s", __FUNCTION__,
                      strerror (errno));
        goto done;
    }
    if (!Jget_int (o, "rank", &rank) || !Jget_str (o, "service", &service)) {
        if (flux_err_respond (h, EPROTO, zmsg) < 0)
            flux_log (h, LOG_ERR, "%s: flux_err_respond: %s", __FUNCTION__,
                      strerror (errno));
        goto done;
    }
    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);
    if (flux_json_request (h, rank, 0, service, in) < 0) {
        if (flux_err_respond (h, errno, zmsg) < 0)
            flux_log (h, LOG_ERR, "%s: flux_err_respond: %s", __FUNCTION__,
                      strerror (errno));
        goto done;
    }
    hashkey = xasprintf ("%d", seq);
    zhash_update (ctx->ping_requests, hashkey, *zmsg);
    *zmsg = NULL;
done:
    Jput (o);
    Jput (in);
    if (hashkey)
        free (hashkey);
    return 0;
}
コード例 #3
0
ファイル: job.c プロジェクト: dinesh121991/flux-core
static int job_request_cb (flux_t h, int typemask, zmsg_t **zmsg, void *arg)
{
    const char *json_str;
    json_object *o = NULL;
    const char *topic;

    if (flux_msg_get_topic (*zmsg, &topic) < 0)
        goto out;
    if (flux_msg_get_payload_json (*zmsg, &json_str) < 0)
        goto out;
    if (json_str && !(o = json_tokener_parse (json_str)))
        goto out;
    if (strcmp (topic, "job.shutdown") == 0) {
        flux_reactor_stop (h);
    }
    if (strcmp (topic, "job.next-id") == 0) {
        if (flux_rank (h) == 0) {
            unsigned long id = lwj_next_id (h);
            json_object *ox = json_id (id);
            flux_json_respond (h, ox, zmsg);
            json_object_put (o);
        }
        else {
            fprintf (stderr, "%s: forwarding request\n", topic);
            flux_json_request (h, FLUX_NODEID_ANY,
                                  FLUX_MATCHTAG_NONE, topic, o);
        }
    }
    if (strcmp (topic, "job.create") == 0) {
        json_object *jobinfo = NULL;
        unsigned long id = lwj_next_id (h);
        bool should_workaround = false;

        //"Fix" for Race Condition
        if (util_json_object_get_boolean (o, "race_workaround",
                                           &should_workaround) < 0) {
            should_workaround = false;
        } else if (should_workaround) {
            if (wait_for_lwj_watch_init (h, id) < 0) {
              flux_err_respond (h, errno, zmsg);
              goto out;
            }
        }

        int rc = kvs_job_new (h, id);
        if (rc < 0) {
            flux_err_respond (h, errno, zmsg);
            goto out;
        }
        add_jobinfo (h, id, o);

        kvs_commit (h);

        /* Generate reply with new jobid */
        jobinfo = util_json_object_new_object ();
        util_json_object_add_int64 (jobinfo, "jobid", id);
        flux_json_respond (h, jobinfo, zmsg);
        json_object_put (jobinfo);
    }

out:
    if (o)
        json_object_put (o);
    zmsg_destroy (zmsg);
    return 0;
}