def execute(self): stop_running = db().query(Task).filter_by( cluster=self.cluster, name='stop_deployment' ).first() if stop_running: if stop_running.status == 'running': raise errors.StopAlreadyRunning( "Stopping deployment task " "is already launched" ) else: db().delete(stop_running) db().commit() deploy_running = db().query(Task).filter_by( cluster=self.cluster, name='deployment', status='running' ).first() if not deploy_running: provisioning_running = db().query(Task).filter_by( cluster=self.cluster, name='provision', status='running' ).first() if provisioning_running: raise errors.DeploymentNotRunning( u"Provisioning interruption for environment " u"'{0}' is not implemented right now".format( self.cluster.id ) ) raise errors.DeploymentNotRunning( u"Nothing to stop - deployment is " u"not running on environment '{0}'".format( self.cluster.id ) ) task = Task( name="stop_deployment", cluster=self.cluster ) db().add(task) db.commit() self._call_silently( task, tasks.StopDeploymentTask, deploy_task=deploy_running ) return task
def execute(self): # locking tasks for processing names = (TASK_NAMES.stop_deployment, TASK_NAMES.deployment, TASK_NAMES.provision) objects.TaskCollection.lock_cluster_tasks(self.cluster.id, names=names) stop_running = objects.TaskCollection.filter_by( None, cluster_id=self.cluster.id, name=TASK_NAMES.stop_deployment, ) stop_running = objects.TaskCollection.order_by(stop_running, 'id').first() if stop_running: if stop_running.status == TASK_STATUSES.running: raise errors.StopAlreadyRunning("Stopping deployment task " "is already launched") else: db().delete(stop_running) db().flush() deployment_task = objects.TaskCollection.filter_by( None, cluster_id=self.cluster.id, name=TASK_NAMES.deployment, ) deployment_task = objects.TaskCollection.order_by( deployment_task, 'id').first() provisioning_task = objects.TaskCollection.filter_by( None, cluster_id=self.cluster.id, name=TASK_NAMES.provision, ) provisioning_task = objects.TaskCollection.order_by( provisioning_task, 'id').first() if not deployment_task and not provisioning_task: db().rollback() raise errors.DeploymentNotRunning( u"Nothing to stop - deployment is " u"not running on environment '{0}'".format(self.cluster.id)) task = Task(name="stop_deployment", cluster=self.cluster) db().add(task) db().commit() self._call_silently(task, tasks.StopDeploymentTask, deploy_task=deployment_task, provision_task=provisioning_task) return task
def execute(self): stop_running = objects.TaskCollection.filter_by( None, cluster_id=self.cluster.id, name=consts.TASK_NAMES.stop_deployment) stop_running = objects.TaskCollection.order_by(stop_running, 'id').first() if stop_running: if stop_running.status in (consts.TASK_STATUSES.running, consts.TASK_STATUSES.pending): raise errors.StopAlreadyRunning("Stopping deployment task " "is already launched") else: db().delete(stop_running) db().commit() deployment_task = objects.TaskCollection.filter_by( None, cluster_id=self.cluster.id, name=consts.TASK_NAMES.deployment, ) deployment_task = deployment_task.filter( Task.status != consts.TASK_STATUSES.pending) deployment_task = objects.TaskCollection.order_by( deployment_task, '-id').first() provisioning_task = objects.TaskCollection.filter_by( None, cluster_id=self.cluster.id, name=consts.TASK_NAMES.provision, ) provisioning_task = provisioning_task.filter( Task.status != consts.TASK_STATUSES.pending) provisioning_task = objects.TaskCollection.order_by( provisioning_task, '-id').first() if not deployment_task and not provisioning_task: db().rollback() raise errors.DeploymentNotRunning( u"Nothing to stop - deployment is " u"not running on environment '{0}'".format(self.cluster.id)) # Updating action logs for deploy task deploy_task = objects.TaskCollection.filter_by( None, cluster_id=self.cluster.id, name=consts.TASK_NAMES.deploy) deploy_task = objects.TaskCollection.order_by(deploy_task, 'id').first() if deploy_task: TaskHelper.set_ready_if_not_finished(deploy_task) db().commit() task = Task(name=consts.TASK_NAMES.stop_deployment, cluster=self.cluster) db().add(task) db().commit() self._call_silently(task, tasks.StopDeploymentTask, deploy_task=deployment_task, provision_task=provisioning_task) return task