Blob Blame History Raw
From 1ffd613e00ab07b5e07c775af1a4294ea995efe6 Mon Sep 17 00:00:00 2001
From: Aravinda VK <avishwan@redhat.com>
Date: Wed, 16 Nov 2016 16:50:50 +0530
Subject: [PATCH 216/227] geo-rep/eventsapi: Add Master node information in
 Geo-rep Events

Added Master node information to GEOREP_ACTIVE, GEOREP_PASSIVE, GEOREP_FAULTY
and GEOREP_CHECKPOINT_COMPLETED events.

EVENT_GEOREP_ACTIVE(master_node and master_node_id are new fields)
{
    "nodeid": NODEID,
    "ts": TIMESTAMP,
    "event": "GEOREP_ACTIVE",
    "message": {
        "master_volume": MASTER_VOLUME_NAME,
        "master_node": MASTER_NODE,
        "master_node_id": MASTER_NODE_ID,
        "slave_host": SLAVE_HOST,
        "slave_volume": SLAVE_VOLUME,
        "brick_path": BRICK_PATH
    }
}

EVENT_GEOREP_PASSIVE(master_node and master_node_id are new fields)
{
    "nodeid": NODEID,
    "ts": TIMESTAMP,
    "event": "GEOREP_PASSIVE",
    "message": {
        "master_volume": MASTER_VOLUME_NAME,
        "master_node": MASTER_NODE,
        "master_node_id": MASTER_NODE_ID,
        "slave_host": SLAVE_HOST,
        "slave_volume": SLAVE_VOLUME,
        "brick_path": BRICK_PATH
    }
}

EVENT_GEOREP_FAULTY(master_node and master_node_id are new fields)
{
    "nodeid": NODEID,
    "ts": TIMESTAMP,
    "event": "GEOREP_FAULTY",
    "message": {
        "master_volume": MASTER_VOLUME_NAME,
        "master_node": MASTER_NODE,
        "master_node_id": MASTER_NODE_ID,
        "current_slave_host": CURRENT_SLAVE_HOST,
        "slave_host": SLAVE_HOST,
        "slave_volume": SLAVE_VOLUME,
        "brick_path": BRICK_PATH
    }
}

EVENT_GEOREP_CHECKPOINT_COMPLETED(master_node and master_node_id are new fields)
{
    "nodeid": NODEID,
    "ts": TIMESTAMP,
    "event": "GEOREP_CHECKPOINT_COMPLETED",
    "message": {
        "master_volume": MASTER_VOLUME_NAME,
        "master_node": MASTER_NODE,
        "master_node_id": MASTER_NODE_ID,
        "slave_host": SLAVE_HOST,
        "slave_volume": SLAVE_VOLUME,
        "brick_path": BRICK_PATH,
        "checkpoint_time": CHECKPOINT_TIME,
        "checkpoint_completion_time": CHECKPOINT_COMPLETION_TIME
    }
}

> Reviewed-on: http://review.gluster.org/15858
> 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: Kotresh HR <khiremat@redhat.com>

BUG: 1388755
Change-Id: Ic91af52fa248c8e982e93a06be861dfd69689f34
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/91989
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 geo-replication/syncdaemon/gsyncd.py       |  9 ++++++-
 geo-replication/syncdaemon/gsyncdstatus.py | 38 +++++++++++++++---------------
 geo-replication/syncdaemon/monitor.py      | 13 ++++++++--
 geo-replication/syncdaemon/resource.py     |  4 +++-
 4 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py
index 195e6d2..76d9939 100644
--- a/geo-replication/syncdaemon/gsyncd.py
+++ b/geo-replication/syncdaemon/gsyncd.py
@@ -285,6 +285,10 @@ def main_i():
     op.add_option('--session-owner', metavar='ID')
     op.add_option('--local-id', metavar='ID', help=SUPPRESS_HELP, default='')
     op.add_option(
+        '--local-node', metavar='NODE', help=SUPPRESS_HELP, default='')
+    op.add_option(
+        '--local-node-id', metavar='NODEID', help=SUPPRESS_HELP, default='')
+    op.add_option(
         '--local-path', metavar='PATH', help=SUPPRESS_HELP, default='')
     op.add_option('-s', '--ssh-command', metavar='CMD', default='ssh')
     op.add_option('--ssh-port', metavar='PORT', type=int, default=22)
@@ -703,7 +707,10 @@ def main_i():
     if status_get:
         master_name, slave_data = get_master_and_slave_data_from_args(args)
         for brick in gconf.path:
