def execute(self, nodes, mclient_remove=True): cluster_id = None if hasattr(self, 'cluster'): cluster_id = self.cluster.id objects.TaskCollection.lock_cluster_tasks(cluster_id) logger.info("Trying to execute node deletion task with nodes %s", ', '.join(str(node.id) for node in nodes)) self.verify_nodes_with_cluster(nodes) objects.NodeCollection.lock_nodes(nodes) if cluster_id is None: # DeletionTask operates on cluster's nodes. # Nodes that are not in cluster are simply deleted. Node.delete_by_ids([n.id for n in nodes]) db().flush() task = Task(name=consts.TASK_NAMES.node_deletion, progress=100, status=consts.TASK_STATUSES.ready) db().add(task) db().flush() return task task = Task(name=consts.TASK_NAMES.node_deletion, cluster=self.cluster) db().add(task) for node in nodes: objects.Node.update(node, {'status': consts.NODE_STATUSES.removing}) db().flush() self._call_silently( task, tasks.DeletionTask, nodes=tasks.DeletionTask.prepare_nodes_for_task( nodes, mclient_remove=mclient_remove)) return task
def execute(self, nodes, mclient_remove=True): cluster_id = None if hasattr(self, 'cluster'): cluster_id = self.cluster.id objects.TaskCollection.lock_cluster_tasks(cluster_id) logger.info("Trying to execute node deletion task with nodes %s", ', '.join(str(node.id) for node in nodes)) self.verify_nodes_with_cluster(nodes) objects.NodeCollection.lock_nodes(nodes) if cluster_id is None: # DeletionTask operates on cluster's nodes. # Nodes that are not in cluster are simply deleted. Node.delete_by_ids([n.id for n in nodes]) db().flush() task = Task(name=consts.TASK_NAMES.node_deletion, progress=100, status=consts.TASK_STATUSES.ready) db().add(task) db().flush() return task task = Task(name=consts.TASK_NAMES.node_deletion, cluster=self.cluster) db().add(task) for node in nodes: objects.Node.update(node, {'status': consts.NODE_STATUSES.removing}) db().flush() self._call_silently(task, tasks.DeletionTask, nodes=tasks.DeletionTask.prepare_nodes_for_task( nodes, mclient_remove=mclient_remove)) return task
def remove_nodes_resp(cls, **kwargs): logger.info( "RPC method remove_nodes_resp received: %s" % jsonutils.dumps(kwargs) ) task_uuid = kwargs.get('task_uuid') nodes = kwargs.get('nodes') or [] error_nodes = kwargs.get('error_nodes') or [] inaccessible_nodes = kwargs.get('inaccessible_nodes') or [] error_msg = kwargs.get('error') status = kwargs.get('status') progress = kwargs.get('progress') if status in [consts.TASK_STATUSES.ready, consts.TASK_STATUSES.error]: progress = 100 # locking tasks on cluster task = objects.Task.get_by_uuid(task_uuid, fail_if_not_found=True) objects.TaskCollection.lock_cluster_tasks(task.cluster_id) task = objects.Task.get_by_uuid( task_uuid, fail_if_not_found=True, lock_for_update=True ) # locking cluster if task.cluster_id is not None: objects.Cluster.get_by_uid( task.cluster_id, fail_if_not_found=True, lock_for_update=True ) # locking nodes all_nodes = itertools.chain(nodes, error_nodes, inaccessible_nodes) all_nodes_ids = [ node['id'] if 'id' in node else node['uid'] for node in all_nodes ] locked_nodes = objects.NodeCollection.filter_by_list( None, 'id', all_nodes_ids, order_by='id' ) objects.NodeCollection.lock_for_update(locked_nodes).all() def get_node_id(n): return n.get('id', int(n.get('uid'))) Node.delete_by_ids([get_node_id(n) for n in nodes]) if(len(inaccessible_nodes) > 0): inaccessible_node_ids = [ get_node_id(n) for n in inaccessible_nodes] logger.warn(u'Nodes %s not answered by RPC, removing from db', inaccessible_nodes) Node.delete_by_ids(inaccessible_node_ids) for node in error_nodes: node_db = objects.Node.get_by_uid(node['uid']) if not node_db: logger.error( u"Failed to delete node '%s' marked as error from Astute:" " node doesn't exist", str(node) ) else: node_db.pending_deletion = False node_db.status = 'error' db().add(node_db) node['name'] = node_db.name db().flush() success_msg = u"No nodes were removed" err_msg = u"No errors occurred" if nodes: success_msg = u"Successfully removed {0} node(s)".format( len(nodes) ) notifier.notify("done", success_msg) if error_nodes: err_msg = u"Failed to remove {0} node(s): {1}".format( len(error_nodes), ', '.join( [n.get('name') or "ID: {0}".format(n['uid']) for n in error_nodes]) ) notifier.notify("error", err_msg) if not error_msg: error_msg = ". ".join([success_msg, err_msg]) data = { 'status': status, 'progress': progress, 'message': error_msg, } objects.Task.update(task, data) cls._update_action_log_entry(status, task.name, task_uuid, nodes)
def execute(self, nodes_to_delete, mclient_remove=True): cluster_id = None if hasattr(self, 'cluster'): cluster_id = self.cluster.id objects.TaskCollection.lock_cluster_tasks(cluster_id) logger.info("Trying to execute node deletion task with nodes %s", ', '.join(str(node.id) for node in nodes_to_delete)) self.verify_nodes_with_cluster(nodes_to_delete) objects.NodeCollection.lock_nodes(nodes_to_delete) if cluster_id is None: # DeletionTask operates on cluster's nodes. # Nodes that are not in cluster are simply deleted. Node.delete_by_ids([n.id for n in nodes_to_delete]) db().flush() task = Task(name=consts.TASK_NAMES.node_deletion, progress=100, status=consts.TASK_STATUSES.ready) db().add(task) db().flush() return task task = Task(name=consts.TASK_NAMES.node_deletion, cluster=self.cluster) db().add(task) for node in nodes_to_delete: objects.Node.update(node, {'status': consts.NODE_STATUSES.removing}) db().flush() nodes_to_deploy = [] objects.Cluster.adjust_nodes_lists_on_controller_removing( self.cluster, nodes_to_delete, nodes_to_deploy) if nodes_to_deploy: objects.NodeCollection.lock_nodes(nodes_to_deploy) # updating nodes objects.NodeCollection.update_slave_nodes_fqdn(nodes_to_deploy) logger.debug("There are nodes to deploy: %s", " ".join([n.fqdn for n in nodes_to_deploy])) task_deployment = task.create_subtask( consts.TASK_NAMES.deployment) deployment_message = self._call_silently( task_deployment, tasks.DeploymentTask, nodes_to_deploy, method_name='message' ) db().flush() # if failed to generate task message for orchestrator # then task is already set to error if task_deployment.status == consts.TASK_STATUSES.error: return task_deployment rpc.cast('naily', [deployment_message]) db().commit() self._call_silently( task, tasks.DeletionTask, nodes=tasks.DeletionTask.prepare_nodes_for_task( nodes_to_delete, mclient_remove=mclient_remove)) return task