Exemple #1
0
static void exit_event_cb (flux_t *h, flux_msg_handler_t *w,
                           const flux_msg_t *msg, void *arg)
{
    ctx_t *ctx = arg;
    barrier_t *b;
    const char *json_str;
    json_object *o = NULL;
    const char *name;
    int errnum;

    if (flux_event_decode (msg, NULL, &json_str) < 0) {
        flux_log_error (h, "%s: decoding event", __FUNCTION__);
        goto done;
    }
    if (!(o = Jfromstr (json_str))
                || !Jget_str (o, "name", &name)
                || !Jget_int (o, "errnum", &errnum)) {
        errno = EPROTO;
        flux_log_error (h, "%s: decoding event", __FUNCTION__);
        goto done;
    }
    if ((b = zhash_lookup (ctx->barriers, name))) {
        b->errnum = errnum;
        zhash_foreach (b->clients, send_enter_response, b);
        zhash_delete (ctx->barriers, name);
    }
done:
    Jput (o);
}
Exemple #2
0
static int exit_event_cb (flux_t h, int typemask, zmsg_t **zmsg, void *arg)
{
    ctx_t *ctx = arg;
    barrier_t *b;
    const char *json_str;
    json_object *o = NULL;
    const char *name;
    int errnum;

    if (flux_event_decode (*zmsg, NULL, &json_str) < 0
            || !(o = Jfromstr (json_str))
            || util_json_object_get_string (o, "name", &name) < 0
            || util_json_object_get_int (o, "errnum", &errnum) < 0) {
        flux_log (h, LOG_ERR, "%s: bad message", __FUNCTION__);
        goto done;
    }
    if ((b = zhash_lookup (ctx->barriers, name))) {
        b->errnum = errnum;
        zhash_foreach (b->clients, send_enter_response, b);
        zhash_delete (ctx->barriers, name);
    }
done:
    if (o)
        json_object_put (o);
    if (*zmsg)
        zmsg_destroy (zmsg);
    return 0;
}
Exemple #3
0
static void job_state_cb (flux_t h, flux_msg_handler_t *w,
                          const flux_msg_t *msg, void *arg)
{
    int64_t jobid = -1;
    json_object *o = NULL;
    const char *topic = NULL;
    const char *json_str = NULL;
    const char *state = NULL;
    int len = 12;

    if (flux_msg_get_topic (msg, &topic) < 0)
        goto done;

    if (flux_event_decode (msg, NULL, &json_str) < 0
            || !(o = Jfromstr (json_str))
            || !Jget_int64 (o, "lwj", &jobid)) {
        flux_log (h, LOG_ERR, "%s: bad message", __FUNCTION__);
        goto done;
    }

    if (strncmp (topic, "jsc", 3) == 0)
       len = 10;

    state = topic + len;
    if (strcmp (state, jsc_job_num2state (J_RESERVED)) == 0)
        fixup_newjob_event (h, jobid);

    if (invoke_cbs (h, jobid, get_update_jcb (h, jobid, state), 0) < 0)
        flux_log (h, LOG_ERR, "job_state_cb: failed to invoke callbacks");

    if (job_is_finished (state))
        delete_jobinfo (h, jobid);
done:
    return;
}
Exemple #4
0
int flux_heartbeat_decode (const flux_msg_t *msg, int *epoch)
{
    const char *json_str, *topic_str;
    JSON out = NULL;
    int rc = -1;

    if (flux_event_decode (msg, &topic_str, &json_str) < 0)
        goto done;
    if (strcmp (topic_str, "hb") != 0 || !(out = Jfromstr (json_str))
                                      || !Jget_int (out, "epoch", epoch)) {
        errno = EPROTO;
        goto done;
    }
    rc = 0;
done:
    Jput (out);
    return rc;
}
Exemple #5
0
int shutdown_decode (const flux_msg_t *msg, double *grace, int *exitcode,
                     int *rank, char *reason, int reason_len)
{
    const char *json_str, *s;
    JSON in = NULL;
    int rc = -1;

    if (flux_event_decode (msg, NULL, &json_str) < 0
                || !(in = Jfromstr (json_str))
                || !Jget_str (in, "reason", &s)
                || !Jget_double (in, "grace", grace)
                || !Jget_int (in, "rank", rank)
                || !Jget_int (in, "exitcode", exitcode)) {
        errno = EPROTO;
        goto done;
    }
    snprintf (reason, reason_len, "%s", s);
    rc = 0;
done:
    Jput (in);
    return rc;
}