def handle(self, dep_update): """handles updating new and extended nodes onto the storage. :param dep_update: :return: a list of all of the nodes (including the non add_node.modification nodes) """ current_nodes = self.sm.list_nodes( filters={ 'deployment_id': dep_update.deployment_id }).items nodes_dict = {node.id: node.to_dict() for node in current_nodes} modified_entities = deployment_update_utils.ModifiedEntitiesDict() # Iterate over the steps of the deployment update and handle each # step according to its operation, passing the deployment update # object, step entity type, entity id and a dict of updated nodes. # Each handler updated the dict of updated nodes, which enables # accumulating changes. for step in dep_update.steps: if step.entity_type in self._supported_entity_types: entity_handler = self._entity_handlers[step.entity_type] entity_updater = getattr(entity_handler, step.action) entity_context = get_entity_context(dep_update.deployment_plan, dep_update.deployment_id, step.entity_type, step.entity_id) entity_id = entity_updater(entity_context, nodes_dict) modified_entities[step.entity_type].append(entity_id) return modified_entities, nodes_dict.values()
def handle(self, dep_update): """handles updating new and extended nodes onto the storage. :param dep_update: :return: a list of all of the nodes (including the non modified nodes) """ current_nodes = self.sm.get_nodes( filters={'deployment_id': dep_update.deployment_id}).items nodes_dict = {node.id: node.to_dict() for node in current_nodes} entities_update_mapper = { OPERATION_TYPE.ADD: self._add_entity, OPERATION_TYPE.REMOVE: self._remove_entity, OPERATION_TYPE.MODIFY: self._modify_entity } # Iterate over the steps of the deployment update and handle each # step according to its operation, passing the deployment update # object, step entity type, entity id and a dict of updated nodes. # Each handler updated the dict of updated nodes, which enables # accumulating changes. for step in dep_update.steps: entity_updater = entities_update_mapper[step.operation] entity_context = get_entity_context(dep_update.blueprint, dep_update.deployment_id, step.entity_type, step.entity_id) entity_id = entity_updater(entity_context, nodes_dict) self.modified_entities[step.entity_type].append(entity_id) return self.modified_entities, nodes_dict.values()
def handle(self, dep_update): deployment = dep_update.deployment.to_dict() modified_entities = { ENTITY_TYPES.WORKFLOW: [], ENTITY_TYPES.OUTPUT: [], ENTITY_TYPES.DESCRIPTION: [] } for step in dep_update.steps: if step.entity_type in self._supported_entity_types: entity_handler = self._entity_handlers[step.entity_type] entity_updater = getattr(entity_handler, step.action) entity_context = get_entity_context(dep_update.deployment_plan, dep_update.deployment_id, step.entity_type, step.entity_id) entity_id = entity_updater(entity_context, deployment) modified_entities[step.entity_type].append(entity_id) return modified_entities, deployment
def _fill_modified_entities(dep_update, supported_entity_types, entity_handlers, modified_entities, current_entities_dict): """ Iterate over the steps of the deployment update and handle each step according to its operation, passing the deployment update object, step entity type, entity id and a dict of updated nodes. Each handler updated the dict of updated nodes, which enables accumulating changes. """ for step in dep_update.steps: if step.entity_type in supported_entity_types: entity_handler = entity_handlers[step.entity_type] entity_updater = getattr(entity_handler, step.action) entity_context = get_entity_context(dep_update.deployment_plan, dep_update.deployment_id, step.entity_type, step.entity_id) entity_id = entity_updater(entity_context, current_entities_dict) modified_entities[step.entity_type].append(entity_id)