use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class DeploymentTopologyStepDefinitions method theNodeInTheDeploymentTopologyShouldHaveThePropertyWithASecretFunctionHavingASecretPath.
@Then("^The node \"([^\"]*)\" in the deployment topology should have the property \"([^\"]*)\" with a secret function having a secret path \"([^\"]*)\"$")
public void theNodeInTheDeploymentTopologyShouldHaveThePropertyWithASecretFunctionHavingASecretPath(String nodeName, String propertyName, String secretPath) throws Throwable {
DeploymentTopologyDTO dto = getDeploymentTopologyDTO();
NodeTemplate node = dto.getTopology().getNodeTemplates().get(nodeName);
FunctionPropertyValue actualPropertyValue = (FunctionPropertyValue) node.getProperties().get(propertyName);
FunctionPropertyValue expectedPropertyValue = new FunctionPropertyValue();
expectedPropertyValue.setFunction(ToscaFunctionConstants.GET_SECRET);
expectedPropertyValue.setParameters(Arrays.asList(secretPath));
Assert.assertEquals(actualPropertyValue, expectedPropertyValue);
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class DeploymentTopologyStepDefinitions method iUpdateThePropertyToASecretWithASecretPathForTheSubstitutedPolicy.
@When("^I update the property \"([^\"]*)\" to a secret with a secret path \"([^\"]*)\" for the substituted policy \"([^\"]*)\"$")
public void iUpdateThePropertyToASecretWithASecretPathForTheSubstitutedPolicy(String propertyName, String secretPath, String nodeName) throws Throwable {
FunctionPropertyValue propertyValue = new FunctionPropertyValue();
propertyValue.setFunction(ToscaFunctionConstants.GET_SECRET);
propertyValue.setParameters(Arrays.asList(secretPath));
updateProperty(propertyName, propertyValue, nodeName, "/rest/v1/applications/%s/environments/%s/deployment-topology/policies/%s/substitution/properties");
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validatePropertyFilters.
private List<Violations> validatePropertyFilters(Map<String, List<PropertyConstraint>> propertyFilters, Map<String, AbstractPropertyValue> propertyValues, Map<String, PropertyDefinition> propertyDefinitionMap, boolean skipInputs) {
List<Violations> violations = Lists.newArrayList();
for (Map.Entry<String, List<PropertyConstraint>> propertyEntry : propertyFilters.entrySet()) {
Violations violation = new Violations(propertyEntry.getKey());
List<NodeFilterConstraintViolation> violatedConstraints = Lists.newArrayList();
violation.violatedConstraints = violatedConstraints;
AbstractPropertyValue value = propertyValues.get(propertyEntry.getKey());
String propertyValue = null;
if (value == null) {
propertyValue = null;
} else if (value instanceof ScalarPropertyValue) {
propertyValue = ((ScalarPropertyValue) value).getValue();
} else {
if (skipInputs) {
continue;
}
if (FunctionEvaluator.isGetInput((FunctionPropertyValue) value)) {
violation.relatedInput = ((FunctionPropertyValue) value).getElementNameToFetch();
}
}
for (PropertyConstraint constraint : propertyEntry.getValue()) {
if (!propertyDefinitionMap.containsKey(propertyEntry.getKey())) {
continue;
}
// the constraint need to be initiazed with the type of the property (to check that actual value type matches the definition type).
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinitionMap.get(propertyEntry.getKey()).getType());
try {
constraint.initialize(toscaType);
constraint.validate(toscaType, propertyValue);
} catch (ConstraintViolationException e) {
violatedConstraints.add(new NodeFilterConstraintViolation(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR, e.getMessage(), e.getConstraintInformation()));
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
violatedConstraints.add(new NodeFilterConstraintViolation(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR, e.getMessage(), null));
}
}
if (!violatedConstraints.isEmpty()) {
violations.add(violation);
}
}
return violations;
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class TopologyPropertiesValidationService method verifyScalableProperties.
private void verifyScalableProperties(Map<String, AbstractPropertyValue> scalableProperties, List<PropertiesTask> toReturnTaskList, String nodeTemplateId, boolean skipInputProperties) {
Set<String> missingProperties = Sets.newHashSet();
Set<String> errorProperties = Sets.newHashSet();
if (skipInputProperties) {
for (Entry<String, AbstractPropertyValue> entry : scalableProperties.entrySet()) {
if (entry.getValue() instanceof FunctionPropertyValue) {
return;
}
}
}
if (MapUtils.isEmpty(scalableProperties)) {
missingProperties.addAll(Lists.newArrayList(NormativeComputeConstants.SCALABLE_MIN_INSTANCES, NormativeComputeConstants.SCALABLE_MAX_INSTANCES, NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES));
} else {
int min = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_MIN_INSTANCES, missingProperties, errorProperties);
int max = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_MAX_INSTANCES, missingProperties, errorProperties);
int init = verifyScalableProperty(scalableProperties, NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, missingProperties, errorProperties);
if (min > 0 && max > 0 && init > 0) {
if (min > init || min > max) {
errorProperties.add(NormativeComputeConstants.SCALABLE_MIN_INSTANCES);
}
if (init > max || init < min) {
errorProperties.add(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES);
}
if (max < min || max < init) {
errorProperties.add(NormativeComputeConstants.SCALABLE_MAX_INSTANCES);
}
}
}
if (!missingProperties.isEmpty()) {
ScalableTask scalableTask = new ScalableTask(nodeTemplateId);
scalableTask.getProperties().put(TaskLevel.REQUIRED, Lists.newArrayList(missingProperties));
toReturnTaskList.add(scalableTask);
}
if (!errorProperties.isEmpty()) {
ScalableTask scalableTask = new ScalableTask(nodeTemplateId);
scalableTask.getProperties().put(TaskLevel.ERROR, Lists.newArrayList(errorProperties));
toReturnTaskList.add(scalableTask);
}
}
use of org.alien4cloud.tosca.model.definitions.FunctionPropertyValue in project alien4cloud by alien4cloud.
the class DeploymentInputService method synchronizeInputs.
/**
* Ensure that the specified input values matches the eventually updated input definitions.
*
* @param inputDefinitions Inputs definitions as specified in the topology.
* @param inputValues Input properties values as specified by the user.
* @return true if there is an update on inputValues (removal or addition). false if nothing has changed
*/
public boolean synchronizeInputs(Map<String, PropertyDefinition> inputDefinitions, Map<String, AbstractPropertyValue> inputValues) {
boolean updated = false;
if (!MapUtils.isEmpty(inputValues)) {
// Ensure that previous defined values are still compatible with the latest input definition (as the topology may have changed).
Iterator<Map.Entry<String, AbstractPropertyValue>> inputPropertyEntryIterator = inputValues.entrySet().iterator();
while (inputPropertyEntryIterator.hasNext()) {
Map.Entry<String, AbstractPropertyValue> inputPropertyEntry = inputPropertyEntryIterator.next();
// remove if the value is null, or the input is not register as one
if (inputPropertyEntry.getValue() == null || !safe(inputDefinitions).containsKey(inputPropertyEntry.getKey())) {
inputPropertyEntryIterator.remove();
} else if (!(inputPropertyEntry.getValue() instanceof FunctionPropertyValue)) {
try {
ConstraintPropertyService.checkPropertyConstraint(inputPropertyEntry.getKey(), ((PropertyValue) inputPropertyEntry.getValue()).getValue(), inputDefinitions.get(inputPropertyEntry.getKey()));
} catch (ConstraintViolationException | ConstraintValueDoNotMatchPropertyTypeException e) {
// Property is not valid anymore for the input, remove the old value
inputPropertyEntryIterator.remove();
updated = true;
}
}
}
}
// set default values for every unset property.
for (Map.Entry<String, PropertyDefinition> inputDefinitionEntry : safe(inputDefinitions).entrySet()) {
AbstractPropertyValue existingValue = inputValues.get(inputDefinitionEntry.getKey());
if (existingValue == null) {
// If user has not specified a value and there is
PropertyValue defaultValue = inputDefinitionEntry.getValue().getDefault();
if (defaultValue != null) {
inputValues.put(inputDefinitionEntry.getKey(), defaultValue);
updated = true;
}
}
}
return updated;
}
Aggregations