public static boolean hasRelationship(NodeTemplate sourceNode, String targetNodeName, String requirementName, String capabilityName) { for (RelationshipTemplate relationshipTemplate : safe(sourceNode.getRelationships()).values()) { if (relationshipTemplate.getTarget().equals(targetNodeName) && relationshipTemplate.getRequirementName().equals(requirementName) && relationshipTemplate.getTargetedCapabilityName().equals(capabilityName)) { return true; } } return false; }
/** * Returns all the nodes that target this node template with the given requirement. */ public static Set<NodeTemplate> getSourceNodes(Topology topology, NodeTemplate nodeTemplate, String capabilityName) { Set<NodeTemplate> result = Sets.newHashSet(); for (NodeTemplate node : topology.getNodeTemplates().values()) { for (RelationshipTemplate relationshipTemplate : safe(node.getRelationships()).values()) { if (relationshipTemplate.getTargetedCapabilityName().equals(capabilityName) && relationshipTemplate.getTarget().equals(nodeTemplate.getName())) { result.add(node); } } } return result; }
private void processTargetOperations(PaaSRelationshipTemplate paaSRelationshipTemplate, ServiceResource serviceResource, Interface templateInterface) { // Drop default target operations as the service is the target of a relationship dropOperations(templateInterface, PRE_CONFIGURE_TARGET, POST_CONFIGURE_TARGET, ADD_SOURCE, REMOVE_SOURCE); // for services that are target of a relationship, all operations related to target (the service) are not run. if (paaSRelationshipTemplate.getTemplate().getTargetedCapabilityName() != null && serviceResource.getCapabilitiesRelationshipTypes() != null) { String relationshipTypeId = serviceResource.getCapabilitiesRelationshipTypes() .get(paaSRelationshipTemplate.getTemplate().getTargetedCapabilityName()); if (relationshipTypeId != null) { RelationshipType relationshipType = toscaTypeSearchService.findByIdOrFail(RelationshipType.class, relationshipTypeId); Interface serviceInterface = safe(relationshipType.getInterfaces()).get(ToscaRelationshipLifecycleConstants.CONFIGURE); if (serviceInterface != null) { overrideOperations(paaSRelationshipTemplate.getTemplate(), templateInterface, relationshipType, serviceInterface, PRE_CONFIGURE_TARGET, POST_CONFIGURE_TARGET, ADD_SOURCE, REMOVE_SOURCE); } } } }
/** * checks if a relationship is still valid * * @param nodeTemplate The source node of the relationship * @param relationshipTemplate The relationship to validate * @param topology The related topology */ private void validateRelationShip(NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate, Topology topology) { // This call should never throw a NotFoundException NodeType nodeType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType()); // validate the requirement checkRequirement(relationshipTemplate, nodeTemplate, nodeType); // validate the targeted capability checkCapability(relationshipTemplate.getTargetedCapabilityName(), topology.getNodeTemplates().get(relationshipTemplate.getTarget())); }
public boolean isCapabilityUpperBoundReachedForTarget(String nodeTemplateName, Map<String, NodeTemplate> nodeTemplates, String capabilityName, Set<CSARDependency> dependencies) { NodeTemplate nodeTemplate = nodeTemplates.get(nodeTemplateName); NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), dependencies); chekCapability(nodeTemplateName, capabilityName, nodeTemplate); CapabilityDefinition capabilityDefinition = getCapabilityDefinition(relatedIndexedNodeType.getCapabilities(), capabilityName); if (capabilityDefinition.getUpperBound() == Integer.MAX_VALUE) { return false; } List<RelationshipEntry> targetRelatedRelationships = TopologyUtils.getTargetRelationships(nodeTemplateName, nodeTemplates); if (targetRelatedRelationships == null || targetRelatedRelationships.isEmpty()) { return false; } int count = 0; for (RelationshipEntry relationshipEntry : targetRelatedRelationships) { if (relationshipEntry.getRelationship().getTargetedCapabilityName().equals(capabilityName)) { count++; } } return count >= capabilityDefinition.getUpperBound(); }
if (relationshipTemplate.getTarget().equals(compositionCouple.nodeName)) { SubstitutionTarget st = compositionCouple.child.getSubstitutionMapping().getCapabilities() .get(relationshipTemplate.getTargetedCapabilityName()); relationshipTemplate.setTarget(st.getNodeTemplateName()); relationshipTemplate.setTargetedCapabilityName(st.getTargetId());
injectTargetedCapabilityProperties(paaSNodeTemplates.get(template.getTarget()), template.getTargetedCapabilityName(), paaSRelationshipTemplate.getInterfaces());
String capabilityStr = relationshipTemplate.getTargetedCapabilityName(); // alien actually supports a capability type in the TOSCA yaml Capability capability = null; if (capabilityStr == null) {
private void updateRelationshipsCapabilitiesRelationships(Topology topology, NodeTemplate nodeTemplate) { List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTemplate.getName(), topology.getNodeTemplates()); for (RelationshipEntry targetRelationshipEntry : targetRelationships) { RelationshipTemplate targetRelationship = targetRelationshipEntry.getRelationship(); Capability capability = safe(nodeTemplate.getCapabilities()).get(targetRelationship.getTargetedCapabilityName()); if (capability == null || isCapabilityNotOfType(capability, targetRelationship.getRequirementType())) { Entry<String, Capability> capabilityEntry = NodeTemplateUtils.getCapabilitEntryyByType(nodeTemplate, targetRelationship.getRequirementType()); targetRelationship.setTargetedCapabilityName(capabilityEntry.getKey()); // check that the relationship type is still valid with the new capability RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, targetRelationship.getType()); if (!isValidRelationship(relationshipType, capabilityEntry.getValue())) { NodeType sourceNodeType = ToscaContext.get(NodeType.class, targetRelationshipEntry.getSource().getType()); RequirementDefinition requirementDefinition = NodeTypeUtils.getRequirementById(sourceNodeType, targetRelationshipEntry.getRelationship().getRequirementName()); NodeType targetNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); CapabilityDefinition capabilityDefinition = NodeTypeUtils.getCapabilityById(targetNodeType, capabilityEntry.getKey()); RelationshipType validRelationshipType = danglingRequirementService.fetchValidRelationshipType(requirementDefinition, capabilityDefinition); targetRelationship.setType(validRelationshipType.getElementId()); targetRelationship.setType(validRelationshipType.getElementId()); targetRelationship.setArtifacts(newLinkedHashMap(safe(validRelationshipType.getArtifacts()))); targetRelationship.setAttributes(newLinkedHashMap(safe(validRelationshipType.getAttributes()))); Map<String, AbstractPropertyValue> properties = new LinkedHashMap(); TemplateBuilder.fillProperties(properties, validRelationshipType.getProperties(), null); targetRelationship.setProperties(properties); } } } }