static void send_create_event (flux_t h, int64_t id, char *topic) { flux_msg_t *msg; char *json = NULL; if (asprintf (&json, "{\"lwj\":%ld}", id) < 0) { errno = ENOMEM; flux_log_error (h, "failed to create state change event"); goto out; } if ((msg = flux_event_encode (topic, json)) == NULL) { flux_log_error (h, "failed to create state change event"); goto out; } if (flux_send (h, msg, 0) < 0) flux_log_error (h, "reserved event failed"); flux_msg_destroy (msg); /* Workaround -- wait for our own event to be published with a * blocking recv. XXX: Remove when publish is synchronous. */ wait_for_event (h, id, topic); out: free (json); }
static int send_state_event (flux_t h, job_state_t st, int64_t j) { flux_msg_t *msg; char *json = NULL; char *topic = NULL; int rc = -1; if ((asprintf (&json, "{\"lwj\":%"PRId64"}", j) < 0) || (asprintf (&topic, "jsc.state.%s", jsc_job_num2state (st)) < 0)) { errno = ENOMEM; flux_log_error (h, "create state change event: %s", jsc_job_num2state (st)); goto done; } if ((msg = flux_event_encode (topic, json)) == NULL) { flux_log_error (h, "flux_event_encode"); goto done; } if (flux_send (h, msg, 0) < 0) flux_log_error (h, "flux_send event"); flux_msg_destroy (msg); rc = 0; done: free (topic); free (json); return rc; }
void cmd_dropcache_all (flux_t h, int argc, char **argv) { if (argc != 0) msg_exit ("dropcache-all: takes no arguments"); flux_msg_t *msg = flux_event_encode ("kvs.dropcache", NULL); if (!msg || flux_send (h, msg, 0) < 0) err_exit ("flux_send"); flux_msg_destroy (msg); }
int flux_recover_all (flux_t h) { zmsg_t *zmsg = flux_event_encode ("live.recover", NULL); if (!zmsg) return -1; int rc = flux_sendmsg (h, &zmsg); zmsg_destroy (&zmsg); return rc; }
flux_msg_t *flux_heartbeat_encode (int epoch) { flux_msg_t *msg; JSON o = Jnew (); Jadd_int (o, "epoch", epoch); msg = flux_event_encode ("hb", Jtostr (o)); Jput (o); return msg; }
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); }
flux_msg_t *shutdown_vencode (double grace, int exitcode, int rank, const char *fmt, va_list ap) { flux_msg_t *msg; JSON out = Jnew (); char reason[REASON_MAX]; vsnprintf (reason, sizeof (reason), fmt, ap); Jadd_str (out, "reason", reason); Jadd_double (out, "grace", grace); Jadd_int (out, "rank", rank); Jadd_int (out, "exitcode", exitcode); msg = flux_event_encode ("shutdown", Jtostr (out)); Jput (out); return msg; }
static int exit_event_send (flux_t *h, const char *name, int errnum) { json_object *o = Jnew (); flux_msg_t *msg = NULL; int rc = -1; Jadd_str (o, "name", name); Jadd_int (o, "errnum", errnum); if (!(msg = flux_event_encode ("barrier.exit", Jtostr (o)))) goto done; if (flux_send (h, msg, 0) < 0) goto done; rc = 0; done: Jput (o); flux_msg_destroy (msg); return rc; }
static int exit_event_send (flux_t h, const char *name, int errnum) { JSON o = Jnew (); zmsg_t *zmsg = NULL; int rc = -1; Jadd_str (o, "name", name); Jadd_int (o, "errnum", errnum); if (!(zmsg = flux_event_encode ("barrier.exit", Jtostr (o)))) goto done; if (flux_sendmsg (h, &zmsg) < 0) goto done; rc = 0; done: Jput (o); zmsg_destroy (&zmsg); return rc; }
void *thread (void *arg) { flux_msg_t *msg; flux_sec_t *sec; int n; if (!(sec = flux_sec_create (sec_typemask, NULL))) log_err_exit ("C: flux_sec_create"); if (flux_sec_comms_init (sec) < 0) log_err_exit ("C: flux_sec_comms_init: %s", flux_sec_errstr (sec)); if (!(msg = flux_event_encode ("foo.topic", "{\"foo\":42}"))) log_err_exit ("C: flux_event_encode"); if ((n = flux_msg_frames (msg)) != 4) log_err_exit ("C: expected 4 frames, got %d", n); if (flux_msg_sendzsock_munge (cs, msg, sec) < 0) log_err_exit ("C: flux_msg_sendzsock_munge"); flux_msg_destroy (msg); flux_sec_destroy (sec); return NULL; }