From c1278de9a5fb6a64455f42b8b17a8d05b74c2420 Mon Sep 17 00:00:00 2001 From: Avra Sengupta Date: Fri, 26 Aug 2016 14:05:07 +0530 Subject: snapshot/eventsapi: Integrate snapshot events with eventsapi 1. EVENT_SNAPSHOT_CREATED : snapshot_name=snap1 volume_name=test_vol snapshot_uuid=26dd6c52-6021-40b1-a507-001a80401d70 2. EVENT_SNAPSHOT_CREATE_FAILED : snapshot_name=snap1 volume_name=test_vol error=Snapshot snap1 already exists 3. EVENT_SNAPSHOT_ACTIVATED : snapshot_name=snap1 snapshot_uuid=26dd6c52-6021-40b1-a507-001a80401d70 4. EVENT_SNAPSHOT_ACTIVATE_FAILED: snapshot_name=snap1 error=Snapshot snap1 is already activated. 5. EVENT_SNAPSHOT_DEACTIVATED : snapshot_name=snap1 snapshot_uuid=26dd6c52-6021-40b1-a507-001a80401d70 6. EVENT_SNAPSHOT_DEACTIVATE_FAILED : snapshot_name=snap3 error=Snapshot (snap3) does not exist. 7. EVENT_SNAPSHOT_SOFT_LIMIT_REACHED : volume_name=test_vol volume_id=2ace2616-5591-4b9b-be2a-38592dda5758 8. EVENT_SNAPSHOT_HARD_LIMIT_REACHED : volume_name=test_vol volume_id=2ace2616-5591-4b9b-be2a-38592dda5758 9. EVENT_SNAPSHOT_RESTORED : snapshot_name=snap1 volume_name=test_vol snapshot_uuid=3a840ec5-08da-4f2b-850d-1d5539a5d14d 10. EVENT_SNAPSHOT_RESTORE_FAILED : snapshot_name=snap10 error=Snapshot (snap10) does not exist 11. EVENT_SNAPSHOT_DELETED : snapshot_name=snap1 snapshot_uuid=d9ff3d4f-f579-4345-a4da-4f9353f0950c 12. EVENT_SNAPSHOT_DELETE_FAILED : snapshot_name=snap2 error=Snapshot (snap2) does not exist 13. EVENT_SNAPSHOT_CLONED : clone_uuid=93ba9f06-cb9c-4ace-aa52-2616e7f31022 snapshot_name=snap1 clone_name=clone2 14. EVENT_SNAPSHOT_CLONE_FAILED : snapshot_name=snap1 clone_name=clone2 error=Volume with name:clone2 already exists 15. EVENT_SNAPSHOT_CONFIG_UPDATED : auto-delete=enable config_type=system_config config_type=volume_config hard_limit=100 16. EVENT_SNAPSHOT_CONFIG_UPDATE_FAILED : error=Invalid snap-max-soft-limit 110. Expected range 1 - 100 17. EVENT_SNAPSHOT_SCHEDULER_INITIALISED : status=Success 18. EVENT_SNAPSHOT_SCHEDULER_INIT_FAILED 19. EVENT_SNAPSHOT_SCHEDULER_ENABLED : status=Successfuly Enabled 20. EVENT_SNAPSHOT_SCHEDULER_ENABLE_FAILED : error=Snapshot scheduler is already enabled. 21. EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_ADDED : status=Successfuly added job job1 22. EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED : status=Failed to add job job1 error=The job already exists. 23. EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_EDITED : status=Successfuly edited job job1 24. EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED : status=Failed to edit job job2 error=The job cannot be found. 25. EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_DELETED : status=Successfuly deleted job job1 26. EVENT_SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED : status=Failed to delete job job1 error=The job cannot be found. 27. EVENT_SNAPSHOT_SCHEDULER_DISABLED : status=Successfuly Disabled 28. EVENT_SNAPSHOT_SCHEDULER_DISABLE_FAILED : error=Snapshot scheduler is already disabled. Change-Id: I3479cc3fb7af3c76ded67cf289f99547d0a55d21 BUG: 1370567 Signed-off-by: Avra Sengupta Reviewed-on: http://review.gluster.org/15329 Tested-by: Aravinda VK Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Rajesh Joseph --- extras/snap_scheduler/snap_scheduler.py | 77 ++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'extras/snap_scheduler/snap_scheduler.py') diff --git a/extras/snap_scheduler/snap_scheduler.py b/extras/snap_scheduler/snap_scheduler.py index af092e2c341..23d5aa3b525 100755 --- a/extras/snap_scheduler/snap_scheduler.py +++ b/extras/snap_scheduler/snap_scheduler.py @@ -19,7 +19,10 @@ import logging.handlers import sys 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 SCRIPT_NAME = "snap_scheduler" scheduler_enabled = False @@ -55,6 +58,42 @@ INVALID_SCHEDULE = 15 INVALID_ARG = 16 VOLUME_DOES_NOT_EXIST = 17 +def print_error (error_num): + if error_num == INTERNAL_ERROR: + return "Internal Error" + elif error_num == SHARED_STORAGE_DIR_DOESNT_EXIST: + return "The shared storage directory ("+SHARED_STORAGE_DIR+")" \ + " does not exist." + elif error_num == SHARED_STORAGE_NOT_MOUNTED: + return "The shared storage directory ("+SHARED_STORAGE_DIR+")" \ + " is not mounted." + elif error_num == ANOTHER_TRANSACTION_IN_PROGRESS: + return "Another transaction is in progress." + elif error_num == INIT_FAILED: + return "Initialisation failed." + elif error_num == SCHEDULING_ALREADY_DISABLED: + return "Snapshot scheduler is already disabled." + elif error_num == SCHEDULING_ALREADY_ENABLED: + return "Snapshot scheduler is already enabled." + elif error_num == NODE_NOT_INITIALISED: + return "The node is not initialised." + elif error_num == ANOTHER_SCHEDULER_ACTIVE: + return "Another scheduler is active." + elif error_num == JOB_ALREADY_EXISTS: + return "The job already exists." + elif error_num == JOB_NOT_FOUND: + return "The job cannot be found." + elif error_num == INVALID_JOBNAME: + return "The job name is invalid." + elif error_num == INVALID_VOLNAME: + return "The volume name is invalid." + elif error_num == INVALID_SCHEDULE: + return "The schedule is invalid." + elif error_num == INVALID_ARG: + return "The argument is invalid." + elif error_num == VOLUME_DOES_NOT_EXIST: + return "The volume does not exist." + def output(msg): print("%s: %s" % (SCRIPT_NAME, msg)) @@ -499,6 +538,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") ret = 0 return ret @@ -545,6 +585,8 @@ def perform_operation(args): ret = initialise_scheduler() if ret != 0: output("Failed to initialise snapshot scheduling") + gf_event (eventtypes.SNAPSHOT_SCHEDULER_INIT_FAILED, + error=print_error(ret)) return ret # Disable snapshot scheduler @@ -552,6 +594,11 @@ def perform_operation(args): ret = disable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) + gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLED, + status="Successfuly Disabled") + else: + gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLE_FAILED, + error=print_error(ret)) return ret # Check if the symlink to GCRON_TASKS is properly set in the shared storage @@ -582,6 +629,11 @@ def perform_operation(args): ret = enable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) + gf_event (eventtypes.SNAPSHOT_SCHEDULER_ENABLED, + status="Successfuly Enabled") + else: + gf_event (eventtypes.SNAPSHOT_SCHEDULER_ENABLE_FAILED, + error=print_error(ret)) return ret # Disable snapshot scheduler @@ -589,6 +641,11 @@ def perform_operation(args): ret = disable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) + gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLED, + status="Successfuly Disabled") + else: + gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLE_FAILED, + error=print_error(ret)) return ret # List snapshot schedules @@ -604,6 +661,12 @@ 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, + status="Successfuly added job "+args.jobname) + else: + gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED, + status="Failed to add job "+args.jobname, + error=print_error(ret)) return ret # Delete snapshot schedules @@ -614,6 +677,12 @@ 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, + status="Successfuly deleted job "+args.jobname) + else: + gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED, + status="Failed to delete job "+args.jobname, + error=print_error(ret)) return ret # Edit snapshot schedules @@ -624,6 +693,12 @@ 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, + status="Successfuly edited job "+args.jobname) + else: + gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED, + status="Failed to edit job "+args.jobname, + error=print_error(ret)) return ret ret = INVALID_ARG -- cgit