use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration in project alien4cloud by alien4cloud.
the class LocationMatchService method onCopyConfiguration.
@EventListener
// We must process location copy before copy of elements that depends from the location.
@Order(20)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
DeploymentMatchingConfiguration sourceConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (sourceConfiguration == null || MapUtils.isEmpty(sourceConfiguration.getLocationGroups())) {
// Nothing to copy
return;
}
// Set the location policy to the target environment.
setLocationPolicy(onDeploymentConfigCopyEvent.getTargetEnvironment(), sourceConfiguration.getOrchestratorId(), sourceConfiguration.getLocationIds());
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration in project alien4cloud by alien4cloud.
the class LocationMatchService method setLocationPolicy.
public void setLocationPolicy(ApplicationEnvironment environment, String orchestratorId, Map<String, String> groupsLocationsMapping) {
if (MapUtils.isEmpty(groupsLocationsMapping)) {
return;
}
DeploymentMatchingConfiguration configuration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
if (configuration == null) {
configuration = new DeploymentMatchingConfiguration(environment.getTopologyVersion(), environment.getId());
} else if (configuration.getLocationGroups() == null) {
configuration.setLocationGroups(Maps.newHashMap());
}
Map<String, String> currentConfiguration = configuration.getLocationIds();
// TODO For now, we only support one location policy for all nodes. So we have a group _A4C_ALL that represents all compute nodes in the topology
// To improve later on for multiple groups support
// throw an exception if multiple location policies provided: not yet supported
// throw an exception if group name is not _A4C_ALL
checkGroups(groupsLocationsMapping);
boolean updated = false;
for (Entry<String, String> matchEntry : groupsLocationsMapping.entrySet()) {
String current = currentConfiguration.get(matchEntry.getKey());
if (current != null && current.equals(matchEntry.getValue())) {
continue;
}
updated = true;
String locationId = matchEntry.getValue();
Location location = locationService.getOrFail(locationId);
locationSecurityService.checkAuthorisation(location, environment.getId());
LocationPlacementPolicy locationPolicy = new LocationPlacementPolicy(locationId);
locationPolicy.setName("Location policy");
Map<String, NodeGroup> groups = configuration.getLocationGroups();
NodeGroup group = new NodeGroup();
group.setName(matchEntry.getKey());
group.setPolicies(Lists.<AbstractPolicy>newArrayList());
group.getPolicies().add(locationPolicy);
groups.put(matchEntry.getKey(), group);
}
if (!updated) {
// nothing has changed.
return;
}
configuration.setOrchestratorId(orchestratorId);
configuration.setMatchedLocationResources(Maps.newHashMap());
configuration.setMatchedNodesConfiguration(Maps.newHashMap());
publisher.publishEvent(new OnMatchedLocationChangedEvent(this, environment, orchestratorId, groupsLocationsMapping));
deploymentConfigurationDao.save(configuration);
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration in project alien4cloud by alien4cloud.
the class NodeMatchingSubstitutionService method onCopyConfiguration.
// FIXME fix this, synch with org.alien4cloud.alm.deployment.configuration.services.PolicyMatchingSubstitutionService#onCopyConfiguration
@EventListener
// Process this after location matching copy (first element).
@Order(30)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
DeploymentMatchingConfiguration sourceConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
DeploymentMatchingConfiguration targetConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
if (sourceConfiguration == null || MapUtils.isEmpty(sourceConfiguration.getLocationGroups()) || targetConfiguration == null || MapUtils.isEmpty(targetConfiguration.getLocationGroups())) {
// Nothing to copy
return;
}
// We have to execute a piece of the deployment flow to find out matching candidates so we copy only required inputs
Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
if (MapUtils.isNotEmpty(topology.getNodeTemplates())) {
Application application = applicationService.getOrFail(target.getApplicationId());
FlowExecutionContext executionContext = new FlowExecutionContext(deploymentConfigurationDao, topology, new EnvironmentContext(application, target));
flowExecutor.execute(topology, getMatchingFlow(), executionContext);
Map<String, Set<String>> locResTemplateIdsPerNodeIds = (Map<String, Set<String>>) executionContext.getExecutionCache().get(FlowExecutionContext.SELECTED_MATCH_NODE_LOCATION_TEMPLATE_BY_NODE_ID_MAP);
// Update the substitution on the target if available substitution is always compatible
Map<String, String> validOnNewEnvSubstitutedNodes = safe(sourceConfiguration.getMatchedLocationResources()).entrySet().stream().filter(entry -> locResTemplateIdsPerNodeIds.containsKey(entry.getKey()) && locResTemplateIdsPerNodeIds.get(entry.getKey()).contains(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (MapUtils.isNotEmpty(validOnNewEnvSubstitutedNodes)) {
if (targetConfiguration.getMatchedLocationResources() == null) {
targetConfiguration.setMatchedLocationResources(Maps.newHashMap());
}
validOnNewEnvSubstitutedNodes.forEach((key, value) -> {
targetConfiguration.getMatchedLocationResources().put(key, value);
// Copy properties set on the node to the new one
targetConfiguration.getMatchedNodesConfiguration().put(key, safe(sourceConfiguration.getMatchedNodesConfiguration()).get(key));
});
deploymentConfigurationDao.save(targetConfiguration);
}
}
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration in project alien4cloud by alien4cloud.
the class OrchestratorPropertiesService method onCopyConfiguration.
@EventListener
// This is one of the last elements to process to place it's order quite far, after location match copy anyway.
@Order(40)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
DeploymentMatchingConfiguration sourceMatchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (sourceMatchingConfiguration == null || MapUtils.isEmpty(sourceMatchingConfiguration.getLocationIds())) {
return;
}
DeploymentMatchingConfiguration targetMatchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (targetMatchingConfiguration == null || MapUtils.isEmpty(targetMatchingConfiguration.getLocationIds()) || !sourceMatchingConfiguration.getOrchestratorId().equals(targetMatchingConfiguration.getOrchestratorId())) {
// If the target does not have the same orchestrator as the source then don't copy the inputs
return;
}
OrchestratorDeploymentProperties sourceProperties = deploymentConfigurationDao.findById(OrchestratorDeploymentProperties.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
if (sourceProperties == null || MapUtils.isEmpty(sourceProperties.getProviderDeploymentProperties())) {
return;
}
OrchestratorDeploymentProperties targetProperties = new OrchestratorDeploymentProperties(target.getTopologyVersion(), target.getId(), sourceProperties.getOrchestratorId());
targetProperties.setProviderDeploymentProperties(sourceProperties.getProviderDeploymentProperties());
deploymentConfigurationDao.save(targetProperties);
}
use of org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration in project alien4cloud by alien4cloud.
the class NodeMatchingCandidateModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, NodeMatchingCandidateModifier.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();
if (matchingConfiguration.getMatchedNodesConfiguration() == null) {
matchingConfiguration.setMatchedNodesConfiguration(Maps.newHashMap());
}
if (matchingConfiguration.getMatchedLocationResources() == null) {
matchingConfiguration.setMatchedLocationResources(Maps.newHashMap());
}
Map<String, Location> locationMap = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
// TODO can we avoid update if the matching configuration is strickly younger than the context last conf update ?
// Fetch available substitutions on the selected locations.
Map<String, List<LocationResourceTemplate>> availableSubstitutions = getAvailableSubstitutions(topology, matchingConfiguration.getLocationGroups(), locationMap, context.getEnvironmentContext().get().getEnvironment().getId());
context.getExecutionCache().put(FlowExecutionContext.MATCHED_NODE_LOCATION_TEMPLATES_BY_NODE_ID_MAP, availableSubstitutions);
}
Aggregations