コード例 #1
0
ファイル: flux-config.c プロジェクト: surajpkn/flux-core
int main (int argc, char *argv[])
{
    int ch;
    flux_conf_t cf;
    char *cmd;
    bool vopt = false;
    flux_t h = NULL;
    char *confdir = NULL;

    log_init ("flux-config");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'v': /* --verbose */
                vopt=  true;
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind == argc)
        usage ();
    cmd = argv[optind++];

    /* Process config from the KVS if running in a session and not
     * forced to use a config file by the command line.
     */
    cf = flux_conf_create ();
    if ((confdir = getenv ("FLUX_CONF_DIRECTORY")))
        flux_conf_set_directory (cf, confdir);
    if (getenv ("FLUX_CONF_USEFILE")) {
        if (vopt)
            msg ("Loading config from %s", flux_conf_get_directory (cf));
        if (flux_conf_load (cf) < 0)
            err_exit ("%s", flux_conf_get_directory (cf));
    } else if (getenv ("FLUX_URI")) {
        if (vopt)
            msg ("Loading config from KVS");
        if (!(h = flux_open (NULL, 0)))
            err_exit ("flux_open");
        if (kvs_conf_load (h, cf) < 0)
            err_exit ("could not load config from KVS");
    }

    if (!strcmp (cmd, "get"))
        config_get (cf, argc - optind, argv + optind);
    else if (!strcmp (cmd, "dump"))
        config_dump (cf, argc - optind, argv + optind);
    else if (!strcmp (cmd, "put"))
        config_put (cf, h, vopt, argc - optind, argv + optind);
    else if (!strcmp (cmd, "save"))
        config_save (cf, vopt, argc - optind, argv + optind);
    else
        usage ();

    if (h)
        flux_close (h);
    flux_conf_destroy (cf);
    log_fini();
    exit (0);
}
コード例 #2
0
ファイル: tbarrier.c プロジェクト: surajpkn/flux-core
int main (int argc, char *argv[])
{
    flux_t h;
    int ch;
    struct timespec t0;
    char *name = NULL;
    int quiet = 0;
    int nprocs = 1;
    int iter = 1;
    int i;

    log_init ("tbarrier");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 'q': /* --quiet */
                quiet = 1;
                break;
            case 'n': /* --nprocs N */
                nprocs = strtoul (optarg, NULL, 10);
                break;
            case 't': /* --test-iterations N */
                iter = strtoul (optarg, NULL, 10);
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind < argc - 1)
        usage ();
    if (optind < argc)
        name = argv[optind++];

    if (!(h = flux_open (NULL, 0)))
        err_exit ("flux_open");

    for (i = 0; i < iter; i++) {
        char *tname = NULL;
        monotime (&t0);
        if (name)
            tname = xasprintf ("%s.%d", name, i);
        if (flux_barrier (h, tname, nprocs) < 0) {
            if (errno == EINVAL && tname == NULL)
                msg_exit ("%s", "provide barrier name if not running as LWJ");
            else
                err_exit ("flux_barrier");
        }
        if (!quiet)
            printf ("barrier name=%s nprocs=%d time=%0.3f ms\n",
                    tname ? tname : "NULL", nprocs, monotime_since (t0));
        if (tname)
            free (tname);
    }

    flux_close (h);
    log_fini ();
    return 0;
}
コード例 #3
0
int main (int argc, char *argv[])
{
    flux_t *h;
    flux_reactor_t *r;
    int last = -1;
    int ch;
    flux_future_t *f;

    log_init ("commit_order");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 'v': /* --verbose */
                verbose = true;
                break;
            case 'c': /* --count N */
                totcount = strtoul (optarg, NULL, 10);
                break;
            case 'f': /* --fanout N */
                max_queue_depth = strtoul (optarg, NULL, 10);
                break;
            case 'n': /* --namespace=NAME */
                if (!(ns = strdup (optarg)))
                    log_err_exit ("out of memory");
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind != argc - 1)
        usage ();
    key = argv[optind++];
    if (totcount < 1 || max_queue_depth < 1)
        usage ();

    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");
    if (!(r = flux_get_reactor (h)))
        log_err_exit ("flux_get_reactor");
    /* One synchronous put before watch request, so that
     * watch request doesn't fail with ENOENT.
     */
    f = commit_int (h, key, txcount++);
    commit_continuation (f, NULL); // destroys f, increments rxcount

    /* Configure watcher
     * Wait for one response before unleashing async puts, to ensure
     * that first value is captured.
     */
    if (!(f = flux_kvs_lookup (h, ns, FLUX_KVS_WATCH, key)))
        log_err_exit ("flux_kvs_lookup");
    watch_continuation (f, &last); // resets f, increments wrxcount
    if (flux_future_then (f, -1., watch_continuation, &last) < 0)
        log_err_exit ("flux_future_then");

    /* Configure mechanism to keep max_queue_depth (--fanout) put RPCs
     * outstanding until totcount (--count) reached.
     */
    if (!(w_prep = flux_prepare_watcher_create (r, prep, NULL)))
        log_err_exit ("flux_prepare_watcher_create");
    if (!(w_check = flux_check_watcher_create (r, check, h)))
        log_err_exit ("flux_check_watcher_create");
    if (!(w_idle = flux_idle_watcher_create (r, NULL, NULL)))
        log_err_exit ("flux_idle_watcher_create");
    flux_watcher_start (w_prep);
    flux_watcher_start (w_check);

    /* Run until work is exhausted.
     */
    if (flux_reactor_run (r, 0) < 0)
        log_err_exit ("flux_reactor_run");

    flux_watcher_destroy (w_prep);
    flux_watcher_destroy (w_check);
    flux_watcher_destroy (w_idle);

    free (ns);
    flux_close (h);
    log_fini ();
    return 0;
}
コード例 #4
0
ファイル: rpc.c プロジェクト: SteVwonder/flux-core
int main (int argc, char *argv[])
{
    flux_msg_t *msg;
    flux_t *h;
    flux_reactor_t *reactor;

    plan (NO_PLAN);

    (void)setenv ("FLUX_CONNECTOR_PATH",
                  flux_conf_get ("connector_path", CONF_FLAG_INTREE), 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 ((reactor = flux_get_reactor(h)) != NULL,
       "obtained reactor");
    if (!h)
        BAIL_OUT ("can't continue without reactor");

    ok (flux_msg_handler_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_run (reactor, 0) == 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", "{}", 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_run (reactor, 0) == 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", "{}",
        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_run (reactor, 0) < 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_run (reactor, 0) == 0,
        "reactor completed normally");
    flux_rpc_destroy (thenbug_r);

    flux_msg_handler_delvec (htab);
    flux_close (h);
    done_testing();
    return (0);
}
コード例 #5
0
ファイル: flux-comms.c プロジェクト: cigolabs/flux-core
int main (int argc, char *argv[])
{
    flux_t h;
    int ch;
    uint32_t rank = FLUX_NODEID_ANY; /* local */
    char *cmd;
    int e;

    log_init ("flux-comms");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 'r': /* --rank N */
                rank = strtoul (optarg, NULL, 10);
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind == argc)
        usage ();
    cmd = argv[optind++];
    if (rank != FLUX_NODEID_ANY
            && (!strcmp (cmd, "recover-all") || !strcmp (cmd, "info")))
        usage ();

    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");

    if (!strcmp (cmd, "reparent")) {
        if (optind != argc - 1)
            usage ();
        if (flux_reparent (h, rank, argv[optind]) < 0)
            log_err_exit ("flux_reparent");
    } else if (!strcmp (cmd, "idle")) {
        if (optind != argc)
            usage ();
        char *peers;
        if (!(peers = flux_lspeer (h, rank)))
            log_err_exit ("flux_peer");
        printf ("%s\n", peers);
        free (peers);
    } else if (!strcmp (cmd, "panic")) {
        char *msg = NULL;
        size_t len = 0;
        if (optind < argc) {
            if ((e = argz_create (argv + optind, &msg, &len)) != 0)
                log_errn_exit (e, "argz_create");
            argz_stringify (msg, len, ' ');
        }
        flux_panic (h, rank, msg);
        if (msg)
            free (msg);
    } else if (!strcmp (cmd, "failover")) {
        if (optind != argc)
            usage ();
        if (flux_failover (h, rank) < 0)
            log_err_exit ("flux_failover");
    } else if (!strcmp (cmd, "recover")) {
        if (optind != argc)
            usage ();
        if (flux_recover (h, rank) < 0)
            log_err_exit ("flux_recover");
    } else if (!strcmp (cmd, "recover-all")) {
        if (optind != argc)
            usage ();
        if (flux_recover_all (h) < 0)
            log_err_exit ("flux_recover_all");
    } else if (!strcmp (cmd, "info")) {
        int arity;
        uint32_t rank, size;
        const char *s;
        if (flux_get_rank (h, &rank) < 0 || flux_get_size (h, &size) < 0)
            log_err_exit ("flux_get_rank/size");
        if (!(s = flux_attr_get (h, "tbon.arity", NULL)))
            log_err_exit ("flux_attr_get tbon.arity");
        arity = strtoul (s, NULL, 10);
        printf ("rank=%d\n", rank);
        printf ("size=%d\n", size);
        printf ("arity=%d\n", arity);
    } else
        usage ();

    flux_close (h);
    log_fini ();
    return 0;
}
コード例 #6
0
ファイル: heartbeat.c プロジェクト: cigolabs/flux-core
int main (int argc, char **argv)
{
    flux_t h;
    heartbeat_t *hb;
    flux_msg_handler_t *w;

    plan (18);

    check_codec ();

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

    ok ((hb = heartbeat_create ()) != NULL,
        "heartbeat_create works");

    heartbeat_set_flux (hb, h);

    ok (heartbeat_get_rate (hb) == 2.,
        "heartbeat_get_rate returns default of 2s");
    errno = 0;
    ok (heartbeat_set_rate (hb, -1) < 1 && errno == EINVAL,
        "heartbeat_set_rate -1 fails with EINVAL");
    errno = 0;
    ok (heartbeat_set_rate (hb, 1000000) < 1 && errno == EINVAL,
        "heartbeat_set_rate 1000000 fails with EINVAL");
    ok (heartbeat_set_ratestr (hb, "250ms") == 0,
        "heartbeat_set_ratestr 250ms works");
    ok (heartbeat_get_rate (hb) == 0.250,
        "heartbeat_get_rate returns what was set");
    ok (heartbeat_set_rate (hb, 0.1) == 0,
        "heartbeat_set_rate 0.1 works");
    ok (heartbeat_get_rate (hb) == 0.1,
        "heartbeat_get_rate returns what was set");

    ok (heartbeat_get_epoch (hb) == 0,
        "heartbeat_get_epoch works, default is zero");

    w = flux_msg_handler_create (h, FLUX_MATCH_EVENT, heartbeat_event_cb, hb);
    ok (w != NULL,
        "created event watcher");
    flux_msg_handler_start (w);

    ok (heartbeat_start (hb) == 0,
        "heartbeat_start works");

    ok (flux_reactor_run (flux_get_reactor (h), 0) == 0,
        "flux reactor exited normally");

    heartbeat_destroy (hb);
    flux_msg_handler_destroy (w);
    flux_close (h);

    done_testing ();
    return 0;
}
コード例 #7
0
ファイル: flux-module.c プロジェクト: dinesh121991/flux-core
int main (int argc, char *argv[])
{
    flux_t h = NULL;
    int ch;
    char *cmd;
    func_t *f;
    opt_t opt = {
        .fanout = 1024,
        .nodeset = NULL,
    };

    log_init ("flux-module");

    if (argc < 2)
        usage ();
    cmd = argv[1];
    argc--;
    argv++;

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 'r': /* --rank=[nodeset|all] */
                if (opt.nodeset)
                    free (opt.nodeset);
                opt.nodeset = xstrdup (optarg);
                break;
            case 'd': /* --direct */
                opt.direct = true;
                break;
            case 'f': /* --fanout */
                opt.fanout = strtoul (optarg, NULL, 10);
                break;
            default:
                usage ();
                break;
        }
    }
    opt.argc = argc - optind;
    opt.argv = argv + optind;

    if (!(f = func_lookup (cmd)))
        msg_exit ("unknown function '%s'", cmd);

    if (strcmp (cmd, "info") != 0) {
        if (!(h = flux_open (NULL, 0)))
            err_exit ("flux_open");
        if (!opt.nodeset) {
            opt.nodeset = xasprintf ("%d", flux_rank (h));
        } else if (!strcmp (opt.nodeset, "all") && flux_size (h) == 1) {
            free (opt.nodeset);
            opt.nodeset= xasprintf ("%d", flux_rank (h));
        } else if (!strcmp (opt.nodeset, "all")) {
            free (opt.nodeset);
            opt.nodeset = xasprintf ("[0-%d]", flux_size (h) - 1);
        }
    }

    f->fun (h, opt);

    if (opt.nodeset)
        free (opt.nodeset);
    if (h)
        flux_close (h);

    log_fini ();
    return 0;
}

