Search in sources :

Example 36 with AbstractPropertyValue

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

the class PaaSUtils method injectInputIntoOperations.

private static void injectInputIntoOperations(String inputName, List<String> path, AbstractPropertyValue value, Map<String, Operation> operations) {
    if (MapUtils.isEmpty(operations)) {
        return;
    }
    if (value != null) {
        value = new FunctionPropertyValue(ToscaFunctionConstants.GET_PROPERTY, path);
    } else {
        value = new ScalarPropertyValue();
    }
    // the input name should be uppercase
    AbstractPropertyValue finalValue = value;
    operations.forEach((operationName, operation) -> {
        if (operation.getInputParameters() == null) {
            operation.setInputParameters(Maps.newHashMap());
        }
        // DO NOT OVERRIDE
        operation.getInputParameters().putIfAbsent(inputName, finalValue);
    });
}
Also used : FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 37 with AbstractPropertyValue

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

the class NodeInstanceService method updateProperties.

private void updateProperties(NodeType nodeType, NodeTemplate nodeTemplate, Map<String, AbstractPropertyValue> nodeProperties) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
    for (Map.Entry<String, AbstractPropertyValue> propertyValueEntry : nodeProperties.entrySet()) {
        if (propertyValueEntry.getValue() != null) {
            AbstractPropertyValue value = PatchUtil.realValue(propertyValueEntry.getValue());
            PropertyDefinition propertyDefinition = safe(nodeType.getProperties()).get(propertyValueEntry.getKey());
            if (propertyDefinition == null) {
                throw new NotFoundException("No property <" + propertyValueEntry.getKey() + "> can be found for node type <" + nodeType.getElementId() + "> in version <" + nodeType.getArchiveVersion() + ">");
            }
            propertyService.setPropertyValue(nodeTemplate, propertyDefinition, propertyValueEntry.getKey(), value);
        }
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 38 with AbstractPropertyValue

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

the class NodeInstanceService method updateCapabilitiesProperties.

private void updateCapabilitiesProperties(CapabilityType capabilityType, Capability targetCapability, Capability patchCapability) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
    for (Map.Entry<String, AbstractPropertyValue> propertyValueEntry : patchCapability.getProperties().entrySet()) {
        if (propertyValueEntry.getValue() != null) {
            AbstractPropertyValue value = PatchUtil.realValue(propertyValueEntry.getValue());
            PropertyDefinition propertyDefinition = safe(capabilityType.getProperties()).get(propertyValueEntry.getKey());
            if (propertyDefinition == null) {
                throw new NotFoundException("No property <" + propertyValueEntry.getKey() + "> can be found for capability <" + capabilityType.getElementId() + ">");
            }
            propertyService.setCapabilityPropertyValue(targetCapability, propertyDefinition, propertyValueEntry.getKey(), value);
        }
    }
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 39 with AbstractPropertyValue

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

the class AbstractSetMatchedPropertyModifier method setProperty.

protected void setProperty(FlowExecutionContext context, V resourceTemplate, U template, DeploymentMatchingConfiguration matchingConfiguration) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    PropertyDefinition propertyDefinition = ((T) ToscaContext.getOrFail(AbstractToscaType.class, resourceTemplate.getTemplate().getType())).getProperties().get(propertyName);
    if (propertyDefinition == null) {
        throw new NotFoundException("No property of name [" + propertyName + "] can be found on the " + getSubject() + " template [" + templateId + "] of type [" + resourceTemplate.getTemplate().getType() + "]");
    }
    AbstractPropertyValue locationResourcePropertyValue = resourceTemplate.getTemplate().getProperties().get(propertyName);
    ensureNotSet(locationResourcePropertyValue, "by the admin in the Location Resource Template", propertyName, propertyValue);
    ensureNotSet(template.getProperties().get(propertyName), "in the portable topology", propertyName, propertyValue);
    // Update the configuration
    NodePropsOverride nodePropsOverride = getTemplatePropsOverride(matchingConfiguration);
    // Perform the update of the property
    if (propertyValue == null) {
        nodePropsOverride.getProperties().remove(propertyName);
    } else {
        AbstractPropertyValue abstractPropertyValue = PropertyService.asPropertyValue(propertyValue);
        if (!(abstractPropertyValue instanceof FunctionPropertyValue)) {
            ConstraintPropertyService.checkPropertyConstraint(propertyName, propertyValue, propertyDefinition);
        }
        nodePropsOverride.getProperties().put(propertyName, abstractPropertyValue);
    }
    context.saveConfiguration(matchingConfiguration);
}
Also used : NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) NotFoundException(alien4cloud.exception.NotFoundException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 40 with AbstractPropertyValue

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

the class InputValidationModifier method process.

/**
 * Validate all required input is provided with a non null value.
 *
 * @param topology The topology to process.
 * @param context The object that stores warnings and errors (tasks) associated with the execution flow. Note that the flow will end-up if an error
 */
@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentInputs> inputsOptional = context.getConfiguration(DeploymentInputs.class, InputValidationModifier.class.getSimpleName());
    PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputValidationModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
    // Define a task regarding properties
    PropertiesTask task = new PropertiesTask();
    task.setCode(TaskCode.INPUT_PROPERTY);
    task.setProperties(Maps.newHashMap());
    task.getProperties().put(TaskLevel.REQUIRED, Lists.newArrayList());
    Map<String, AbstractPropertyValue> inputValues = safe(inputsOptional.orElse(new DeploymentInputs()).getInputs());
    Map<String, PropertyValue> predefinedInputValues = safe(preconfiguredInputsConfiguration.getInputs());
    // override deployer inputValues with predefinedInputValues
    inputValues = Maps.newHashMap(inputValues);
    inputValues.putAll(predefinedInputValues);
    for (Entry<String, PropertyDefinition> propDef : safe(topology.getInputs()).entrySet()) {
        if (propDef.getValue().isRequired() && inputValues.get(propDef.getKey()) == null) {
            task.getProperties().get(TaskLevel.REQUIRED).add(propDef.getKey());
        }
    }
    if (CollectionUtils.isNotEmpty(task.getProperties().get(TaskLevel.REQUIRED))) {
        context.log().error(task);
    }
    // Check input artifacts
    deploymentInputArtifactValidationService.validate(topology, inputsOptional.orElse(new DeploymentInputs())).forEach(inputArtifactTask -> context.log().error(inputArtifactTask));
}
Also used : PropertiesTask(alien4cloud.topology.task.PropertiesTask) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) 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