Search in sources :

Example 6 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask in project alien4cloud by alien4cloud.

the class AbstractPostMatchingSetupModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, AbstractPostMatchingSetupModifier.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 deploymentMatchingConfiguration = configurationOptional.get();
    Map<String, String> lastUserSubstitutions = getUserMatches(deploymentMatchingConfiguration);
    Map<String, NodePropsOverride> propertiesOverrides = getPropertiesOverrides(deploymentMatchingConfiguration);
    boolean configChanged = false;
    Iterator<Entry<String, NodePropsOverride>> propertiesOverrideIter = safe(propertiesOverrides).entrySet().iterator();
    while (propertiesOverrideIter.hasNext()) {
        Entry<String, NodePropsOverride> nodePropsOverrideEntry = propertiesOverrideIter.next();
        if (lastUserSubstitutions.containsKey(nodePropsOverrideEntry.getKey())) {
            // Merge the user overrides into the node.
            configChanged = mergeNode(topology, context, nodePropsOverrideEntry.getKey(), nodePropsOverrideEntry.getValue());
        } else {
            // This node is no more a matched node, remove from configuration
            configChanged = true;
            context.log().info("Definition of user properties for " + getSubject() + " [" + nodePropsOverrideEntry.getKey() + "] have been removed as the " + getSubject() + " is not available for matching anymore.");
            propertiesOverrideIter.remove();
        }
    }
    // If the configuration has changed then update it.
    if (configChanged) {
        context.saveConfiguration(deploymentMatchingConfiguration);
    }
}
Also used : Entry(java.util.Map.Entry) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)

Example 7 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask in project alien4cloud by alien4cloud.

the class AbstractMatchingConfigAutoSelectModifier 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 substitution may be incomplete or not valid anymore so let's check them and eventually select default values
    Map<String, T> availableResourceTemplatesById = Maps.newHashMap();
    // map of nodeId -> location resource template ids required to create
    Map<String, Set<String>> resourceTemplatesByTemplateId = Maps.newHashMap();
    // historical deployment topology dto object
    for (Map.Entry<String, List<T>> entry : availableMatches.entrySet()) {
        // Fill locResTemplateIdsPerNodeIds
        Set<String> lrtIds = Sets.newHashSet();
        resourceTemplatesByTemplateId.put(entry.getKey(), lrtIds);
        // We leverage the loop to also create a map of resources by id for later usage.
        for (T lrt : entry.getValue()) {
            availableResourceTemplatesById.put(lrt.getId(), lrt);
            lrtIds.add(lrt.getId());
        }
        // select default values
        if (!lastUserMatches.containsKey(entry.getKey())) {
            if (entry.getValue().isEmpty()) {
                // report that no node has been found on the location with the topology criteria
                consumeNoMatchingFound(context, new NodeMatchingTask(entry.getKey()));
            } else {
                // Only take the first element as selected if no configuration has been set before
                // let an info so the user know that we made a default selection for him
                context.log().info("Automatic matching for template <" + entry.getKey() + ">");
                lastUserMatches.put(entry.getKey(), entry.getValue().iterator().next().getId());
            }
        }
    }
    // This is required for next modifier so we cache them here for performance reasons.
    context.getExecutionCache().put(getResourceTemplateByIdMapCacheKey(), availableResourceTemplatesById);
    context.getExecutionCache().put(getResourceTemplateByTemplateIdCacheKey(), resourceTemplatesByTemplateId);
    // matchingConfiguration.setMatchedPolicies(lastUserMatches);
    // TODO Do that only if updated...
    context.saveConfiguration(matchingConfiguration);
}
Also used : Set(java.util.Set) NodeMatchingTask(alien4cloud.topology.task.NodeMatchingTask) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) List(java.util.List) Map(java.util.Map)

Example 8 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask 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 9 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask 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 10 with LocationPolicyTask

use of alien4cloud.topology.task.LocationPolicyTask 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)

Aggregations

LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)11 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)10 Map (java.util.Map)5 List (java.util.List)4 Location (alien4cloud.model.orchestrators.locations.Location)3 NotFoundException (alien4cloud.exception.NotFoundException)2 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 NodeMatchingConfigAutoSelectModifier (org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier)2 NodePropsOverride (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 NodeMatchingTask (alien4cloud.topology.task.NodeMatchingTask)1 UnavailableLocationTask (alien4cloud.topology.task.UnavailableLocationTask)1 OrchestratorDeploymentProperties (org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)1 ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)1 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)1 ConstraintViolationException (org.alien4cloud.tosca.exceptions.ConstraintViolationException)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1