Search in sources :

Example 56 with PropertyDefinition

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

the class ToscaPropertyFormDescriptorGenerator method generateDescriptorForDataType.

private Map<String, Object> generateDescriptorForDataType(Set<String> processedDataTypes, DataType dataType, Set<CSARDependency> dependencies) {
    Map<String, Object> dataTypeDescriptors = Maps.newHashMap();
    if (dataType instanceof PrimitiveDataType) {
        dataTypeDescriptors.put(TYPE_KEY, TOSCA_TYPE);
        PropertyDefinition propertyDefinition = new PropertyDefinition();
        propertyDefinition.setType(dataType.getDerivedFrom().get(0));
        propertyDefinition.setConstraints(((PrimitiveDataType) dataType).getConstraints());
        dataTypeDescriptors.put(TOSCA_DEFINITION_KEY, propertyDefinition);
    } else {
        dataTypeDescriptors.put(TYPE_KEY, COMPLEX_TYPE);
        Map<String, Object> propertyTypes = Maps.newHashMap();
        dataTypeDescriptors.put(PROPERTY_TYPE_KEY, propertyTypes);
        if (dataType.getProperties() != null) {
            for (Map.Entry<String, PropertyDefinition> propertyDefinitionEntry : dataType.getProperties().entrySet()) {
                propertyTypes.put(propertyDefinitionEntry.getKey(), doGenerateDescriptor(processedDataTypes, propertyDefinitionEntry.getValue(), dependencies));
            }
            dataTypeDescriptors.put(ORDER_KEY, dataType.getProperties().keySet());
        }
    }
    return dataTypeDescriptors;
}
Also used : PrimitiveDataType(org.alien4cloud.tosca.model.types.PrimitiveDataType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Map(java.util.Map)

Example 57 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition 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)

Example 58 with PropertyDefinition

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

the class OrchestratorPropertiesValidationService method validate.

public PropertiesTask validate(OrchestratorDeploymentProperties orchestratorDeploymentProperties) {
    if (orchestratorDeploymentProperties == null || StringUtils.isBlank(orchestratorDeploymentProperties.getOrchestratorId())) {
        return null;
    }
    Map<String, PropertyDefinition> deploymentProperties = orchestratorDeploymentService.getDeploymentPropertyDefinitions(orchestratorDeploymentProperties.getOrchestratorId());
    if (MapUtils.isEmpty(deploymentProperties)) {
        return null;
    }
    Map<String, String> properties = orchestratorDeploymentProperties.getProviderDeploymentProperties();
    if (properties == null) {
        properties = Maps.newHashMap();
    }
    PropertiesTask task = null;
    List<String> required = Lists.newArrayList();
    for (Entry<String, PropertyDefinition> entry : deploymentProperties.entrySet()) {
        if (entry.getValue().isRequired()) {
            String value = properties.get(entry.getKey());
            if (StringUtils.isBlank(value)) {
                required.add(entry.getKey());
            }
        }
    }
    if (CollectionUtils.isNotEmpty(required)) {
        task = new PropertiesTask(Maps.<TaskLevel, List<String>>newHashMap());
        task.setCode(TaskCode.ORCHESTRATOR_PROPERTY);
        task.getProperties().put(TaskLevel.REQUIRED, required);
    }
    return task;
}
Also used : PropertiesTask(alien4cloud.topology.task.PropertiesTask) TaskLevel(alien4cloud.topology.task.TaskLevel) List(java.util.List) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 59 with PropertyDefinition

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

the class InputPropertiesStepDefinitions method getPropertyDefinition.

private PropertyDefinition getPropertyDefinition(String nodeName, String propertyName) throws Throwable {
    PropertyDefinition propDef = null;
    String url = String.format("/rest/v1/topologies/%s", Context.getInstance().getTopologyId());
    String response = Context.getRestClientInstance().get(url);
    TopologyDTO topologyDTO = JsonUtil.read(response, TopologyDTO.class, Context.getJsonMapper()).getData();
    NodeTemplate template = MapUtils.getObject(topologyDTO.getTopology().getNodeTemplates(), nodeName);
    if (template != null) {
        NodeType nodeType = MapUtils.getObject(topologyDTO.getNodeTypes(), template.getType());
        if (nodeType != null) {
            propDef = MapUtils.getObject(nodeType.getProperties(), propertyName);
        }
    }
    if (propDef == null) {
        throw new NullPointerException("The property definition is required for node " + nodeName + " and property " + propertyName + ", please check your cucumber scenario.");
    }
    return propDef;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) NodeType(org.alien4cloud.tosca.model.types.NodeType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 60 with PropertyDefinition

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

the class InputPropertiesStepDefinitions method I_define_the_property_of_the_node_as_of_typeId_as_input_property.

@When("^I define the property \"([^\"]*)\" of the node \"([^\"]*)\" of typeId \"([^\"]*)\" as input property$")
public void I_define_the_property_of_the_node_as_of_typeId_as_input_property(String inputId, String nodeName, String typeId) throws Throwable {
    // get the component to use the right property definition
    String componentResponse = Context.getRestClientInstance().get("/rest/v1/components/" + typeId);
    RestResponse<NodeType> componentResult = JsonUtil.read(componentResponse, NodeType.class, Context.getJsonMapper());
    PropertyDefinition propertyDefinition = componentResult.getData().getProperties().get(inputId);
    String fullUrl = String.format("/rest/v1/topologies/%s/inputs/%s", Context.getInstance().getTopologyId(), inputId);
    String json = JsonUtil.toString(propertyDefinition);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(fullUrl, json));
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) When(cucumber.api.java.en.When)

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