Search in sources :

Example 21 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.

the class DeploymentTopologyStepDefinitions method assertCapabilityPropertyValueEquals.

private void assertCapabilityPropertyValueEquals(NodeTemplate node, String capabilityName, String propertyName, String expectedPropertyValue) {
    assertNotNull(node);
    Capability capability = MapUtils.getObject(node.getCapabilities(), capabilityName);
    assertNotNull(capability);
    AbstractPropertyValue abstractProperty = MapUtils.getObject(capability.getProperties(), propertyName);
    assertEquals(expectedPropertyValue, PropertyUtil.getScalarValue(abstractProperty));
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 22 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.

the class DeploymentTopologyStepDefinitions method The_deployment_topology_sould_have_the_following_input_properties.

@Then("^the deployment topology should have the following inputs properties$")
public void The_deployment_topology_sould_have_the_following_input_properties(Map<String, String> expectedStringInputProperties) throws Throwable {
    DeploymentTopologyDTO dto = getDTOAndassertNotNull();
    Map<String, AbstractPropertyValue> expectedInputProperties = Maps.newHashMap();
    for (Entry<String, String> inputEntry : expectedStringInputProperties.entrySet()) {
        expectedInputProperties.put(inputEntry.getKey(), new ScalarPropertyValue(inputEntry.getValue()));
    }
    assertPropMapContains(dto.getTopology().getAllInputProperties(), expectedInputProperties);
}
Also used : ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Then(cucumber.api.java.en.Then)

Example 23 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue 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 24 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue 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 25 with AbstractPropertyValue

use of org.alien4cloud.tosca.model.definitions.AbstractPropertyValue in project alien4cloud by alien4cloud.

the class TopologyPropertiesValidationService method validateNodeTemplate.

public void validateNodeTemplate(List<PropertiesTask> toReturnTaskList, NodeType relatedIndexedNodeType, NodeTemplate nodeTemplate, String nodeTempalteName, boolean skipInputProperties) {
    // Define a task regarding properties
    PropertiesTask task = new PropertiesTask();
    task.setNodeTemplateName(nodeTempalteName);
    task.setComponent(relatedIndexedNodeType);
    task.setCode(TaskCode.PROPERTIES);
    task.setProperties(Maps.newHashMap());
    // Check the properties of node template
    if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
        addRequiredPropertyIdToTaskProperties(null, nodeTemplate.getProperties(), relatedIndexedNodeType.getProperties(), task, skipInputProperties);
    }
    // Check relationships PD
    for (Map.Entry<String, RelationshipTemplate> relationshipEntry : safe(nodeTemplate.getRelationships()).entrySet()) {
        RelationshipTemplate relationship = relationshipEntry.getValue();
        if (relationship.getProperties() == null || relationship.getProperties().isEmpty()) {
            continue;
        }
        addRequiredPropertyIdToTaskProperties("relationships[" + relationshipEntry.getKey() + "]", relationship.getProperties(), safe(ToscaContext.getOrFail(RelationshipType.class, relationshipEntry.getValue().getType()).getProperties()), task, skipInputProperties);
    }
    for (Map.Entry<String, Capability> capabilityEntry : safe(nodeTemplate.getCapabilities()).entrySet()) {
        Capability capability = capabilityEntry.getValue();
        if (capability.getProperties() == null || capability.getProperties().isEmpty()) {
            continue;
        }
        addRequiredPropertyIdToTaskProperties("capabilities[" + capabilityEntry.getKey() + "]", capability.getProperties(), safe(ToscaContext.getOrFail(CapabilityType.class, capabilityEntry.getValue().getType()).getProperties()), task, skipInputProperties);
        if (capability.getType().equals(NormativeCapabilityTypes.SCALABLE)) {
            Map<String, AbstractPropertyValue> scalableProperties = capability.getProperties();
            verifyScalableProperties(scalableProperties, toReturnTaskList, nodeTempalteName, skipInputProperties);
        }
    }
    if (MapUtils.isNotEmpty(task.getProperties())) {
        toReturnTaskList.add(task);
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) PropertiesTask(alien4cloud.topology.task.PropertiesTask) Capability(org.alien4cloud.tosca.model.templates.Capability) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)57 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)23 Map (java.util.Map)18 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)14 Capability (org.alien4cloud.tosca.model.templates.Capability)14 NotFoundException (alien4cloud.exception.NotFoundException)10 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)9 Test (org.junit.Test)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)7 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)5 List (java.util.List)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)4 ListPropertyValue (org.alien4cloud.tosca.model.definitions.ListPropertyValue)4 HashMap (java.util.HashMap)3