use of org.alien4cloud.tosca.model.definitions.PropertyValue 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"));
}
use of org.alien4cloud.tosca.model.definitions.PropertyValue in project alien4cloud by alien4cloud.
the class ToscaTypeConverterTest method convert_complex_data_type_to_property_value.
@Test
public void convert_complex_data_type_to_property_value() throws Exception {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType("alien.nodes.test.ComplexDataType");
PropertyValue propertyValue = converter.toPropertyValue(ImmutableMap.of("nested", "nested value", "nested_array", Arrays.asList("item1", "item2", "item3"), "nested_map", ImmutableMap.of("key1", "value1", "key2", "value2")), propertyDefinition);
assertThat(propertyValue).isInstanceOf(ComplexPropertyValue.class);
ComplexPropertyValue complexPropertyValue = (ComplexPropertyValue) propertyValue;
assertThat(complexPropertyValue.getValue().get("nested_map")).isEqualTo(ImmutableMap.of("key1", "value1", "key2", "value2"));
assertThat(complexPropertyValue.getValue().get("nested_array")).isEqualTo(Arrays.asList("item1", "item2", "item3"));
assertThat(complexPropertyValue.getValue().get("nested")).isEqualTo("nested value");
}
use of org.alien4cloud.tosca.model.definitions.PropertyValue in project alien4cloud by alien4cloud.
the class FunctionEvaluator method getPropertyValue.
private static AbstractPropertyValue getPropertyValue(Map<String, AbstractPropertyValue> properties, Map<String, PropertyDefinition> propertyDefinitions, String propertyAccessPath) {
if (properties == null || !properties.containsKey(propertyAccessPath)) {
String propertyName = PropertyUtil.getPropertyNameFromComplexPath(propertyAccessPath);
if (propertyName == null) {
// Non complex
return PropertyUtil.getDefaultFromPropertyDefinitions(propertyAccessPath, propertyDefinitions);
} else {
// Complex
PropertyDefinition propertyDefinition = propertyDefinitions.get(propertyName);
AbstractPropertyValue rawValue;
if (propertyDefinition == null) {
return null;
} else if (ToscaTypes.isSimple(propertyDefinition.getType())) {
// It's a complex path (with '.') but the type in definition is finally simple
return null;
} else if (properties != null && (rawValue = properties.get(propertyName)) != null) {
if (!(rawValue instanceof PropertyValue)) {
throw new NotSupportedException("Only support static value in a get_property");
}
Object value = MapUtil.get(((PropertyValue) rawValue).getValue(), propertyAccessPath.substring(propertyName.length() + 1));
return new ScalarPropertyValue(PropertyUtil.serializePropertyValue(value));
} else {
return null;
}
}
} else {
return properties.get(propertyAccessPath);
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyValue 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);
}
}
use of org.alien4cloud.tosca.model.definitions.PropertyValue in project alien4cloud by alien4cloud.
the class InputsModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
EnvironmentContext environmentContext = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context."));
ApplicationEnvironment environment = environmentContext.getEnvironment();
DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
if (deploymentInputs.getInputs() == null) {
deploymentInputs.setInputs(Maps.newHashMap());
}
Map<String, Location> locations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
Map<String, PropertyValue> applicationInputs = inputService.getAppContextualInputs(context.getEnvironmentContext().get().getApplication(), topology.getInputs());
Map<String, PropertyValue> locationInputs = inputService.getLocationContextualInputs(locations, topology.getInputs());
// If the initial topology or any modifier configuration has changed since last inputs update then we refresh inputs.
if (deploymentInputs.getLastUpdateDate() == null || deploymentInputs.getLastUpdateDate().before(context.getLastFlowParamUpdate())) {
// FIXME exclude the application and location provided inputs from this method as it process them...
boolean updated = deploymentInputService.synchronizeInputs(topology.getInputs(), deploymentInputs.getInputs());
if (updated) {
// save the config if changed. This is for ex, if an input has been deleted from the topology
context.saveConfiguration(deploymentInputs);
}
}
PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputsModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
Map<String, AbstractPropertyValue> inputValues = Maps.newHashMap(deploymentInputs.getInputs());
inputValues.putAll(applicationInputs);
inputValues.putAll(locationInputs);
inputValues.putAll(preconfiguredInputsConfiguration.getInputs());
// Now that we have inputs ready let's process get_input functions in the topology to actually replace values.
if (topology.getNodeTemplates() != null) {
FunctionEvaluatorContext evaluatorContext = new FunctionEvaluatorContext(topology, inputValues);
for (Entry<String, NodeTemplate> entry : topology.getNodeTemplates().entrySet()) {
NodeTemplate nodeTemplate = entry.getValue();
processGetInput(evaluatorContext, nodeTemplate, nodeTemplate.getProperties());
if (nodeTemplate.getRelationships() != null) {
for (Entry<String, RelationshipTemplate> relEntry : nodeTemplate.getRelationships().entrySet()) {
RelationshipTemplate relationshipTemplate = relEntry.getValue();
processGetInput(evaluatorContext, relationshipTemplate, relationshipTemplate.getProperties());
}
}
if (nodeTemplate.getCapabilities() != null) {
for (Entry<String, Capability> capaEntry : nodeTemplate.getCapabilities().entrySet()) {
Capability capability = capaEntry.getValue();
processGetInput(evaluatorContext, nodeTemplate, capability.getProperties());
}
}
if (nodeTemplate.getRequirements() != null) {
for (Entry<String, Requirement> requirementEntry : nodeTemplate.getRequirements().entrySet()) {
Requirement requirement = requirementEntry.getValue();
processGetInput(evaluatorContext, nodeTemplate, requirement.getProperties());
}
}
}
}
}
Aggregations