Alex Lourie has uploaded a new change for review. Change subject: packaging: [DO NOT MERGE] Handling active tasks during upgrade ......................................................................
packaging: [DO NOT MERGE] Handling active tasks during upgrade DO NOT MERGE!!! Added a function call that checks that there are no running tasks nor compensations. If there are such tasks, we first try to stop them, and if there are still tasks after a certain timeout, we stop the upgrade and recommend clearing the tasks before they continue. Change-Id: I90abb3d1e6ad0ac5557485e40064e811fc87f491 Signed-off-by: Alex Lourie <alou...@redhat.com> --- M packaging/fedora/setup/engine-upgrade.py 1 file changed, 89 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/40/8740/1 diff --git a/packaging/fedora/setup/engine-upgrade.py b/packaging/fedora/setup/engine-upgrade.py index 14bbd6a..0bc3c35 100755 --- a/packaging/fedora/setup/engine-upgrade.py +++ b/packaging/fedora/setup/engine-upgrade.py @@ -8,6 +8,7 @@ import logging import traceback import types +import time import pwd from optparse import OptionParser import common_utils as utils @@ -15,6 +16,10 @@ from miniyum import MiniYum # Consts + +WAIT_PERIOD = 60 +MAX_CYCLES = 20 + #TODO: Work with a real list here RPM_LIST = """ ovirt-engine @@ -56,6 +61,11 @@ UNSUPPORTED_VERSION = "2.2" #MSGS +MSG_STOP_RUNNING_TASKS = "Info: There are following running tasks and compensations \ +found in the manager:\n\nTasks:\n%s\n\nCompensations:\n%s\n\n\ +Would you like to proceed with the upgrade (and try to stop tasks automatically)?\n Answering \ +'no' will stop the upgrade." +MSG_RUNNING_TASKS_CLEARED = "Info: no running tasks found. Continue" MSG_ERROR_USER_NOT_ROOT = "Error: insufficient permissions for user %s, you must run with user root." MSG_NO_ROLLBACK = "Error: Current installation " MSG_RC_ERROR = "Return Code is not zero" @@ -738,6 +748,83 @@ MSG_ERROR_CONNECT_DB ) +def getRunningTasks(): + + runningTasks = {} + + # Get async tasks: + query = "select action_type from async_tasks;" + runningTasks['async_tasks'], rc = utils.execRemoteSqlCommand( + userName=SERVER_ADMIN, + dbHost=SERVER_NAME, + dbPort=SERVER_PORT, + dbName=basedefs.DB_NAME, + sqlQuery=query, + failOnError=True, + errMsg="Can't get async tasks list", + ) + + + # Get compensations + query = "select command_type, entity type from business_entity_snapshot;" + runningTasks['compensations'], rc = utils.execRemoteSqlCommand( + userName=SERVER_ADMIN, + dbHost=SERVER_NAME, + dbPort=SERVER_PORT, + dbName=basedefs.DB_NAME, + sqlQuery=query, + failOnError=True, + errMsg="Can't get compensations list", + ) + + + return runningTasks + +def checkRunningTasks(): + # Find running tasks first + runningTasks = getRunningTasks() + + if len(runningTasks['async_tasks']) > 0 or \ + len(runningTasks['compensations']) > 0: + + try: + # TODO: update runningTasks names/presentation and compensations + answerYes = utils.askYesNo(MSG_STOP_RUNNING_TASKS % + (runningTasks['async_tasks'], + runningTasks['compensations'])) + if not answerYes: + raise Exception("User decided not to stop running tasks.\ + Stopping upgrade.") + + # restart jboss/engine in maintenace mode (i.e different port): + configureMaintMode() + configureZombies() + startMaintMode() + + # Pull tasks in a loop for some time + # WAIT_PERIOD = 60 (seconds, between trials) + # MAX_CYCLES = 20 (how many times to try) + count = 0 + while runningTasks > 0 and count < MAX_CYCLES: + time.sleep(WAIT_PERIOD) + runningTasks = getRunningTasks() + count += 1 + + # Restore normal configuration + restoreNormalMode() + + # Check if there are still running tasks + if len(runningTasks) > 0: + # There are still tasks running, so ask user what to do + raise Exception("There are still running tasks. Please make sure \ + that there are no running before you continue. \ + Stopping upgrade.") + + + except: + raise Exception("Couldn't find detect tasks in rhevm") + + def main(options): # BEGIN: PROCESS-INITIALIZATION miniyumsink = utils.MiniYumSink() @@ -840,6 +927,8 @@ runFunc(stopEngineService, MSG_INFO_STOP_ENGINE) if updateRelatedToDB: runFunc([[stopDbRelatedServices, etlService, notificationService]], MSG_INFO_STOP_DB) + + runFunc([checkRunningTasks], MSG_RUNNING_TASKS_CLEARED) else: # This means that user chose not to stop ovirt-engine logging.debug("exiting gracefully") -- To view, visit http://gerrit.ovirt.org/8740 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I90abb3d1e6ad0ac5557485e40064e811fc87f491 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alex Lourie <alou...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches