use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue 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.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class TemplateBuilder method fillProperties.
public static void fillProperties(Map<String, AbstractPropertyValue> properties, Map<String, PropertyDefinition> propertiesDefinitions, Map<String, AbstractPropertyValue> originalProperties, boolean adaptToType) {
if (propertiesDefinitions == null || properties == null) {
return;
}
for (Map.Entry<String, PropertyDefinition> entry : propertiesDefinitions.entrySet()) {
AbstractPropertyValue originalValue = MapUtils.getObject(originalProperties, entry.getKey());
if (originalValue == null) {
AbstractPropertyValue pv = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(entry.getValue());
properties.put(entry.getKey(), pv);
} else if (originalValue instanceof FunctionPropertyValue || originalValue instanceof ConcatPropertyValue) {
properties.put(entry.getKey(), originalValue);
} else {
// we check the property type before accepting it
try {
ConstraintPropertyService.checkPropertyConstraint(entry.getKey(), originalValue, entry.getValue());
properties.put(entry.getKey(), originalValue);
} catch (ConstraintFunctionalException e) {
log.debug("Not able to merge property <" + entry.getKey() + "> value due to a type check exception", e);
if (adaptToType) {
AbstractPropertyValue pv = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(entry.getValue());
properties.put(entry.getKey(), pv);
}
}
}
}
if (!adaptToType) {
// maybe we could put validations here actually.
for (Map.Entry<String, AbstractPropertyValue> originalProperty : safe(originalProperties).entrySet()) {
if (!properties.containsKey(originalProperty.getKey())) {
properties.put(originalProperty.getKey(), originalProperty.getValue());
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class SetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeCapabilityPropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} does not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName());
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());
// Check that the property definition of the input is indeed compatible with the property definition of the capability.
inputPropertyDefinition.checkIfCompatibleOrFail(capabilityPropertyDefinition);
FunctionPropertyValue getInput = new FunctionPropertyValue();
getInput.setFunction(ToscaFunctionConstants.GET_INPUT);
getInput.setParameters(Arrays.asList(operation.getInputName()));
capabilityTemplate.getProperties().put(operation.getPropertyName(), getInput);
log.debug("Associate the property [ {} ] of capability template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class SetNodePropertyAsInputProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
PropertyDefinition inputPropertyDefinition = getOrFail(topology.getInputs(), operation.getInputName(), "Input {} not found in topology", operation.getInputName());
NodeType indexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
PropertyDefinition nodePropertyDefinition = getOrFail(indexedNodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
// Check that the property definition of the input is indeed compatible with the property definition of the capability.
inputPropertyDefinition.checkIfCompatibleOrFail(nodePropertyDefinition);
FunctionPropertyValue getInput = new FunctionPropertyValue();
getInput.setFunction(ToscaFunctionConstants.GET_INPUT);
getInput.setParameters(Arrays.asList(operation.getInputName()));
nodeTemplate.getProperties().put(operation.getPropertyName(), getInput);
log.debug("Associate the property [ {} ] of the node template [ {} ] to input [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), operation.getInputName(), topology.getId());
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class DeploymentTopologyStepDefinitions method iSetTheInputsPropertyAsASecretWithTheFollowingParameters.
@When("^I set the inputs property \"([^\"]*)\" as a secret with the following parameters$")
public void iSetTheInputsPropertyAsASecretWithTheFollowingParameters(String propertyName, Map<String, String> parameters) throws Throwable {
FunctionPropertyValue functionPropertyValue = new FunctionPropertyValue();
functionPropertyValue.setFunction(parameters.get("functionName"));
functionPropertyValue.setParameters(Arrays.asList(parameters.get("secretPath")));
UpdateDeploymentTopologyRequest request = new UpdateDeploymentTopologyRequest();
request.setInputProperties(parseAndReplaceProperties(ImmutableMap.of(propertyName, functionPropertyValue)));
executeUpdateDeploymentTopologyCall(request);
}
Aggregations