Search in sources :

Example 6 with PropertyDefinition

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

the class UnsetNodeCapabilityPropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
    // check if the node property value is a get_secret
    AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
    if (currentValue != null && !isGetSecret(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not an secret.", operation.getPropertyName(), operation.getNodeName());
    }
    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());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
    capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove secret property [ {} ] of capability template [ {} ] of node [ {} ] 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) NotFoundException(alien4cloud.exception.NotFoundException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 7 with PropertyDefinition

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

the class UnsetRelationshipPropertyAsSecretProcessor method processRelationshipOperation.

@Override
protected void processRelationshipOperation(Csar csar, Topology topology, UnsetRelationshipPropertyAsSecretOperation 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());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(relationshipPropertyDefinition);
    relationshipTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove secret from 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) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 8 with PropertyDefinition

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

the class InputsMappingFileVariableResolverTest method check_uber_input_can_be_parsed.

@Ignore("Update when ToscaTypeConverter behavior is clearly defined")
@Test
public // Bad test
void check_uber_input_can_be_parsed() throws Exception {
    inputsPropertyDefinitions.put("uber_input", buildPropDef("datatype.uber"));
    /*
         * 
         * uber_input:
         * simple_var:
         * int_field: ${int_variable}
         * float_field: ${float_variable}
         * string_field: ${string_variable}
         * concat_field: ${int_variable}${float_variable}
         * simple_static:
         * int_field: 51
         * float_field: 16.64
         * string_field: "leffe"
         * complex:
         * complex_with_list: ${complex_with_list}
         * int_list:
         * - ${int_variable}
         * - ${int_variable}
         * float_list:
         * - ${float_variable}
         * - ${float_variable}
         * mix_list:
         * - ${int_variable}
         * - ${float_variable}
         * - ${string_variable}
         * static_mix_list:
         * - "jenlain"
         * - 16.64
         * - "kwak"
         * complex_with_var_in_leaf: ${complex_with_var_in_leaf}
         * 
         */
    inputsMappingFileVariableResolverConfigured.customConverter(new ToscaTypeConverter((concreteType, id) -> {
        DataType dataType = null;
        switch(id) {
            case "datatype.uber":
                dataType = new DataType();
                dataType.setDeriveFromSimpleType(false);
                dataType.setProperties(// 
                ImmutableMap.of(// 
                "simple_var", // 
                buildPropDef("datatype.uber.simple_var"), // 
                "complex", // 
                buildPropDef("datatype.uber.complex"), // 
                "simple_static", // 
                buildPropDef("datatype.uber.simple_static"), // 
                "complex_with_var_in_leaf", // 
                buildPropDef("datatype.uber.complex_with_var_in_leaf")));
                break;
            case "datatype.uber.simple_var":
                dataType = new DataType();
                dataType.setDeriveFromSimpleType(false);
                dataType.setProperties(// 
                ImmutableMap.of(// 
                "int_field", // 
                buildPropDef(ToscaTypes.INTEGER), // 
                "float_field", // 
                buildPropDef(ToscaTypes.FLOAT), // 
                "string_field", // 
                buildPropDef(ToscaTypes.STRING), // 
                "concat_field", // 
                buildPropDef(ToscaTypes.STRING)));
                break;
            case "datatype.uber.simple_static":
                dataType = new DataType();
                dataType.setDeriveFromSimpleType(false);
                dataType.setProperties(// 
                ImmutableMap.of(// 
                "int_field", // 
                buildPropDef(ToscaTypes.INTEGER), // 
                "float_field", // 
                buildPropDef(ToscaTypes.FLOAT), // 
                "string_field", // 
                buildPropDef(ToscaTypes.STRING)));
                break;
            case "datatype.uber.complex":
                dataType = new DataType();
                dataType.setDeriveFromSimpleType(false);
                dataType.setProperties(// 
                ImmutableMap.<String, PropertyDefinition>builder().put("complex_with_list", buildPropDef("datatype.uber.complex.complex_with_list")).put("int_list", // 
                buildPropDef(ToscaTypes.LIST, ToscaTypes.FLOAT)).put("float_list", // 
                buildPropDef(ToscaTypes.LIST, ToscaTypes.STRING)).put("mix_list", // 
                buildPropDef(ToscaTypes.LIST, ToscaTypes.STRING)).put("static_mix_list", buildPropDef(ToscaTypes.LIST, ToscaTypes.STRING)).build());
                break;
            case "datatype.uber.complex.complex_with_list":
                dataType = new DataType();
                dataType.setDeriveFromSimpleType(false);
                dataType.setProperties(// NEED TO BE
                ImmutableMap.<String, PropertyDefinition>builder().put("subfield1", buildPropDef(ToscaTypes.STRING)).put("subfield2", buildPropDef(ToscaTypes.MAP, buildPropDef(ToscaTypes.LIST, ToscaTypes.STRING))).build());
                break;
            case "datatype.uber.complex_with_var_in_leaf":
                dataType = new DataType();
                dataType.setDeriveFromSimpleType(false);
                dataType.setProperties(// 
                ImmutableMap.of("complex", // 
                buildPropDef(ToscaTypes.MAP, ToscaTypes.STRING)));
                break;
        }
        return dataType;
    }));
    Map<String, PropertyValue> inputsMappingFileResolved = resolve("src/test/resources/alien/variables/inputs_mapping_uber.yml");
    assertThat(inputsMappingFileResolved).containsOnlyKeys("uber_input");
    assertThat(inputsMappingFileResolved.get("uber_input")).isInstanceOf(ComplexPropertyValue.class);
    ComplexPropertyValue uberInput = (ComplexPropertyValue) inputsMappingFileResolved.get("uber_input");
    assertThat(sub(ScalarPropertyValue.class, uberInput, "simple_var", "string_field").getValue()).isEqualTo("text");
    assertThat(sub(ScalarPropertyValue.class, uberInput, "simple_var", "concat_field").getValue()).isEqualTo("13.14");
    assertThat(sub(ScalarPropertyValue.class, uberInput, "simple_static", "int_field").getValue()).isEqualTo("51");
    assertThat(sub(ScalarPropertyValue.class, uberInput, "simple_static", "float_field").getValue()).isEqualTo("16.64");
    assertThat(sub(ScalarPropertyValue.class, uberInput, "simple_static", "string_field").getValue()).isEqualTo("leffe");
    assertThat(sub(ListPropertyValue.class, uberInput, "complex", "int_list").getValue()).isEqualTo(Arrays.asList(new ScalarPropertyValue("1"), new ScalarPropertyValue("1")));
    assertThat(sub(ListPropertyValue.class, uberInput, "complex", "float_list").getValue()).hasSize(2);
    assertThat(sub(ListPropertyValue.class, uberInput, "complex", "mix_list").getValue()).hasSize(3);
    assertThat(sub(ListPropertyValue.class, uberInput, "complex", "static_mix_list").getValue()).hasSize(3);
    assertThat(sub(ListPropertyValue.class, uberInput, "complex", "complex_with_list", "subfield2", "sublist").getValue()).hasSize(3);
    assertThat(sub(ScalarPropertyValue.class, uberInput, "complex_with_var_in_leaf", "complex", "subfield").getValue()).isEqualTo("text");
}
Also used : ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) Arrays(java.util.Arrays) InputsMappingFileVariableResolver.configure(org.alien4cloud.tosca.variable.InputsMappingFileVariableResolver.configure) DataType(org.alien4cloud.tosca.model.types.DataType) ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) ImmutableMap(com.google.common.collect.ImmutableMap) InputsMappingFileVariableResolverConfigured(org.alien4cloud.tosca.variable.InputsMappingFileVariableResolver.InputsMappingFileVariableResolverConfigured) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test) Maps(com.google.common.collect.Maps) PropertiesYamlParser(org.alien4cloud.tosca.utils.PropertiesYamlParser) Ignore(org.junit.Ignore) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) Map(java.util.Map) Application(alien4cloud.model.application.Application) PropertyDefinitionUtils.buildPropDef(org.alien4cloud.tosca.variable.PropertyDefinitionUtils.buildPropDef) ToscaTypes(org.alien4cloud.tosca.normative.types.ToscaTypes) Assert(org.junit.Assert) Before(org.junit.Before) Resource(org.springframework.core.io.Resource) DataType(org.alien4cloud.tosca.model.types.DataType) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with PropertyDefinition

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

