Search in sources :

Example 26 with FunctionPropertyValue

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

the class DeleteInputProcessor method removeInputIdInProperties.

/**
 * Remove the inputId for the {@link FunctionPropertyValue} of a Map of properties.
 *
 * @param properties the list of properties values currently defined in the topology.
 * @param propertyDefinitions the list of definitions of properties (matching the list of values).
 * @param inputId The id of the input to remove.
 */
private void removeInputIdInProperties(final Map<String, AbstractPropertyValue> properties, final Map<String, PropertyDefinition> propertyDefinitions, final String inputId) {
    if (properties == null) {
        return;
    }
    for (Map.Entry<String, AbstractPropertyValue> propertyEntry : properties.entrySet()) {
        if (propertyEntry.getValue() instanceof FunctionPropertyValue) {
            FunctionPropertyValue functionPropertyValue = (FunctionPropertyValue) propertyEntry.getValue();
            if (ToscaFunctionConstants.GET_INPUT.equals(functionPropertyValue.getFunction()) && functionPropertyValue.getTemplateName().equals(inputId)) {
                PropertyDefinition pd = propertyDefinitions.get(propertyEntry.getKey());
                AbstractPropertyValue pv = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(pd);
                propertyEntry.setValue(pv);
            }
        }
    }
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 27 with FunctionPropertyValue

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

the class SetRelationshipPropertyAsInputProcessor method processRelationshipOperation.

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

Example 28 with FunctionPropertyValue

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

the class SetNodePropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    NodeType indexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
    getOrFail(indexedNodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
    if (operation.getPropertyName().equals(FORBIDDEN_PROPERTY)) {
        throw new UnsupportedSecretException("We cannot set a secret on the property " + operation.getPropertyName());
    }
    if ("".equals(operation.getSecretPath())) {
        throw new InvalidSecretPathException("The secret path to the property " + operation.getPropertyName() + " is null.");
    }
    FunctionPropertyValue getSecret = new FunctionPropertyValue();
    getSecret.setFunction(ToscaFunctionConstants.GET_SECRET);
    getSecret.setParameters(Arrays.asList(operation.getSecretPath()));
    nodeTemplate.getProperties().put(operation.getPropertyName(), getSecret);
    log.debug("Associate the property [ {} ] of the node template [ {} ] as secret [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), operation.getSecretPath(), topology.getId());
}
Also used : UnsupportedSecretException(org.alien4cloud.tosca.editor.exception.UnsupportedSecretException) NodeType(org.alien4cloud.tosca.model.types.NodeType) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) InvalidSecretPathException(org.alien4cloud.tosca.editor.exception.InvalidSecretPathException)

Example 29 with FunctionPropertyValue

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

the class SetRelationshipPropertyAsSecretProcessor method processRelationshipOperation.

@Override
protected void processRelationshipOperation(Csar csar, Topology topology, SetRelationshipPropertyAsSecretOperation operation, NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate) {
    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());
    FunctionPropertyValue secretFunction = new FunctionPropertyValue();
    secretFunction.setFunction(ToscaFunctionConstants.GET_SECRET);
    secretFunction.setParameters(Arrays.asList(operation.getSecretPath()));
    relationshipTemplate.getProperties().put(operation.getPropertyName(), secretFunction);
    log.debug("Associate the property [ {} ] of relationship template [ {} ] of node [ {} ] to secret <path: {} > of the topology [ {} ].", operation.getPropertyName(), operation.getRelationshipName(), operation.getNodeName(), operation.getSecretPath(), topology.getId());
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 30 with FunctionPropertyValue

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

the class FunctionEvaluatorTest method setPropertiesValues.

private void setPropertiesValues(Map<String, AbstractPropertyValue> properties, String prefix) {
    ScalarPropertyValue scalarPropValue = new ScalarPropertyValue(prefix + "scalar value");
    Map<String, Object> complex = Maps.newHashMap();
    complex.put("scalar", prefix + "complex scalar value");
    complex.put("map", Maps.newHashMap());
    ((Map) complex.get("map")).put("element_1", prefix + "element 1 value");
    ((Map) complex.get("map")).put("element_2", prefix + "element 2 value");
    complex.put("list", Lists.newArrayList(prefix + "list value 1", prefix + "list value 2"));
    ComplexPropertyValue complexPropValue = new ComplexPropertyValue(complex);
    FunctionPropertyValue getInputPropValue = new FunctionPropertyValue(ToscaFunctionConstants.GET_INPUT, Lists.newArrayList("scalar_input"));
    FunctionPropertyValue getSecretPropValue = new FunctionPropertyValue(ToscaFunctionConstants.GET_SECRET, Lists.newArrayList("my/path"));
    FunctionPropertyValue getScalarPropValue = new FunctionPropertyValue(ToscaFunctionConstants.GET_PROPERTY, Lists.newArrayList("SELF", "scalar_prop"));
    FunctionPropertyValue getComplexPropValue = new FunctionPropertyValue(ToscaFunctionConstants.GET_PROPERTY, Lists.newArrayList("SELF", "complex_prop.scalar"));
    FunctionPropertyValue getComplexPropListValue = new FunctionPropertyValue(ToscaFunctionConstants.GET_PROPERTY, Lists.newArrayList("SELF", "complex_prop.list[1]"));
    FunctionPropertyValue getComplexPropMapValue = new FunctionPropertyValue(ToscaFunctionConstants.GET_PROPERTY, Lists.newArrayList("SELF", "complex_prop.map.element_1"));
    ConcatPropertyValue concatPropValue = new ConcatPropertyValue();
    concatPropValue.setFunction_concat("concat");
    concatPropValue.setParameters(Lists.newArrayList(new ScalarPropertyValue("input is: "), getInputPropValue, new ScalarPropertyValue(" property is: "), getScalarPropValue));
    ConcatPropertyValue concatGetSecretPropValue = new ConcatPropertyValue();
    concatGetSecretPropValue.setFunction_concat("concat");
    concatGetSecretPropValue.setParameters(Lists.newArrayList(new ScalarPropertyValue("input is: "), getSecretPropValue));
    FunctionPropertyValue getConcatPropValue = new FunctionPropertyValue(ToscaFunctionConstants.GET_PROPERTY, Lists.newArrayList("SELF", "concat_prop"));
    ConcatPropertyValue concatGetConcatPropValue = new ConcatPropertyValue();
    concatGetConcatPropValue.setFunction_concat("concat");
    concatGetConcatPropValue.setParameters(Lists.newArrayList(new ScalarPropertyValue("get concat is: "), getConcatPropValue));
    properties.put("scalar_prop", scalarPropValue);
    properties.put("complex_prop", complexPropValue);
    properties.put("get_input_prop", getInputPropValue);
    properties.put("get_secret_prop", getSecretPropValue);
    properties.put("get_scalar_prop", getScalarPropValue);
    properties.put("get_complex_prop", getComplexPropValue);
    properties.put("get_complex_prop_list", getComplexPropListValue);
    properties.put("get_complex_prop_map", getComplexPropMapValue);
    properties.put("concat_prop", concatPropValue);
    properties.put("concat_prop_and_get_secret", concatGetSecretPropValue);
    properties.put("get_concat_prop", getConcatPropValue);
    properties.put("concat_get_concat_prop", concatGetConcatPropValue);
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) Map(java.util.Map) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)

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