Exemple #1
0
int lsmod_hash_cb (uint32_t nodeid, const char *json_str, zhash_t *mods)
{
    flux_modlist_t modlist;
    mod_t *m;
    int i, len;
    const char *name, *digest;
    int size, idle;
    int rc = -1;

    if (!(modlist = flux_lsmod_json_decode (json_str)))
        goto done;
    if ((len = flux_modlist_count (modlist)) == -1)
        goto done;
    for (i = 0; i < len; i++) {
        if (flux_modlist_get (modlist, i, &name, &size, &digest, &idle) < 0)
            goto done;
        if ((m = zhash_lookup (mods, digest))) {
            if (idle < m->idle)
                m->idle = idle;
            if (!nodeset_add_rank (m->nodeset, nodeid))
                oom ();
        } else {
            m = mod_create (name, size, digest, idle, nodeid);
            zhash_update (mods, digest, m);
            zhash_freefn (mods, digest, (zhash_free_fn *)mod_destroy);
        }
    }
    rc = 0;
done:
    if (modlist)
        flux_modlist_destroy (modlist);
    return rc;
}
Exemple #2
0
void test_lsmod_codec (void)
{
    flux_modlist_t *mods;
    int idle, size;
    const char *name, *digest;
    char *json_str;
    int status;

    mods = flux_modlist_create ();
    ok (mods != NULL,
        "flux_modlist_create works");
    ok (flux_modlist_append (mods, "foo", 42, "aa", 3, 0) == 0,
        "first flux_modlist_append works");
    ok (flux_modlist_append (mods, "bar", 43, "bb", 2, 1) == 0,
        "second flux_modlist_append works");
    ok (flux_modlist_count (mods) == 2,
        "flux_modlist_count works");
    ok (flux_modlist_get (mods, 0, &name, &size, &digest, &idle, &status) == 0
        && name && size == 42 && digest && idle == 3 && status == 0
        && !strcmp (name, "foo") && !strcmp (digest, "aa"),
        "flux_modlist_get(0) works");
    ok (flux_modlist_get (mods, 1, &name, &size, &digest, &idle, &status) == 0
        && name && size == 43 && digest && idle == 2 && status == 1
        && !strcmp (name, "bar") && !strcmp (digest, "bb"),
        "flux_modlist_get(1) works");

    /* again after encode/decode */
    ok ((json_str = flux_lsmod_json_encode (mods)) != NULL,
        "flux_lsmod_json_encode works");
    flux_modlist_destroy (mods);
    ok ((mods = flux_lsmod_json_decode (json_str)) != NULL,
        "flux_lsmod_json_decode works");
    ok (flux_modlist_count (mods) == 2,
        "flux_modlist_count still works");
    ok (flux_modlist_get (mods, 0, &name, &size, &digest, &idle, &status) == 0
        && name && size == 42 && digest && idle == 3 && status == 0
        && !strcmp (name, "foo") && !strcmp (digest, "aa"),
        "flux_modlist_get(0) still works");
    ok (flux_modlist_get (mods, 1, &name, &size, &digest, &idle, &status) == 0
        && name && size == 43 && digest && idle == 2 && status == 1
        && !strcmp (name, "bar") && !strcmp (digest, "bb"),
        "flux_modlist_get(1) still works");

    flux_modlist_destroy (mods);
    free (json_str);
}