Search in sources :

Example 51 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition 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());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 52 with PropertyDefinition

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

the class UnsetNodeCapabilityPropertyAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodeCapabilityPropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
    Capability capabilityTemplate = getOrFail(nodeTemplate.getCapabilities(), operation.getCapabilityName(), "Capability {} do not exist for node {}", operation.getCapabilityName(), operation.getNodeName());
    // check if the node property value is a get_input
    AbstractPropertyValue currentValue = capabilityTemplate.getProperties().get(operation.getPropertyName());
    if (!isGetInput(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not associated to an input.", operation.getPropertyName(), operation.getNodeName());
    }
    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());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(capabilityPropertyDefinition);
    capabilityTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove association from property [ {} ] of capability template [ {} ] of node [ {} ] to an input of the topology [ {} ].", operation.getPropertyName(), operation.getCapabilityName(), operation.getNodeName(), topology.getId());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 53 with PropertyDefinition

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

the class TopologyPropertiesValidationService method addRequiredPropertyIdToTaskProperties.

private void addRequiredPropertyIdToTaskProperties(String prefix, Map<String, AbstractPropertyValue> properties, Map<String, PropertyDefinition> relatedProperties, PropertiesTask task, boolean skipInputProperties) {
    for (Map.Entry<String, AbstractPropertyValue> propertyEntry : properties.entrySet()) {
        PropertyDefinition propertyDef = relatedProperties.get(propertyEntry.getKey());
        String propertyErrorKey = prefix == null ? propertyEntry.getKey() : prefix + "." + propertyEntry.getKey();
        AbstractPropertyValue value = propertyEntry.getValue();
        if (propertyDef != null && propertyDef.isRequired()) {
            if (value == null) {
                addRequiredPropertyError(task, propertyErrorKey);
            } else if (value instanceof ScalarPropertyValue) {
                String propertyValue = ((ScalarPropertyValue) value).getValue();
                if (StringUtils.isBlank(propertyValue)) {
                    addRequiredPropertyError(task, propertyErrorKey);
                }
            } else if (value instanceof ComplexPropertyValue) {
                Map<String, Object> mapValue = ((ComplexPropertyValue) value).getValue();
                if (MapUtils.isEmpty(mapValue)) {
                    addRequiredPropertyError(task, propertyErrorKey);
                }
            } else if (value instanceof ListPropertyValue) {
                List<Object> listValue = ((ListPropertyValue) value).getValue();
                if (listValue.isEmpty()) {
                    addRequiredPropertyError(task, propertyErrorKey);
                }
            } else if (FunctionEvaluator.containGetSecretFunction(value)) {
                // this is a get_secret function, we should not validate the get_secret here
                continue;
            } else if (skipInputProperties) {
                // get_input Will be validated later on
                continue;
            } else {
                addRequiredPropertyError(task, propertyErrorKey);
            }
        }
    }
}
Also used : ListPropertyValue(org.alien4cloud.tosca.model.definitions.ListPropertyValue) List(java.util.List) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 54 with PropertyDefinition

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

the class SetMatchedNodePropertyModifier method setNodeCapabilityProperty.

