Search in sources :

Example 6 with FunctionPropertyValue

use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.

the class PropertyValueChecker method checkProperty.

public void checkProperty(String propertyName, Node propertyValueNode, AbstractPropertyValue propertyValue, PropertyDefinition propertyDefinition, Map<String, PropertyDefinition> inputs, String templateName) {
    if (propertyValue instanceof FunctionPropertyValue) {
        FunctionPropertyValue function = (FunctionPropertyValue) propertyValue;
        String parameters = function.getParameters().get(0);
        // check get_input only
        if (function.getFunction().equals("get_input")) {
            if (inputs == null || !inputs.keySet().contains(parameters)) {
                ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.MISSING_TOPOLOGY_INPUT, templateName, propertyValueNode.getStartMark(), parameters, propertyValueNode.getEndMark(), propertyName));
            }
        }
    } else if (propertyValue instanceof PropertyValue<?>) {
        checkProperty(propertyName, propertyValueNode, (PropertyValue<?>) propertyValue, propertyDefinition, templateName);
    }
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)

Example 7 with FunctionPropertyValue

use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.

the class TemplateBuilder method fillProperties.

public static void fillProperties(Map<String, AbstractPropertyValue> properties, Map<String, PropertyDefinition> propertiesDefinitions, Map<String, AbstractPropertyValue> originalProperties, boolean adaptToType) {
    if (propertiesDefinitions == null || properties == null) {
        return;
    }
    for (Map.Entry<String, PropertyDefinition> entry : propertiesDefinitions.entrySet()) {
        AbstractPropertyValue originalValue = MapUtils.getObject(originalProperties, entry.getKey());
        if (originalValue == null) {
            AbstractPropertyValue pv = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(entry.getValue());
            properties.put(entry.getKey(), pv);
        } else if (originalValue instanceof FunctionPropertyValue || originalValue instanceof ConcatPropertyValue) {
            properties.put(entry.getKey(), originalValue);
        } else {
            // we check the property type before accepting it
            try {
                ConstraintPropertyService.checkPropertyConstraint(entry.getKey(), originalValue, entry.getValue());
                properties.put(entry.getKey(), originalValue);
            } catch (ConstraintFunctionalException e) {
                log.debug("Not able to merge property <" + entry.getKey() + "> value due to a type check exception", e);
                if (adaptToType) {
                    AbstractPropertyValue pv = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(entry.getValue());
                    properties.put(entry.getKey(), pv);
                }
            }
        }
    }
    if (!adaptToType) {
        // maybe we could put validations here actually.
        for (Map.Entry<String, AbstractPropertyValue> originalProperty : safe(originalProperties).entrySet()) {
            if (!properties.containsKey(originalProperty.getKey())) {
                properties.put(originalProperty.getKey(), originalProperty.getValue());
            }
        }
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Map(java.util.Map) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)

Example 8 with FunctionPropertyValue

use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.

the class SetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.

@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());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 9 with FunctionPropertyValue

use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.

the class SetNodePropertyAsInputProcessor method processNodeOperation.

@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());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 10 with FunctionPropertyValue

use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.

the class DeploymentTopologyStepDefinitions method iSetTheInputsPropertyAsASecretWithTheFollowingParameters.

@When("^I set the inputs property \"([^\"]*)\" as a secret with the following parameters$")
public void iSetTheInputsPropertyAsASecretWithTheFollowingParameters(String propertyName, Map<String, String> parameters) throws Throwable {
    FunctionPropertyValue functionPropertyValue = new FunctionPropertyValue();
    functionPropertyValue.setFunction(parameters.get("functionName"));
    functionPropertyValue.setParameters(Arrays.asList(parameters.get("secretPath")));
    UpdateDeploymentTopologyRequest request = new UpdateDeploymentTopologyRequest();
    request.setInputProperties(parseAndReplaceProperties(ImmutableMap.of(propertyName, functionPropertyValue)));
    executeUpdateDeploymentTopologyCall(request);
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) UpdateDeploymentTopologyRequest(alien4cloud.rest.application.model.UpdateDeploymentTopologyRequest) When(cucumber.api.java.en.When)

Aggregations

FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)37 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)12 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 Map (java.util.Map)7 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)6 And (cucumber.api.java.en.And)5 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)5 When (cucumber.api.java.en.When)4 RestResponse (alien4cloud.rest.model.RestResponse)3 TopologyDTO (alien4cloud.topology.TopologyDTO)3 JavaType (com.fasterxml.jackson.databind.JavaType)3 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)3 Capability (org.alien4cloud.tosca.model.templates.Capability)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 NotFoundException (alien4cloud.exception.NotFoundException)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)2