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);
}
}
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);
}
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
}
}
}
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);
}
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.");
}
Aggregations