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, nodes_key, top_level_entity_id, relatonships_key, relationship_index, operations_key, operation_id, *modification_breadcrumbs): super(RelationshipInterfaceOperationContext, self).__init__( plan, deployment_id, ENTITY_TYPES.OPERATION, top_level_entity_id) self._relationships_index = utils.parse_index(relationship_index) self._operations_key = operations_key self._operation_id = operation_id self._modification_breadcrumbs = modification_breadcrumbs entity_keys = [nodes_key, top_level_entity_id, relatonships_key, relationship_index, operation_id] entity_keys.extend(modification_breadcrumbs) self._entity_id = ':'.join(entity_keys)
def modify(self, ctx, current_entities): source_index = ctx.relationship_index target_index = deployment_update_utils.parse_index( ctx.modification_breadcrumbs[0]) relationships = current_entities[ctx.raw_node_id][ctx.RELATIONSHIPS] self._resize_relationships(relationships, target_index) relationship = ctx.storage_node.relationships[source_index] relationships[target_index] = relationship return ctx.raw_node_id, (source_index, target_index)
def __init__(self, plan, deployment_id, nodes_key, top_level_entity_id, relatonships_key, relationship_index, operations_key, operation_id, *modification_breadcrumbs): super(RelationshipInterfaceOperationContext, self).__init__(plan, deployment_id, ENTITY_TYPES.OPERATION, top_level_entity_id) self._relationships_index = utils.parse_index(relationship_index) self._operations_key = operations_key self._operation_id = operation_id self._modification_breadcrumbs = modification_breadcrumbs entity_keys = [ nodes_key, top_level_entity_id, relatonships_key, relationship_index, operation_id ] entity_keys.extend(modification_breadcrumbs) self._entity_id = ':'.join(entity_keys)
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 __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)