Search in sources :

Example 21 with FunctionPropertyValue

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

the class InputService method onCopyConfiguration.

@EventListener
@Order(10)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
    ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
    ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
    DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    if (deploymentInputs == null || MapUtils.isEmpty(deploymentInputs.getInputs())) {
        // Nothing to copy
        return;
    }
    Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
    if (MapUtils.isNotEmpty(topology.getInputs())) {
        Map<String, PropertyDefinition> inputsDefinitions = topology.getInputs();
        Map<String, AbstractPropertyValue> inputsToCopy = deploymentInputs.getInputs().entrySet().stream().filter(inputEntry -> inputsDefinitions.containsKey(inputEntry.getKey())).filter(inputEntry -> {
            // Copy only inputs which satisfy the new input definition
            try {
                if (!(inputEntry.getValue() instanceof FunctionPropertyValue)) {
                    ConstraintPropertyService.checkPropertyConstraint(inputEntry.getKey(), PropertyService.asPropertyValue(inputEntry.getValue()), inputsDefinitions.get(inputEntry.getKey()));
                }
                return true;
            } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
                return false;
            }
        }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (MapUtils.isNotEmpty(inputsToCopy)) {
            DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
            if (targetDeploymentInputs == null) {
                targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
            }
            // Copy inputs from original topology
            targetDeploymentInputs.setInputs(inputsToCopy);
            deploymentConfigurationDao.save(targetDeploymentInputs);
        }
    }
}
Also used : ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) TagUtil(alien4cloud.utils.TagUtil) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) MetaPropertiesService(alien4cloud.common.MetaPropertiesService) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) Inject(javax.inject.Inject) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Service(org.springframework.stereotype.Service) Application(alien4cloud.model.application.Application) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Map(java.util.Map) ConstraintPropertyService(alien4cloud.utils.services.ConstraintPropertyService) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) EventListener(org.springframework.context.event.EventListener) PropertyService(alien4cloud.utils.services.PropertyService) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) Topology(org.alien4cloud.tosca.model.templates.Topology) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 22 with FunctionPropertyValue

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

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

the class TopologyTreeBuilderService method processIValueForOperationOutput.

private <V extends AbstractInstantiableToscaType> void processIValueForOperationOutput(String name, IValue iValue, final IPaaSTemplate<V> paaSTemplate, final Map<String, PaaSNodeTemplate> paaSNodeTemplates, final boolean fromAttributes) {
    if (iValue instanceof FunctionPropertyValue) {
        FunctionPropertyValue function = (FunctionPropertyValue) iValue;
        if (ToscaFunctionConstants.GET_OPERATION_OUTPUT.equals(function.getFunction())) {
            String formatedAttributeName = null;
            List<? extends IPaaSTemplate> paaSTemplates = FunctionEvaluator.getPaaSTemplatesFromKeyword(paaSTemplate, function.getTemplateName(), paaSNodeTemplates);
            if (fromAttributes) {
                // nodeId:attributeName
                formatedAttributeName = AlienUtils.prefixWith(AlienUtils.COLON_SEPARATOR, name, paaSTemplate.getId());
            }
            registerOperationOutput(paaSTemplates, function.getInterfaceName(), function.getOperationName(), function.getElementNameToFetch(), formatedAttributeName);
        }
    } else if (iValue instanceof ConcatPropertyValue) {
        ConcatPropertyValue concatFunction = (ConcatPropertyValue) iValue;
        for (IValue param : concatFunction.getParameters()) {
            processIValueForOperationOutput(name, param, paaSTemplate, paaSNodeTemplates, false);
        }
    }
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ConcatPropertyValue(org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)

Example 24 with FunctionPropertyValue

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

the class PropertyService method asFunctionPropertyValue.

public static <T extends AbstractPropertyValue> T asFunctionPropertyValue(Object propertyValue) {
    if (propertyValue instanceof Map) {
        Map valueAsMap = (Map) propertyValue;
        if (valueAsMap.keySet().contains("function") && valueAsMap.keySet().contains("parameters")) {
            if (!ToscaFunctionConstants.GET_SECRET.equals(valueAsMap.get("function"))) {
                throw new InvalidArgumentException("Property function " + valueAsMap.get("function") + " is invalid");
            }
            FunctionPropertyValue functionPropertyValue = new FunctionPropertyValue();
            functionPropertyValue.setFunction((String) valueAsMap.get("function"));
            functionPropertyValue.setParameters((List<String>) valueAsMap.get("parameters"));
            return (T) functionPropertyValue;
        }
    }
    return (T) new ComplexPropertyValue((Map<String, Object>) propertyValue);
}
Also used : InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) Map(java.util.Map)

Example 25 with FunctionPropertyValue

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

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