コード例 #1
0
ファイル: watch.c プロジェクト: SteVwonder/flux-core
/* Timer pops every 1 ms, writing a new value to key.
 * After 10 calls, it calls kvs_unwatch().
 * After 20 calls, it calls flux_reactor_stop().
 * The kvs_unwatch_cb() counts the number of times it is called, should be 10.
 */
void test_unwatch (int argc, char **argv)
{
    struct timer_ctx ctx;
    flux_reactor_t *r;
    int count = 0;
    flux_watcher_t *timer;

    if (argc != 1) {
        fprintf (stderr, "Usage: unwatch key\n");
        exit (1);
    }
    ctx.key = argv[0];
    if (!(ctx.h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");
    r = flux_get_reactor (ctx.h);
    if (kvs_watch_int (ctx.h, ctx.key, unwatch_watch_cb, &count) < 0)
        log_err_exit ("kvs_watch_int %s", ctx.key);
    if (!(timer = flux_timer_watcher_create (r, 0.001, 0.001,
                                             unwatch_timer_cb, &ctx)))
        log_err_exit ("flux_timer_watcher_create");
    flux_watcher_start (timer);
    if (flux_reactor_run (r, 0) < 0)
        log_err_exit ("flux_reactor_run");
    if (count != 10)
        log_msg_exit ("watch called %d times (should be 10)", count);
    flux_watcher_destroy (timer);
    flux_close (ctx.h);
}
コード例 #2
0
ファイル: watch.c プロジェクト: SteVwonder/flux-core
void test_selfmod (int argc, char **argv)
{
    flux_t *h;
    char *key;

    if (argc != 1) {
        fprintf (stderr, "Usage: selfmod key\n");
        exit (1);
    }
    key = argv[0];
    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");

    if (kvs_put_int (h, key, -1) < 0)
        log_err_exit ("kvs_put_int");
    if (kvs_commit (h) < 0)
        log_err_exit ("kvs_commit");
    if (kvs_watch_int (h, key, selfmod_watch_cb, h) < 0)
        log_err_exit ("kvs_watch_int");

    log_msg ("reactor: start");
    flux_reactor_run (flux_get_reactor (h), 0);
    log_msg ("reactor: end");

    flux_close (h);
}
コード例 #3
0
ファイル: watch.c プロジェクト: SteVwonder/flux-core
/* This is a sanity check that watch/unwatch in a loop doesn't
 * leak matchtags.
 */
void test_unwatchloop (int argc, char **argv)
{
    int i;
    flux_t *h;
    char *key;

    if (argc != 1) {
        fprintf (stderr, "Usage: unwatch key\n");
        exit (1);
    }
    key = argv[0];
    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");
    uint32_t avail = flux_matchtag_avail (h, 0);
    for (i = 0; i < 1000; i++) {
        if (kvs_watch_int (h, key, unwatchloop_cb, NULL) < 0)
            log_err_exit ("kvs_watch_int[%d] %s", i, key);
        if (kvs_unwatch (h, key) < 0)
            log_err_exit ("kvs_unwatch[%d] %s", i, key);
    }
    uint32_t leaked = avail - flux_matchtag_avail (h, 0);
    if (leaked > 0)
        log_msg_exit ("leaked %u matchtags", leaked);

    flux_close (h);
}
コード例 #4
0
ファイル: getas.c プロジェクト: SteVwonder/flux-core
int main (int argc, char *argv[])
{
    int ch;
    const char *type = NULL;
    const char *directory = NULL;
    const char *key;
    flux_t *h;

    log_init ("getas");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 't': /* --type TYPE  */
                type = optarg;
                break;
            case 'd': /* --directory DIR */
                directory = optarg;
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind != argc - 1)
        usage ();
    key = argv[optind++];

    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");
    if (directory)
        dirgetas (h, directory, key, type);
    else
        getas (h, key, type);
    flux_close (h);
}
コード例 #5
0
ファイル: heartbeat.c プロジェクト: tpatki/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", CONNECTOR_PATH, 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;
}
コード例 #6
0
ファイル: watch.c プロジェクト: SteVwonder/flux-core
void *thread (void *arg)
{
    thd_t *t = arg;

    if (!(t->h = flux_open (NULL, 0))) {
        log_err ("%d: flux_open", t->n);
        goto done;
    }
    signal_ready ();
    /* The first kvs.watch reply is handled synchronously, then other kvs.watch
     * replies will arrive asynchronously and be handled by the reactor.
     */
    if (kvs_watch_int (t->h, key, mt_watch_cb, t) < 0) {
        log_err ("%d: kvs_watch_int", t->n);
        goto done;
    }
    if (kvs_watch_int (t->h, "nonexistent-key", mt_watchnil_cb, t) < 0) {
        log_err ("%d: kvs_watch_int", t->n);
        goto done;
    }
    if (kvs_watch_int (t->h, key_stable, mt_watchstable_cb, t) < 0) {
        log_err ("%d: kvs_watch_int", t->n);
        goto done;
    }
    if (flux_reactor_run (flux_get_reactor (t->h), 0) < 0) {
        log_err ("%d: flux_reactor_run", t->n);
        goto done;
    }
done:
    if (t->h)
        flux_close (t->h);

    return NULL;
}
コード例 #7
0
ファイル: reduce.c プロジェクト: flux-framework/flux-core
int main (int argc, char *argv[])
{
    flux_t *h;

    plan (NO_PLAN);

    (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_attr_set_cacheonly (h, "rank", "0");
    flux_attr_set_cacheonly (h, "tbon.level", "0");
    flux_attr_set_cacheonly (h, "tbon.maxlevel", "0");

    test_nopolicy (h); // 6
    test_hwm (h); // 37
    test_timed(h); // 18

    flux_close (h);
    done_testing();
    return (0);
}
コード例 #8
0
ファイル: hwloc.c プロジェクト: dongahn/flux-core
/*
 * Free parsed JSON object and RPC for hwloc toplogy
 */
static void hwloc_topo_destroy (struct hwloc_topo *t)
{
    json_object_put (t->o);
    flux_rpc_destroy (t->rpc);
    flux_close (t->h);
    free (t);
}
コード例 #9
0
int main (int argc, char *argv[])
{
    flux_t *h;
    const char *key;
    flux_future_t *f;

    if (argc != 2) {
        fprintf (stderr, "Usage: waitcreate_cancel key\n");
        return (1);
    }
    key = argv[1];
    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");

    if (!(f = flux_kvs_lookup (h, NULL, FLUX_KVS_WAITCREATE, key)))
        log_err_exit ("flux_kvs_lookup");

    if (flux_kvs_lookup_cancel (f) < 0)
        log_err_exit ("flux_kvs_lookup_cancel");

    if (flux_kvs_lookup_get (f, NULL) < 0) {
        if (errno != ENODATA)
            log_err_exit ("flux_kvs_lookup_get");
        flux_future_destroy (f);
    }
    else
        log_msg_exit ("flux_kvs_lookup_get returned success");

    flux_close (h);
    return (0);
}
コード例 #10
0
ファイル: attr.c プロジェクト: cigolabs/flux-core
static int cmd_setattr (optparse_t *p, int ac, char *av[])
{
    int n;
    const char *name = NULL, *val = NULL;
    flux_t h;

    log_init ("flux-setattr");

    n = optparse_optind (p);
    if (optparse_hasopt (p, "expunge") && n == ac - 1) {
        name = av[n];
    } else if (!optparse_hasopt (p, "expunge") && n == ac - 2) {
        name = av[n];
        val = av[n + 1];
    } else {
        optparse_print_usage (p);
        exit (1);
    }

    h = builtin_get_flux_handle (p);
    if (flux_attr_set (h, name, val) < 0)
        log_err_exit ("%s", av[1]);
    flux_close (h);
    return (0);
}
コード例 #11
0
ファイル: content.c プロジェクト: SteVwonder/flux-core
static int internal_content_load (optparse_t *p, int ac, char *av[])
{
    int n;
    const char *blobref;
    uint8_t *data;
    int size;
    flux_t *h;
    flux_rpc_t *rpc;
    const char *topic;

    n = optparse_optind (p);
    if (n != ac - 1) {
        optparse_print_usage (p);
        exit (1);
    }
    blobref = av[n];
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (optparse_hasopt (p, "bypass-cache"))
        topic = "content-backing.load";
    else
        topic = "content.load";
    if (!(rpc = flux_rpc_raw (h, topic, blobref, strlen (blobref) + 1, 0, 0)))
        log_err_exit ("%s", topic);
    if (flux_rpc_get_raw (rpc, &data, &size) < 0)
        log_err_exit ("%s", topic);
    if (write_all (STDOUT_FILENO, data, size) < 0)
        log_err_exit ("write");
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
コード例 #12
0
ファイル: content.c プロジェクト: SteVwonder/flux-core
static int internal_content_store (optparse_t *p, int ac, char *av[])
{
    const uint32_t blob_size_limit = 1048576; /* RFC 10 */
    uint8_t *data;
    int size;
    flux_t *h;
    flux_rpc_t *rpc;
    const char *topic;

    if (optparse_optind (p)  != ac) {
        optparse_print_usage (p);
        exit (1);
    }
    if ((size = read_all (STDIN_FILENO, &data)) < 0)
        log_err_exit ("read");
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (optparse_hasopt (p, "dry-run")) {
        int flags;
        const char *hashfun;

        if (size > blob_size_limit)
            log_errn_exit (EFBIG, "content-store");
        if (!(hashfun = flux_attr_get (h, "content-hash", &flags)))
            log_err_exit ("flux_attr_get content-hash");
        if (!strcmp (hashfun, "sha1")) {
            uint8_t hash[SHA1_DIGEST_SIZE];
            char hashstr[SHA1_STRING_SIZE];
            SHA1_CTX sha1_ctx;

            SHA1_Init (&sha1_ctx);
            SHA1_Update (&sha1_ctx, (uint8_t *)data, size);
            SHA1_Final (&sha1_ctx, hash);
            sha1_hashtostr (hash, hashstr);
            printf ("%s\n", hashstr);
        } else
            log_msg_exit ("content-store: unsupported hash function: %s", hashfun);
    } else {
        const char *blobref;
        int blobref_size;
        if (optparse_hasopt (p, "bypass-cache"))
            topic = "content-backing.store";
        else
            topic = "content.store";
        if (!(rpc = flux_rpc_raw (h, topic, data, size, 0, 0)))
            log_err_exit ("%s", topic);
        if (flux_rpc_get_raw (rpc, &blobref, &blobref_size) < 0)
            log_err_exit ("%s", topic);
        if (!blobref || blobref[blobref_size - 1] != '\0')
            log_msg_exit ("%s: protocol error", topic);
        printf ("%s\n", blobref);
        flux_rpc_destroy (rpc);
    }
    flux_close (h);
    free (data);
    return (0);
}
コード例 #13
0
ファイル: flux-waitjob.c プロジェクト: dongahn/flux-sched
static void sig_handler (int s)
{
    if (s == SIGINT) {
        fprintf (stdout, "Exit on INT\n\n");
        /* this will call freectx */
        flux_close (sig_flux_h);
        log_fini ();
        exit (0);
    }
}
コード例 #14
0
ファイル: flux-jstat.c プロジェクト: tpatki/flux-core
int main (int argc, char *argv[])
{
    flux_t h; 
    int ch = 0;
    int rc = 0;
    char *cmd = NULL;
    const char *j = NULL;
    const char *ofn = NULL;
    const char *attr = NULL;
    const char *jcbstr = NULL;

    log_init ("flux-jstat");
    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage (0);
                break;
            case 'o': /* --testout */
                ofn = xasprintf ("%s", optarg);
                break;
            default:
                usage (1);
                break;
        }
    }
    if (optind == argc)
        usage (1);

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

    flux_log_set_facility (h, "jstat");
    cmd = argv[optind++];

    if (!strcmp ("notify", cmd))
        rc = handle_notify_req (h, (const char *)ofn);
    else if (!strcmp ("query", cmd) && optind == argc - 2) {
        j = (const char *)(*(argv+optind));
        attr = (const char *)(*(argv+optind+1));
        rc = handle_query_req (h, strtol (j, NULL, 10), attr, ofn); 
    }
    else if (!strcmp ("update", cmd) && optind == argc - 3) {
        j = (const char *)(*(argv+optind));
        attr = (const char *)(*(argv+optind+1));
        jcbstr = (const char *)(*(argv+optind+2));
        rc = handle_update_req (h, strtol (j, NULL, 10), attr, jcbstr, ofn);
    }
    else 
        usage (1);

    flux_close (h);
    log_fini ();

    return (!rc)? 0: 42;
}
コード例 #15
0
ファイル: commit.c プロジェクト: trws/flux-core
void *thread (void *arg)
{
    thd_t *t = arg;
    char *key, *fence_name = NULL;
    int i, flags = 0;
    struct timespec t0;
    uint32_t rank;
    flux_future_t *f;
    flux_kvs_txn_t *txn;

    if (!(t->h = flux_open (NULL, 0))) {
        log_err ("%d: flux_open", t->n);
        goto done;
    }
    if (flux_get_rank (t->h, &rank) < 0) {
        log_err ("%d: flux_get_rank", t->n);
        goto done;
    }
    for (i = 0; i < count; i++) {
        if (!(txn = flux_kvs_txn_create ()))
            log_err_exit ("flux_kvs_txn_create");
        key = xasprintf ("%s.%"PRIu32".%d.%d", prefix, rank, t->n, i);
        if (fopt)
            fence_name = xasprintf ("%s-%d", prefix, i);
        if (sopt)
            monotime (&t0);
        if (flux_kvs_txn_pack (txn, 0, key, "i", 42) < 0)
            log_err_exit ("%s", key);
        if (nopt && (i % nopt_divisor) == 0)
            flags |= FLUX_KVS_NO_MERGE;
        else
            flags = 0;
        if (fopt) {
            if (!(f = flux_kvs_fence (t->h, flags, fence_name,
                                                   fence_nprocs, txn))
                    || flux_future_get (f, NULL) < 0)
                log_err_exit ("flux_kvs_fence");
            flux_future_destroy (f);
        } else {
            if (!(f = flux_kvs_commit (t->h, flags, txn))
                    || flux_future_get (f, NULL) < 0)
                log_err_exit ("flux_kvs_commit");
            flux_future_destroy (f);
        }
        if (sopt && zlist_append (t->perf, ddup (monotime_since (t0))) < 0)
            oom ();
        free (key);
        free (fence_name);
        flux_kvs_txn_destroy (txn);
    }
done:
    if (t->h)
        flux_close (t->h);
    return NULL;
}
コード例 #16
0
ファイル: module.c プロジェクト: surajpkn/flux-core
static void *module_thread (void *arg)
{
    module_t *p = arg;
    assert (p->magic == MODULE_MAGIC);
    sigset_t signal_set;
    int errnum;
    char *uri = xasprintf ("shmem://%s", zuuid_str (p->uuid));
    char **av = NULL;
    char *rankstr = NULL;
    int ac;

    assert (p->zctx);

    /* Connect to broker socket, enable logging, register built-in services
     */
    if (!(p->h = flux_open (uri, 0)))
        err_exit ("flux_open %s", uri);
    if (flux_opt_set (p->h, FLUX_OPT_ZEROMQ_CONTEXT,
                      p->zctx, sizeof (p->zctx)) < 0)
        err_exit ("flux_opt_set ZEROMQ_CONTEXT");

    rankstr = xasprintf ("%u", p->rank);
    if (flux_attr_fake (p->h, "rank", rankstr, FLUX_ATTRFLAG_IMMUTABLE) < 0) {
        err ("%s: error faking rank attribute", p->name);
        goto done;
    }
    flux_log_set_facility (p->h, p->name);
    modservice_register (p->h, p);

    /* Block all signals
     */
    if (sigfillset (&signal_set) < 0)
        err_exit ("%s: sigfillset", p->name);
    if ((errnum = pthread_sigmask (SIG_BLOCK, &signal_set, NULL)) != 0)
        errn_exit (errnum, "pthread_sigmask");

    /* Run the module's main().
     */
    ac = argz_count (p->argz, p->argz_len);
    av = xzmalloc (sizeof (av[0]) * (ac + 1));
    argz_extract (p->argz, p->argz_len, av);
    if (p->main(p->h, ac, av) < 0) {
        err ("%s: mod_main returned error", p->name);
        goto done;
    }
done:
    if (rankstr)
        free (rankstr);
    if (av)
        free (av);
    flux_close (p->h);
    p->h = NULL;
    return NULL;
}
コード例 #17
0
ファイル: transactionmerge.c プロジェクト: trws/flux-core
void *watchthread (void *arg)
{
    thd_t *t = arg;
    watch_count_t wc;
    flux_kvs_txn_t *txn;
    flux_future_t *f;
    flux_reactor_t *r;
    flux_watcher_t *pw = NULL;
    flux_watcher_t *tw = NULL;

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

    /* Make sure key doesn't already exist, initial value may affect
     * test by chance (i.e. initial value = 0, commit 0 and thus no
     * change)
     */
    if (!(txn = flux_kvs_txn_create ()))
        log_err_exit ("flux_kvs_txn_create");
    if (flux_kvs_txn_unlink (txn, 0, key) < 0)
        log_err_exit ("flux_kvs_txn_unlink");
    if (!(f = flux_kvs_commit (t->h, 0, txn)) || flux_future_get (f, NULL) < 0)
        log_err_exit ("flux_kvs_commit");
    flux_future_destroy (f);
    flux_kvs_txn_destroy (txn);

    r = flux_get_reactor (t->h);

    if (flux_kvs_watch (t->h, key, watch_count_cb, t) < 0)
        log_err_exit ("flux_kvs_watch %s", key);

    pw = flux_prepare_watcher_create (r, watch_prepare_cb, NULL);

    wc.t = t;
    wc.lastcount = -1;

    /* So test won't hang if there's a bug */
    tw = flux_timer_watcher_create (r,
                                    WATCH_TIMEOUT,
                                    WATCH_TIMEOUT,
                                    watch_timeout_cb,
                                    &wc);

    flux_watcher_start (pw);
    flux_watcher_start (tw);

    if (flux_reactor_run (r, 0) < 0)
        log_err_exit ("flux_reactor_run");

    flux_watcher_destroy (pw);
    flux_watcher_destroy (tw);
    flux_close (t->h);
    return NULL;
}
コード例 #18
0
ファイル: reactor.c プロジェクト: surajpkn/flux-core
static void leak_msg_handler (void)
{
    flux_t h;
    flux_msg_handler_t *w;

    if (!(h = flux_open ("loop://", 0)))
        exit (1);
    if (!(w = flux_msg_handler_create (h, FLUX_MATCH_ANY, dummy, NULL)))
        exit (1);
    flux_msg_handler_start (w);
    flux_close (h);
}
コード例 #19
0
ファイル: panic.c プロジェクト: flux-framework/flux-core
int main (int argc, char *argv[])
{
    flux_t *h;
    flux_msg_t *msg;
    const char *topic;
    const char *reason;
    int flags;

    plan (NO_PLAN);

    if (!(h = loopback_create (0)))
        BAIL_OUT ("loopback_create failed");

    /* Send request
     */
    ok (flux_panic (h, 0, 0, "fubar") == 0,
        "flux_panic works");

    /* Receive request on the loopback
     */
    msg = flux_recv (h, FLUX_MATCH_ANY, 0);
    ok (msg != NULL,
        "flux_recv received message on loop");
    ok (flux_request_unpack (msg, &topic, "{s:s s:i}",
                             "reason", &reason, "flags", &flags) == 0,
        "flux_request_unpack worked on panic request");
    ok (topic != NULL && !strcmp (topic, "cmb.panic"),
        "topic string is correct");
    ok (!strcmp (reason, "fubar"),
        "reason is correct");
    ok (flags == 0,
        "flags is correct");
    flux_msg_destroy (msg);

    /* invalid arguments
     */
    errno = 0;
    ok (flux_panic (NULL, 0, 0, "foo") < 0 && errno == EINVAL,
        "flux_panic h=NULL fails with EINVAL");
    errno = 0;
    ok (flux_panic (h, 0, 1, "foo") < 0 && errno == EINVAL,
        "flux_panic flags=1 fails with EINVAL");
    errno = 0;
    ok (flux_panic (h, 0, 0, NULL) < 0 && errno == EINVAL,
        "flux_panic reason=NULL fails with EINVAL");

    flux_close (h);

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

    plan (35);

    (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0);
    ok ((h = flux_open ("loop://", FLUX_O_COPROC)) != NULL,
        "opened loop connector");
    if (!h)
        BAIL_OUT ("can't continue without loop handle");
    ok ((reactor = flux_get_reactor (h)) != NULL,
        "obtained reactor");
    if (!reactor)
        BAIL_OUT ("can't continue without reactor");

    flux_fatal_set (h, fatal_err, NULL);
    flux_fatal_error (h, __FUNCTION__, "Foo");
    ok (fatal_tested == true,
        "flux_fatal function is called on fatal error");

    /* create nodeset for last _then test */
    ok ((then_ns = nodeset_create ()) != NULL,
        "nodeset created ok");

    ok (flux_msghandler_addvec (h, htab, htablen, 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
        && flux_send (h, msg, 0) == 0,
        "sent message to initiate test");
    ok (flux_reactor_run (reactor, 0) == 0,
        "reactor completed normally");
    flux_msg_destroy (msg);

    /* Check result of last _then test */
    ok (nodeset_count (then_ns) == 128,
        "then callback worked with correct nodemap");
    nodeset_destroy (then_ns);
    flux_rpc_destroy (then_r);

    flux_close (h);

    done_testing();
    return (0);
}
コード例 #21
0
ファイル: flux-waitjob.c プロジェクト: dongahn/flux-sched
int main (int argc, char *argv[])
{
    flux_t h;
    int ch = 0;
    int64_t jobid = -1;
    char *sfn = NULL;
    char *cfn = NULL;
    wjctx_t *ctx = NULL;

    log_init ("flux-waitjob");
    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 's': /* --sync-start */
                sfn = xstrdup (optarg);
                break;
            case 'c': /* --sync-complete */
                cfn = xstrdup (optarg);
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind == argc)
        usage ();

    jobid = strtol (argv[optind], NULL, 10);
    if (jobid <= 0)
        log_err_exit ("jobid must be a positive number");
    else if (!(h = flux_open  (NULL, 0)))
        log_err_exit ("flux_open");

    ctx = getctx (h);
    if (sfn)
        ctx->start = sfn;
    if (cfn)
        ctx->complete = cfn;
    ctx->jobid = jobid;

    flux_log_set_appname (h, "waitjob");
    wait_job_complete (h);

    flux_close (h);
    log_fini ();

    return 0;
}
コード例 #22
0
ファイル: flux-up.c プロジェクト: dinesh121991/flux-core
int main (int argc, char *argv[])
{
    flux_t h;
    int ch;
    bool uopt = false;
    bool dopt = false;
    fmt_t fmt = FMT_RANGED;
    ns_t *ns;

    log_init ("flux-up");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'c': /* --comma */
                fmt = FMT_COMMA;
                break;
            case 'n': /* --newline */
                fmt = FMT_NEWLINE;
                break;
            case 'u': /* --up */
                uopt = true;
                break;
            case 'd': /* --down */
                dopt = true;
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind != argc)
        usage ();

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

    if (!(ns = ns_fromkvs (h)))
        ns = ns_guess (h);
    if (dopt)
        ns_print_down (ns, fmt);
    else if (uopt)
        ns_print_up (ns, fmt);
    else
        ns_print_all (ns, fmt);
    ns_destroy (ns);

    flux_close (h);
    log_fini ();
    return 0;
}
コード例 #23
0
ファイル: trpc.c プロジェクト: dinesh121991/flux-core
int main (int argc, char **argv)
{
    flux_t h;
    flux_rpc_t *rpc;

    if (!(h = flux_open (NULL, 0)))
        err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, "cmb.info", NULL, FLUX_NODEID_ANY, 0)))
        err_exit ("flux_rpc");
    get_rank (rpc);
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
コード例 #24
0
ファイル: flux-logger.c プロジェクト: tpatki/flux-core
int main (int argc, char *argv[])
{
    flux_t h;
    int ch;
    char *message = NULL;
    size_t len = 0;
    char *priority = "user.notice";
    int level;
    char *facility;
    int e;

    log_init ("flux-logger");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 'p': /* --priority facility.level */
                priority = optarg;
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind == argc)
        usage ();

    if ((e = argz_create (argv + optind, &message, &len)) != 0)
        errn_exit (e, "argz_create");
    argz_stringify (message, len, ' ');

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

    if (parse_logstr (priority, &level, &facility) < 0)
        msg_exit ("bad priority argument");
    flux_log_set_facility (h, facility);
    if (flux_log (h, level, "%s", message) < 0)
        err_exit ("flux_log");

    flux_close (h);

    free (message);
    free (facility);
    log_fini ();
    return 0;
}
コード例 #25
0
ファイル: tsend.c プロジェクト: cigolabs/flux-core
int main (int argc, char **argv)
{
    flux_t h;
    flux_msg_t *msg;

    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");
    if (!(msg = flux_event_encode ("snack.bar.closing", NULL)))
        log_err_exit ("flux_event_encode");
    if (flux_send (h, msg, 0) < 0)
        log_err_exit ("flux_send");
    flux_msg_destroy (msg);
    flux_close (h);
    return (0);
}
コード例 #26
0
ファイル: flux-logger.c プロジェクト: cigolabs/flux-core
int main (int argc, char *argv[])
{
    flux_t h;
    int ch;
    char *message = NULL;
    size_t len = 0;
    int severity = LOG_NOTICE;
    char *appname = "logger";
    int e;

    log_init ("flux-logger");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'h': /* --help */
                usage ();
                break;
            case 's': /* --severity LEVEL */
                if ((severity = stdlog_string_to_severity (optarg)) < 0)
                    log_msg_exit ("invalid severity: Use emerg|alert|crit|err|warning|notice|info|debug");
                break;
            case 'n': /* --appname NAME */
                appname = optarg;
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind == argc)
        usage ();

    if ((e = argz_create (argv + optind, &message, &len)) != 0)
        log_errn_exit (e, "argz_create");
    argz_stringify (message, len, ' ');

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

    flux_log_set_appname (h, appname);
    flux_log (h, severity, "%s", message);

    flux_close (h);

    free (message);
    log_fini ();
    return 0;
}
コード例 #27
0
ファイル: attr.c プロジェクト: tpatki/flux-core
static int cmd_getattr (optparse_t *p, int ac, char *av[])
{
    flux_t h = NULL;
    const char *val;
    int n, flags;

    n = optparse_optind (p);
    if (n != ac - 1)
        optparse_fatal_usage (p, 1, NULL);

    h = builtin_get_flux_handle (p);
    if (!(val = flux_attr_get (h, av[n], &flags)))
        err_exit ("%s", av[n]);
    printf ("%s\n", val);
    flux_close (h);
    return (0);
}
コード例 #28
0
ファイル: watch.c プロジェクト: SteVwonder/flux-core
void test_simulwatch (int argc, char **argv)
{
    int i, max;
    const char *key;
    flux_t *h;
    int start, fin, count = 0;
    int exit_rc = 0;

    if (argc != 2) {
        fprintf (stderr, "Usage: simulwatch key count\n");
        exit (1);
    }
    key = argv[0];
    max = strtoul (argv[1], NULL, 10);
    if (!(h = flux_open (NULL, 0)))
        log_err_exit ("flux_open");
    if (get_watch_stats (h, &start) < 0)
        log_err_exit ("kvs.stats.get");
    for (i = 0; i < max; i++) {
        if (kvs_watch_int (h, key, simulwatch_cb, &count) < 0)
            log_err_exit ("kvs_watch_int[%d] %s", i, key);
        if ((i % 4096 == 0 && i > 0 && i + 4096 < max))
            log_msg ("%d of %d watchers registered (continuing)", i, max);
    }
    log_msg ("%d of %d watchers registered", i, max);
    if (count != max)
        exit_rc = 1;
    log_msg ("callback called %d of %d times", count, max);
    if (get_watch_stats (h, &fin) < 0)
        log_err_exit ("kvs.stats.get");
    if (fin - start != count)
        exit_rc = 1;
    log_msg ("%d of %d watchers running", fin - start, count);
    if (kvs_unwatch (h, key) < 0)
        log_err_exit ("kvs.unwatch");
    if (get_watch_stats (h, &fin) < 0)
        log_err_exit ("kvs.stats.get");
    if (fin - start != 0)
        exit_rc = 1;
    log_msg ("%d of %d watchers running after unwatch",
             fin - start, count);
    flux_close (h);
    if (exit_rc != 0)
        exit (exit_rc);
}
コード例 #29
0
ファイル: heaptrace.c プロジェクト: SteVwonder/flux-core
static int internal_heaptrace_stop (optparse_t *p, int ac, char *av[])
{
    flux_t *h;
    flux_rpc_t *rpc;

    if (optparse_optind (p) != ac) {
        optparse_print_usage (p);
        exit (1);
    }
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, "cmb.heaptrace.stop", NULL, FLUX_NODEID_ANY, 0))
            || flux_rpc_get (rpc, NULL) < 0)
        log_err_exit ("cmb.heaptrace.stop");
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
コード例 #30
0
ファイル: attr.c プロジェクト: tpatki/flux-core
static int cmd_lsattr (optparse_t *p, int ac, char *av[])
{
    const char *name, *val;
    flux_t h;
    if (optparse_optind (p) != ac)
        optparse_fatal_usage (p, 1, NULL);
    h = builtin_get_flux_handle (p);
    name = flux_attr_first (h);
    while (name) {
        if (optparse_hasopt (p, "values")) {
            val = flux_attr_get (h, name, NULL);
            printf ("%-40s%s\n", name, val ? val : "-");
        } else {
            printf ("%s\n", name);
        }
        name = flux_attr_next (h);
    }
    flux_close (h);
    return (0);
}