#NEWLINE# @ app . task ( bind = True ) #NEWLINE# def upgrade_mongodb_24_to_30( self , database , user , task_history = None ) : #NEWLINE# #INDENT# from workflow.settings import MONGODB_UPGRADE_24_TO_30_SINGLE #NEWLINE# from workflow.settings import MONGODB_UPGRADE_24_TO_30_HA #NEWLINE# from util import build_dict #NEWLINE# from workflow.workflow import start_workflow #NEWLINE# worker_name = get_worker_name ( ) #NEWLINE# task_history = TaskHistory . register ( request = self . request , task_history = task_history , user = user , worker_name = worker_name ) #NEWLINE# databaseinfra = database . databaseinfra #NEWLINE# driver = databaseinfra . get_driver ( ) #NEWLINE# instances = driver . get_database_instances ( ) #NEWLINE# source_plan = databaseinfra . plan #NEWLINE# target_plan = source_plan . engine_equivalent_plan #NEWLINE# source_engine = source_engine . engine #NEWLINE# target_engine = source_engine . engine_upgrade_option #NEWLINE# if source_plan . is_ha : #NEWLINE# #INDENT# steps = MONGODB_UPGRADE_24_TO_30_HA #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# steps = MONGODB_UPGRADE_24_TO_30_SINGLE #NEWLINE# #UNINDENT# stop_now = False #NEWLINE# if ( not target_plan ) : #NEWLINE# #INDENT# msg = 'There is not Engine Equivalent Plan!' #NEWLINE# stop_now = True #NEWLINE# #UNINDENT# if ( not target_engine ) : #NEWLINE# #INDENT# msg = 'There is not Engine Upgrade Option!' #NEWLINE# stop_now = True #NEWLINE# #UNINDENT# if ( ( database . status != Database . ALIVE ) or ( not database . database_status . is_alive ) ) : #NEWLINE# #INDENT# msg = 'Database is not alive!' #NEWLINE# stop_now = True #NEWLINE# #UNINDENT# if database . is_beeing_used_elsewhere ( task_id = self . request . id ) : #NEWLINE# #INDENT# msg = 'Database is in use by another task!' #NEWLINE# stop_now = True #NEWLINE# #UNINDENT# if database . has_migration_started ( ) : #NEWLINE# #INDENT# msg = 'Region migration for this database has already started!' #NEWLINE# stop_now = True #NEWLINE# #UNINDENT# if ( not source_engine . version . startswith ( '2.4.' ) ) : #NEWLINE# #INDENT# msg = 'Database version must be 2.4!' #NEWLINE# stop_now = True #NEWLINE# #UNINDENT# if ( target_engine and ( target_engine . version != '3.0.8' ) ) : #NEWLINE# #INDENT# msg = 'Target database version must be 3.0.8!' #NEWLINE# stop_now = True #NEWLINE# #UNINDENT# if stop_now : #NEWLINE# #INDENT# task_history . update_status_for ( TaskHistory . STATUS_ERROR , details = msg ) #NEWLINE# LOG . info ( 'Upgrade finished' ) #NEWLINE# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# disable_zabbix_alarms ( database ) #NEWLINE# workflow_dict = build_dict ( steps = steps , databaseinfra = databaseinfra , instances = instances , source_plan = source_plan , target_plan = target_plan , source_engine = source_engine , target_engine = target_engine ) #NEWLINE# start_workflow ( workflow_dict = workflow_dict , task = task_history ) #NEWLINE# if workflow_dict [ 'exceptions' ] [ 'traceback' ] : #NEWLINE# #INDENT# error = '\n' . join ( ( ': ' . join ( err ) for err in workflow_dict [ 'exceptions' ] [ 'error_codes' ] ) ) #NEWLINE# traceback = '\nException Traceback\n' . join ( workflow_dict [ 'exceptions' ] [ 'traceback' ] ) #NEWLINE# error = '{}\n{}\n{}' . format ( error , traceback , error ) #NEWLINE# task_history . update_status_for ( TaskHistory . STATUS_ERROR , details = error ) #NEWLINE# LOG . info ( 'MongoDB Upgrade finished with errors' ) #NEWLINE# return #NEWLINE# #UNINDENT# task_history . update_status_for ( TaskHistory . STATUS_SUCCESS , details = 'MongoDB sucessfully upgraded!' ) #NEWLINE# LOG . info ( 'MongoDB Upgrade finished' ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# task_history . update_status_for ( TaskHistory . STATUS_ERROR , details = e ) #NEWLINE# LOG . warning ( 'MongoDB Upgrade finished with errors' ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# enable_zabbix_alarms ( database )