private Map<String, NodeType> getNodeTypes(Topology topology) { Map<String, NodeType> nodeTypes = Maps.newHashMap(); for (NodeTemplate template : safe(topology.getNodeTemplates()).values()) { if (!nodeTypes.containsKey(template.getType())) { NodeType nodeType = ToscaContext.getOrFail(NodeType.class, template.getType()); nodeTypes.put(nodeType.getElementId(), nodeType); } } return nodeTypes; } }
/** * Get the possible inputs candidates to be associated with this node template property. */ @ApiOperation(value = "Get the possible inputs candidates to be associated with this property.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ]") @RequestMapping(value = "/node", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public RestResponse<List<String>> getNodetemplatePropertyInputCandidate( @ApiParam(value = "The topology id.", required = true) @NotBlank @PathVariable final String topologyId, @ApiParam(value = "The node temlate id.", required = true) @NotBlank @RequestParam(value = "nodeTemplateName") final String nodeTemplateName, @ApiParam(value = "The property id.", required = true) @NotBlank @RequestParam("propertyId") final String propertyId) { List<String> inputCandidates = editorService.getInputCandidates(topologyId, nodeTemplateName, nodeTemplate -> ToscaContext.get(NodeType.class, nodeTemplate.getType()).getProperties().get(propertyId)); return RestResponseBuilder.<List<String>> builder().data(inputCandidates).build(); }
public List<DeprecatedNodeTask> validate(Topology topology) { List<DeprecatedNodeTask> taskList = Lists.newArrayList(); topology.getNodeTemplates().forEach((nodeTemplateName, nodeTemplate) -> { NodeType type = ToscaContext.get(NodeType.class, nodeTemplate.getType()); if (isDeprecated(type)) { taskList.add(new DeprecatedNodeTask(nodeTemplateName, type)); } }); return taskList; }
/** * Put the locationResourceTemplates to the appropriate List of the locationResources passed as param */ private void setLocationRessource(List<LocationResourceTemplate> locationResourceTemplates, LocationResources locationResources) { for (LocationResourceTemplate resourceTemplate : locationResourceTemplates) { String templateType = resourceTemplate.getTemplate().getType(); if (locationResources.getConfigurationTypes().containsKey(templateType)) { locationResources.getConfigurationTemplates().add(resourceTemplate); } if (locationResources.getNodeTypes().containsKey(templateType)) { locationResources.getNodeTemplates().add(resourceTemplate); } } }
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); } } } }
public static boolean isComputeOrNetwork(String nodeId, TopologyContext topologyContext) { NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId); if (nodeTemplate == null) { return false; } NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType()); return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, NETWORK_TYPE); }
public static boolean isComputeOrVolume(String nodeId, TopologyContext topologyContext) { NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId); if (nodeTemplate == null) { return false; } NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType()); return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, "tosca.nodes.BlockStorage"); }
private List<NodeTemplate> getTargets(PolicyTemplate policy, Topology topology, FlowExecutionContext context) { List<NodeTemplate> targets = Lists.newArrayList(); for (String targetName : safe(policy.getTargets())) { NodeTemplate target = safe(topology.getNodeTemplates()).get(targetName); // This modifier is injected after matching phase. Nodes must have been matched against valid type. if (!AWS_MOCK_COMPUTE_TYPE.equals(target.getType())) { context.log().error("Anti-affinity policy {} is not correctly configured, target {} is not an instance of {}.", policy.getName(), target.getName(), AWS_MOCK_COMPUTE_TYPE); return null; } targets.add(target); } return targets; } }
private void fillCapabilities(Topology topology, NodeType substituteNodeType) { if (topology.getSubstitutionMapping().getCapabilities() != null) { for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getCapabilities().entrySet()) { String key = e.getKey(); String nodeName = e.getValue().getNodeTemplateName(); String capabilityName = e.getValue().getTargetId(); NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName); NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType()); CapabilityDefinition capabilityDefinition = IndexedModelUtils.getCapabilityDefinitionById(nodeTemplateType.getCapabilities(), capabilityName); // We cannot change the capability definition here or we will change the original one so we need a clone capabilityDefinition = CloneUtil.clone(capabilityDefinition); capabilityDefinition.setId(key); substituteNodeType.getCapabilities().add(capabilityDefinition); } } }
private void fillRequirements(Topology topology, NodeType substituteNodeType) { if (topology.getSubstitutionMapping().getRequirements() != null) { for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getRequirements().entrySet()) { String key = e.getKey(); String nodeName = e.getValue().getNodeTemplateName(); String requirementName = e.getValue().getTargetId(); NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName); NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType()); RequirementDefinition requirementDefinition = IndexedModelUtils.getRequirementDefinitionById(nodeTemplateType.getRequirements(), requirementName); // We cannot change the capability definition here or we will change the original one so we need a clone requirementDefinition = CloneUtil.clone(requirementDefinition); requirementDefinition.setId(key); substituteNodeType.getRequirements().add(requirementDefinition); } } }
/** * validate that a node still has a capability, by checkibg directly from the related node type * * @param capabilityName The name of the capability to check * @param nodeTemplate The node template in which to check for the capability */ private void checkCapability(String capabilityName, NodeTemplate nodeTemplate) { // FIXME check if the relationship is still valid concerning binded capability // This call should never throw a NotFoundException NodeType indexedNodeType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType()); Map<String, CapabilityDefinition> capabilitiesMap = AlienUtils.fromListToMap(indexedNodeType.getCapabilities(), "id", true); if (!AlienUtils.safe(capabilitiesMap).containsKey(capabilityName)) { throw new InvalidStateException("A capability with name [" + capabilityName + "] cannot be found in the node [" + nodeTemplate.getName() + "]."); } }
/** * 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())); }
@Override public LocationResourceTemplateWithDependencies duplicateResourceTemplate(String resourceId) { LocationResourceTemplate locationResourceTemplate = getOrFail(resourceId); locationResourceTemplate.setId(UUID.randomUUID().toString()); locationResourceTemplate.setName(locationResourceTemplate.getName() + "_" + "copy"); locationResourceTemplate.setGenerated(false); Location location = locationService.getOrFail(locationResourceTemplate.getLocationId()); NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, locationResourceTemplate.getTemplate().getType(), location.getDependencies()); publishCreatedEventAndSaveResource(location, locationResourceTemplate, resourceType); return new LocationResourceTemplateWithDependencies(locationResourceTemplate, Sets.newHashSet(location.getDependencies())); }
public static boolean isNativeOrSubstitutionNode(String nodeId, TopologyContext topologyContext) { NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId); if (nodeTemplate == null) { return false; } NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType()); if (nodeType.isAbstract() || nodeType.getSubstitutionTopologyId() != null) { return true; } // TODO: the following should be removed after merge with orchestrator refactoring branch // (since these types will be abstract) return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, NETWORK_TYPE) || isOfType(nodeType, "tosca.nodes.BlockStorage"); }
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; }
@Override protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsSecretOperation operation, NodeTemplate nodeTemplate) { // check if the node property value is a get_secret AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName()); if (currentValue != null && !isGetSecret(currentValue)) { throw new NotFoundException("Property {} of node {} is not associated to an secret.", operation.getPropertyName(), operation.getNodeName()); } NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); PropertyDefinition nodePropertyDefinition = getOrFail(nodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName()); AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(nodePropertyDefinition); nodeTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue); log.debug("Remove secret property [ {} ] of the node template [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), topology.getId()); } }
private void validateCommand(OperationExecRequest operationRequest, Topology topology) throws ConstraintFunctionalException { NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operationRequest.getNodeTemplateName(), TopologyUtils.getNodeTemplates(topology)); NodeType indexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies()); Map<String, Interface> interfaces = IndexedModelUtils.mergeInterfaces(indexedNodeType.getInterfaces(), nodeTemplate.getInterfaces()); if (interfaces == null || interfaces.get(operationRequest.getInterfaceName()) == null) { throw new NotFoundException("Interface [" + operationRequest.getInterfaceName() + "] not found in the node template [" + operationRequest.getNodeTemplateName() + "] related to [" + indexedNodeType.getId() + "]"); } Interface interfass = interfaces.get(operationRequest.getInterfaceName()); validateOperation(interfass, operationRequest, topology.getDependencies()); }
@Override protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) { // check if the node property value is a get_input AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName()); if (!isGetInput(currentValue)) { throw new NotFoundException("Property {} of node {} is not associated to an input.", operation.getPropertyName(), operation.getNodeName()); } NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); PropertyDefinition nodePropertyDefinition = getOrFail(nodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName()); AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(nodePropertyDefinition); nodeTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue); log.debug("Remove association from property [ {} ] of the node template [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), topology.getId()); } }
private void setTemplateCapabilityProperty(LocationResourceTemplate resourceTemplate, String capabilityName, String propertyName, Object propertyValue) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException { Location location = locationService.getOrFail(resourceTemplate.getLocationId()); NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, resourceTemplate.getTemplate().getType(), location.getDependencies()); Capability capability = getOrFailCapability(resourceTemplate.getTemplate(), capabilityName); CapabilityDefinition capabilityDefinition = getOrFailCapabilityDefinition(resourceType, capabilityName); CapabilityType capabilityType = csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), location.getDependencies()); PropertyDefinition propertyDefinition = getOrFailCapabilityPropertyDefinition(capabilityType, propertyName); propertyService.setCapabilityPropertyValue(location.getDependencies(), capability, propertyDefinition, propertyName, propertyValue); }
@Then("^The RestResponse should contain a nodetemplate named \"([^\"]*)\" and type \"([^\"]*)\"") public void The_RestResponse_should_contain_a_nodetemplate_named_and_type(String key, String type) throws Throwable { TopologyDTO topologyDTO = JsonUtil.read(Context.getInstance().getRestResponse(), TopologyDTO.class, Context.getJsonMapper()).getData(); assertNotNull(topologyDTO); assertNotNull(topologyDTO.getTopology()); assertNotNull(topologyDTO.getTopology().getNodeTemplates()); assertEquals(type, topologyDTO.getTopology().getNodeTemplates().get(key).getType()); }