3604df
From 1ffd613e00ab07b5e07c775af1a4294ea995efe6 Mon Sep 17 00:00:00 2001
3604df
From: Aravinda VK <avishwan@redhat.com>
3604df
Date: Wed, 16 Nov 2016 16:50:50 +0530
3604df
Subject: [PATCH 216/227] geo-rep/eventsapi: Add Master node information in
3604df
 Geo-rep Events
3604df
3604df
Added Master node information to GEOREP_ACTIVE, GEOREP_PASSIVE, GEOREP_FAULTY
3604df
and GEOREP_CHECKPOINT_COMPLETED events.
3604df
3604df
EVENT_GEOREP_ACTIVE(master_node and master_node_id are new fields)
3604df
{
3604df
    "nodeid": NODEID,
3604df
    "ts": TIMESTAMP,
3604df
    "event": "GEOREP_ACTIVE",
3604df
    "message": {
3604df
        "master_volume": MASTER_VOLUME_NAME,
3604df
        "master_node": MASTER_NODE,
3604df
        "master_node_id": MASTER_NODE_ID,
3604df
        "slave_host": SLAVE_HOST,
3604df
        "slave_volume": SLAVE_VOLUME,
3604df
        "brick_path": BRICK_PATH
3604df
    }
3604df
}
3604df
3604df
EVENT_GEOREP_PASSIVE(master_node and master_node_id are new fields)
3604df
{
3604df
    "nodeid": NODEID,
3604df
    "ts": TIMESTAMP,
3604df
    "event": "GEOREP_PASSIVE",
3604df
    "message": {
3604df
        "master_volume": MASTER_VOLUME_NAME,
3604df
        "master_node": MASTER_NODE,
3604df
        "master_node_id": MASTER_NODE_ID,
3604df
        "slave_host": SLAVE_HOST,
3604df
        "slave_volume": SLAVE_VOLUME,
3604df
        "brick_path": BRICK_PATH
3604df
    }
3604df
}
3604df
3604df
EVENT_GEOREP_FAULTY(master_node and master_node_id are new fields)
3604df
{
3604df
    "nodeid": NODEID,
3604df
    "ts": TIMESTAMP,
3604df
    "event": "GEOREP_FAULTY",
3604df
    "message": {
3604df
        "master_volume": MASTER_VOLUME_NAME,
3604df
        "master_node": MASTER_NODE,
3604df
        "master_node_id": MASTER_NODE_ID,
3604df
        "current_slave_host": CURRENT_SLAVE_HOST,
3604df
        "slave_host": SLAVE_HOST,
3604df
        "slave_volume": SLAVE_VOLUME,
3604df
        "brick_path": BRICK_PATH
3604df
    }
3604df
}
3604df
3604df
EVENT_GEOREP_CHECKPOINT_COMPLETED(master_node and master_node_id are new fields)
3604df
{
3604df
    "nodeid": NODEID,
3604df
    "ts": TIMESTAMP,
3604df
    "event": "GEOREP_CHECKPOINT_COMPLETED",
3604df
    "message": {
3604df
        "master_volume": MASTER_VOLUME_NAME,
3604df
        "master_node": MASTER_NODE,
3604df
        "master_node_id": MASTER_NODE_ID,
3604df
        "slave_host": SLAVE_HOST,
3604df
        "slave_volume": SLAVE_VOLUME,
3604df
        "brick_path": BRICK_PATH,
3604df
        "checkpoint_time": CHECKPOINT_TIME,
3604df
        "checkpoint_completion_time": CHECKPOINT_COMPLETION_TIME
3604df
    }
3604df
}
3604df
3604df
> Reviewed-on: http://review.gluster.org/15858
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: Kotresh HR <khiremat@redhat.com>
3604df
3604df
BUG: 1388755
3604df
Change-Id: Ic91af52fa248c8e982e93a06be861dfd69689f34
3604df
Signed-off-by: Aravinda VK <avishwan@redhat.com>
3604df
Reviewed-on: https://code.engineering.redhat.com/gerrit/91989
3604df
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
3604df
---
3604df
 geo-replication/syncdaemon/gsyncd.py       |  9 ++++++-
3604df
 geo-replication/syncdaemon/gsyncdstatus.py | 38 +++++++++++++++---------------
3604df
 geo-replication/syncdaemon/monitor.py      | 13 ++++++++--
3604df
 geo-replication/syncdaemon/resource.py     |  4 +++-
3604df
 4 files changed, 41 insertions(+), 23 deletions(-)
3604df
3604df
diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py
3604df
index 195e6d2..76d9939 100644
3604df
--- a/geo-replication/syncdaemon/gsyncd.py
3604df
+++ b/geo-replication/syncdaemon/gsyncd.py
3604df
@@ -285,6 +285,10 @@ def main_i():
3604df
     op.add_option('--session-owner', metavar='ID')
