def _validate_relationship(self, dep_update, step): """ validates relation type entity id :param dep_update: :param step: deployment update step :return: """ entity_keys = utils.get_entity_keys(step.entity_id) if len(entity_keys) < 4: return False NODES, source_node_id, RELATIONSHIPS, relationship_index = entity_keys # assert the index is indeed readable relationship_index = utils.parse_index(relationship_index) if not relationship_index: return if step.operation == OPERATION_TYPE.REMOVE: source_node = self.sm.get_node(dep_update.deployment_id, source_node_id).to_dict() else: source_node = utils.get_raw_node(dep_update.blueprint, source_node_id) if not source_node or \ len(source_node[RELATIONSHIPS]) < relationship_index: return relationship = source_node[RELATIONSHIPS][relationship_index] target_node_id = relationship['target_id'] if step.operation == OPERATION_TYPE.REMOVE: return self.sm.get_node(dep_update.deployment_id, target_node_id) else: return utils.get_raw_node(dep_update.blueprint, target_node_id)
def __init__(self, plan, deployment_id, entity_type, node_id): self.sm = storage_manager.get_storage_manager() self._deployment_id = deployment_id self._entity_type = entity_type self._node_id = node_id self._plan = plan self._raw_node = utils.get_raw_node(self.blueprint, self._node_id)
def __init__(self, plan, deployment_id, entity_type, top_level_entity_id): super(NodeContextBase, self).__init__(plan, deployment_id, entity_type, top_level_entity_id) self._raw_super_entity = utils.get_raw_node(self.deployment_plan, self._top_level_entity_id)
def add(self, ctx, current_entities): get_blueprints_manager()._create_deployment_nodes( deployment_id=ctx.deployment_id, blueprint_id=None, plan=ctx.deployment_plan, node_ids=ctx.raw_node_id) current_entities[ctx.raw_node_id] = ctx.storage_node.to_dict() # node_handler.raw_node # Update new node relationships target nodes. Since any relationship # with target interface requires the target node to hold a plugin # which supports the operation, we should update the mapping for # this plugin under the target node. target_ids = [ r['target_id'] for r in ctx.raw_node.get(ctx.RELATIONSHIPS, []) ] for node_id in target_ids: node = self.sm.get_node(ctx.deployment_id, node_id) node.plugins = deployment_update_utils.get_raw_node( ctx.deployment_plan, node_id)['plugins'] self.sm.update_entity(node) current_entities[node_id] = node.to_dict() return ctx.raw_node_id
def __init__(self, plan, deployment_id, entity_type, top_level_entity_id): super(NodeContextBase, self).__init__(plan, deployment_id, entity_type, top_level_entity_id) self._raw_super_entity = \ utils.get_raw_node(self.deployment_plan, self._top_level_entity_id)
def _validate_node(self, dep_update, step): """ validates node type entity id :param dep_update: :param step: deployment update step :return: """ NODES, node_id = utils.get_entity_keys(step.entity_id) if step.operation == OPERATION_TYPE.REMOVE: return self.sm.get_node(dep_update.deployment_id, node_id) else: return utils.get_raw_node(dep_update.blueprint, node_id)
def __init__(self, plan, deployment_id, nodes_key, top_level_entity_id, relationships_key, relationship_index, *modification_breadcrumbs): super(RelationshipContext, self).__init__(plan, deployment_id, ENTITY_TYPES.RELATIONSHIP, top_level_entity_id) self._relationship_index = utils.parse_index(relationship_index) self._modification_breadcrumbs = modification_breadcrumbs self._raw_target_node = utils.get_raw_node(self.deployment_plan, self.target_id) entity_keys = [ nodes_key, top_level_entity_id, relationships_key, relationship_index ] entity_keys.extend(modification_breadcrumbs) self._entity_id = ':'.join(entity_keys)
def _validate_property(self, dep_update, step): property_keys = utils.get_entity_keys(step.entity_id) if len(property_keys) < 2: return NODES, node_id, PROPERTIES = property_keys[:3] property_id = property_keys[3:] storage_node = self.sm.get_node(dep_update.deployment_id, node_id) raw_node = utils.get_raw_node(dep_update.blueprint, node_id) is_in_old = utils.traverse_object(storage_node.properties, property_id) is_in_new = utils.traverse_object(raw_node[PROPERTIES], property_id) if step.operation == OPERATION_TYPE.REMOVE: return is_in_old elif step.operation == OPERATION_TYPE.ADD: return is_in_new else: return is_in_old and is_in_new
def add(self, ctx, current_entities): self.rm._create_deployment_nodes(deployment_id=ctx.deployment_id, plan=ctx.deployment_plan, node_ids=ctx.raw_node_id) # node_handler.raw_node current_entities[ctx.raw_node_id] = ctx.storage_node.to_dict() # Update new node relationships target nodes. Since any relationship # with target interface requires the target node to hold a plugin # which supports the operation, we should update the mapping for # this plugin under the target node. target_ids = [r['target_id'] for r in ctx.raw_node.get(ctx.RELATIONSHIPS, [])] for node_id in target_ids: node = get_node(ctx.deployment_id, node_id) node.plugins = deployment_update_utils.get_raw_node( ctx.deployment_plan, node_id)['plugins'] self.sm.update(node) current_entities[node_id] = node.to_dict() return ctx.raw_node_id
def __init__(self, plan, deployment_id, nodes_key, node_id, relationships_key, relationship_index, *modification_breadcrumbs): super(RelationshipContext, self).__init__(plan, deployment_id, ENTITY_TYPES.RELATIONSHIP, node_id) self._relationship_index = utils.parse_index(relationship_index) self._modification_breadcrumbs = modification_breadcrumbs self._raw_target_node = utils.get_raw_node(self.blueprint, self.target_id) entity_keys = [nodes_key, node_id, relationships_key, relationship_index] entity_keys.extend(modification_breadcrumbs) self._entity_id = ':'.join(entity_keys)
def _validate_operation(self, dep_update, step): operation_keys = utils.get_entity_keys(step.entity_id) if len(operation_keys) < 2: return NODES, node_id, operation_host = operation_keys[:3] operation_id = operation_keys[3:] base_node = self.sm.get_node(dep_update.deployment_id, node_id) is_in_old = utils.traverse_object(getattr(base_node, operation_host), operation_id) modified_node = utils.get_raw_node(dep_update.blueprint, node_id) is_in_new = utils.traverse_object(modified_node[operation_host], operation_id) if step.operation == OPERATION_TYPE.REMOVE: return is_in_old elif step.operation == OPERATION_TYPE.ADD: return is_in_new else: return is_in_old and is_in_new
def _add_node(self, ctx, current_nodes): """ handles adding a node :param ctx: :return: the new node """ get_blueprints_manager()._create_deployment_nodes( deployment_id=ctx.deployment_id, blueprint_id='N/A', plan=ctx.blueprint, node_ids=ctx.raw_node_id ) current_nodes[ctx.raw_node_id] = \ ctx.storage_node.to_dict() # node_handler.raw_node # Update new node relationships target nodes. Since any relationship # with target interface requires the target node to hold a plugin # which supports the operation, we should update the mapping for # this plugin under the target node. target_ids = [r['target_id'] for r in ctx.raw_node.get('relationships', [])] for node_id in target_ids: self.sm.update_node( deployment_id=ctx.deployment_id, node_id=node_id, changes={ 'plugins': utils.get_raw_node(ctx.blueprint, node_id)['plugins'] }) current_nodes[node_id] = \ self.sm.get_node(ctx.deployment_id, node_id).to_dict() return ctx.raw_node_id