use of org.alien4cloud.tosca.model.definitions.ScalarPropertyValue in project alien4cloud by alien4cloud.
the class PaaSUtils method injectInputIntoOperations.
private static void injectInputIntoOperations(String inputName, List<String> path, AbstractPropertyValue value, Map<String, Operation> operations) {
if (MapUtils.isEmpty(operations)) {
return;
}
if (value != null) {
value = new FunctionPropertyValue(ToscaFunctionConstants.GET_PROPERTY, path);
} else {
value = new ScalarPropertyValue();
}
// the input name should be uppercase
AbstractPropertyValue finalValue = value;
operations.forEach((operationName, operation) -> {
if (operation.getInputParameters() == null) {
operation.setInputParameters(Maps.newHashMap());
}
// DO NOT OVERRIDE
operation.getInputParameters().putIfAbsent(inputName, finalValue);
});
}
use of org.alien4cloud.tosca.model.definitions.ScalarPropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluator method getFromPath.
private static AbstractPropertyValue getFromPath(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, Map<String, AbstractPropertyValue> properties, String propertyPath) {
if (propertyPath.contains(".")) {
String propertyName = propertyPath.split("\\.")[0];
AbstractPropertyValue propertyValue = properties.get(propertyName);
if (!(propertyValue instanceof PropertyValue)) {
// if the value is not a property value resolve it first
propertyValue = tryResolveValue(evaluatorContext, targetTemplate, properties, propertyValue);
if (propertyValue == null) {
return null;
}
}
// now it is a property value
Object value = MapUtil.get(((PropertyValue) propertyValue).getValue(), propertyPath.substring(propertyName.length() + 1));
if (value == null) {
return null;
} else if (value instanceof String) {
return new ScalarPropertyValue((String) value);
} else if (value instanceof List) {
return new ListPropertyValue((List<Object>) value);
} else if (value instanceof Map) {
return new ComplexPropertyValue((Map<String, Object>) value);
}
throw new IllegalArgumentException("The value of a property must be a scalar, a list or a map.");
}
return safe(properties).get(propertyPath);
}
use of org.alien4cloud.tosca.model.definitions.ScalarPropertyValue 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);
}
use of org.alien4cloud.tosca.model.definitions.ScalarPropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluatorTest method getEvaluationContext.
/**
* Generate the topology below (no need type validations) and inputs to be used for next tests.
*
* @return A function evaluator context for the test topology.
*/
private FunctionEvaluatorContext getEvaluationContext() {
NodeTemplate myNode = new NodeTemplate();
myNode.setProperties(Maps.newHashMap());
setPropertiesValues(myNode.getProperties(), "");
Capability capability = new Capability();
myNode.setCapabilities(Maps.newHashMap());
myNode.getCapabilities().put("my_capability", capability);
capability.setProperties(Maps.newHashMap());
setPropertiesValues(capability.getProperties(), "capa ");
Topology topology = new Topology();
topology.setNodeTemplates(Maps.newHashMap());
topology.getNodeTemplates().put("my_node", myNode);
Map<String, AbstractPropertyValue> inputs = Maps.newHashMap();
inputs.put("scalar_input", new ScalarPropertyValue("scalar input value"));
return new FunctionEvaluatorContext(topology, inputs);
}
use of org.alien4cloud.tosca.model.definitions.ScalarPropertyValue in project alien4cloud by alien4cloud.
the class InputsMappingFileVariableResolverTest method check_inputs_mapping_can_be_parsed_when_variable.
@Ignore("Update when ToscaTypeConverter behavior is clearly defined")
@Test
public // Bad test
void check_inputs_mapping_can_be_parsed_when_variable() throws Exception {
inputsMappingFileVariableResolverConfigured.customConverter(new ToscaTypeConverter((concreteType, id) -> {
if (id.equals("datatype.complex_input_entry.sub1")) {
DataType dataType = new DataType();
dataType.setDeriveFromSimpleType(false);
dataType.setProperties(//
ImmutableMap.of(//
"complex", //
buildPropDef(ToscaTypes.MAP, ToscaTypes.STRING)));
return dataType;
}
if (id.equals("datatype.complex_input_entry")) {
DataType dataType = new DataType();
dataType.setDeriveFromSimpleType(false);
dataType.setProperties(//
ImmutableMap.of(//
"sub1", //
buildPropDef("datatype.complex_input_entry.sub1"), //
"sub2", //
buildPropDef(ToscaTypes.MAP, ToscaTypes.STRING), //
"field01", //
buildPropDef(ToscaTypes.STRING)));
return dataType;
}
return null;
}));
Map<String, PropertyValue> inputsMappingFileResolved = resolve("src/test/resources/alien/variables/inputs_mapping_with_variables.yml");
assertThat(inputsMappingFileResolved.get("int_input")).isEqualTo(new ScalarPropertyValue("1"));
assertThat(inputsMappingFileResolved.get("float_input")).isEqualTo(new ScalarPropertyValue("3.14"));
assertThat(inputsMappingFileResolved.get("string_input")).isEqualTo(new ScalarPropertyValue("text_3.14"));
//
assertThat(inputsMappingFileResolved.get("complex_input")).isEqualTo(new ComplexPropertyValue(//
ImmutableMap.of("sub1", new ComplexPropertyValue(//
ImmutableMap.of("complex", //
new ComplexPropertyValue(ImmutableMap.of("subfield", new ScalarPropertyValue("text"))))), "sub2", new ComplexPropertyValue(//
ImmutableMap.of("subfield21", //
new ScalarPropertyValue("1"))), "field01", //
new ScalarPropertyValue("text"))));
}
Aggregations