Search in sources :

Example 1 with OnDeploymentConfigCopyEvent

use of org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent 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 2 with OnDeploymentConfigCopyEvent

use of org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent in project alien4cloud by alien4cloud.

the class NodeMatchingSubstitutionService method onCopyConfiguration.

// FIXME fix this, synch with org.alien4cloud.alm.deployment.configuration.services.PolicyMatchingSubstitutionService#onCopyConfiguration
@EventListener
// Process this after location matching copy (first element).
@Order(30)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
    ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
    ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
    DeploymentMatchingConfiguration sourceConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    DeploymentMatchingConfiguration targetConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
    if (sourceConfiguration == null || MapUtils.isEmpty(sourceConfiguration.getLocationGroups()) || targetConfiguration == null || MapUtils.isEmpty(targetConfiguration.getLocationGroups())) {
        // Nothing to copy
        return;
    }
    // We have to execute a piece of the deployment flow to find out matching candidates so we copy only required inputs
    Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
    if (MapUtils.isNotEmpty(topology.getNodeTemplates())) {
        Application application = applicationService.getOrFail(target.getApplicationId());
        FlowExecutionContext executionContext = new FlowExecutionContext(deploymentConfigurationDao, topology, new EnvironmentContext(application, target));
        flowExecutor.execute(topology, getMatchingFlow(), executionContext);
        Map<String, Set<String>> locResTemplateIdsPerNodeIds = (Map<String, Set<String>>) executionContext.getExecutionCache().get(FlowExecutionContext.SELECTED_MATCH_NODE_LOCATION_TEMPLATE_BY_NODE_ID_MAP);
        // Update the substitution on the target if available substitution is always compatible
        Map<String, String> validOnNewEnvSubstitutedNodes = safe(sourceConfiguration.getMatchedLocationResources()).entrySet().stream().filter(entry -> locResTemplateIdsPerNodeIds.containsKey(entry.getKey()) && locResTemplateIdsPerNodeIds.get(entry.getKey()).contains(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (MapUtils.isNotEmpty(validOnNewEnvSubstitutedNodes)) {
            if (targetConfiguration.getMatchedLocationResources() == null) {
                targetConfiguration.setMatchedLocationResources(Maps.newHashMap());
            }
            validOnNewEnvSubstitutedNodes.forEach((key, value) -> {
                targetConfiguration.getMatchedLocationResources().put(key, value);
                // Copy properties set on the node to the new one
                targetConfiguration.getMatchedNodesConfiguration().put(key, safe(sourceConfiguration.getMatchedNodesConfiguration()).get(key));
            });
            deploymentConfigurationDao.save(targetConfiguration);
        }
    }
}
Also used : EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationService(alien4cloud.application.ApplicationService) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) NodeMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Set(java.util.Set) SetMatchedNodeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedNodeModifier) EventListener(org.springframework.context.event.EventListener) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NotFoundException(alien4cloud.exception.NotFoundException) List(java.util.List) EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) FlowExecutor(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutor) AbstractComposedModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.AbstractComposedModifier) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) NodeMatchingCompositeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingCompositeModifier) Topology(org.alien4cloud.tosca.model.templates.Topology) Set(java.util.Set) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 3 with OnDeploymentConfigCopyEvent

use of org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent in project alien4cloud by alien4cloud.

the class InputArtifactService method onCopyConfiguration.

@EventListener
@Order(11)
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.getInputArtifacts())) {
        // Nothing to copy
        return;
    }
    Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
    if (MapUtils.isNotEmpty(topology.getInputArtifacts())) {
        Map<String, DeploymentArtifact> inputsArtifactsDefinitions = topology.getInputArtifacts();
        // Copy only artifacts which exists in the new topology's definition
        Map<String, DeploymentArtifact> inputsArtifactsToCopy = deploymentInputs.getInputArtifacts().entrySet().stream().filter(inputEntry -> inputsArtifactsDefinitions.containsKey(inputEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (MapUtils.isNotEmpty(inputsArtifactsToCopy)) {
            // There's something to copy
            DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
            if (targetDeploymentInputs == null) {
                targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
            }
            targetDeploymentInputs.setInputArtifacts(inputsArtifactsToCopy);
            deploymentConfigurationDao.save(targetDeploymentInputs);
        }
    }
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) IOException(java.io.IOException) HashMap(java.util.HashMap) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Collectors(java.util.stream.Collectors) NotFoundException(alien4cloud.exception.NotFoundException) Inject(javax.inject.Inject) IFileRepository(alien4cloud.component.repository.IFileRepository) Service(org.springframework.stereotype.Service) Map(java.util.Map) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) MultipartFile(org.springframework.web.multipart.MultipartFile) Topology(org.alien4cloud.tosca.model.templates.Topology) ArtifactRepositoryConstants(alien4cloud.component.repository.ArtifactRepositoryConstants) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) InputStream(java.io.InputStream) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) HashMap(java.util.HashMap) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 4 with OnDeploymentConfigCopyEvent

