@Override public void process(Csar csar, Topology topology, UpdateInputExpressionOperation operation) { if (topology.getInputs() == null || !topology.getInputs().containsKey(operation.getName())) { throw new NotFoundException("Input <" + operation.getName() + "> is not defined in topology <" + topology.getId() + ">"); } super.process(csar, topology, operation); }
@Override public void process(Csar csar, Topology topology, T operation) { Map<String, PropertyDefinition> inputs = topology.getInputs(); if (inputs == null) { if (create()) { inputs = Maps.newHashMap(); } else { throw new NotFoundException("The topology has no defined input"); } } processInputOperation(csar, topology, operation, inputs); }
public void setInputValues(ApplicationEnvironment environment, Topology topology, Map<String, Object> inputProperties) { if (safe(inputProperties).isEmpty()) { return; } // Get the configuration object DeploymentInputs configuration = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId())); if (configuration == null) { configuration = new DeploymentInputs(environment.getTopologyVersion(), environment.getId()); } for (Map.Entry<String, Object> inputPropertyValue : inputProperties.entrySet()) { if (topology.getInputs() == null || topology.getInputs().get(inputPropertyValue.getKey()) == null) { throw new NotFoundException("Input", inputPropertyValue.getKey(), "Input <" + inputPropertyValue.getKey() + "> cannot be found on topology for application <" + environment.getApplicationId() + "> environement <" + environment.getId() + ">"); } try { propertyService.setPropertyValue(configuration.getInputs(), topology.getInputs().get(inputPropertyValue.getKey()), inputPropertyValue.getKey(), inputPropertyValue.getValue()); } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) { throw new ConstraintTechnicalException("Dispatching constraint violation.", e); } } // Save configuration deploymentConfigurationDao.save(configuration); }
Map<String, PropertyDefinition> inputs = topology.getInputs(); List<String> inputIds = new ArrayList<String>(); if (inputs != null && !inputs.isEmpty()) {
inputValues.putAll(predefinedInputValues); for (Entry<String, PropertyDefinition> propDef : safe(topology.getInputs()).entrySet()) { if (propDef.getValue().isRequired() && inputValues.get(propDef.getKey()) == null) { task.getProperties().get(TaskLevel.REQUIRED).add(propDef.getKey());
/** * Check that the value of a property has the right type and match constraints. * * @param type The type that defines the properties (NodeType, CapabilityType, RequirementType). * @param propertyValues The map of values. * @param templateName The name of the node template /capability template / requirement template. */ public void checkProperties(final AbstractInheritableToscaType type, final Map<String, AbstractPropertyValue> propertyValues, final String templateName) { if (type == null) { return; // if the type is null we cannot check properties against their definition. Error is managed elsewhere. } ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance(); Topology topology = archiveRoot.getTopology(); for (Map.Entry<String, AbstractPropertyValue> propertyEntry : safe(propertyValues).entrySet()) { String propertyName = propertyEntry.getKey(); AbstractPropertyValue propertyValue = propertyEntry.getValue(); Node propertyValueNode = ParsingContextExecution.getObjectToNodeMap().get(propertyValue); if (type.getProperties() == null || !type.getProperties().containsKey(propertyName)) { ParsingContextExecution.getParsingErrors() .add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.UNRECOGNIZED_PROPERTY, templateName, propertyValueNode.getStartMark(), "Property " + propertyName + " does not exist in type " + type.getElementId(), propertyValueNode.getEndMark(), propertyName)); continue; } PropertyDefinition propertyDefinition = type.getProperties().get(propertyName); checkProperty(propertyName, propertyValueNode, propertyValue, propertyDefinition, topology.getInputs(), templateName); } }
safe(instance.getInputs()).entrySet().forEach(propertyDefinitionPostProcessor); safe(instance.getInputArtifacts()).values().forEach(typeDeploymentArtifactPostProcessor);
.resolve(inputsMappingsMap, topology.getInputs()); for (Map.Entry<String, PropertyValue> entry : safe(inputsResolvingResult.getResolved()).entrySet()) { try { ConstraintPropertyService.checkPropertyConstraint(entry.getKey(), entry.getValue(), topology.getInputs().get(entry.getKey())); } catch (ConstraintViolationException e) { violations.put(entry.getKey(), getConstraintInformation(e.getMessage(), e.getConstraintInformation()));
@Override protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) { PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName()); NodeType indexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType()); PropertyDefinition nodePropertyDefinition = getOrFail(indexedNodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName()); // Check that the property definition of the input is indeed compatible with the property definition of the capability. inputPropertyDefinition.checkIfCompatibleOrFail(nodePropertyDefinition); FunctionPropertyValue getInput = new FunctionPropertyValue(); getInput.setFunction(ToscaFunctionConstants.GET_INPUT); getInput.setParameters(Arrays.asList(operation.getInputName())); nodeTemplate.getProperties().put(operation.getPropertyName(), getInput); log.debug("Associate the property [ {} ] of the node template [ {} ] to input [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), operation.getInputName(), topology.getId()); } }
@Override protected void processRelationshipOperation(Csar csar, Topology topology, SetRelationshipPropertyAsInputOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) { PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName()); RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType()); PropertyDefinition relationshipPropertyDefinition = getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property {} do not exist for relationship {} of node {}", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName()); // Check that the property definition of the input is indeed compatible with the property definition of the capability. inputPropertyDefinition.checkIfCompatibleOrFail(relationshipPropertyDefinition); FunctionPropertyValue getInput = new FunctionPropertyValue(); getInput.setFunction(ToscaFunctionConstants.GET_INPUT); getInput.setParameters(Arrays.asList(operation.getInputName())); relationshipTemplate.getProperties().put(operation.getPropertyName(), getInput); log.debug("Associate the property [ {} ] of relationship template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName(), topology.getId()); } }
@Then("^The topology should have the property \"([^\"]*)\" defined as input property$") public void The_topology_should_have_the_property_of_the_node_defined_as_input_property(String inputId) throws Throwable { String response = Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId()); JavaType restResponseType = Context.getJsonMapper().getTypeFactory().constructParametricType(RestResponse.class, TopologyDTO.class); TopologyDTO topologyDTO = ((RestResponse<TopologyDTO>) Context.getJsonMapper().readValue(response, restResponseType)).getData(); Map<String, PropertyDefinition> inputProperties = topologyDTO.getTopology().getInputs(); Assert.assertNotNull(inputProperties); PropertyDefinition inputPropertieDefinition = inputProperties.get(inputId); Assert.assertNotNull(inputPropertieDefinition); }
@Override protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsInputOperation operation, NodeTemplate nodeTemplate) { Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName()); PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName()); CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capabilityTemplate.getType()); PropertyDefinition capabilityPropertyDefinition = getOrFail(capabilityType.getProperties(), operation.getPropertyName(), "Property {} do not exist for capability {} of node {}", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName()); // Check that the property definition of the input is indeed compatible with the property definition of the capability. inputPropertyDefinition.checkIfCompatibleOrFail(capabilityPropertyDefinition); FunctionPropertyValue getInput = new FunctionPropertyValue(); getInput.setFunction(ToscaFunctionConstants.GET_INPUT); getInput.setParameters(Arrays.asList(operation.getInputName())); capabilityTemplate.getProperties().put(operation.getPropertyName(), getInput); log.debug("Associate the property [ {} ] of capability template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId()); } }
@Then("^The topology should not have the property \"([^\"]*)\" defined as input property$") public void The_topology_should_not_have_the_property_defined_as_input_property(String inputId) throws Throwable { TopologyDTO topologyDTO = JsonUtil.read(Context.getRestClientInstance().get("/rest/v1/topologies/" + Context.getInstance().getTopologyId()), TopologyDTO.class, Context.getJsonMapper()).getData(); Map<String, PropertyDefinition> inputProperties = topologyDTO.getTopology().getInputs(); Assert.assertFalse(inputProperties.containsKey(inputId)); }
substituteNodeType.setProperties(topology.getInputs());