Search in sources :

Example 1 with DeploymentInputs

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.

the class InputArtifactsModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
    DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
    if (deploymentInputs.getInputArtifacts() == null) {
        deploymentInputs.setInputArtifacts(Maps.newHashMap());
    }
    boolean updated = false;
    // Cleanup inputs artifacts that does not exists anymore
    Iterator<Entry<String, DeploymentArtifact>> inputArtifactsIterator = safe(deploymentInputs.getInputArtifacts()).entrySet().iterator();
    while (inputArtifactsIterator.hasNext()) {
        Entry<String, DeploymentArtifact> inputArtifactEntry = inputArtifactsIterator.next();
        if (!topology.getInputArtifacts().containsKey(inputArtifactEntry.getKey())) {
            inputArtifactsIterator.remove();
            updated = true;
        }
    }
    processInputArtifacts(topology, deploymentInputs.getInputArtifacts());
    // should save if deploymentInput updated
    if (updated) {
        context.saveConfiguration(deploymentInputs);
    }
}
Also used : Entry(java.util.Map.Entry) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 2 with DeploymentInputs

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.

the class InputsModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    EnvironmentContext environmentContext = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context."));
    ApplicationEnvironment environment = environmentContext.getEnvironment();
    DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
    if (deploymentInputs.getInputs() == null) {
        deploymentInputs.setInputs(Maps.newHashMap());
    }
    Map<String, Location> locations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
    Map<String, PropertyValue> applicationInputs = inputService.getAppContextualInputs(context.getEnvironmentContext().get().getApplication(), topology.getInputs());
    Map<String, PropertyValue> locationInputs = inputService.getLocationContextualInputs(locations, topology.getInputs());
    // If the initial topology or any modifier configuration has changed since last inputs update then we refresh inputs.
    if (deploymentInputs.getLastUpdateDate() == null || deploymentInputs.getLastUpdateDate().before(context.getLastFlowParamUpdate())) {
        // FIXME exclude the application and location provided inputs from this method as it process them...
        boolean updated = deploymentInputService.synchronizeInputs(topology.getInputs(), deploymentInputs.getInputs());
        if (updated) {
            // save the config if changed. This is for ex, if an input has been deleted from the topology
            context.saveConfiguration(deploymentInputs);
        }
    }
    PreconfiguredInputsConfiguration preconfiguredInputsConfiguration = context.getConfiguration(PreconfiguredInputsConfiguration.class, InputsModifier.class.getSimpleName()).orElseThrow(() -> new IllegalStateException("PreconfiguredInputsConfiguration must be in the context"));
    Map<String, AbstractPropertyValue> inputValues = Maps.newHashMap(deploymentInputs.getInputs());
    inputValues.putAll(applicationInputs);
    inputValues.putAll(locationInputs);
    inputValues.putAll(preconfiguredInputsConfiguration.getInputs());
    // Now that we have inputs ready let's process get_input functions in the topology to actually replace values.
    if (topology.getNodeTemplates() != null) {
        FunctionEvaluatorContext evaluatorContext = new FunctionEvaluatorContext(topology, inputValues);
        for (Entry<String, NodeTemplate> entry : topology.getNodeTemplates().entrySet()) {
            NodeTemplate nodeTemplate = entry.getValue();
            processGetInput(evaluatorContext, nodeTemplate, nodeTemplate.getProperties());
            if (nodeTemplate.getRelationships() != null) {
                for (Entry<String, RelationshipTemplate> relEntry : nodeTemplate.getRelationships().entrySet()) {
                    RelationshipTemplate relationshipTemplate = relEntry.getValue();
                    processGetInput(evaluatorContext, relationshipTemplate, relationshipTemplate.getProperties());
                }
            }
            if (nodeTemplate.getCapabilities() != null) {
                for (Entry<String, Capability> capaEntry : nodeTemplate.getCapabilities().entrySet()) {
                    Capability capability = capaEntry.getValue();
                    processGetInput(evaluatorContext, nodeTemplate, capability.getProperties());
                }
            }
            if (nodeTemplate.getRequirements() != null) {
                for (Entry<String, Requirement> requirementEntry : nodeTemplate.getRequirements().entrySet()) {
                    Requirement requirement = requirementEntry.getValue();
                    processGetInput(evaluatorContext, nodeTemplate, requirement.getProperties());
                }
            }
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) PreconfiguredInputsConfiguration(org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration) FunctionEvaluatorContext(org.alien4cloud.tosca.utils.FunctionEvaluatorContext) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) Requirement(org.alien4cloud.tosca.model.templates.Requirement) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Location(alien4cloud.model.orchestrators.locations.Location)