3604df
     op.add_option('--local-id', metavar='ID', help=SUPPRESS_HELP, default='')
3604df
     op.add_option(
3604df
+        '--local-node', metavar='NODE', help=SUPPRESS_HELP, default='')
3604df
+    op.add_option(
3604df
+        '--local-node-id', metavar='NODEID', help=SUPPRESS_HELP, default='')
3604df
+    op.add_option(
3604df
         '--local-path', metavar='PATH', help=SUPPRESS_HELP, default='')
3604df
     op.add_option('-s', '--ssh-command', metavar='CMD', default='ssh')
3604df
     op.add_option('--ssh-port', metavar='PORT', type=int, default=22)
3604df
@@ -703,7 +707,10 @@ def main_i():
3604df
     if status_get:
3604df
         master_name, slave_data = get_master_and_slave_data_from_args(args)
3604df
         for brick in gconf.path:
3604df
-            brick_status = GeorepStatus(gconf.state_file, brick,
3604df
+            brick_status = GeorepStatus(gconf.state_file,
3604df
+                                        gconf.local_node,
3604df
+                                        brick,
3604df
+                                        gconf.local_node_id,
3604df
                                         master_name,
3604df
                                         slave_data,
3604df
                                         getattr(gconf, "pid_file", None))
3604df
diff --git a/geo-replication/syncdaemon/gsyncdstatus.py b/geo-replication/syncdaemon/gsyncdstatus.py
3604df
index 6575fcd..2c1a48d 100644
3604df
--- a/geo-replication/syncdaemon/gsyncdstatus.py
3604df
+++ b/geo-replication/syncdaemon/gsyncdstatus.py
3604df
@@ -116,8 +116,8 @@ def set_monitor_status(status_file, status):
3604df
 
3604df
 
3604df
 class GeorepStatus(object):
3604df
-    def __init__(self, monitor_status_file, brick, master, slave,
3604df
-                 monitor_pid_file=None):
3604df
+    def __init__(self, monitor_status_file, master_node, brick, master_node_id,
3604df
+                 master, slave, monitor_pid_file=None):
3604df
         self.master = master
3604df
         slv_data = slave.split("::")
3604df
         self.slave_host = slv_data[0]
3604df
@@ -132,10 +132,22 @@ class GeorepStatus(object):
3604df
         os.close(fd)
3604df
         fd = os.open(self.monitor_status_file, os.O_CREAT | os.O_RDWR)
3604df
         os.close(fd)
3604df
+        self.master_node = master_node
3604df
+        self.master_node_id = master_node_id
3604df
         self.brick = brick
3604df
         self.default_values = get_default_values()
3604df
         self.monitor_pid_file = monitor_pid_file
3604df
 
3604df
+    def send_event(self, event_type, **kwargs):
3604df
+        gf_event(event_type,
3604df
+                 master_volume=self.master,
3604df
+                 master_node=self.master_node,
3604df
+                 master_node_id=self.master_node_id,
3604df
+                 slave_host=self.slave_host,
3604df
+                 slave_volume=self.slave_volume,
3604df
+                 brick_path=self.brick,
3604df
+                 **kwargs)
3604df
+
3604df
     def _update(self, mergerfunc):
3604df
         with LockedOpen(self.filename, 'r+') as f:
3604df
             try:
3604df
@@ -186,13 +198,9 @@ class GeorepStatus(object):
3604df
 
3604df
     def trigger_gf_event_checkpoint_completion(self, checkpoint_time,
3604df
                                                checkpoint_completion_time):
3604df
-        gf_event(EVENT_GEOREP_CHECKPOINT_COMPLETED,
3604df
-                 master_volume=self.master,
3604df
-                 slave_host=self.slave_host,
3604df
-                 slave_volume=self.slave_volume,
3604df
-                 brick_path=self.brick,
3604df
-                 checkpoint_time=checkpoint_time,
3604df
-                 checkpoint_completion_time=checkpoint_completion_time)
3604df
+        self.send_event(EVENT_GEOREP_CHECKPOINT_COMPLETED,
3604df
+                        checkpoint_time=checkpoint_time,
3604df
+                        checkpoint_completion_time=checkpoint_completion_time)
3604df
 
3604df
     def set_last_synced(self, value, checkpoint_time):
3604df
         def merger(data):
3604df
@@ -252,19 +260,11 @@ class GeorepStatus(object):
3604df
 
3604df
     def set_active(self):
3604df
         if self.set_field("worker_status", "Active"):
3604df
-            gf_event(EVENT_GEOREP_ACTIVE,
3604df
-                     master_volume=self.master,
3604df
-                     slave_host=self.slave_host,
3604df
-                     slave_volume=self.slave_volume,
3604df
-                     brick_path=self.brick)
3604df
+            self.send_event(EVENT_GEOREP_ACTIVE)
3604df
 
3604df
     def set_passive(self):
3604df
         if self.set_field("worker_status", "Passive"):
3604df
-            gf_event(EVENT_GEOREP_PASSIVE,
3604df
-                     master_volume=self.master,
3604df
-                     slave_host=self.slave_host,
3604df
-                     slave_volume=self.slave_volume,
3604df
-                     brick_path=self.brick)
3604df
+            self.send_event(EVENT_GEOREP_PASSIVE)
3604df
 
3604df
     def get_monitor_status(self):
3604df
         data = ""
3604df
diff --git a/geo-replication/syncdaemon/monitor.py b/geo-replication/syncdaemon/monitor.py
3604df
index 7eddd26..8fdd68d 100644
3604df
--- a/geo-replication/syncdaemon/monitor.py
3604df
+++ b/geo-replication/syncdaemon/monitor.py
3604df
@@ -123,8 +123,8 @@ class Volinfo(object):
3604df
     @memoize
3604df
     def bricks(self):
3604df
         def bparse(b):
3604df
-            host, dirp = b.text.split(':', 2)
3604df
-            return {'host': host, 'dir': dirp}
3604df
+            host, dirp = b.find("name").text.split(':', 2)
3604df
+            return {'host': host, 'dir': dirp, 'uuid': b.find("hostUuid").text}
3604df
         return [bparse(b) for b in self.get('brick')]
3604df
 
3604df
     @property
3604df
@@ -212,7 +212,9 @@ class Monitor(object):
3604df
         """
3604df
         if not self.status.get(w[0]['dir'], None):
3604df
             self.status[w[0]['dir']] = GeorepStatus(gconf.state_file,
3604df
+                                                    w[0]['host'],
3604df
                                                     w[0]['dir'],
3604df
+                                                    w[0]['uuid'],
3604df
                                                     master,
3604df
                                                     "%s::%s" % (slave_host,
3604df
                                                                 slave_vol))
3604df
@@ -286,6 +288,9 @@ class Monitor(object):
3604df
                 os.close(rw)
3604df
                 os.close(ww)
3604df
                 os.execv(sys.executable, argv + ['--local-path', w[0]['dir'],
3604df
+                                                 '--local-node', w[0]['host'],
3604df
+                                                 '--local-node-id',
3604df
+                                                 w[0]['uuid'],
3604df
                                                  '--agent',
3604df
                                                  '--rpc-fd',
3604df
                                                  ','.join([str(ra), str(wa),
3604df
@@ -298,6 +303,9 @@ class Monitor(object):
3604df
                 os.close(wa)
3604df
                 os.execv(sys.executable, argv + ['--feedback-fd', str(pw),
3604df
                                                  '--local-path', w[0]['dir'],
3604df
+                                                 '--local-node', w[0]['host'],
3604df
+                                                 '--local-node-id',
3604df
+                                                 w[0]['uuid'],
3604df
                                                  '--local-id',
3604df
                                                  '.' + escape(w[0]['dir']),
3604df
                                                  '--rpc-fd',
3604df
@@ -381,6 +389,7 @@ class Monitor(object):
3604df
                     gf_event(EVENT_GEOREP_FAULTY,
3604df
                              master_volume=master.volume,
3604df
                              master_node=w[0]['host'],
3604df
+                             master_node_id=w[0]['uuid'],
3604df
                              slave_host=slave_host,
3604df
                              slave_volume=slave_vol,
3604df
                              current_slave_host=current_slave_host,
3604df
diff --git a/geo-replication/syncdaemon/resource.py b/geo-replication/syncdaemon/resource.py
3604df
index 998fe27..b887d37 100644
3604df
--- a/geo-replication/syncdaemon/resource.py
3604df
+++ b/geo-replication/syncdaemon/resource.py
3604df
@@ -1494,7 +1494,9 @@ class GLUSTER(AbstractUrl, SlaveLocal, SlaveRemote):
3604df
             changelog_agent = RepceClient(int(inf), int(ouf))
3604df
             master_name, slave_data = get_master_and_slave_data_from_args(
3604df
                 sys.argv)
3604df
-            status = GeorepStatus(gconf.state_file, gconf.local_path,
3604df
+            status = GeorepStatus(gconf.state_file, gconf.local_node,
3604df
+                                  gconf.local_path,
3604df
+                                  gconf.local_node_id,
3604df
                                   master_name, slave_data)
3604df
             status.reset_on_worker_start()
3604df
             rv = changelog_agent.version()
3604df
-- 
3604df
2.9.3
3604df