private void setNodeCapabilityProperty(FlowExecutionContext context, LocationResourceTemplate locationResourceTemplate, NodeTemplate nodeTemplate, String capabilityName, DeploymentMatchingConfiguration matchingConfiguration) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    Capability locationResourceCapability = locationResourceTemplate.getTemplate().getCapabilities().get(capabilityName);
    if (locationResourceCapability == null) {
        throw new NotFoundException("The capability <" + capabilityName + "> cannot be found on node template <" + templateId + "> of type <" + locationResourceTemplate.getTemplate().getType() + ">");
    }
    PropertyDefinition propertyDefinition = ToscaContext.getOrFail(CapabilityType.class, locationResourceCapability.getType()).getProperties().get(propertyName);
    if (propertyDefinition == null) {
        throw new NotFoundException("No property with name <" + propertyName + "> can be found on capability <" + capabilityName + "> of type <" + locationResourceCapability.getType() + ">");
    }
    AbstractPropertyValue locationResourcePropertyValue = locationResourceTemplate.getTemplate().getCapabilities().get(capabilityName).getProperties().get(propertyName);
    ensureNotSet(locationResourcePropertyValue, "by the admin in the Location Resource Template", propertyName, propertyValue);
    AbstractPropertyValue originalNodePropertyValue = safe(nodeTemplate.getCapabilities().get(capabilityName).getProperties()).get(propertyName);
    ensureNotSet(originalNodePropertyValue, "in the portable topology", propertyName, propertyValue);
    // Update the configuration
    NodePropsOverride nodePropsOverride = getTemplatePropsOverride(matchingConfiguration);
    if (propertyValue == null && nodePropsOverride.getCapabilities().get(capabilityName) != null) {
        nodePropsOverride.getCapabilities().get(capabilityName).getProperties().remove(propertyName);
    } else {
        // Set check constraints
        ConstraintPropertyService.checkPropertyConstraint(propertyName, propertyValue, propertyDefinition);
        NodeCapabilitiesPropsOverride nodeCapabilitiesPropsOverride = nodePropsOverride.getCapabilities().computeIfAbsent(capabilityName, k -> new NodeCapabilitiesPropsOverride());
        nodeCapabilitiesPropsOverride.getProperties().put(propertyName, PropertyService.asPropertyValue(propertyValue));
    }
    context.saveConfiguration(matchingConfiguration);
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride) NotFoundException(alien4cloud.exception.NotFoundException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) NodeCapabilitiesPropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodeCapabilitiesPropsOverride)

Example 55 with PropertyDefinition

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

the class PropertyDefinitionConverter method convert.