-            brick_status = GeorepStatus(gconf.state_file, brick,
+            brick_status = GeorepStatus(gconf.state_file,
+                                        gconf.local_node,
+                                        brick,
+                                        gconf.local_node_id,
                                         master_name,
                                         slave_data,
                                         getattr(gconf, "pid_file", None))
diff --git a/geo-replication/syncdaemon/gsyncdstatus.py b/geo-replication/syncdaemon/gsyncdstatus.py
index 6575fcd..2c1a48d 100644
--- a/geo-replication/syncdaemon/gsyncdstatus.py
+++ b/geo-replication/syncdaemon/gsyncdstatus.py
@@ -116,8 +116,8 @@ def set_monitor_status(status_file, status):
 
 
 class GeorepStatus(object):
-    def __init__(self, monitor_status_file, brick, master, slave,
-                 monitor_pid_file=None):
+    def __init__(self, monitor_status_file, master_node, brick, master_node_id,
+                 master, slave, monitor_pid_file=None):
         self.master = master
         slv_data = slave.split("::")
         self.slave_host = slv_data[0]
@@ -132,10 +132,22 @@ class GeorepStatus(object):
         os.close(fd)
         fd = os.open(self.monitor_status_file, os.O_CREAT | os.O_RDWR)
         os.close(fd)
+        self.master_node = master_node
+        self.master_node_id = master_node_id
         self.brick = brick
         self.default_values = get_default_values()
         self.monitor_pid_file = monitor_pid_file
 
+    def send_event(self, event_type, **kwargs):
+        gf_event(event_type,
+                 master_volume=self.master,
+                 master_node=self.master_node,
+                 master_node_id=self.master_node_id,
+                 slave_host=self.slave_host,
+                 slave_volume=self.slave_volume,
+                 brick_path=self.brick,
+                 **kwargs)
+
     def _update(self, mergerfunc):
         with LockedOpen(self.filename, 'r+') as f:
             try:
@@ -186,13 +198,9 @@ class GeorepStatus(object):
 
     def trigger_gf_event_checkpoint_completion(self, checkpoint_time,
                                                checkpoint_completion_time):
-        gf_event(EVENT_GEOREP_CHECKPOINT_COMPLETED,
-                 master_volume=self.master,
-                 slave_host=self.slave_host,
-                 slave_volume=self.slave_volume,
-                 brick_path=self.brick,
-                 checkpoint_time=checkpoint_time,
-                 checkpoint_completion_time=checkpoint_completion_time)
+        self.send_event(EVENT_GEOREP_CHECKPOINT_COMPLETED,
+                        checkpoint_time=checkpoint_time,
+                        checkpoint_completion_time=checkpoint_completion_time)
 
     def set_last_synced(self, value, checkpoint_time):
         def merger(data):
@@ -252,19 +260,11 @@ class GeorepStatus(object):
 
     def set_active(self):
         if self.set_field("worker_status", "Active"):
-            gf_event(EVENT_GEOREP_ACTIVE,
-                     master_volume=self.master,
-                     slave_host=self.slave_host,
-                     slave_volume=self.slave_volume,
-                     brick_path=self.brick)
+            self.send_event(EVENT_GEOREP_ACTIVE)
 
     def set_passive(self):
         if self.set_field("worker_status", "Passive"):
-            gf_event(EVENT_GEOREP_PASSIVE,
-                     master_volume=self.master,
-                     slave_host=self.slave_host,
-                     slave_volume=self.slave_volume,
-                     brick_path=self.brick)
+            self.send_event(EVENT_GEOREP_PASSIVE)
 
     def get_monitor_status(self):
         data = ""
diff --git a/geo-replication/syncdaemon/monitor.py b/geo-replication/syncdaemon/monitor.py
index 7eddd26..8fdd68d 100644
--- a/geo-replication/syncdaemon/monitor.py
+++ b/geo-replication/syncdaemon/monitor.py
@@ -123,8 +123,8 @@ class Volinfo(object):
     @memoize
     def bricks(self):
         def bparse(b):
-            host, dirp = b.text.split(':', 2)
-            return {'host': host, 'dir': dirp}
+            host, dirp = b.find("name").text.split(':', 2)
+            return {'host': host, 'dir': dirp, 'uuid': b.find("hostUuid").text}
         return [bparse(b) for b in self.get('brick')]
 
     @property
@@ -212,7 +212,9 @@ class Monitor(object):
         """
         if not self.status.get(w[0]['dir'], None):
             self.status[w[0]['dir']] = GeorepStatus(gconf.state_file,
+                                                    w[0]['host'],
                                                     w[0]['dir'],
+                                                    w[0]['uuid'],
                                                     master,
                                                     "%s::%s" % (slave_host,
                                                                 slave_vol))
@@ -286,6 +288,9 @@ class Monitor(object):
                 os.close(rw)
                 os.close(ww)
                 os.execv(sys.executable, argv + ['--local-path', w[0]['dir'],
+                                                 '--local-node', w[0]['host'],
+                                                 '--local-node-id',
+                                                 w[0]['uuid'],
                                                  '--agent',
                                                  '--rpc-fd',
                                                  ','.join([str(ra), str(wa),
@@ -298,6 +303,9 @@ class Monitor(object):
                 os.close(wa)
                 os.execv(sys.executable, argv + ['--feedback-fd', str(pw),
                                                  '--local-path', w[0]['dir'],
+                                                 '--local-node', w[0]['host'],
+                                                 '--local-node-id',
+                                                 w[0]['uuid'],
                                                  '--local-id',
                                                  '.' + escape(w[0]['dir']),
                                                  '--rpc-fd',
@@ -381,6 +389,7 @@ class Monitor(object):
                     gf_event(EVENT_GEOREP_FAULTY,
                              master_volume=master.volume,
                              master_node=w[0]['host'],
+                             master_node_id=w[0]['uuid'],
                              slave_host=slave_host,
                              slave_volume=slave_vol,
                              current_slave_host=current_slave_host,
diff --git a/geo-replication/syncdaemon/resource.py b/geo-replication/syncdaemon/resource.py
index 998fe27..b887d37 100644
--- a/geo-replication/syncdaemon/resource.py
+++ b/geo-replication/syncdaemon/resource.py
@@ -1494,7 +1494,9 @@ class GLUSTER(AbstractUrl, SlaveLocal, SlaveRemote):
             changelog_agent = RepceClient(int(inf), int(ouf))
             master_name, slave_data = get_master_and_slave_data_from_args(
                 sys.argv)
-            status = GeorepStatus(gconf.state_file, gconf.local_path,
+            status = GeorepStatus(gconf.state_file, gconf.local_node,
+                                  gconf.local_path,
+                                  gconf.local_node_id,
                                   master_name, slave_data)
             status.reset_on_worker_start()
             rv = changelog_agent.version()
-- 
2.9.3