/** * 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 fillSubstituteAttributesFromOutputProperties(Topology topology, NodeType substituteNodeType) { Map<String, Set<String>> outputProperties = topology.getOutputProperties(); if (outputProperties != null) { for (Map.Entry<String, Set<String>> ope : outputProperties.entrySet()) { String nodeName = ope.getKey(); NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName); NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType()); for (String propertyName : ope.getValue()) { PropertyDefinition pd = nodeTemplateType.getProperties().get(propertyName); // is a conflict addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType); } } } }
if (child.getOutputProperties() != null) { for (Entry<String, Set<String>> ope : child.getOutputProperties().entrySet()) { String nodeName = ope.getKey(); for (String op : ope.getValue()) { if (op.equals(proxyAttributeName)) { Map<String, Set<String>> parentOps = parent.getOutputProperties(); if (parentOps == null) { parentOps = Maps.newHashMap();
@Override protected void processNodeOperation(Csar csar, Topology topology, UnSetNodePropertyAsOutputOperation operation, NodeTemplate nodeTemplate) { // check if the property exists check(operation, topology, nodeTemplate); Map<String, Set<String>> outputs = topology.getOutputProperties(); removeAndClean(operation, outputs); topology.setOutputProperties(outputs); log.debug("Unset node [ {} ]'s property [ {} ] as output for the topology [ {} ].", operation.getNodeName(), 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, SetNodePropertyAsOutputOperation operation, NodeTemplate nodeTemplate) { // check if the property exists Map<String, AbstractPropertyValue> properties = nodeTemplate.getProperties(); if (!AlienUtils.safe(properties).containsKey(operation.getPropertyName())) { throw new NotFoundException("Property " + operation.getPropertyName() + "not found in node template " + operation.getNodeName() + "."); } Map<String, Set<String>> outputs = topology.getOutputProperties(); if (outputs == null) { outputs = Maps.newHashMap(); } if (outputs.containsKey(operation.getNodeName())) { outputs.get(operation.getNodeName()).add(operation.getPropertyName()); } else { outputs.put(operation.getNodeName(), Sets.newHashSet(operation.getPropertyName())); } topology.setOutputProperties(outputs); log.debug("Set node [ {} ]'s property [ {} ] as output for the topology [ {} ].", operation.getNodeName(), operation.getPropertyName(), topology.getId()); }
@Then("^The topology should not have the property \"([^\"]*)\" of the node \"([^\"]*)\" defined as output property$") public void The_topology_should_not_have_the_property_of_the_node_defined_as_output_property(String propertyName, String nodeName) throws Throwable { TopologyDTO topologyDTO = getTopologyDTO(); Map<String, Set<String>> outputProperties = topologyDTO.getTopology().getOutputProperties(); if (outputProperties != null) { Set<String> outputPropertiesOfNode = outputProperties.get(nodeName); if (outputPropertiesOfNode != null) { Assert.assertFalse(outputPropertiesOfNode.contains(propertyName)); } } }
@SuppressWarnings("unchecked") private void check(UnSetNodePropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) { Map<String, AbstractPropertyValue> properties = nodeTemplate.getProperties(); if (!AlienUtils.safe(properties).containsKey(operation.getPropertyName())) { throw new NotFoundException("Property " + operation.getPropertyName() + "not found in node template " + operation.getNodeName() + "."); } Set<String> values = (Set<String>) MapUtil.get(topology.getOutputProperties(), operation.getNodeName()); if (!AlienUtils.safe(values).contains(operation.getPropertyName())) { throw new NotFoundException("Node " + operation.getNodeName() + " 's property " + operation.getPropertyName() + " not found in outputs"); } }
MapUtil.replaceKey(topology.getOutputProperties(), oldName, newName); MapUtil.replaceKey(topology.getOutputCapabilityProperties(), oldName, newName); MapUtil.replaceKey(topology.getOutputAttributes(), oldName, newName);
@Then("^The topology should have the property \"([^\"]*)\" of the node \"([^\"]*)\" defined as output property$") public void The_topology_should_have_the_property_of_the_node_defined_as_output_property(String propertyName, String nodeName) throws Throwable { TopologyDTO topologyDTO = getTopologyDTO(); Map<String, Set<String>> outputProperties = topologyDTO.getTopology().getOutputProperties(); Assert.assertNotNull(outputProperties); Set<String> outputPropertiesOfNode = outputProperties.get(nodeName); Assert.assertNotNull(outputPropertiesOfNode); Assert.assertTrue(outputPropertiesOfNode.contains(propertyName)); }
/** * 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); } } } } }