Search in sources :

Example 1 with NodeMatchingTask

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

Aggregations

LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)1 NodeMatchingTask (alien4cloud.topology.task.NodeMatchingTask)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)1