From 73effb9f22fad8ee6084521c62566b5b4a46792c Mon Sep 17 00:00:00 2001
From: Aravinda VK <avishwan@redhat.com>
Date: Wed, 3 Aug 2016 12:16:43 +0530
Subject: [PATCH 33/86] eventsapi: Geo-replication User driven events
Following Geo-replication Events are added
GEOREP_CREATE/GEOREP_START/GEOREP_STOP/GEOREP_DELETE/GEOREP_PAUSE/GEOREP_RESUME
{
"nodeid": NODEID,
"ts": TIMESTAMP,
"event": EVENT_TYPE,
"message": {
"master": MASTER_VOLUME_NAME,
"slave": SLAVE_DETAILS
}
}
GEOREP_CONFIG_SET
{
"nodeid": NODEID,
"ts": TIMESTAMP,
"event": GEOREP_CONFIG_SET,
"message": {
"master": MASTER_VOLUME_NAME,
"slave": SLAVE_DETAILS,
"option": OPTION_NAME,
"value": OPTION_VALUE
}
}
GEOREP_CONFIG_RESET
{
"nodeid": NODEID,
"ts": TIMESTAMP,
"event": GEOREP_CONFIG_RESET,
"message": {
"master": MASTER_VOLUME_NAME,
"slave": SLAVE_DETAILS,
"option": OPTION_NAME
}
}
> Reviewed-on: http://review.gluster.org/15077
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> Reviewed-by: Kotresh HR <khiremat@redhat.com>
BUG: 1361118
Change-Id: I78c81aabd022ebb042b3eae3c6b5a284a6c2801f
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/84739
Reviewed-by: Milind Changire <mchangir@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
cli/src/cli-cmd-volume.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++
events/eventskeygen.py | 9 +++
2 files changed, 134 insertions(+), 0 deletions(-)
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 4202622..7e53514 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -1958,6 +1958,14 @@ cli_cmd_volume_gsync_set_cbk (struct cli_state *state, struct cli_cmd_word *word
rpc_clnt_procedure_t *proc = NULL;
call_frame_t *frame = NULL;
cli_local_t *local = NULL;
+#if (USE_EVENTS)
+ int ret1 = -1;
+ int cmd_type = -1;
+ int tmpi = 0;
+ char *tmp = NULL;
+ char *events_str = NULL;
+ int event_type = -1;
+#endif
proc = &cli_rpc_prog->proctable [GLUSTER_CLI_GSYNC_SET];
@@ -1983,6 +1991,123 @@ out:
if (ret && parse_err == 0)
cli_out (GEOREP" command failed");
+#if (USE_EVENTS)
+ if (ret == 0) {
+ events_str = gf_strdup ("");
+
+ /* Type of Geo-rep Action - Create, Start etc */
+ ret1 = dict_get_int32 (options, "type", &cmd_type);
+ if (ret1)
+ cmd_type = -1;
+
+ /* Only capture Events for modification commands */
+ switch (cmd_type) {
+ case GF_GSYNC_OPTION_TYPE_CREATE:
+ event_type = EVENT_GEOREP_CREATE;
+ break;
+ case GF_GSYNC_OPTION_TYPE_START:
+ event_type = EVENT_GEOREP_START;
+ break;
+ case GF_GSYNC_OPTION_TYPE_STOP:
+ event_type = EVENT_GEOREP_STOP;
+ break;
+ case GF_GSYNC_OPTION_TYPE_PAUSE:
+ event_type = EVENT_GEOREP_PAUSE;
+ break;
+ case GF_GSYNC_OPTION_TYPE_RESUME:
+ event_type = EVENT_GEOREP_RESUME;
+ break;
+ case GF_GSYNC_OPTION_TYPE_DELETE:
+ event_type = EVENT_GEOREP_DELETE;
+ break;
+ case GF_GSYNC_OPTION_TYPE_CONFIG:
+ ret1 = dict_get_str (options, "subop", &tmp);
+ if (ret1)
+ tmp = "";
+
+ /* For Config Set additionally capture key and value */
+ /* For Config Reset capture key */
+ if (strcmp (tmp, "set") == 0) {
+ event_type = EVENT_GEOREP_CONFIG_SET;
+
+ ret1 = dict_get_str (options, "op_name", &tmp);
+ if (ret1)
+ tmp = "";
+
+ gf_asprintf (&events_str, "%soption=%s;",
+ events_str, tmp);
+
+ ret1 = dict_get_str (options, "op_value", &tmp);
+ if (ret1)
+ tmp = "";
+
+ gf_asprintf (&events_str, "%svalue=%s;",
+ events_str, tmp);
+ } else if (strcmp (tmp, "del") == 0) {
+ event_type = EVENT_GEOREP_CONFIG_RESET;
+
+ ret1 = dict_get_str (options, "op_name", &tmp);
+ if (ret1)
+ tmp = "";
+
+ gf_asprintf (&events_str, "%soption=%s;",
+ events_str, tmp);
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (event_type > -1) {
+ /* Capture all optional arguments used */
+ ret1 = dict_get_int32 (options, "force", &tmpi);
+ if (ret1 == 0)
+ gf_asprintf (&events_str, "%sforce=%d;",
+ events_str, tmpi);
+
+ ret1 = dict_get_int32 (options, "push_pem", &tmpi);
+ if (ret1 == 0)
+ gf_asprintf (&events_str, "%spush_pem=%d;",
+ events_str, tmpi);
+
+ ret1 = dict_get_int32 (options, "no_verify", &tmpi);
+ if (ret1 == 0)
+ gf_asprintf (&events_str, "%sno_verify=%d;",
+ events_str, tmpi);
+
+ ret1 = dict_get_int32 (options, "ssh_port", &tmpi);
+ if (ret1 == 0)
+ gf_asprintf (&events_str, "%sssh_port=%d;",
+ events_str, tmpi);
+
+ ret1 = dict_get_int32 (options, "reset-sync-time",
+ &tmpi);
+ if (ret1 == 0)
+ gf_asprintf (&events_str,
+ "%sreset_sync_time=%d;",
+ events_str, tmpi);
+
+ /* Capture Master and Slave Info */
+ ret1 = dict_get_str (options, "master", &tmp);
+ if (ret1)
+ tmp = "";
+ gf_asprintf (&events_str, "%smaster=%s;",
+ events_str, tmp);
+
+ ret1 = dict_get_str (options, "slave", &tmp);
+ if (ret1)
+ tmp = "";
+ gf_asprintf (&events_str, "%sslave=%s",
+ events_str, tmp);
+
+ gf_event (event_type, "%s", events_str);
+ }
+
+ /* Allocated by gf_strdup and gf_asprintf */
+ GF_FREE (events_str);
+ }
+#endif
+
CLI_STACK_DESTROY (frame);
return ret;
diff --git a/events/eventskeygen.py b/events/eventskeygen.py
index 5bb0319..bccb91a 100644
--- a/events/eventskeygen.py
+++ b/events/eventskeygen.py
@@ -30,6 +30,15 @@ keys = (
"EVENT_VOLUME_DELETE",
"EVENT_VOLUME_SET",
"EVENT_VOLUME_RESET",
+
+ "EVENT_GEOREP_CREATE",
+ "EVENT_GEOREP_START",
+ "EVENT_GEOREP_STOP",
+ "EVENT_GEOREP_PAUSE",
+ "EVENT_GEOREP_RESUME",
+ "EVENT_GEOREP_DELETE",
+ "EVENT_GEOREP_CONFIG_SET",
+ "EVENT_GEOREP_CONFIG_RESET",
)
LAST_EVENT = "EVENT_LAST"
--
1.7.1