public PropertyDefinition convert(FormPropertyDefinition definitionAnnotation) {
    if (definitionAnnotation == null) {
        return null;
    }
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(definitionAnnotation.type());
    // FIXME ? can be other than a scalar here ?
    propertyDefinition.setDefault(new ScalarPropertyValue(definitionAnnotation.defaultValue()));
    propertyDefinition.setDescription(definitionAnnotation.description());
    propertyDefinition.setPassword(definitionAnnotation.isPassword());
    propertyDefinition.setRequired(definitionAnnotation.isRequired());
    List<PropertyConstraint> constraints = Lists.newArrayList();
    if (!definitionAnnotation.constraints().equal().isEmpty()) {
        EqualConstraint equalConstraint = new EqualConstraint();
        equalConstraint.setEqual(definitionAnnotation.constraints().equal());
        constraints.add(equalConstraint);
    }
    if (!definitionAnnotation.constraints().greaterOrEqual().isEmpty()) {
        GreaterOrEqualConstraint greaterOrEqualConstraint = new GreaterOrEqualConstraint();
        greaterOrEqualConstraint.setGreaterOrEqual(definitionAnnotation.constraints().greaterOrEqual());
        constraints.add(greaterOrEqualConstraint);
    }
    if (!definitionAnnotation.constraints().greaterThan().isEmpty()) {
        GreaterThanConstraint greaterThanConstraint = new GreaterThanConstraint();
        greaterThanConstraint.setGreaterThan(definitionAnnotation.constraints().greaterThan());
        constraints.add(greaterThanConstraint);
    }
    if (!definitionAnnotation.constraints().inRange().isEmpty()) {
        String inRangeText = definitionAnnotation.constraints().inRange();
        Matcher matcher = IN_RANGE_REGEXP.matcher(inRangeText);
        if (matcher.matches()) {
            InRangeConstraint inRangeConstraint = new InRangeConstraint();
            inRangeConstraint.setRangeMinValue(matcher.group(1).trim());
            inRangeConstraint.setRangeMaxValue(matcher.group(2).trim());
            constraints.add(inRangeConstraint);
        } else {
            throw new FormDescriptorGenerationException("In range constraint definition must be in this format '[ $min - $max ]'");
        }
    }
    if (definitionAnnotation.constraints().length() >= 0) {
        LengthConstraint lengthConstraint = new LengthConstraint();
        lengthConstraint.setLength(definitionAnnotation.constraints().length());
        constraints.add(lengthConstraint);
    }
    if (!definitionAnnotation.constraints().lessOrEqual().isEmpty()) {
        LessOrEqualConstraint lessOrEqualConstraint = new LessOrEqualConstraint();
        lessOrEqualConstraint.setLessOrEqual(definitionAnnotation.constraints().lessOrEqual());
        constraints.add(lessOrEqualConstraint);
    }
    if (!definitionAnnotation.constraints().lessThan().isEmpty()) {
        LessThanConstraint lessThanConstraint = new LessThanConstraint();
        lessThanConstraint.setLessThan(definitionAnnotation.constraints().lessThan());
        constraints.add(lessThanConstraint);
    }
    if (definitionAnnotation.constraints().maxLength() >= 0) {
        MaxLengthConstraint maxLengthConstraint = new MaxLengthConstraint();
        maxLengthConstraint.setMaxLength(definitionAnnotation.constraints().maxLength());
        constraints.add(maxLengthConstraint);
    }
    if (definitionAnnotation.constraints().minLength() >= 0) {
        MinLengthConstraint minLengthConstraint = new MinLengthConstraint();
        minLengthConstraint.setMinLength(definitionAnnotation.constraints().minLength());
        constraints.add(minLengthConstraint);
    }
    if (!definitionAnnotation.constraints().pattern().isEmpty()) {
        PatternConstraint patternConstraint = new PatternConstraint();
        patternConstraint.setPattern(definitionAnnotation.constraints().pattern());
        constraints.add(patternConstraint);
    }
    if (definitionAnnotation.constraints().validValues().length > 0) {
        ValidValuesConstraint validValuesConstraint = new ValidValuesConstraint();
        validValuesConstraint.setValidValues(Lists.newArrayList(definitionAnnotation.constraints().validValues()));
        constraints.add(validValuesConstraint);
    }
    if (!constraints.isEmpty()) {
        propertyDefinition.setConstraints(constraints);
    }
    return propertyDefinition;
}
Also used : LengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) GreaterOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.GreaterOrEqualConstraint) FormDescriptorGenerationException(alien4cloud.ui.form.exception.FormDescriptorGenerationException) Matcher(java.util.regex.Matcher) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) FormPropertyDefinition(alien4cloud.ui.form.annotation.FormPropertyDefinition) LessThanConstraint(org.alien4cloud.tosca.model.definitions.constraints.LessThanConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) LessOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.LessOrEqualConstraint) ValidValuesConstraint(org.alien4cloud.tosca.model.definitions.constraints.ValidValuesConstraint) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) GreaterThanConstraint(org.alien4cloud.tosca.model.definitions.constraints.GreaterThanConstraint) InRangeConstraint(org.alien4cloud.tosca.model.definitions.constraints.InRangeConstraint) PatternConstraint(org.alien4cloud.tosca.model.definitions.constraints.PatternConstraint) LessOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.LessOrEqualConstraint) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint) GreaterOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.GreaterOrEqualConstraint)

Aggregations

PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)101 Test (org.junit.Test)42 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)23 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)20 Map (java.util.Map)19 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeType (org.alien4cloud.tosca.model.types.NodeType)15 NotFoundException (alien4cloud.exception.NotFoundException)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)11 MinLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)11 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)10 MaxLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint)10 Capability (org.alien4cloud.tosca.model.templates.Capability)10 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)10 DataType (org.alien4cloud.tosca.model.types.DataType)9 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)8 Set (java.util.Set)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)8 LengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint)8