Skip to content

Commit

Permalink
events/dht: dht cli events
Browse files Browse the repository at this point in the history
Adding events for add/remove brick and rebalance
from the cli.

Change-Id: I4e07cb7224e1b63a2926db055f87a02220c5d043
BUG: 1371874
Signed-off-by: N Balachandran <nbalacha@redhat.com>
Reviewed-on: http://review.gluster.org/15500
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Smoke: Gluster Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
  • Loading branch information
N Balachandran authored and Atin Mukherjee committed Sep 15, 2016
1 parent a046e4d commit 957e400
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 2 deletions.
170 changes: 168 additions & 2 deletions cli/src/cli-cmd-volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word,
int sent = 0;
int parse_error = 0;
cli_local_t *local = NULL;
#if (USE_EVENTS)
eventtypes_t event = EVENT_LAST;
#endif

#ifdef GF_SOLARIS_HOST_OS
cli_out ("Command not supported on Solaris");
goto out;
Expand Down Expand Up @@ -638,6 +642,19 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word,
cli_cmd_sent_status_get (&sent);
if ((sent == 0) && (parse_error == 0))
cli_out ("Volume rebalance failed");
} else {

#if (USE_EVENTS)
if (!(strcmp (words[wordcount-1], "start")) ||
!(strcmp (words[wordcount-1], "force"))) {
event = EVENT_VOLUME_REBALANCE_START;
} else if (!strcmp (words[wordcount-1], "stop")) {
event = EVENT_VOLUME_REBALANCE_STOP;
}

if (event != EVENT_LAST)
gf_event (event, "volume=%s", (char *)words[2]);
#endif
}

CLI_STACK_DESTROY (frame);
Expand Down Expand Up @@ -849,6 +866,115 @@ cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word,

}

static
int
cli_event_remove_brick_str (dict_t *options, char **event_str,
eventtypes_t *event)
{
int ret = -1;
char *bricklist = NULL;
char *brick = NULL;
char *volname = NULL;
char key[256] = {0,};
const char *eventstrformat = "volume=%s;bricks=%s";
int32_t command = 0;
int32_t i = 1;
int32_t count = 0;
int32_t eventstrlen = 1;
char *tmp_ptr = NULL;

if (!options || !event_str || !event)
goto out;

ret = dict_get_str (options, "volname", &volname);
if (ret || !volname) {
gf_log ("cli", GF_LOG_ERROR, "Failed to fetch volname");
ret = -1;
goto out;
}
/* Get the list of bricks for the event */
ret = dict_get_int32 (options, "command", &command);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Failed to fetch command");
ret = -1;
goto out;
}

switch (command) {
case GF_OP_CMD_START:
*event = EVENT_VOLUME_REMOVE_BRICK_START;
break;
case GF_OP_CMD_COMMIT:
*event = EVENT_VOLUME_REMOVE_BRICK_COMMIT;
break;
case GF_OP_CMD_COMMIT_FORCE:
*event = EVENT_VOLUME_REMOVE_BRICK_FORCE;
break;
case GF_OP_CMD_STOP:
*event = EVENT_VOLUME_REMOVE_BRICK_STOP;
break;
default:
*event = EVENT_LAST;
break;
}

ret = -1;

if (*event == EVENT_LAST) {
goto out;
}

/* I could just get this from words[] but this is cleaner in case the
* format changes */
while (i) {
snprintf (key, sizeof (key), "brick%d", i);
ret = dict_get_str (options, key, &brick);
if (ret) {
break;
}
eventstrlen += strlen (brick) + 1;
i++;
}

count = --i;

eventstrlen += 1;

bricklist = GF_CALLOC (eventstrlen, sizeof (char), gf_common_mt_char);
if (!bricklist) {
goto out;
}

tmp_ptr = bricklist;

i = 1;
while (i <= count) {
snprintf (key, sizeof (key), "brick%d", i);
ret = dict_get_str (options, key, &brick);
if (ret) {
break;
}
snprintf (tmp_ptr, eventstrlen, "%s ", brick);
eventstrlen -= (strlen (brick) + 1);
tmp_ptr += (strlen (brick) + 1);
i++;
}

if (!ret) {
gf_asprintf (event_str, eventstrformat, volname,
bricklist);
} else {
gf_asprintf (event_str, eventstrformat, volname,
"<unavailable>");
}

ret = 0;
out:
GF_FREE (bricklist);
return ret;
}


