Search in sources :

Example 1 with PropertyValue

use of org.alien4cloud.tosca.model.definitions.PropertyValue in project yorc-a4c-plugin by ystia.

the class ToscaComponentUtils method formatOperationInputs.

public static String formatOperationInputs(int indentLevel, Map<String, ? extends IValue> properties) throws IOException {
    StringBuilder buffer = new StringBuilder();
    for (Map.Entry<String, ? extends IValue> propertyEntry : properties.entrySet()) {
        if (propertyEntry.getValue() != null) {
            if (propertyEntry.getValue() instanceof PropertyValue && ((PropertyValue) propertyEntry.getValue()).getValue() == null) {
                continue;
            }
            buffer.append("\n").append(ToscaPropertySerializerUtils.indent(indentLevel)).append(propertyEntry.getKey()).append(": ");
            if (!propertyEntry.getValue().isDefinition()) {
                buffer.append(ToscaPropertySerializerUtils.formatPropertyValue(indentLevel, (AbstractPropertyValue) propertyEntry.getValue()));
            } else {
                Map<String, Object> velocityContext = ToscaComponentExporter.getVelocityContext();
                velocityContext.put("indent", indentLevel + 1);
                String template;
                if (propertyEntry.getValue() instanceof PropertyDefinition) {
                    velocityContext.put("property", propertyEntry.getValue());
                    template = "org/ystia/yorc/alien4cloud/plugin/tosca/property_def.vm";
                } else if (propertyEntry.getValue() instanceof AttributeDefinition) {
                    velocityContext.put("attribute", propertyEntry.getValue());
                    template = "org/ystia/yorc/alien4cloud/plugin/tosca/attribute_def.vm";
                } else {
                    throw new RuntimeException("Unsupported type: " + propertyEntry.getValue().getClass());
                }
                StringWriter writer = new StringWriter();
                VelocityUtil.generate(template, writer, velocityContext);
                buffer.append("\n").append(ToscaPropertySerializerUtils.indent(indentLevel + 1)).append(writer.toString());
            }
        }
    }
    return buffer.toString();
}
Also used : StringWriter(java.io.StringWriter) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) AttributeDefinition(org.alien4cloud.tosca.model.definitions.AttributeDefinition) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 2 with PropertyValue

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

the class FunctionEvaluatorTest method nodeGetComplexPropList.

@Test
public void nodeGetComplexPropList() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    PropertyValue resolved = resolveValue(context, template, template.getProperties(), template.getProperties().get("get_complex_prop_list"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(ScalarPropertyValue.class, resolved.getClass());
    Assert.assertEquals("list value 2", resolved.getValue());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Test(org.junit.Test)

Example 3 with PropertyValue

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

the class FunctionEvaluatorTest method nodeGetComplexPropMap.

@Test
public void nodeGetComplexPropMap() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    PropertyValue resolved = resolveValue(context, template, template.getProperties(), template.getProperties().get("get_complex_prop_map"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(ScalarPropertyValue.class, resolved.getClass());
    Assert.assertEquals("element 1 value", resolved.getValue());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Test(org.junit.Test)

Example 4 with PropertyValue

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

the class FunctionEvaluatorTest method nodeConcatGetConcatProp.

@Test
public void nodeConcatGetConcatProp() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    PropertyValue resolved = resolveValue(context, template, template.getProperties(), template.getProperties().get("concat_get_concat_prop"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(ScalarPropertyValue.class, resolved.getClass());
    Assert.assertEquals("get concat is: input is: scalar input value property is: scalar value", resolved.getValue());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Test(org.junit.Test)

Example 5 with PropertyValue

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

the class FunctionEvaluatorTest method nodeGetConcatProp.

@Test
public void nodeGetConcatProp() {
    FunctionEvaluatorContext context = getEvaluationContext();
    NodeTemplate template = context.getTopology().getNodeTemplates().get("my_node");
    PropertyValue resolved = resolveValue(context, template, template.getProperties(), template.getProperties().get("get_concat_prop"));
    Assert.assertNotNull(resolved);
    Assert.assertEquals(ScalarPropertyValue.class, resolved.getClass());
    Assert.assertEquals("input is: scalar input value property is: scalar value", resolved.getValue());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Test(org.junit.Test)

Aggregations

PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)28 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)20 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)17 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)16 Test (org.junit.Test)15 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)13 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)11 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)10 Map (java.util.Map)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)9 ListPropertyValue (org.alien4cloud.tosca.model.definitions.ListPropertyValue)5 DataType (org.alien4cloud.tosca.model.types.DataType)5 Application (alien4cloud.model.application.Application)3 Location (alien4cloud.model.orchestrators.locations.Location)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Maps (com.google.common.collect.Maps)3 Arrays (java.util.Arrays)3 PreconfiguredInputsConfiguration (org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration)3 ToscaTypes (org.alien4cloud.tosca.normative.types.ToscaTypes)3 PropertiesYamlParser (org.alien4cloud.tosca.utils.PropertiesYamlParser)3