char *sha1 (const char *path)
{
    zfile_t *zf = zfile_new (NULL, path);
    char *digest = NULL;
    if (zf)
        digest = xstrdup (zfile_digest (zf));
    zfile_destroy (&zf);
    return digest;
}
コード例 #8
0
ファイル: watch.c プロジェクト: tpatki/flux-core
void test_mt (int argc, char **argv)
{
    thd_t *thd;
    int i, rc;
    flux_t h;
    int errors = 0;

    if (argc != 3) {
        fprintf (stderr, "Usage: mt nthreads changes key\n");
        exit (1);
    }
    nthreads = strtoul (argv[0], NULL, 10);
    changes = strtoul (argv[1], NULL, 10);
    key = argv[2];

    thd = xzmalloc (sizeof (*thd) * nthreads);

    if (!(h = flux_open (NULL, 0)))
        err_exit ("flux_open");

    /* Set initial value of 'key' to -1 */
    if (kvs_put_int (h, key, -1) < 0)
        err_exit ("kvs_put_int %s", key);
    key_stable = xasprintf ("%s-stable", key);
    if (kvs_put_int (h, key_stable, 0) < 0)
        err_exit ("kvs_put_int %s", key);

    if (kvs_commit (h) < 0)
        err_exit ("kvs_commit");

    for (i = 0; i < nthreads; i++) {
        thd[i].n = i;
        thd[i].last_val = -42;
        if ((rc = pthread_attr_init (&thd[i].attr)))
            errn (rc, "pthread_attr_init");
        if ((rc = pthread_create (&thd[i].tid, &thd[i].attr, thread, &thd[i])))
            errn (rc, "pthread_create");
    }
    wait_ready ();

    for (i = 0; i < changes; i++) {
        if (kvs_put_int (h, key, i) < 0)
            err_exit ("kvs_put_int %s", key);
        if (kvs_commit (h) < 0)
            err_exit ("kvs_commit");
    }

    /* Verify that callbacks were called the correct number of times.
     * The nil and stable callbacks will be called exactly once before the
     * reactor is started, then should never be called again.
     * Due to commit merging on the master, the changing callback may
     * miss intervening values but it shouldn't be called extra times.
     */
    for (i = 0; i < nthreads; i++) {
        if ((rc = pthread_join (thd[i].tid, NULL)))
            errn (rc, "pthread_join");
        if (thd[i].nil_count != 1) {
            msg ("%d: nil callback called %d times (expected one)",
                 i, thd[i].nil_count);
            errors++;
        }
        if (thd[i].stable_count != 1) {
            msg ("%d: stable callback called %d times (expected one)",
                 i, thd[i].stable_count);
            errors++;
        }
        if (thd[i].change_count > changes + 1) {
            msg ("%d: changing callback called %d times (expected <= %d)",
                 i, thd[i].change_count, changes + 1);
            errors++;
        }
    }
    if (errors > 0)
        exit (1);

    free (thd);
    free (key_stable);

    flux_close (h);
}