From 7e00626b0dcd04b4f38d7cb1a3288ba6740ed9b6 Mon Sep 17 00:00:00 2001 From: Aravinda VK Date: Tue, 19 Jul 2016 17:28:14 +0530 Subject: eventsapi: Volume Set and Reset Events Example of published data for Volume Set: { "nodeid": NODEID, "ts": TIMESTAMP, "event": "VOLUME_SET", "message": { "name": VOLUME_NAME, "options": [[KEY1, VALUE1], [KEY2, VALUE2],..] } } Example of published data for Volume Reset: { "nodeid": NODEID, "ts": TIMESTAMP, "event": "VOLUME_RESET", "message": { "name": VOLUME_NAME, "option": KEY } } BUG: 1358671 Change-Id: If30cc95396459b2a9993b3412ee6d05d27f6a86a Signed-off-by: Aravinda VK Reviewed-on: http://review.gluster.org/14973 NetBSD-regression: NetBSD Build System Smoke: Gluster Build System CentOS-regression: Gluster Build System Reviewed-by: Atin Mukherjee --- cli/src/cli-cmd-volume.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'cli') diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 6d44095d75..af815da51e 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -665,6 +665,10 @@ cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, call_frame_t *frame = NULL; dict_t *options = NULL; cli_local_t *local = NULL; +#if (USE_EVENTS) + int ret1 = -1; + char *tmp_opt = NULL; +#endif proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RESET_VOLUME]; @@ -692,6 +696,18 @@ out: cli_out ("Volume reset failed"); } +#if (USE_EVENTS) + if (ret == 0) { + ret1 = dict_get_str (options, "key", &tmp_opt); + if (ret1) + tmp_opt = ""; + + gf_event (EVENT_VOLUME_RESET, "name=%s;option=%s", + (char *)words[2], + tmp_opt); + } +#endif + CLI_STACK_DESTROY (frame); return ret; @@ -758,6 +774,15 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word, cli_local_t *local = NULL; char *op_errstr = NULL; +#if (USE_EVENTS) + int ret1 = -1; + int i = 1; + char dict_key[50] = {0,}; + char *tmp_opt = NULL; + char *opts_str = NULL; + int num_options = 0; +#endif + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SET_VOLUME]; frame = create_frame (THIS, THIS->ctx->pool); @@ -790,6 +815,43 @@ out: cli_out ("Volume set failed"); } +#if (USE_EVENTS) + if (ret == 0) { + ret1 = dict_get_int32 (options, "count", &num_options); + if (ret1) + num_options = 0; + else + num_options = num_options/2; + + /* Initialize opts_str */ + opts_str = gf_strdup (""); + + /* Prepare String in format options=KEY1,VALUE1,KEY2,VALUE2 */ + for (i = 1; i <= num_options; i++) { + sprintf (dict_key, "key%d", i); + ret1 = dict_get_str (options, dict_key, &tmp_opt); + if (ret1) + tmp_opt = ""; + + gf_asprintf (&opts_str, "%s,%s", opts_str, tmp_opt); + + sprintf (dict_key, "value%d", i); + ret1 = dict_get_str (options, dict_key, &tmp_opt); + if (ret1) + tmp_opt = ""; + + gf_asprintf (&opts_str, "%s,%s", opts_str, tmp_opt); + } + + gf_event (EVENT_VOLUME_SET, "name=%s;options=%s", + (char *)words[2], + opts_str); + + /* Allocated by gf_strdup and gf_asprintf */ + GF_FREE (opts_str); + } +#endif + CLI_STACK_DESTROY (frame); return ret; -- cgit