the class ToscaTypeConverterTest method convert_version_to_property_value.

@Test
public void convert_version_to_property_value() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.VERSION);
    PropertyValue propertyValue = converter.toPropertyValue("3.4-SNAPSHOT", propertyDefinition);
    Object version = ToscaTypes.fromYamlTypeName(propertyDefinition.getType()).parse(propertyValue.getValue().toString());
    assertThat(version).isInstanceOf(Version.class);
    assertThat(version).isEqualTo(new Version("3.4-SNAPSHOT"));
}
Also used : Version(alien4cloud.utils.version.Version) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 10 with PropertyDefinition

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

the class ToscaTypeConverterTest method convert_version.

@Test
public void convert_version() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.VERSION);
    Object value = converter.toPropertyValue("3.4-SNAPSHOT", propertyDefinition);
    assertThat(value).isInstanceOf(ScalarPropertyValue.class);
    assertThat(value).isEqualTo(new ScalarPropertyValue("3.4-SNAPSHOT"));
}
Also used : ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Aggregations

PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)101 Test (org.junit.Test)42 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)23 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)20 Map (java.util.Map)19 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeType (org.alien4cloud.tosca.model.types.NodeType)15 NotFoundException (alien4cloud.exception.NotFoundException)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)11 MinLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)11 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)10 MaxLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint)10 Capability (org.alien4cloud.tosca.model.templates.Capability)10 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)10 DataType (org.alien4cloud.tosca.model.types.DataType)9 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)8 Set (java.util.Set)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)8 LengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint)8