Search in sources :

Example 11 with FunctionPropertyValue

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);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) Then(cucumber.api.java.en.Then)

Example 12 with FunctionPropertyValue

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");
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) When(cucumber.api.java.en.When)

Example 13 with FunctionPropertyValue

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;
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) NodeFilterConstraintViolation(alien4cloud.topology.task.NodeFilterConstraintViolation) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) Violations(alien4cloud.topology.task.NodeFilterToSatisfy.Violations) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) List(java.util.List) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 14 with FunctionPropertyValue

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);
    }
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ScalableTask(alien4cloud.topology.task.ScalableTask) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 15 with FunctionPropertyValue

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;
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Aggregations

FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)37 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)12 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 Map (java.util.Map)7 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)6 And (cucumber.api.java.en.And)5 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)5 When (cucumber.api.java.en.When)4 RestResponse (alien4cloud.rest.model.RestResponse)3 TopologyDTO (alien4cloud.topology.TopologyDTO)3 JavaType (com.fasterxml.jackson.databind.JavaType)3 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)3 Capability (org.alien4cloud.tosca.model.templates.Capability)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 NotFoundException (alien4cloud.exception.NotFoundException)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)2