use of alien4cloud.model.orchestrators.locations.Location 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);
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class PolicyMatchingCandidateModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, PolicyMatchingCandidateModifier.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.getMatchedPolicies() == null) {
matchingConfiguration.setMatchedPolicies(Maps.newHashMap());
}
Map<String, Location> locationMap = (Map<String, Location>) context.getExecutionCache().get(FlowExecutionContext.DEPLOYMENT_LOCATIONS_MAP_CACHE_KEY);
// TODO 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<PolicyLocationResourceTemplate>> availableSubstitutions = getAvailableMatches(topology, context, matchingConfiguration.getLocationGroups(), locationMap, context.getEnvironmentContext().get().getEnvironment().getId());
context.getExecutionCache().put(FlowExecutionContext.MATCHED_POLICY_LOCATION_TEMPLATES_BY_NODE_ID_MAP, availableSubstitutions);
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class DeployService method update.
public void update(SecretProviderCredentials secretProviderCredentials, final DeploymentTopology deploymentTopology, final IDeploymentSource deploymentSource, final Deployment existingDeployment, final IPaaSCallback<Object> callback) {
Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deploymentTopology);
Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
final Location firstLocation = locations.values().iterator().next();
deploymentLockService.doWithDeploymentWriteLock(existingDeployment.getOrchestratorDeploymentId(), () -> {
// Get the orchestrator that will perform the deployment
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(firstLocation.getOrchestratorId());
PaaSTopologyDeploymentContext deploymentContext = saveDeploymentTopologyAndGenerateDeploymentContext(secretProviderCredentials, deploymentTopology, existingDeployment, locations);
// After update we allow running a post_update workflow automatically, however as adding workflow in update depends on orchestrator we have to check
// if such option is possible on the selected orchestrator.
final DeploymentTopology deployedTopology = alienMonitorDao.findById(DeploymentTopology.class, existingDeployment.getId());
// enrich the callback
IPaaSCallback<Object> callbackWrapper = new IPaaSCallback<Object>() {
@Override
public void onSuccess(Object data) {
existingDeployment.setVersionId(deploymentTopology.getVersionId());
alienDao.save(existingDeployment);
// Trigger post update workflow if defined in both the initial and current topologies.
if (deploymentTopology.getWorkflows().get(NormativeWorkflowNameConstants.POST_UPDATE) != null && deployedTopology.getWorkflows().get(NormativeWorkflowNameConstants.POST_UPDATE) != null) {
scheduler.execute(() -> tryLaunchingPostUpdateWorkflow(System.currentTimeMillis(), existingDeployment, orchestratorPlugin, deploymentContext, callback));
}
}
@Override
public void onFailure(Throwable throwable) {
log(existingDeployment, throwable);
callback.onFailure(throwable);
}
};
// Build the context for deployment and deploy
orchestratorPlugin.update(deploymentContext, callbackWrapper);
log.debug("Triggered deployment of topology [{}] on location [{}], generated deployment with id [{}]", deploymentTopology.getInitialTopologyId(), firstLocation.getId(), existingDeployment.getId());
return null;
});
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method buildPaaSTopologyDeploymentContext.
/**
* Build the deployment context from an operation execution request
*
* @param request the operation execution request
* @return the deployment context
*/
public PaaSTopologyDeploymentContext buildPaaSTopologyDeploymentContext(OperationExecRequest request) {
Deployment deployment = deploymentService.getActiveDeploymentOrFail(request.getApplicationEnvironmentId());
DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deploymentTopology);
Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials = secretProviderService.generateToken(locations, request.getSecretProviderPluginName(), request.getSecretProviderCredentials());
return deploymentContextService.buildTopologyDeploymentContext(secretProviderConfigurationAndCredentials, deployment, deploymentTopologyService.getLocations(deploymentTopology), deploymentTopology);
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method doScale.
private void doScale(final String nodeTemplateId, final int instances, final IPaaSCallback<Object> callback, final Deployment deployment, final DeploymentTopology topology, SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology, nodeTemplateId);
// get the secret provider configuration from the location
Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(topology);
Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
SecretProviderConfigurationAndCredentials authResponse = null;
if (secretProviderService.isSecretProvided(secretProviderConfigurationAndCredentials)) {
authResponse = secretProviderService.generateToken(locations, secretProviderConfigurationAndCredentials.getSecretProviderConfiguration().getPluginName(), secretProviderConfigurationAndCredentials.getCredentials());
}
// Get alien4cloud specific interface to support cluster controller nodes.
Capability clusterControllerCapability = NodeTemplateUtils.getCapabilityByType(nodeTemplate, AlienCapabilityTypes.CLUSTER_CONTROLLER);
if (clusterControllerCapability == null) {
doScaleNode(nodeTemplateId, instances, callback, deployment, topology, nodeTemplate, authResponse);
} else {
triggerClusterManagerScaleOperation(nodeTemplateId, instances, callback, deployment, topology, clusterControllerCapability, secretProviderConfigurationAndCredentials);
}
}
Aggregations