use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method switchInstanceMaintenanceMode.
/**
* Switch an instance in a deployment to maintenance mode. If so the orchestrator should not perform self healing operations for this instance.
*
* @param applicationEnvironmentId The id of the application environment.
* @param nodeTemplateId The id of the node template on which to enable maintenance mode.
* @param instanceId The id of the instance.
* @param maintenanceModeOn true if we should enable the maintenance mode, false if we should disable it.
* @throws MaintenanceModeException In case the operation fails.
*/
public void switchInstanceMaintenanceMode(String applicationEnvironmentId, String nodeTemplateId, String instanceId, boolean maintenanceModeOn) throws MaintenanceModeException {
Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, deploymentTopology, null);
orchestratorPlugin.switchInstanceMaintenanceMode(deploymentContext, nodeTemplateId, instanceId, maintenanceModeOn);
}
use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.
the class WorkflowExecutionService method launchWorkflow.
/**
* Launch a given workflow.
*/
public synchronized void launchWorkflow(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, String applicationEnvironmentId, String workflowName, Map<String, Object> params, IPaaSCallback<?> iPaaSCallback) {
Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
final DeploymentTopology topology = alienMonitorDao.findById(DeploymentTopology.class, deployment.getId());
// 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());
}
PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, deploymentTopology, authResponse);
orchestratorPlugin.launchWorkflow(deploymentContext, workflowName, params, iPaaSCallback);
}
use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin 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.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method switchMaintenanceMode.
/**
* Switch all instances in a deployment to maintenance mode. If so the orchestrator should not perform self healing operations for this instance.
*
* @param applicationEnvironmentId The id of the application environment.
* @param maintenanceModeOn true if we should enable the maintenance mode, false if we should disable it.
* @throws MaintenanceModeException In case the operation fails.
*/
public void switchMaintenanceMode(String applicationEnvironmentId, boolean maintenanceModeOn) throws MaintenanceModeException {
Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, deploymentTopology, null);
orchestratorPlugin.switchMaintenanceMode(deploymentContext, maintenanceModeOn);
}
use of alien4cloud.orchestrators.plugin.IOrchestratorPlugin in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method triggerClusterManagerScaleOperation.
private void triggerClusterManagerScaleOperation(final String nodeTemplateId, final int instances, final IPaaSCallback<Object> callback, final Deployment deployment, final DeploymentTopology topology, Capability clusterControllerCapability, SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
NodeOperationExecRequest scaleOperationRequest = new NodeOperationExecRequest();
// Instance id is not specified for cluster control nodes
scaleOperationRequest.setNodeTemplateName(nodeTemplateId);
scaleOperationRequest.setInterfaceName(AlienInterfaceTypes.CLUSTER_CONTROL);
scaleOperationRequest.setOperationName(AlienInterfaceTypes.CLUSTER_CONTROL_OP_SCALE);
int currentInstances = TopologyUtils.getScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, clusterControllerCapability);
int expectedInstances = currentInstances + instances;
log.info("Scaling [ {} ] node from [ {} ] to [ {} ]. Updating runtime topology...", nodeTemplateId, currentInstances, expectedInstances);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, expectedInstances, clusterControllerCapability);
alienMonitorDao.save(topology);
scaleOperationRequest.setParameters(Maps.newHashMap());
scaleOperationRequest.getParameters().put(AlienInterfaceTypes.CLUSTER_CONTROL_OP_SCALE_PARAMS_INSTANCES_DELTA, String.valueOf(instances));
scaleOperationRequest.getParameters().put(AlienInterfaceTypes.CLUSTER_CONTROL_OP_SCALE_PARAMS_EXPECTED_INSTANCES, String.valueOf(expectedInstances));
orchestratorPlugin.executeOperation(deploymentContextService.buildTopologyDeploymentContext(secretProviderConfigurationAndCredentials, deployment, deploymentTopologyService.getLocations(topology), topology), scaleOperationRequest, new IPaaSCallback<Map<String, String>>() {
@Override
public void onSuccess(Map<String, String> data) {
callback.onSuccess(data);
}
@Override
public void onFailure(Throwable throwable) {
log.info("Failed to scale [ {} ] node from [ {} ] to [ {} ]. rolling back to {}...", nodeTemplateId, currentInstances, expectedInstances, currentInstances);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, currentInstances, clusterControllerCapability);
alienMonitorDao.save(topology);
callback.onFailure(throwable);
}
});
}
Aggregations