Ejemplo n.º 1
0
int kvs_conf_save (flux_t h, flux_conf_t cf)
{
    flux_conf_itr_t itr = flux_conf_itr_create (cf);
    const char *key;
    int rc = -1;

    if (kvs_unlink (h, kvs_conf_root) < 0)
        goto done;
    if (kvs_commit (h) < 0)
        goto done;
    while ((key = flux_conf_next (itr))) {
        char *nkey = xasprintf ("%s.%s", kvs_conf_root, key);
        const char *val = flux_conf_get (cf, key);
        int n = kvs_put_string (h, nkey, val);
        free (nkey);
        if (n < 0)
            goto done;
    }       
    if (kvs_commit (h) < 0)
        goto done;
    rc = 0;
done:
    flux_conf_itr_destroy (itr);
    return rc;
}
Ejemplo n.º 2
0
static void config_hwloc_paths (flux_t h, const char *dirpath)
{
    uint32_t size, rank;
    const char *key_prefix = "config.resource.hwloc.xml";
    char key[64];
    char path[PATH_MAX];
    int n;

    if (flux_get_size (h, &size) < 0)
        log_err_exit ("flux_get_size");
    for (rank = 0; rank < size; rank++) {
        n = snprintf (key, sizeof (key), "%s.%"PRIu32, key_prefix, rank);
        assert (n < sizeof (key));
        if (dirpath == NULL) {
            /* Remove any per rank xml and reload default xml */
            if (kvs_unlink (h, key) < 0)
                log_err_exit ("kvs_unlink");
            continue;
        }
        n = snprintf (path, sizeof (path), "%s/%"PRIu32".xml", dirpath, rank);
        assert (n < sizeof (path));
        if (access (path, R_OK) < 0)
            log_err_exit ("%s", path);
        if (kvs_put_string (h, key, path) < 0)
            log_err_exit ("kvs_put_string");
    }
    if (kvs_commit (h) < 0)
        log_err_exit ("kvs_commit");
}
Ejemplo n.º 3
0
static int update_state (flux_t h, int64_t j, JSON o)
{
    int rc = -1;
    int64_t st = 0;
    char *key;

    if (!Jget_int64 (o, JSC_STATE_PAIR_NSTATE, &st)) return -1;
    if ((st >= J_FOR_RENT) || (st < J_NULL)) return -1;

    key = xasprintf ("lwj.%"PRId64".state", j);
    if (kvs_put_string (h, key, jsc_job_num2state ((job_state_t)st)) < 0)
        flux_log_error (h, "update %s", key);
    else if (kvs_commit (h) < 0)
        flux_log_error (h, "commit %s", key);
    else {
        flux_log (h, LOG_DEBUG, "job (%"PRId64") assigned new state: %s", j,
              jsc_job_num2state ((job_state_t)st));
        rc = 0;
    }
    free (key);

    if (send_state_event (h, st, j) < 0)
        flux_log_error (h, "send state event");

    return rc;
}
Ejemplo n.º 4
0
static int kvs_job_new (flux_t h, unsigned long jobid)
{
    int rc;
    char *key;

    if (asprintf (&key, "lwj.%lu.state", jobid) < 0)
        return (-1);

    flux_log (h, LOG_INFO, "Setting job %ld to reserved", jobid);
    rc = kvs_put_string (h, key, "reserved");
    kvs_commit (h);

    free (key);
    return rc;
}
Ejemplo n.º 5
0
static int update_rdl (flux_t h, int64_t j, const char *rs)
{
    int rc = -1;
    char *key = xasprintf ("lwj.%"PRId64".rdl", j);
    if (kvs_put_string (h, key, rs) < 0)
        flux_log_error (h, "update %s", key);
    else if (kvs_commit (h) < 0)
        flux_log_error (h, "commit failed");
    else {
        flux_log (h, LOG_DEBUG, "job (%"PRId64") assigned new rdl.", j);
        rc = 0;
    }
    free (key);

    return rc;
}
Ejemplo n.º 6
0
static int update_rdl (flux_t h, int64_t j, const char *rs)
{
    int rc = -1;
    char key[20] = {'\0'}; 

    snprintf (key, 20, "lwj.%ld.rdl", j);
    if (kvs_put_string (h, key, rs) < 0) 
        flux_log (h, LOG_ERR, "update %s: %s", key, strerror (errno));
    else if (kvs_commit (h) < 0) 
        flux_log (h, LOG_ERR, "commit failed");
    else {
        flux_log (h, LOG_DEBUG, "job (%ld) assigned new rdl.", j);
        rc = 0;
    }

    return rc;
}
Ejemplo n.º 7
0
void cmd_put (flux_t h, int argc, char **argv)
{
    int i;

    if (argc == 0)
        msg_exit ("put: specify one or more key=value pairs");
    for (i = 0; i < argc; i++) {
        char *key = xstrdup (argv[i]);
        char *val = strchr (key, '=');
        if (!val)
            msg_exit ("put: you must specify a value as key=value");
        *val++ = '\0';
        if (kvs_put (h, key, val) < 0) {
            if (errno != EINVAL || kvs_put_string (h, key, val) < 0)
                err_exit ("%s", key);
        }
        free (key);
    }
    if (kvs_commit (h) < 0)
        err_exit ("kvs_commit");
}
Ejemplo n.º 8
0
static int kvs_job_set_state (flux_t h, unsigned long jobid, const char *state)
{
    int rc;
    char *key = NULL;
    char *link = NULL;
    char *target = NULL;

    /*  Create lwj entry in lwj-active dir at first:
     */
    if ((asprintf (&key, "lwj-active.%lu.state", jobid) < 0)
        || (asprintf (&link, "lwj.%lu", jobid) < 0)
        || (asprintf (&target, "lwj-active.%lu", jobid) < 0)) {
        flux_log_error (h, "kvs_job_set_state: asprintf");
        return (-1);
    }

    flux_log (h, LOG_INFO, "Setting job %ld to %s", jobid, state);
    if ((rc = kvs_put_string (h, key, state)) < 0) {
        flux_log_error (h, "kvs_put_string (%s)", key);
        goto out;
    }

    /*
     *  Create link from lwj.<id> to lwj-active.<id>
     */
    if ((rc = kvs_symlink (h, link, target)) < 0) {
        flux_log_error (h, "kvs_symlink (%s, %s)", link, key);
        goto out;
    }

    if ((rc = kvs_commit (h)) < 0)
        flux_log_error (h, "kvs_job_set_state: kvs_commit");

out:
    free (key);
    free (link);
    free (target);
    return rc;
}
Ejemplo n.º 9
0
static int update_state (flux_t h, int64_t j, JSON o)
{
    int rc = -1;
    int64_t st = 0;
    char key[20] = {'\0'}; 

    if (!Jget_int64 (o, JSC_STATE_PAIR_NSTATE, &st)) return -1;
    if ((st >= J_FOR_RENT) || (st < J_NULL)) return -1; 

    snprintf (key, 20, "lwj.%ld.state", j);
    if (kvs_put_string (h, key, jsc_job_num2state ((job_state_t)st)) < 0) 
        flux_log (h, LOG_ERR, "update %s: %s", key, strerror (errno));
    else if (kvs_commit (h) < 0) 
        flux_log (h, LOG_ERR, "commit %s: %s", key, strerror (errno));
    else {
        flux_log (h, LOG_DEBUG, "job (%ld) assigned new state: %s", j, 
              jsc_job_num2state ((job_state_t)st));
        rc = 0;
    }

    return rc;
}