/** * 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 fillSubstituteAttributesFromTypeAtttributes(Topology topology, NodeType substituteNodeType) { Map<String, IValue> attributes = substituteNodeType.getAttributes(); Map<String, Set<String>> outputAttributes = topology.getOutputAttributes(); if (outputAttributes != null) { for (Map.Entry<String, Set<String>> oae : outputAttributes.entrySet()) { String nodeName = oae.getKey(); NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology, nodeName); NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType()); for (String attributeName : oae.getValue()) { IValue ivalue = nodeTemplateType.getAttributes().get(attributeName); // FIXME we have an issue here : if several nodes have the same attribute name, or if an attribute and a property have the same name, there // is a conflict if (ivalue != null && !attributes.containsKey(attributeName)) { attributes.put(attributeName, ivalue); } } } } }
if (child.getOutputAttributes() != null) { for (Entry<String, Set<String>> oae : child.getOutputAttributes().entrySet()) { String nodeName = oae.getKey(); for (String oa : oae.getValue()) { if (oa.equals(proxyAttributeName)) { Map<String, Set<String>> parentOas = parent.getOutputAttributes(); if (parentOas == null) { parentOas = Maps.newHashMap();
@Override protected void processNodeOperation(Csar csar, Topology topology, UnSetNodeAttributeAsOutputOperation operation, NodeTemplate nodeTemplate) { // check if the attribute exists check(operation, topology, nodeTemplate); Map<String, Set<String>> outputs = topology.getOutputAttributes(); removeAndClean(operation, outputs); topology.setOutputAttributes(outputs); log.debug("Unset node [ {} ]'s attribute [ {} ] as output for the topology [ {} ].", operation.getNodeName(), operation.getAttributeName(), topology.getId()); }
@Override protected void processNodeOperation(Csar csar, Topology topology, SetNodeAttributeAsOutputOperation operation, NodeTemplate nodeTemplate) { // check if the attribute exists Map<String, IValue> attributes = nodeTemplate.getAttributes(); if (!AlienUtils.safe(attributes).containsKey(operation.getAttributeName())) { throw new NotFoundException("Attribute " + operation.getAttributeName() + "not found in node template " + operation.getNodeName() + "."); } Map<String, Set<String>> outputs = topology.getOutputAttributes(); if (outputs == null) { outputs = Maps.newHashMap(); } if (outputs.containsKey(operation.getNodeName())) { outputs.get(operation.getNodeName()).add(operation.getAttributeName()); } else { outputs.put(operation.getNodeName(), Sets.newHashSet(operation.getAttributeName())); } topology.setOutputAttributes(outputs); log.debug("Set node [ {} ]'s attribute [ {} ] as output for the topology [ {} ].", operation.getNodeName(), operation.getAttributeName(), 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); }
@Then("^The topology should not have the attribute \"([^\"]*)\" of the node \"([^\"]*)\" defined as output attribute$") public void The_topology_should_not_have_the_attribute_of_the_node_defined_as_output_attribute(String attributeName, String nodeName) throws Throwable { TopologyDTO topologyDTO = getTopologyDTO(); Map<String, Set<String>> outputAttributes = topologyDTO.getTopology().getOutputAttributes(); if (outputAttributes != null) { Set<String> outputAttributesOfNode = outputAttributes.get(nodeName); if (outputAttributesOfNode != null) { Assert.assertFalse(outputAttributesOfNode.contains(attributeName)); } } }
@SuppressWarnings("unchecked") private void check(UnSetNodeAttributeAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) { Map<String, IValue> attributes = nodeTemplate.getAttributes(); if (!AlienUtils.safe(attributes).containsKey(operation.getAttributeName())) { throw new NotFoundException("Attribute " + operation.getAttributeName() + "not found in node template " + operation.getNodeName() + "."); } Set<String> values = (Set<String>) MapUtil.get(topology.getOutputAttributes(), operation.getNodeName()); if (!AlienUtils.safe(values).contains(operation.getAttributeName())) { throw new NotFoundException("Node " + operation.getNodeName() + " 's attribute " + operation.getAttributeName() + " not found in outputs"); } }
@Then("^The topology should have the attribute \"([^\"]*)\" of the node \"([^\"]*)\" defined as output attribute$") public void The_topology_should_have_the_attribute_of_the_node_defined_as_output_attribute(String attributeName, String nodeName) throws Throwable { TopologyDTO topologyDTO = getTopologyDTO(); Map<String, Set<String>> outputAttributes = topologyDTO.getTopology().getOutputAttributes(); Assert.assertNotNull(outputAttributes); Set<String> outputAttributesOfNode = outputAttributes.get(nodeName); Assert.assertNotNull(outputAttributesOfNode); Assert.assertTrue(outputAttributesOfNode.contains(attributeName)); }
if (compositionCouple.parent.getOutputAttributes() != null) { Set<String> outputAttributes = compositionCouple.parent.getOutputAttributes().remove(compositionCouple.nodeName); if (outputAttributes != null) { for (String proxyAttributeName : outputAttributes) {
MapUtil.replaceKey(topology.getOutputAttributes(), oldName, newName);
/** * 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); } } } } }