summaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2016-11-18 13:13:21 +0530
committerRajesh Joseph <rjoseph@redhat.com>2016-11-20 22:18:13 -0800
commit6b2c40d337bd30eea3ce56a71db8864e61a9a411 (patch)
tree6208262dd8a8a4992b891d1d0d8450009df7057f /extras
parent5310be8838f8db748a698bd3a98f8d00a4114e65 (diff)
snapshot/scheduler: Removing dependency of scheduler on eventing
Change-Id: I7de156d8186c32092ec5e9d174d023f4782947c0 BUG: 1396364 Signed-off-by: Avra Sengupta <asengupt@redhat.com> 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>
Diffstat (limited to 'extras')
-rwxr-xr-xextras/snap_scheduler/snap_scheduler.py77
1 files changed, 61 insertions, 16 deletions
diff --git a/extras/snap_scheduler/snap_scheduler.py b/extras/snap_scheduler/snap_scheduler.py
index 23d5aa3b525..b426cc7bb73 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()