Blob Blame History Raw
From bcacbcec4bc3d2dd1c11e6b64d39a422a08d9b34 Mon Sep 17 00:00:00 2001
From: Avra Sengupta <asengupt@redhat.com>
Date: Fri, 18 Nov 2016 13:13:21 +0530
Subject: [PATCH 178/206] snapshot/scheduler: Removing dependency of scheduler
 on eventing

> Reviewed-on: http://review.gluster.org/15876
> Reviewed-by: Aravinda VK <avishwan@redhat.com>
> 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: Rajesh Joseph <rjoseph@redhat.com>

(cherry picked from commit 6b2c40d337bd30eea3ce56a71db8864e61a9a411)

Change-Id: I7de156d8186c32092ec5e9d174d023f4782947c0
BUG: 1396361
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/90659
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 extras/snap_scheduler/snap_scheduler.py | 77 ++++++++++++++++++++++++++-------
 1 file changed, 61 insertions(+), 16 deletions(-)

diff --git a/extras/snap_scheduler/snap_scheduler.py b/extras/snap_scheduler/snap_scheduler.py
index 23d5aa3..b426cc7 100755
--- a/extras/snap_scheduler/snap_scheduler.py
+++ b/extras/snap_scheduler/snap_scheduler.py
@@ -21,8 +21,48 @@ import shutil
 from errno import EEXIST
 from conf import GLUSTERFS_LIBEXECDIR
 sys.path.insert(1, GLUSTERFS_LIBEXECDIR)
-from events.gf_event import gf_event
-from events import eventtypes
+
+EVENTS_ENABLED = True
+try:
+    from events.eventtypes import SNAPSHOT_SCHEDULER_INITIALISED \
+                         as EVENT_SNAPSHOT_SCHEDULER_INITIALISED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_INIT_FAILED \
+                         as EVENT_SNAPSHOT_SCHEDULER_INIT_FAILED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_DISABLED \
+                         as EVENT_SNAPSHOT_SCHEDULER_DISABLED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_DISABLE_FAILED \
+                         as EVENT_SNAPSHOT_SCHEDULER_DISABLE_FAILED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_ENABLED \
+                         as EVENT_SNAPSHOT_SCHEDULER_ENABLED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_ENABLE_FAILED \
+                         as EVENT_SNAPSHOT_SCHEDULER_ENABLE_FAILED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_SCHEDULE_ADDED \
+                         as EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_ADDED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED \
+                         as EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_SCHEDULE_DELETED \
+                         as EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_DELETED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED \
+                         as EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_SCHEDULE_EDITED \
+                         as EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_EDITED
+    from events.eventtypes import SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED \
+                         as EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED
+except ImportError:
+    # Events APIs not installed, dummy eventtypes with None
+    EVENTS_ENABLED = False
+    EVENT_SNAPSHOT_SCHEDULER_INITIALISED = None
+    EVENT_SNAPSHOT_SCHEDULER_INIT_FAILED = None
+    EVENT_SNAPSHOT_SCHEDULER_DISABLED = None
+    EVENT_SNAPSHOT_SCHEDULER_DISABLE_FAILED = None
+    EVENT_SNAPSHOT_SCHEDULER_ENABLED = None
+    EVENT_SNAPSHOT_SCHEDULER_ENABLE_FAILED = None
+    EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_ADDED = None
+    EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED = None
+    EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_DELETED = None
+    EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED = None
+    EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_EDITED = None
+    EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED = None
 
 SCRIPT_NAME = "snap_scheduler"
 scheduler_enabled = False
@@ -538,7 +578,7 @@ def initialise_scheduler():
 
     log.info("Successfully initialised snapshot scheduler for this node")
     output("Successfully initialised snapshot scheduler for this node")
-    gf_event (eventtypes.SNAPSHOT_SCHEDULER_INITIALISED, status="Success")
+    gf_event (EVENT_SNAPSHOT_SCHEDULER_INITIALISED, status="Success")
 
     ret = 0
     return ret
@@ -585,7 +625,7 @@ def perform_operation(args):
         ret = initialise_scheduler()
         if ret != 0:
             output("Failed to initialise snapshot scheduling")
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_INIT_FAILED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_INIT_FAILED,
                       error=print_error(ret))
         return ret
 
@@ -594,10 +634,10 @@ def perform_operation(args):
         ret = disable_scheduler()
         if ret == 0:
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_DISABLED,
                       status="Successfuly Disabled")
         else:
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLE_FAILED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_DISABLE_FAILED,
                       error=print_error(ret))
         return ret
 
@@ -629,10 +669,10 @@ def perform_operation(args):
         ret = enable_scheduler()
         if ret == 0:
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_ENABLED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_ENABLED,
                       status="Successfuly Enabled")
         else:
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_ENABLE_FAILED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_ENABLE_FAILED,
                       error=print_error(ret))
         return ret
 
@@ -641,10 +681,10 @@ def perform_operation(args):
         ret = disable_scheduler()
         if ret == 0:
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_DISABLED,
                       status="Successfuly Disabled")
         else:
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLE_FAILED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_DISABLE_FAILED,
                       error=print_error(ret))
         return ret
 
@@ -661,10 +701,10 @@ def perform_operation(args):
         ret = add_schedules(args.jobname, args.schedule, args.volname)
         if ret == 0:
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_ADDED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_ADDED,
                       status="Successfuly added job "+args.jobname)
         else:
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED,
                       status="Failed to add job "+args.jobname,
                       error=print_error(ret))
         return ret
@@ -677,10 +717,10 @@ def perform_operation(args):
         ret = delete_schedules(args.jobname)
         if ret == 0:
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_DELETED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_DELETED,
                       status="Successfuly deleted job "+args.jobname)
         else:
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED,
                       status="Failed to delete job "+args.jobname,
                       error=print_error(ret))
         return ret
@@ -693,10 +733,10 @@ def perform_operation(args):
         ret = edit_schedules(args.jobname, args.schedule, args.volname)
         if ret == 0:
             subprocess.Popen(["touch", "-h", GCRON_TASKS])
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_EDITED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_EDITED,
                       status="Successfuly edited job "+args.jobname)
         else:
-            gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED,
+            gf_event (EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED,
                       status="Failed to edit job "+args.jobname,
                       error=print_error(ret))
         return ret
@@ -704,6 +744,11 @@ def perform_operation(args):
     ret = INVALID_ARG
     return ret
 
+def gf_event(event_type, **kwargs):
+    if EVENTS_ENABLED:
+        from events.gf_event import gf_event as gfevent
+        gfevent(event_type, **kwargs)
+
 
 def main(argv):
     initLogger()
-- 
2.9.3