Example 3 with DeploymentInputs

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.

the class InputArtifactService method updateInputArtifact.

public void updateInputArtifact(ApplicationEnvironment environment, Topology topology, String inputArtifactId, DeploymentArtifact updatedArtifact) {
    checkInputArtifactExist(inputArtifactId, topology);
    DeploymentInputs deploymentInputs = getDeploymentInputs(environment.getTopologyVersion(), environment.getId());
    DeploymentArtifact artifact = getDeploymentArtifact(inputArtifactId, deploymentInputs);
    artifact.setArtifactName(updatedArtifact.getArtifactName());
    artifact.setArtifactRef(updatedArtifact.getArtifactRef());
    artifact.setArtifactRepository(updatedArtifact.getArtifactRepository());
    artifact.setArtifactType(updatedArtifact.getArtifactType());
    artifact.setRepositoryName(updatedArtifact.getRepositoryName());
    artifact.setRepositoryURL(updatedArtifact.getRepositoryURL());
    artifact.setRepositoryCredential(updatedArtifact.getRepositoryCredential());
    artifact.setArchiveName(updatedArtifact.getArchiveName());
    artifact.setArchiveVersion(updatedArtifact.getArchiveVersion());
    deploymentConfigurationDao.save(deploymentInputs);
}
Also used : DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 4 with DeploymentInputs

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs 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 5 with DeploymentInputs

use of org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs in project alien4cloud by alien4cloud.

the class InputService method setInputValues.

public void setInputValues(ApplicationEnvironment environment, Topology topology, Map<String, Object> inputProperties) {
    if (safe(inputProperties).isEmpty()) {
        return;
    }
    // Get the configuration object
    DeploymentInputs configuration = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
    if (configuration == null) {
        configuration = new DeploymentInputs(environment.getTopologyVersion(), environment.getId());
    }
    for (Map.Entry<String, Object> inputPropertyValue : inputProperties.entrySet()) {
        if (topology.getInputs() == null || topology.getInputs().get(inputPropertyValue.getKey()) == null) {
            throw new NotFoundException("Input", inputPropertyValue.getKey(), "Input <" + inputPropertyValue.getKey() + "> cannot be found on topology for application <" + environment.getApplicationId() + "> environement <" + environment.getId() + ">");
        }
        try {
            propertyService.setPropertyValue(configuration.getInputs(), topology.getInputs().get(inputPropertyValue.getKey()), inputPropertyValue.getKey(), inputPropertyValue.getValue());
        } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
            throw new ConstraintTechnicalException("Dispatching constraint violation.", e);
        }
    }
    // Save configuration
    deploymentConfigurationDao.save(configuration);
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) NotFoundException(alien4cloud.exception.NotFoundException) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) Map(java.util.Map) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)

Aggregations

DeploymentInputs (org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs)10 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)5 NotFoundException (alien4cloud.exception.NotFoundException)4 Map (java.util.Map)4 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)4 PreconfiguredInputsConfiguration (org.alien4cloud.alm.deployment.configuration.model.PreconfiguredInputsConfiguration)3 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)3 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)3 Topology (org.alien4cloud.tosca.model.templates.Topology)3 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 Location (alien4cloud.model.orchestrators.locations.Location)2 TopologyServiceCore (alien4cloud.topology.TopologyServiceCore)2 InputStream (java.io.InputStream)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 OnDeploymentConfigCopyEvent (org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent)2 AbstractDeploymentConfig (org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig)2 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)2 ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)2 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)2