Search in sources :

Example 16 with DeploymentMatchingConfiguration

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

the class AbstractMatchingConfigCleanupModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, this.getClass().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();
    Map<String, String> lastUserMatches = getLastUserMatches(matchingConfiguration);
    Map<String, List<T>> availableMatches = getAvailableMatches(context);
    // Last user defined matching choices may not be valid anymore so clean up
    // When the user has removed some mapped nodes from the topology the previous substitution configuration still exits.
    Iterator<Entry<String, String>> lastUserSubstitutionsIterator = lastUserMatches.entrySet().iterator();
    while (lastUserSubstitutionsIterator.hasNext()) {
        Map.Entry<String, String> entry = lastUserSubstitutionsIterator.next();
        // The node is still in the topology but we have to check that the existing substitution value is still a valid option.
        List<T> availableSubstitutionsForPolicy = availableMatches.get(entry.getKey());
        if (availableSubstitutionsForPolicy == null) {
            // no options => remove existing mapping
            lastUserSubstitutionsIterator.remove();
        // TODO add log
        } else if (!contains(availableSubstitutionsForPolicy, entry.getValue())) {
            // If the selected value is not a valid choice anymore then remove it
            lastUserSubstitutionsIterator.remove();
        // TODO add log
        }
    }
}
Also used : Entry(java.util.Map.Entry) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) List(java.util.List) Map(java.util.Map)

Example 17 with DeploymentMatchingConfiguration

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

the class AbstractMatchingReplaceModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    this.init(topology, context);
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, this.getClass().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();
    Map<String, String> lastUserSubstitutions = getUserMatches(matchingConfiguration);
    Map<String, V> matchesById = getMatchesById(context);
    Map<String, T> topologyTemplateMap = getTopologyTemplates(topology);
    Map<String, T> originalTemplates = Maps.newHashMap();
    Map<String, T> replacedTemplates = Maps.newHashMap();
    // Now modify the topology to replace nodes with the one selected during matching
    for (Map.Entry<String, String> substitutedNodeEntry : lastUserSubstitutions.entrySet()) {
        // Substitute the node template of the topology by those matched
        String templateId = substitutedNodeEntry.getKey();
        String matchedLocationResourceId = substitutedNodeEntry.getValue();
        originalTemplates.put(templateId, topologyTemplateMap.get(templateId));
        processReplacement(topology, topologyTemplateMap, matchesById, templateId, matchedLocationResourceId);
        replacedTemplates.put(templateId, topologyTemplateMap.get(templateId));
    }
    context.getExecutionCache().put(getOriginalTemplateCacheKey(), originalTemplates);
    context.getExecutionCache().put(getReplacedTemplateCacheKey(), replacedTemplates);
}
Also used : LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) Map(java.util.Map)

Example 18 with DeploymentMatchingConfiguration

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

the class AbstractSetMatchedModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    executed = true;
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, NodeMatchingConfigAutoSelectModifier.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();
    Map<String, String> lastUserSubstitutions = getLastUserMatches(matchingConfiguration);
    Map<String, Set<String>> templateIdToAvailableSubstitutions = getAvailableSubstitutions(context);
    // Check the provided resourceTemplate is a valid substitution match and update matching configuration
    Set<String> availableSubstitutions = templateIdToAvailableSubstitutions.get(templateId);
    if (safe(availableSubstitutions).contains(resourceTemplateId)) {
        lastUserSubstitutions.put(templateId, resourceTemplateId);
        context.saveConfiguration(matchingConfiguration);
        return;
    }
    throw new NotFoundException("Requested substitution <" + resourceTemplateId + "> for " + getSubject() + " <" + templateId + "> is not available as a match.");
}
Also used : Set(java.util.Set) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) NotFoundException(alien4cloud.exception.NotFoundException) NodeMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier)

Example 19 with DeploymentMatchingConfiguration

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

the class AbstractSetMatchedPropertyModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, NodeMatchingConfigAutoSelectModifier.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();
    Map<String, String> lastUserSubstitutions = getUserMatches(matchingConfiguration);
    U template = getTemplates(topology).get(templateId);
    if (template == null) {
        throw new NotFoundException("Topology [" + topology.getId() + "] does not contains any " + getSubject() + " with id [" + templateId + "]");
    }
    String substitutionId = lastUserSubstitutions.get(templateId);
    if (substitutionId == null) {
        throw new NotFoundException("The " + getSubject() + " [" + templateId + "] from topology [" + topology.getId() + "] is not matched.");
    }
    Map<String, V> allAvailableResourceTemplates = getAvailableResourceTemplates(context);
    V resourceTemplate = allAvailableResourceTemplates.get(substitutionId);
    try {
        setProperty(context, resourceTemplate, template, matchingConfiguration);
    } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
        throw new ConstraintTechnicalException("Dispatching constraint violation.", e);
    }
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) NotFoundException(alien4cloud.exception.NotFoundException) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) NodeMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)

Example 20 with DeploymentMatchingConfiguration

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

the class LocationMatchingModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    // first process
    processLocationMatching(topology, context);
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, LocationMatchingModifier.class.getSimpleName());
    // perform validation
    locationPolicyValidationService.validateLocationPolicies(configurationOptional.orElse(new DeploymentMatchingConfiguration())).forEach(locationPolicyTask -> context.log().error(locationPolicyTask));
    // No errors from validation let's inject location topology modifiers if any.
    if (context.log().isValid()) {
        Map<String, Location> selectedLocations = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
        List<Location> locationsWithVault = selectedLocations.values().stream().filter(location -> location.getSecretProviderConfiguration() != null && location.getSecretProviderConfiguration().getConfiguration() != null).collect(Collectors.toList());
        boolean needVaultCredential = locationsWithVault.size() > 0;
        if (needVaultCredential) {
            List<SecretCredentialInfo> secretCredentialInfos = new LinkedList<>();
            for (Location location : locationsWithVault) {
                try {
                    SecretCredentialInfo info = new SecretCredentialInfo();
                    String pluginName = location.getSecretProviderConfiguration().getPluginName();
                    Object rawSecretConfiguration = location.getSecretProviderConfiguration().getConfiguration();
                    secretCredentialInfos.add(secretProviderService.getSecretCredentialInfo(pluginName, rawSecretConfiguration));
                } catch (Exception e) {
                    log.error("Cannot process secret provider configuration", e);
                }
            }
            context.getExecutionCache().put(FlowExecutionContext.SECRET_CREDENTIAL, secretCredentialInfos);
        } else {
            context.getExecutionCache().remove(FlowExecutionContext.SECRET_CREDENTIAL);
        }
        for (LocationModifierReference modifierReference : safe(selectedLocations.values().iterator().next().getModifiers())) {
            if (pluginManager.getPluginOrFail(modifierReference.getPluginId()).isEnabled()) {
                injectLocationTopologyModfier(context, selectedLocations.values().iterator().next().getName(), modifierReference);
            } else {
                log.info("The plugin " + modifierReference.getPluginId() + " is not activated. Ignoring " + modifierReference.getBeanName() + ".");
            }
        }
    }
}
Also used : LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) LocationService(alien4cloud.orchestrators.locations.services.LocationService) PluginManager(alien4cloud.plugin.PluginManager) MetaPropertiesService(alien4cloud.common.MetaPropertiesService) LocationPolicyValidationService(alien4cloud.topology.validation.LocationPolicyValidationService) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Location(alien4cloud.model.orchestrators.locations.Location) Inject(javax.inject.Inject) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) LocationMatchingService(alien4cloud.deployment.matching.services.location.LocationMatchingService) Lists(com.google.common.collect.Lists) Map(java.util.Map) SecretProviderService(org.alien4cloud.secret.services.SecretProviderService) LinkedList(java.util.LinkedList) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) ILocationMatch(alien4cloud.model.deployment.matching.ILocationMatch) ToscaContext(alien4cloud.tosca.context.ToscaContext) MapUtils(org.apache.commons.collections4.MapUtils) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) List(java.util.List) Component(org.springframework.stereotype.Component) Slf4j(lombok.extern.slf4j.Slf4j) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Optional(java.util.Optional) Topology(org.alien4cloud.tosca.model.templates.Topology) SecretCredentialInfo(org.alien4cloud.alm.deployment.configuration.model.SecretCredentialInfo) LinkedList(java.util.LinkedList) MissingPluginException(alien4cloud.plugin.exception.MissingPluginException) LocationModifierReference(alien4cloud.model.orchestrators.locations.LocationModifierReference) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) 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