@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()); }
@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"); } }
public ServiceNodeTemplate(NodeTemplate nodeTemplate, Map<String, String> attributeValues) { super(nodeTemplate.getType(), nodeTemplate.getProperties(), nodeTemplate.getAttributes(), nodeTemplate.getRelationships(), nodeTemplate.getRequirements(), nodeTemplate.getCapabilities(), nodeTemplate.getInterfaces(), nodeTemplate.getArtifacts()); this.attributeValues = attributeValues; }
instance.setAttributes(tempObject.getAttributes()); instance.setCapabilities(tempObject.getCapabilities()); instance.setProperties(tempObject.getProperties());
@Override protected void processServiceResourceReplacement(Topology topology, Map<String, NodeTemplate> topologyTemplateMap, String nodeId, String serviceResourceId) { ServiceResource serviceResource = getServiceResourceService().getOrFail(serviceResourceId); NodeTemplate serviceNodeTemplate = serviceResource.getNodeInstance().getNodeTemplate(); ServiceNodeTemplate substitutionNodeTemplate = new ServiceNodeTemplate(serviceNodeTemplate.getType(), serviceNodeTemplate.getProperties(), serviceNodeTemplate.getAttributes(), serviceNodeTemplate.getRelationships(), serviceNodeTemplate.getRequirements(), serviceNodeTemplate.getCapabilities(), serviceNodeTemplate.getInterfaces(), serviceNodeTemplate.getArtifacts()); substitutionNodeTemplate.setServiceResourceId(serviceResource.getId()); substitutionNodeTemplate.setAttributeValues(serviceResource.getNodeInstance().getAttributeValues()); NodeTemplate abstractTopologyNode = topologyTemplateMap.put(nodeId, substitutionNodeTemplate); substitutionNodeTemplate.setName(abstractTopologyNode.getName()); substitutionNodeTemplate.setRelationships(abstractTopologyNode.getRelationships()); // add all the necessary dependencies to the topology Csar csar = getToscaTypeSearchService().getArchive(serviceResource.getDependency().getName(), serviceResource.getDependency().getVersion()); Set<CSARDependency> dependencies = Sets.newHashSet(); if (csar.getDependencies() != null) { dependencies.addAll(csar.getDependencies()); } dependencies.add(new CSARDependency(csar.getName(), csar.getVersion())); topology.getDependencies().addAll(dependencies); } }