def _call_silently(self, task, instance, *args, **kwargs): # create action_log for task al = TaskHelper.create_action_log(task) method = getattr(instance, kwargs.pop('method_name', 'execute')) if task.status == consts.TASK_STATUSES.error: TaskHelper.update_action_log(task, al) return try: to_return = method(task, *args, **kwargs) # update action_log instance for task # for asynchronous task it will be not final update # as they also are updated in rpc receiver TaskHelper.update_action_log(task, al) return to_return except errors.NoChanges as e: self._finish_task(task, al, consts.TASK_STATUSES.ready, str(e)) except Exception as exc: if any([ not hasattr(exc, "log_traceback"), hasattr(exc, "log_traceback") and exc.log_traceback ]): logger.error(traceback.format_exc()) self._finish_task(task, al, consts.TASK_STATUSES.error, str(exc))
def execute(self, force=False, **kwargs): try: self.clear_tasks_history(force=force) except errors.TaskAlreadyRunning: raise errors.DeploymentAlreadyStarted( "Can't reset environment '{0}' when " "running deployment task exists.".format( self.cluster.id ) ) # FIXME(aroma): remove updating of 'deployed_before' # when stop action is reworked. 'deployed_before' # flag identifies whether stop action is allowed for the # cluster. Please, refer to [1] for more details. # [1]: https://bugs.launchpad.net/fuel/+bug/1529691 objects.Cluster.set_deployed_before_flag(self.cluster, value=False) nodes = objects.Cluster.get_nodes_by_role( self.cluster, consts.VIRTUAL_NODE_TYPES.virt ) for node in nodes: objects.Node.reset_vms_created_state(node) objects.ClusterPluginLinkCollection.delete_by_cluster_id( self.cluster.id) db().commit() supertask = Task( name=consts.TASK_NAMES.reset_environment, cluster=self.cluster ) db().add(supertask) al = TaskHelper.create_action_log(supertask) reset_nodes = supertask.create_subtask( consts.TASK_NAMES.reset_nodes ) remove_keys_task = supertask.create_subtask( consts.TASK_NAMES.remove_keys ) remove_ironic_bootstrap_task = supertask.create_subtask( consts.TASK_NAMES.remove_ironic_bootstrap ) db.commit() rpc.cast('naily', [ tasks.ResetEnvironmentTask.message(reset_nodes), tasks.RemoveIronicBootstrap.message(remove_ironic_bootstrap_task), tasks.RemoveClusterKeys.message(remove_keys_task) ]) TaskHelper.update_action_log(supertask, al) return supertask
def execute(self, **kwargs): # FIXME(aroma): remove updating of 'deployed_before' # when stop action is reworked. 'deployed_before' # flag identifies whether stop action is allowed for the # cluster. Please, refer to [1] for more details. # [1]: https://bugs.launchpad.net/fuel/+bug/1529691 objects.Cluster.set_deployed_before_flag(self.cluster, value=False) deploy_running = db().query(Task).filter_by( cluster=self.cluster, name=consts.TASK_NAMES.deploy, status='running').first() if deploy_running: raise errors.DeploymentAlreadyStarted( u"Can't reset environment '{0}' when " u"deployment is running".format(self.cluster.id)) obsolete_tasks = db().query(Task).filter_by( cluster_id=self.cluster.id, ).filter( Task.name.in_([ consts.TASK_NAMES.deploy, consts.TASK_NAMES.deployment, consts.TASK_NAMES.stop_deployment ])) for task in obsolete_tasks: db().delete(task) nodes = objects.Cluster.get_nodes_by_role( self.cluster, consts.VIRTUAL_NODE_TYPES.virt) for node in nodes: objects.Node.reset_vms_created_state(node) db().commit() supertask = Task(name=consts.TASK_NAMES.reset_environment, cluster=self.cluster) db().add(supertask) al = TaskHelper.create_action_log(supertask) remove_keys_task = supertask.create_subtask( consts.TASK_NAMES.reset_environment) remove_ironic_bootstrap_task = supertask.create_subtask( consts.TASK_NAMES.reset_environment) db.commit() rpc.cast('naily', [ tasks.ResetEnvironmentTask.message(supertask), tasks.RemoveIronicBootstrap.message(remove_ironic_bootstrap_task), tasks.RemoveClusterKeys.message(remove_keys_task) ]) TaskHelper.update_action_log(supertask, al) return supertask
def execute(self): deploy_running = db().query(Task).filter_by( cluster=self.cluster, name=consts.TASK_NAMES.deploy, status='running' ).first() if deploy_running: raise errors.DeploymentAlreadyStarted( u"Can't reset environment '{0}' when " u"deployment is running".format( self.cluster.id ) ) obsolete_tasks = db().query(Task).filter_by( cluster_id=self.cluster.id, ).filter( Task.name.in_([ consts.TASK_NAMES.deploy, consts.TASK_NAMES.deployment, consts.TASK_NAMES.stop_deployment ]) ) for task in obsolete_tasks: db().delete(task) nodes = objects.Cluster.get_nodes_by_role( self.cluster, consts.VIRTUAL_NODE_TYPES.virt) for node in nodes: objects.Node.reset_vms_created_state(node) db().commit() supertask = Task( name=consts.TASK_NAMES.reset_environment, cluster=self.cluster ) db().add(supertask) al = TaskHelper.create_action_log(supertask) remove_keys_task = supertask.create_subtask( consts.TASK_NAMES.reset_environment ) db.commit() rpc.cast('naily', [ tasks.ResetEnvironmentTask.message(supertask), tasks.RemoveClusterKeys.message(remove_keys_task) ]) TaskHelper.update_action_log(supertask, al) return supertask
def _finish_task(self, task, log_item, status, message): data = {'status': status, 'progress': 100, 'message': message} # update task entity with given data objects.Task.update(task, data) # NOTE(romcheg): Flushing the data is required to unlock # tasks in order to temporary fix issues with # the deadlock detection query in tests and let the tests pass. # TODO(akislitsky): Get rid of this flush as soon as # task locking issues are resolved. db().flush() TaskHelper.update_action_log(task, log_item) db().commit()
def execute(self): deploy_running = db().query(Task).filter_by( cluster=self.cluster, name=consts.TASK_NAMES.deploy, status='running').first() if deploy_running: raise errors.DeploymentAlreadyStarted( u"Can't reset environment '{0}' when " u"deployment is running".format(self.cluster.id)) obsolete_tasks = db().query(Task).filter_by( cluster_id=self.cluster.id, ).filter( Task.name.in_([ consts.TASK_NAMES.deploy, consts.TASK_NAMES.deployment, consts.TASK_NAMES.stop_deployment ])) for task in obsolete_tasks: db().delete(task) nodes = objects.Cluster.get_nodes_by_role( self.cluster, consts.VIRTUAL_NODE_TYPES.virt) for node in nodes: objects.Node.reset_vms_created_state(node) db().commit() supertask = Task(name=consts.TASK_NAMES.reset_environment, cluster=self.cluster) db().add(supertask) al = TaskHelper.create_action_log(supertask) remove_keys_task = supertask.create_subtask( consts.TASK_NAMES.reset_environment) db.commit() rpc.cast('naily', [ tasks.ResetEnvironmentTask.message(supertask), tasks.RemoveClusterKeys.message(remove_keys_task) ]) TaskHelper.update_action_log(supertask, al) return supertask
def _call_silently(self, task, instance, *args, **kwargs): # create action_log for task al = TaskHelper.create_action_log(task) method = getattr(instance, kwargs.pop('method_name', 'execute')) if task.status == TASK_STATUSES.error: TaskHelper.update_action_log(task, al) return try: to_return = method(task, *args, **kwargs) # update action_log instance for task # for asynchronous task it will be not final update # as they also are updated in rpc receiver TaskHelper.update_action_log(task, al) return to_return except Exception as exc: err = str(exc) if any([ not hasattr(exc, "log_traceback"), hasattr(exc, "log_traceback") and exc.log_traceback ]): logger.error(traceback.format_exc()) # update task entity with given data data = {'status': 'error', 'progress': 100, 'message': err} objects.Task.update(task, data) TaskHelper.update_action_log(task, al)
def _call_silently(self, task, instance, *args, **kwargs): # create action_log for task al = TaskHelper.create_action_log(task) method = getattr(instance, kwargs.pop('method_name', 'execute')) if task.status == consts.TASK_STATUSES.error: TaskHelper.update_action_log(task, al) return try: to_return = method(task, *args, **kwargs) # update action_log instance for task # for asynchronous task it will be not final update # as they also are updated in rpc receiver TaskHelper.update_action_log(task, al) return to_return except Exception as exc: err = str(exc) if any([ not hasattr(exc, "log_traceback"), hasattr(exc, "log_traceback") and exc.log_traceback ]): logger.error(traceback.format_exc()) # update task entity with given data data = {'status': 'error', 'progress': 100, 'message': err} objects.Task.update(task, data) # NOTE(romcheg): Flushing the data is required to unlock # tasks in order to temporary fix issues with # the deadlock detection query in tests and let the tests pass. # TODO(akislitsky): Get rid of this flush as soon as # task locking issues are resolved. db().flush() TaskHelper.update_action_log(task, al) db().commit()
def execute(self, **kwargs): # FIXME(aroma): remove updating of 'deployed_before' # when stop action is reworked. 'deployed_before' # flag identifies whether stop action is allowed for the # cluster. Please, refer to [1] for more details. # [1]: https://bugs.launchpad.net/fuel/+bug/1529691 objects.Cluster.set_deployed_before_flag(self.cluster, value=False) deploy_running = db().query(Task).filter_by( cluster=self.cluster, name=consts.TASK_NAMES.deploy, status='running' ).first() if deploy_running: raise errors.DeploymentAlreadyStarted( u"Can't reset environment '{0}' when " u"deployment is running".format( self.cluster.id ) ) obsolete_tasks = db().query(Task).filter_by( cluster_id=self.cluster.id, ).filter( Task.name.in_([ consts.TASK_NAMES.deploy, consts.TASK_NAMES.deployment, consts.TASK_NAMES.stop_deployment ]) ) for task in obsolete_tasks: db().delete(task) nodes = objects.Cluster.get_nodes_by_role( self.cluster, consts.VIRTUAL_NODE_TYPES.virt) for node in nodes: objects.Node.reset_vms_created_state(node) db().commit() supertask = Task( name=consts.TASK_NAMES.reset_environment, cluster=self.cluster ) db().add(supertask) al = TaskHelper.create_action_log(supertask) remove_keys_task = supertask.create_subtask( consts.TASK_NAMES.reset_environment ) remove_ironic_bootstrap_task = supertask.create_subtask( consts.TASK_NAMES.reset_environment ) db.commit() rpc.cast('naily', [ tasks.ResetEnvironmentTask.message(supertask), tasks.RemoveIronicBootstrap.message(remove_ironic_bootstrap_task), tasks.RemoveClusterKeys.message(remove_keys_task) ]) TaskHelper.update_action_log(supertask, al) return supertask