int
cli_cmd_volume_add_brick_cbk (struct cli_state *state,
struct cli_cmd_word *word, const char **words,
Expand All @@ -863,6 +989,12 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state,
gf_answer_t answer = GF_ANSWER_NO;
cli_local_t *local = NULL;

#if (USE_EVENTS)
char *event_str = NULL;
char *bricks = NULL;
const char *eventstrformat = "volume=%s;bricks=%s";
#endif

const char *question = "Changing the 'stripe count' of the volume is "
"not a supported feature. In some cases it may result in data "
"loss on the volume. Also there may be issues with regular "
Expand Down Expand Up @@ -891,6 +1023,20 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state,
}
}

#if (USE_EVENTS)
/* Get the list of bricks for the event */

ret = dict_get_str (options, "bricks", &bricks);

if (!ret) {
gf_asprintf (&event_str, eventstrformat, (char *)words[2],
&bricks[1] /*Skip leading space*/);
} else {
gf_asprintf (&event_str, eventstrformat, (char *)words[2],
"<unavailable>");
}
#endif

if (state->mode & GLUSTER_MODE_WIGNORE) {
ret = dict_set_int32 (options, "force", _gf_true);
if (ret) {
Expand All @@ -913,10 +1059,14 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state,
cli_cmd_sent_status_get (&sent);
if ((sent == 0) && (parse_error == 0))
cli_out ("Volume add-brick failed");
} else {
#if (USE_EVENTS)
gf_event (EVENT_VOLUME_ADD_BRICK, event_str);
GF_FREE (event_str);
#endif
}

CLI_STACK_DESTROY (frame);

return ret;
}

Expand Down Expand Up @@ -1787,7 +1937,11 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state,
int need_question = 0;
cli_local_t *local = NULL;
char *volname = NULL;

#if (USE_EVENTS)
eventtypes_t event = EVENT_LAST;
char *event_str = NULL;
int event_ret = -1;
#endif
const char *question = "Removing brick(s) can result in data loss. "
"Do you want to Continue?";

Expand All @@ -1810,6 +1964,10 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state,
goto out;
}

#if (USE_EVENTS)
event_ret = cli_event_remove_brick_str (options, &event_str, &event);
#endif

if (!strcmp (volname, GLUSTER_SHARED_STORAGE)) {
question = "Removing brick from the shared storage volume"
"(gluster_shared_storage), will affect features "
Expand Down Expand Up @@ -1841,10 +1999,18 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state,
cli_cmd_sent_status_get (&sent);
if ((sent == 0) && (parse_error == 0))
cli_out ("Volume remove-brick failed");
} else {
#if (USE_EVENTS)
if (!event_ret) {
gf_event (event, event_str);
GF_FREE (event_str);
}
#endif
}

CLI_STACK_DESTROY (frame);


return ret;

}
Expand Down
22 changes: 22 additions & 0 deletions events/eventskeygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"EVENT_AFR_SUBVOLS_DOWN",
"EVENT_AFR_SPLIT_BRAIN",

#tier events
"EVENT_TIER_ATTACH",
"EVENT_TIER_ATTACH_FORCE",
"EVENT_TIER_DETACH_START",
Expand All @@ -162,6 +163,27 @@
"EVENT_TIER_WATERMARK_DROPPED_TO_MID",
"EVENT_TIER_WATERMARK_RAISED_TO_MID",
"EVENT_TIER_WATERMARK_DROPPED_TO_LOW",

#dht events
#add/remove brick events
"EVENT_VOLUME_ADD_BRICK",
"EVENT_VOLUME_ADD_BRICK_FAILED",
"EVENT_VOLUME_REMOVE_BRICK_START",
"EVENT_VOLUME_REMOVE_BRICK_START_FAILED",
"EVENT_VOLUME_REMOVE_BRICK_COMMIT",
"EVENT_VOLUME_REMOVE_BRICK_COMMIT_FAILED",
"EVENT_VOLUME_REMOVE_BRICK_STOP",
"EVENT_VOLUME_REMOVE_BRICK_STOP_FAILED",
"EVENT_VOLUME_REMOVE_BRICK_FORCE",
"EVENT_VOLUME_REMOVE_BRICK_FORCE_FAILED",
"EVENT_VOLUME_REMOVE_BRICK_FAILED",

#rebalance events
"EVENT_VOLUME_REBALANCE_START",
"EVENT_VOLUME_REBALANCE_STOP",
"EVENT_VOLUME_REBALANCE_FAILED",
"EVENT_VOLUME_REBALANCE_COMPLETE",

)

LAST_EVENT = "EVENT_LAST"
Expand Down

0 comments on commit 957e400

Please sign in to comment.