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