|
|
3604df |
From b39e5538a174b0fd25f6551ed291b9e0a05ca195 Mon Sep 17 00:00:00 2001
|
|
|
3604df |
From: Aravinda VK <avishwan@redhat.com>
|
|
|
3604df |
Date: Tue, 19 Jul 2016 17:28:14 +0530
|
|
|
3604df |
Subject: [PATCH 31/86] eventsapi: Volume Set and Reset Events
|
|
|
3604df |
|
|
|
3604df |
Example of published data for Volume Set:
|
|
|
3604df |
|
|
|
3604df |
{
|
|
|
3604df |
"nodeid": NODEID,
|
|
|
3604df |
"ts": TIMESTAMP,
|
|
|
3604df |
"event": "VOLUME_SET",
|
|
|
3604df |
"message": {
|
|
|
3604df |
"name": VOLUME_NAME,
|
|
|
3604df |
"options": [[KEY1, VALUE1], [KEY2, VALUE2],..]
|
|
|
3604df |
}
|
|
|
3604df |
}
|
|
|
3604df |
|
|
|
3604df |
Example of published data for Volume Reset:
|
|
|
3604df |
|
|
|
3604df |
{
|
|
|
3604df |
"nodeid": NODEID,
|
|
|
3604df |
"ts": TIMESTAMP,
|
|
|
3604df |
"event": "VOLUME_RESET",
|
|
|
3604df |
"message": {
|
|
|
3604df |
"name": VOLUME_NAME,
|
|
|
3604df |
"option": KEY
|
|
|
3604df |
}
|
|
|
3604df |
}
|
|
|
3604df |
|
|
|
3604df |
> Reviewed-on: http://review.gluster.org/14973
|
|
|
3604df |
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
|
|
|
3604df |
> Smoke: Gluster Build System <jenkins@build.gluster.org>
|
|
|
3604df |
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
|
|
|
3604df |
> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
|
|
|
3604df |
|
|
|
3604df |
BUG: 1351589
|
|
|
3604df |
Change-Id: If30cc95396459b2a9993b3412ee6d05d27f6a86a
|
|
|
3604df |
Signed-off-by: Aravinda VK <avishwan@redhat.com>
|
|
|
3604df |
|
|
|
3604df |
Reviewed-on: https://code.engineering.redhat.com/gerrit/84737
|
|
|
3604df |
Reviewed-by: Milind Changire <mchangir@redhat.com>
|
|
|
3604df |
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
|
|
|
3604df |
---
|
|
|
3604df |
cli/src/cli-cmd-volume.c | 62 +++++++++++++++++++++++++++++++++++++++++
|
|
|
3604df |
events/eventskeygen.py | 2 +
|
|
|
3604df |
events/src/eventtypes.py | 2 +
|
|
|
3604df |
events/src/handlers.py | 19 ++++++++++++
|
|
|
3604df |
libglusterfs/src/eventtypes.h | 2 +
|
|
|
3604df |
5 files changed, 87 insertions(+), 0 deletions(-)
|
|
|
3604df |
|
|
|
3604df |
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
|
|
|
3604df |
index 5296093..4202622 100644
|
|
|
3604df |
--- a/cli/src/cli-cmd-volume.c
|
|
|
3604df |
+++ b/cli/src/cli-cmd-volume.c
|
|
|
3604df |
@@ -665,6 +665,10 @@ cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word,
|
|
|
3604df |
call_frame_t *frame = NULL;
|
|
|
3604df |
dict_t *options = NULL;
|
|
|
3604df |
cli_local_t *local = NULL;
|
|
|
3604df |
+#if (USE_EVENTS)
|
|
|
3604df |
+ int ret1 = -1;
|
|
|
3604df |
+ char *tmp_opt = NULL;
|
|
|
3604df |
+#endif
|
|
|
3604df |
|
|
|
3604df |
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RESET_VOLUME];
|
|
|
3604df |
|
|
|
3604df |
@@ -692,6 +696,18 @@ out:
|
|
|
3604df |
cli_out ("Volume reset failed");
|
|
|
3604df |
}
|
|
|
3604df |
|
|
|
3604df |
+#if (USE_EVENTS)
|
|
|
3604df |
+ if (ret == 0) {
|
|
|
3604df |
+ ret1 = dict_get_str (options, "key", &tmp_opt);
|
|
|
3604df |
+ if (ret1)
|
|
|
3604df |
+ tmp_opt = "";
|
|
|
3604df |
+
|
|
|
3604df |
+ gf_event (EVENT_VOLUME_RESET, "name=%s;option=%s",
|
|
|
3604df |
+ (char *)words[2],
|
|
|
3604df |
+ tmp_opt);
|
|
|
3604df |
+ }
|
|
|
3604df |
+#endif
|
|
|
3604df |
+
|
|
|
3604df |
CLI_STACK_DESTROY (frame);
|
|
|
3604df |
|
|
|
3604df |
return ret;
|
|
|
3604df |
@@ -758,6 +774,15 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word,
|
|
|
3604df |
cli_local_t *local = NULL;
|
|
|
3604df |
char *op_errstr = NULL;
|
|
|
3604df |
|
|
|
3604df |
+#if (USE_EVENTS)
|
|
|
3604df |
+ int ret1 = -1;
|
|
|
3604df |
+ int i = 1;
|
|
|
3604df |
+ char dict_key[50] = {0,};
|
|
|
3604df |
+ char *tmp_opt = NULL;
|
|
|
3604df |
+ char *opts_str = NULL;
|
|
|
3604df |
+ int num_options = 0;
|
|
|
3604df |
+#endif
|
|
|
3604df |
+
|
|
|
3604df |
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SET_VOLUME];
|
|
|
3604df |
|
|
|
3604df |
frame = create_frame (THIS, THIS->ctx->pool);
|
|
|
3604df |
@@ -790,6 +815,43 @@ out:
|
|
|
3604df |
cli_out ("Volume set failed");
|
|
|
3604df |
}
|
|
|
3604df |
|
|
|
3604df |
+#if (USE_EVENTS)
|
|
|
3604df |
+ if (ret == 0) {
|
|
|
3604df |
+ ret1 = dict_get_int32 (options, "count", &num_options);
|
|
|
3604df |
+ if (ret1)
|
|
|
3604df |
+ num_options = 0;
|
|
|
3604df |
+ else
|
|
|
3604df |
+ num_options = num_options/2;
|
|
|
3604df |
+
|
|
|
3604df |
+ /* Initialize opts_str */
|
|
|
3604df |
+ opts_str = gf_strdup ("");
|
|
|
3604df |
+
|
|
|
3604df |
+ /* Prepare String in format options=KEY1,VALUE1,KEY2,VALUE2 */
|
|
|
3604df |
+ for (i = 1; i <= num_options; i++) {
|
|
|
3604df |
+ sprintf (dict_key, "key%d", i);
|
|
|
3604df |
+ ret1 = dict_get_str (options, dict_key, &tmp_opt);
|
|
|
3604df |
+ if (ret1)
|
|
|
3604df |
+ tmp_opt = "";
|
|
|
3604df |
+
|
|
|
3604df |
+ gf_asprintf (&opts_str, "%s,%s", opts_str, tmp_opt);
|
|
|
3604df |
+
|
|
|
3604df |
+ sprintf (dict_key, "value%d", i);
|
|
|
3604df |
+ ret1 = dict_get_str (options, dict_key, &tmp_opt);
|
|
|
3604df |
+ if (ret1)
|
|
|
3604df |
+ tmp_opt = "";
|
|
|
3604df |
+
|
|
|
3604df |
+ gf_asprintf (&opts_str, "%s,%s", opts_str, tmp_opt);
|
|
|
3604df |
+ }
|
|
|
3604df |
+
|
|
|
3604df |
+ gf_event (EVENT_VOLUME_SET, "name=%s;options=%s",
|
|
|
3604df |
+ (char *)words[2],
|
|
|
3604df |
+ opts_str);
|
|
|
3604df |
+
|
|
|
3604df |
+ /* Allocated by gf_strdup and gf_asprintf */
|
|
|
3604df |
+ GF_FREE (opts_str);
|
|
|
3604df |
+ }
|
|
|
3604df |
+#endif
|
|
|
3604df |
+
|
|
|
3604df |
CLI_STACK_DESTROY (frame);
|
|
|
3604df |
|
|
|
3604df |
return ret;
|
|
|
3604df |
diff --git a/events/eventskeygen.py b/events/eventskeygen.py
|
|
|
3604df |
index 656a7dc..f9bdb9f 100644
|
|
|
3604df |
--- a/events/eventskeygen.py
|
|
|
3604df |
+++ b/events/eventskeygen.py
|
|
|
3604df |
@@ -25,6 +25,8 @@ keys = (
|
|
|
3604df |
"EVENT_VOLUME_START",
|
|
|
3604df |
"EVENT_VOLUME_STOP",
|
|
|
3604df |
"EVENT_VOLUME_DELETE",
|
|
|
3604df |
+ "EVENT_VOLUME_SET",
|
|
|
3604df |
+ "EVENT_VOLUME_RESET",
|
|
|
3604df |
)
|
|
|
3604df |
|
|
|
3604df |
LAST_EVENT = "EVENT_LAST"
|
|
|
3604df |
diff --git a/events/src/eventtypes.py b/events/src/eventtypes.py
|
|
|
3604df |
index 4812e65..b09e5bc 100644
|
|
|
3604df |
--- a/events/src/eventtypes.py
|
|
|
3604df |
+++ b/events/src/eventtypes.py
|
|
|
3604df |
@@ -6,4 +6,6 @@ all_events = [
|
|
|
3604df |
"EVENT_VOLUME_START",
|
|
|
3604df |
"EVENT_VOLUME_STOP",
|
|
|
3604df |
"EVENT_VOLUME_DELETE",
|
|
|
3604df |
+ "EVENT_VOLUME_SET",
|
|
|
3604df |
+ "EVENT_VOLUME_RESET",
|
|
|
3604df |
]
|
|
|
3604df |
diff --git a/events/src/handlers.py b/events/src/handlers.py
|
|
|
3604df |
index 9b756a9..21d3e83 100644
|
|
|
3604df |
--- a/events/src/handlers.py
|
|
|
3604df |
+++ b/events/src/handlers.py
|
|
|
3604df |
@@ -19,3 +19,22 @@ def generic_handler(ts, key, data):
|
|
|
3604df |
Ex: handle_event_volume_create(ts, key, data)
|
|
|
3604df |
"""
|
|
|
3604df |
utils.publish(ts, key, data)
|
|
|
3604df |
+
|
|
|
3604df |
+
|
|
|
3604df |
+def handle_event_volume_set(ts, key, data):
|
|
|
3604df |
+ """
|
|
|
3604df |
+ Recieved data will have all the options as one string, split into
|
|
|
3604df |
+ list of options. "key1,value1,key2,value2" into
|
|
|
3604df |
+ [[key1, value1], [key2, value2]]
|
|
|
3604df |
+ """
|
|
|
3604df |
+ opts = data.get("options", "").strip(",").split(",")
|
|
|
3604df |
+ data["options"] = []
|
|
|
3604df |
+ for i, opt in enumerate(opts):
|
|
|
3604df |
+ if i % 2 == 0:
|
|
|
3604df |
+ # Add new array with key
|
|
|
3604df |
+ data["options"].append([opt])
|
|
|
3604df |
+ else:
|
|
|
3604df |
+ # Add to the last added array
|
|
|
3604df |
+ data["options"][-1].append(opt)
|
|
|
3604df |
+
|
|
|
3604df |
+ utils.publish(ts, key, data)
|
|
|
3604df |
diff --git a/libglusterfs/src/eventtypes.h b/libglusterfs/src/eventtypes.h
|
|
|
3604df |
index 874f8cc..20c4b02 100644
|
|
|
3604df |
--- a/libglusterfs/src/eventtypes.h
|
|
|
3604df |
+++ b/libglusterfs/src/eventtypes.h
|
|
|
3604df |
@@ -16,6 +16,8 @@ typedef enum {
|
|
|
3604df |
EVENT_VOLUME_START,
|
|
|
3604df |
EVENT_VOLUME_STOP,
|
|
|
3604df |
EVENT_VOLUME_DELETE,
|
|
|
3604df |
+ EVENT_VOLUME_SET,
|
|
|
3604df |
+ EVENT_VOLUME_RESET,
|
|
|
3604df |
EVENT_LAST
|
|
|
3604df |
} eventtypes_t;
|
|
|
3604df |
|
|
|
3604df |
--
|
|
|
3604df |
1.7.1
|
|
|
3604df |
|