diff options
author | Aravinda VK <avishwan@redhat.com> | 2016-05-05 18:34:41 +0530 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2016-07-18 13:52:20 -0700 |
commit | 5ed781ecf531b7916e51c174426e222dab717fb8 (patch) | |
tree | 62fdb63045d4bc9350713aeaa3a8639a316b24ed /libglusterfs/src | |
parent | 386340967926fa062e2c1eee4784f951846167b3 (diff) |
eventsapi: Gluster Eventing Feature implementation
[Depends on http://review.gluster.org/14627]
Design is available in `glusterfs-specs`, A change from the design
is support of webhook instead of Websockets as discussed in the design
http://review.gluster.org/13115
Since Websocket support depends on REST APIs, I will add Websocket support
once REST APIs patch gets merged
Usage:
Run following command to start/stop Eventsapi server in all Peers,
which will collect the notifications from any Gluster daemon and emits
to configured client.
gluster-eventsapi start|stop|restart|reload
Status of running services can be checked using,
gluster-eventsapi status
Events listener is a HTTP(S) server which listens to events emited by
the Gluster. Create a HTTP Server to listen on POST and register that
URL using,
gluster-eventsapi webhook-add <URL> [--bearer-token <TOKEN>]
For example, if HTTP Server running in `http://192.168.122.188:9000`
then add that URL using,
gluster-eventsapi webhook-add http://192.168.122.188:9000
If it expects a Token then specify it using `--bearer-token` or `-t`
We can also test Webhook if all peer nodes can send message or not
using,
gluster-eventsapi webhook-test <URL> [--bearer-token <TOKEN>]
Configurations can be viewed/updated using,
gluster-eventsapi config-get [--name]
gluster-eventsapi config-set <NAME> <VALUE>
gluster-eventsapi config-reset <NAME|all>
If any one peer node was down during config-set/reset or webhook
modifications, Run sync command from good node when a peer node comes
back. Automatic update is not yet implemented.
gluster-eventsapi sync
Basic Events Client(HTTP Server) is included with the code, Start
running the client with required port and start listening to the
events.
/usr/share/glusterfs/scripts/eventsdash.py --port 8080
Default port is 9000, if no port is specified, once it started running
then configure gluster-eventsapi to send events to that client.
Eventsapi Client can be outside of the Cluster, it can be run event on
Windows. But only requirement is the client URL should be accessible
by all peer nodes.(Or ngrok(https://ngrok.com) like tools can be used)
Events implemented with this patch,
- Volume Create
- Volume Start
- Volume Stop
- Volume Delete
- Peer Attach
- Peer Detach
It is easy to add/support more events, since it touches Gluster cmd
code and to avoid merge conflicts I will add support for more events
once this patch merges.
BUG: 1334044
Change-Id: I316827ac9dd1443454df7deffe4f54835f7f6a08
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Reviewed-on: http://review.gluster.org/14248
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/Makefile.am | 6 | ||||
-rw-r--r-- | libglusterfs/src/events.c | 83 | ||||
-rw-r--r-- | libglusterfs/src/events.h.in | 23 | ||||
-rw-r--r-- | libglusterfs/src/eventtypes.h | 22 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs.h | 4 |
5 files changed, 138 insertions, 0 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 2ec0f34a670..1dbea92b2bb 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -71,6 +71,12 @@ libglusterfs_la_SOURCES += $(CONTRIBDIR)/uuid/clear.c \ $(CONTRIBDIR)/uuid/unpack.c endif +if BUILD_EVENTS +libglusterfs_la_SOURCES += events.c + +libglusterfs_la_HEADERS += events.h eventtypes.h +endif + libgfchangelog_HEADERS = changelog.h EXTRA_DIST = graph.l graph.y defaults-tmpl.c diff --git a/libglusterfs/src/events.c b/libglusterfs/src/events.c new file mode 100644 index 00000000000..9d781874a8a --- /dev/null +++ b/libglusterfs/src/events.c @@ -0,0 +1,83 @@ +/* + Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <stdio.h> +#include <unistd.h> +#include <time.h> +#include <stdarg.h> +#include <string.h> +#include "syscall.h" +#include "mem-pool.h" +#include "events.h" + +int +gf_event (int event, char *fmt, ...) +{ + int sock = -1; + char eventstr[EVENTS_MSG_MAX] = ""; + struct sockaddr_un server; + va_list arguments; + char *msg = NULL; + int ret = 0; + size_t eventstr_size = 0; + + if (event < 0 || event >= EVENT_LAST) { + ret = EVENT_ERROR_INVALID_INPUTS; + goto out; + } + + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock < 0) { + ret = EVENT_ERROR_SOCKET; + goto out; + } + server.sun_family = AF_UNIX; + strcpy(server.sun_path, EVENT_PATH); + + if (connect(sock, + (struct sockaddr *) &server, + sizeof(struct sockaddr_un)) < 0) { + ret = EVENT_ERROR_CONNECT; + goto out; + } + + va_start (arguments, fmt); + ret = gf_vasprintf (&msg, fmt, arguments); + va_end (arguments); + if (ret < 0) { + ret = EVENT_ERROR_INVALID_INPUTS; + goto out; + } + + eventstr_size = snprintf(NULL, 0, "%u %d %s", (unsigned)time(NULL), + event, msg); + + if (eventstr_size + 1 > EVENTS_MSG_MAX) { + eventstr_size = EVENTS_MSG_MAX - 1; + } + + snprintf(eventstr, eventstr_size+1, "%u %d %s", + (unsigned)time(NULL), event, msg); + + if (sys_write(sock, eventstr, strlen(eventstr)) <= 0) { + ret = EVENT_ERROR_SEND; + goto out; + } + + ret = EVENT_SEND_OK; + + out: + sys_close(sock); + GF_FREE(msg); + return ret; +} diff --git a/libglusterfs/src/events.h.in b/libglusterfs/src/events.h.in new file mode 100644 index 00000000000..37692bef732 --- /dev/null +++ b/libglusterfs/src/events.h.in @@ -0,0 +1,23 @@ +/* + Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef __EVENTS_H__ +#define __EVENTS_H__ + +#include <stdio.h> + +#include "eventtypes.h" + +#define EVENT_PATH "@localstatedir@/run/gluster/events.sock" +#define EVENTS_MSG_MAX 2048 + +extern int gf_event(int key, char *fmt, ...); + +#endif /* __EVENTS_H__ */ diff --git a/libglusterfs/src/eventtypes.h b/libglusterfs/src/eventtypes.h new file mode 100644 index 00000000000..874f8ccf114 --- /dev/null +++ b/libglusterfs/src/eventtypes.h @@ -0,0 +1,22 @@ +#ifndef __EVENTTYPES_H__ +#define __EVENTTYPES_H__ + +typedef enum { + EVENT_SEND_OK, + EVENT_ERROR_INVALID_INPUTS, + EVENT_ERROR_SOCKET, + EVENT_ERROR_CONNECT, + EVENT_ERROR_SEND, +} event_errors_t; + +typedef enum { + EVENT_PEER_ATTACH, + EVENT_PEER_DETACH, + EVENT_VOLUME_CREATE, + EVENT_VOLUME_START, + EVENT_VOLUME_STOP, + EVENT_VOLUME_DELETE, + EVENT_LAST +} eventtypes_t; + +#endif /* __EVENTTYPES_H__ */ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 8d387bafb3b..d11cbdcb8ee 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -37,6 +37,10 @@ #include "lkowner.h" #include "compat-uuid.h" +#if (USE_EVENTS) +#include "events.h" +#endif + #define GF_YES 1 #define GF_NO 0 |