use of org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent in project alien4cloud by alien4cloud.

the class PolicyMatchingSubstitutionService method onCopyConfiguration.

// FIXME fix this, synch with org.alien4cloud.alm.deployment.configuration.services.MatchingSubstitutionService#onCopyConfiguration
// @EventListener
// @Order(30) // Process this after location matching copy (first element).
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
    ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
    ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
    DeploymentMatchingConfiguration sourceConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    DeploymentMatchingConfiguration targetConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
    if (sourceConfiguration == null || MapUtils.isEmpty(sourceConfiguration.getLocationGroups()) || targetConfiguration == null || MapUtils.isEmpty(targetConfiguration.getLocationGroups())) {
        // Nothing to copy
        return;
    }
    // We have to execute a piece of the deployment flow to find out matching candidates so we copy only required inputs
    Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
    if (MapUtils.isNotEmpty(topology.getNodeTemplates())) {
        Application application = applicationService.getOrFail(target.getApplicationId());
        FlowExecutionContext executionContext = new FlowExecutionContext(deploymentConfigurationDao, topology, new EnvironmentContext(application, target));
        flowExecutor.execute(topology, getMatchingFlow(), executionContext);
        Map<String, Set<String>> locResTemplateIdsPerNodeIds = (Map<String, Set<String>>) executionContext.getExecutionCache().get(FlowExecutionContext.SELECTED_MATCH_NODE_LOCATION_TEMPLATE_BY_NODE_ID_MAP);
        // Update the substitution on the target if available substitution is always compatible
        Map<String, String> validOnNewEnvSubstitutedNodes = safe(sourceConfiguration.getMatchedLocationResources()).entrySet().stream().filter(entry -> locResTemplateIdsPerNodeIds.containsKey(entry.getKey()) && locResTemplateIdsPerNodeIds.get(entry.getKey()).contains(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (MapUtils.isNotEmpty(validOnNewEnvSubstitutedNodes)) {
            if (targetConfiguration.getMatchedLocationResources() == null) {
                targetConfiguration.setMatchedLocationResources(Maps.newHashMap());
            }
            validOnNewEnvSubstitutedNodes.forEach((key, value) -> {
                targetConfiguration.getMatchedLocationResources().put(key, value);
                // Copy properties set on the node to the new one
                targetConfiguration.getMatchedNodesConfiguration().put(key, safe(sourceConfiguration.getMatchedNodesConfiguration()).get(key));
            });
            deploymentConfigurationDao.save(targetConfiguration);
        }
    }
}
Also used : EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) PolicyMatchingCompositeModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.PolicyMatchingCompositeModifier) PolicyMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.PolicyMatchingConfigAutoSelectModifier) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationService(alien4cloud.application.ApplicationService) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) MapUtils(org.apache.commons.collections4.MapUtils) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Set(java.util.Set) SetMatchedPolicyModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.action.SetMatchedPolicyModifier) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) NotFoundException(alien4cloud.exception.NotFoundException) List(java.util.List) EnvironmentContext(org.alien4cloud.alm.deployment.configuration.flow.EnvironmentContext) FlowExecutor(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutor) AbstractComposedModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.AbstractComposedModifier) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Topology(org.alien4cloud.tosca.model.templates.Topology) Set(java.util.Set) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application) Map(java.util.Map)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)4 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)4 TopologyServiceCore (alien4cloud.topology.TopologyServiceCore)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 OnDeploymentConfigCopyEvent (org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent)4 AbstractDeploymentConfig (org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig)4 Csar (org.alien4cloud.tosca.model.Csar)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 MapUtils (org.apache.commons.collections4.MapUtils)4 Service (org.springframework.stereotype.Service)4 Application (alien4cloud.model.application.Application)3 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)3 Maps (com.google.common.collect.Maps)3 EventListener (org.springframework.context.event.EventListener)3 Order (org.springframework.core.annotation.Order)3 ApplicationService (alien4cloud.application.ApplicationService)2 List (java.util.List)2 Set (java.util.Set)2