Search in sources :

Example 6 with DeploymentMatchingConfiguration

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

the class LocationMatchService method onCopyConfiguration.

@EventListener
// We must process location copy before copy of elements that depends from the location.
@Order(20)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
    ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
    DeploymentMatchingConfiguration sourceConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    if (sourceConfiguration == null || MapUtils.isEmpty(sourceConfiguration.getLocationGroups())) {
        // Nothing to copy
        return;
    }
    // Set the location policy to the target environment.
    setLocationPolicy(onDeploymentConfigCopyEvent.getTargetEnvironment(), sourceConfiguration.getOrchestratorId(), sourceConfiguration.getLocationIds());
}
Also used : DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 7 with DeploymentMatchingConfiguration

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

the class LocationMatchService method setLocationPolicy.

public void setLocationPolicy(ApplicationEnvironment environment, String orchestratorId, Map<String, String> groupsLocationsMapping) {
    if (MapUtils.isEmpty(groupsLocationsMapping)) {
        return;
    }
    DeploymentMatchingConfiguration configuration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
    if (configuration == null) {
        configuration = new DeploymentMatchingConfiguration(environment.getTopologyVersion(), environment.getId());
    } else if (configuration.getLocationGroups() == null) {
        configuration.setLocationGroups(Maps.newHashMap());
    }
    Map<String, String> currentConfiguration = configuration.getLocationIds();
    // TODO For now, we only support one location policy for all nodes. So we have a group _A4C_ALL that represents all compute nodes in the topology
    // To improve later on for multiple groups support
    // throw an exception if multiple location policies provided: not yet supported
    // throw an exception if group name is not _A4C_ALL
    checkGroups(groupsLocationsMapping);
    boolean updated = false;
    for (Entry<String, String> matchEntry : groupsLocationsMapping.entrySet()) {
        String current = currentConfiguration.get(matchEntry.getKey());
        if (current != null && current.equals(matchEntry.getValue())) {
            continue;
        }
        updated = true;
        String locationId = matchEntry.getValue();
        Location location = locationService.getOrFail(locationId);
        locationSecurityService.checkAuthorisation(location, environment.getId());
        LocationPlacementPolicy locationPolicy = new LocationPlacementPolicy(locationId);
        locationPolicy.setName("Location policy");
        Map<String, NodeGroup> groups = configuration.getLocationGroups();
        NodeGroup group = new NodeGroup();
        group.setName(matchEntry.getKey());
        group.setPolicies(Lists.<AbstractPolicy>newArrayList());
        group.getPolicies().add(locationPolicy);
        groups.put(matchEntry.getKey(), group);
    }
    if (!updated) {
        // nothing has changed.
        return;
    }
    configuration.setOrchestratorId(orchestratorId);
    configuration.setMatchedLocationResources(Maps.newHashMap());
    configuration.setMatchedNodesConfiguration(Maps.newHashMap());
    publisher.publishEvent(new OnMatchedLocationChangedEvent(this, environment, orchestratorId, groupsLocationsMapping));
    deploymentConfigurationDao.save(configuration);
}
Also used : OnMatchedLocationChangedEvent(org.alien4cloud.alm.deployment.configuration.events.OnMatchedLocationChangedEvent) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) LocationPlacementPolicy(org.alien4cloud.tosca.model.templates.LocationPlacementPolicy) Location(alien4cloud.model.orchestrators.locations.Location) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 8 with DeploymentMatchingConfiguration

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

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

the class OrchestratorPropertiesService method onCopyConfiguration.

@EventListener
// This is one of the last elements to process to place it's order quite far, after location match copy anyway.
@Order(40)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
    ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
    ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
    DeploymentMatchingConfiguration sourceMatchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    if (sourceMatchingConfiguration == null || MapUtils.isEmpty(sourceMatchingConfiguration.getLocationIds())) {
        return;
    }
    DeploymentMatchingConfiguration targetMatchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    if (targetMatchingConfiguration == null || MapUtils.isEmpty(targetMatchingConfiguration.getLocationIds()) || !sourceMatchingConfiguration.getOrchestratorId().equals(targetMatchingConfiguration.getOrchestratorId())) {
        // If the target does not have the same orchestrator as the source then don't copy the inputs
        return;
    }
    OrchestratorDeploymentProperties sourceProperties = deploymentConfigurationDao.findById(OrchestratorDeploymentProperties.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    if (sourceProperties == null || MapUtils.isEmpty(sourceProperties.getProviderDeploymentProperties())) {
        return;
    }
    OrchestratorDeploymentProperties targetProperties = new OrchestratorDeploymentProperties(target.getTopologyVersion(), target.getId(), sourceProperties.getOrchestratorId());
    targetProperties.setProviderDeploymentProperties(sourceProperties.getProviderDeploymentProperties());
    deploymentConfigurationDao.save(targetProperties);
}
Also used : DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 10 with DeploymentMatchingConfiguration

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

the class NodeMatchingCandidateModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, NodeMatchingCandidateModifier.class.getSimpleName());
    if (!configurationOptional.isPresent()) {
        // we should not end-up here as location matching should be processed first
        context.log().error(new LocationPolicyTask());
        return;
    }
    DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
    if (matchingConfiguration.getMatchedNodesConfiguration() == null) {
        matchingConfiguration.setMatchedNodesConfiguration(Maps.newHashMap());
    }
    if (matchingConfiguration.getMatchedLocationResources() == null) {
        matchingConfiguration.setMatchedLocationResources(Maps.newHashMap());
    }
    Map<String, Location> locationMap = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
    // TODO can we avoid update if the matching configuration is strickly younger than the context last conf update ?
    // Fetch available substitutions on the selected locations.
    Map<String, List<LocationResourceTemplate>> availableSubstitutions = getAvailableSubstitutions(topology, matchingConfiguration.getLocationGroups(), locationMap, context.getEnvironmentContext().get().getEnvironment().getId());
    context.getExecutionCache().put(FlowExecutionContext.MATCHED_NODE_LOCATION_TEMPLATES_BY_NODE_ID_MAP, availableSubstitutions);
}
Also used : LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) List(java.util.List) Map(java.util.Map) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)23 LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)10 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)8 Map (java.util.Map)8 List (java.util.List)7 NotFoundException (alien4cloud.exception.NotFoundException)6 Location (alien4cloud.model.orchestrators.locations.Location)5 Set (java.util.Set)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)4 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)3 Maps (com.google.common.collect.Maps)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 ITopologyModifier (org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier)3 NodeMatchingConfigAutoSelectModifier (org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier)3 NodePropsOverride (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)3 OrchestratorDeploymentProperties (org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)3 Csar (org.alien4cloud.tosca.model.Csar)3 MapUtils (org.apache.commons.collections4.MapUtils)3