/** * Remove a nodeTemplate outputs in a topology */ private void removeOutputs(String nodeTemplateName, Topology topology) { if (topology.getOutputProperties() != null) { topology.getOutputProperties().remove(nodeTemplateName); } if (topology.getOutputAttributes() != null) { topology.getOutputAttributes().remove(nodeTemplateName); } if (topology.getOutputCapabilityProperties() != null) { topology.getOutputCapabilityProperties().remove(nodeTemplateName); } }
private void fillAttributesFromOutputCapabilitiesProperties(Topology topology, NodeType substituteNodeType) { Map<String, Map<String, Set<String>>> outputCapabilityProperties = topology.getOutputCapabilityProperties(); if (outputCapabilityProperties != null) { for (Map.Entry<String, Map<String, Set<String>>> ocpe : outputCapabilityProperties.entrySet()) { String nodeName = ocpe.getKey(); NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName); for (Map.Entry<String, Set<String>> cpe : ocpe.getValue().entrySet()) { String capabilityName = cpe.getKey(); String capabilityTypeName = nodeTemplate.getCapabilities().get(capabilityName).getType(); CapabilityType capabilityType = ToscaContext.getOrFail(CapabilityType.class, capabilityTypeName); for (String propertyName : cpe.getValue()) { PropertyDefinition pd = capabilityType.getProperties().get(propertyName); // there is a conflict addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType); } } } } }
if (child.getOutputCapabilityProperties() != null) { for (Entry<String, Map<String, Set<String>>> ocpe : child.getOutputCapabilityProperties().entrySet()) { String nodeName = ocpe.getKey(); for (Entry<String, Set<String>> cpes : ocpe.getValue().entrySet()) { if (op.equals(proxyAttributeName)) { Map<String, Map<String, Set<String>>> parentOcps = parent.getOutputCapabilityProperties(); if (parentOcps == null) { parentOcps = Maps.newHashMap();
@Override protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsOutputOperation operation, NodeTemplate nodeTemplate) { // check if the capability / property exists check(operation, topology, nodeTemplate); //ensure non null maps and collections Map<String, Map<String, Set<String>>> outputs = emptyIfNull(topology.getOutputCapabilityProperties()); Map<String, Set<String>> capabilitiesOutputs = emptyIfNull(outputs.get(operation.getNodeName())); outputs.put(operation.getNodeName(), capabilitiesOutputs); Set<String> outputProperties = emptyIfNull(capabilitiesOutputs.get(operation.getCapabilityName())); capabilitiesOutputs.put(operation.getCapabilityName(), outputProperties); outputProperties.add(operation.getPropertyName()); topology.setOutputCapabilityProperties(outputs); log.debug("Set node[ {} ] capability [ {} ]'s property [ {} ] as output for the topology [ {} ].", operation.getNodeName(), operation.getCapabilityName(), operation.getPropertyName(), topology.getId()); }
/** * Copy outputs of a node template in a topology */ private void copyOutputs(Topology topology, String toCopy, String copyName) { // Output properties copyValue(topology.getOutputProperties(), toCopy, copyName); // output capabilities properties copyCapabilitiesOutputProperties(topology.getOutputCapabilityProperties(), toCopy, copyName); // output attributes copyValue(topology.getOutputAttributes(), toCopy, copyName); }
@Override protected void processNodeOperation(Csar csar, Topology topology, UnSetNodeCapabilityPropertyAsOutputOperation operation, NodeTemplate nodeTemplate) { // check if the capability / property exists check(operation, topology, nodeTemplate); Map<String, Map<String, Set<String>>> outputs = topology.getOutputCapabilityProperties(); removeAndClean(operation, outputs); topology.setOutputCapabilityProperties(outputs); log.debug("Set node[ {} ] capability [ {} ]'s property [ {} ] as output for the topology [ {} ].", operation.getNodeName(), operation.getCapabilityName(), operation.getPropertyName(), topology.getId()); }
@Then("^The topology should not have the capability property \"([^\"]*)\" of the capability \"([^\"]*)\" for the node \"([^\"]*)\" defined as output property$") public void The_topology_should_not_have_the_capability_property_of_the_capability_for_the_node_defined_as_output_property(String propertyName, String capabilityId, String nodeName) throws Throwable { TopologyDTO topologyDTO = getTopologyDTO(); Map<String, Map<String, Set<String>>> outputCapabilityProperties = topologyDTO.getTopology().getOutputCapabilityProperties(); Assert.assertNotNull(outputCapabilityProperties); Map<String, Set<String>> outputPropertiesOfNode = outputCapabilityProperties.get(nodeName); Assert.assertNotNull(outputPropertiesOfNode); Set<String> outputPropertiesOfCapability = outputPropertiesOfNode.get(capabilityId); Assert.assertNotNull(outputPropertiesOfCapability); Assert.assertFalse(outputPropertiesOfCapability.contains(propertyName)); }
@Then("^The topology should have the capability property \"([^\"]*)\" of the capability \"([^\"]*)\" for the node \"([^\"]*)\" defined as output property$") public void The_topology_should_have_the_capability_property_of_the_capability_for_the_node_defined_as_output_property(String propertyName, String capabilityId, String nodeName) throws Throwable { TopologyDTO topologyDTO = getTopologyDTO(); Map<String, Map<String, Set<String>>> outputCapabilityProperties = topologyDTO.getTopology().getOutputCapabilityProperties(); Assert.assertNotNull(outputCapabilityProperties); Map<String, Set<String>> outputPropertiesOfNode = outputCapabilityProperties.get(nodeName); Assert.assertNotNull(outputPropertiesOfNode); Set<String> outputPropertiesOfCapability = outputPropertiesOfNode.get(capabilityId); Assert.assertNotNull(outputPropertiesOfCapability); Assert.assertTrue(outputPropertiesOfCapability.contains(propertyName)); }
MapUtil.replaceKey(topology.getOutputCapabilityProperties(), oldName, newName); MapUtil.replaceKey(topology.getOutputAttributes(), oldName, newName);
@SuppressWarnings("unchecked") private void check(UnSetNodeCapabilityPropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) { if (nodeTemplate.getCapabilities() == null || nodeTemplate.getCapabilities().get(operation.getCapabilityName()) == null) { throw new NotFoundException("Capability " + operation.getCapabilityName() + " not found in node template " + operation.getNodeName()); } Capability capabilityTemplate = nodeTemplate.getCapabilities().get(operation.getCapabilityName()); CapabilityType indexedCapabilityType = EditionContextManager.get().getToscaContext().getElement(CapabilityType.class, capabilityTemplate.getType(), true); if (indexedCapabilityType.getProperties() == null || !indexedCapabilityType.getProperties().containsKey(operation.getPropertyName())) { throw new NotFoundException("Property " + operation.getPropertyName() + " not found in capability " + operation.getCapabilityName() + " of node " + operation.getNodeName()); } Set<String> values = (Set<String>) MapUtil.get(topology.getOutputCapabilityProperties(), operation.getNodeName().concat(".").concat(operation.getCapabilityName())); if (!AlienUtils.safe(values).contains(operation.getPropertyName())) { throw new NotFoundException("Node " + operation.getNodeName() + " capability " + operation.getCapabilityName() + " 's property " + operation.getPropertyName() + " not found in outputs"); } }
/** * Update properties in a topology */ private static void updateOnNodeTemplateNameChange(String oldNodeTemplateName, String newNodeTemplateName, Topology topology) { // Output properties updateKey(topology.getOutputProperties(), oldNodeTemplateName, newNodeTemplateName); // output capabilities properties updateKey(topology.getOutputCapabilityProperties(), oldNodeTemplateName, newNodeTemplateName); // output attributes updateKey(topology.getOutputAttributes(), oldNodeTemplateName, newNodeTemplateName); // substitution mapping if (topology.getSubstitutionMapping() != null) { if (topology.getSubstitutionMapping().getCapabilities() != null) { for (SubstitutionTarget st : topology.getSubstitutionMapping().getCapabilities().values()) { if (st.getNodeTemplateName().equals(oldNodeTemplateName)) { st.setNodeTemplateName(newNodeTemplateName); } } } if (topology.getSubstitutionMapping().getRequirements() != null) { for (SubstitutionTarget st : topology.getSubstitutionMapping().getRequirements().values()) { if (st.getNodeTemplateName().equals(oldNodeTemplateName)) { st.setNodeTemplateName(newNodeTemplateName); } } } } }