Search in sources :

Example 11 with IOrchestratorPlugin

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);
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 12 with IOrchestratorPlugin

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);
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment) SecretProviderConfigurationAndCredentials(alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Location(alien4cloud.model.orchestrators.locations.Location)

Example 13 with IOrchestratorPlugin

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;
    });
}
Also used : IPaaSCallback(alien4cloud.paas.IPaaSCallback) PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Location(alien4cloud.model.orchestrators.locations.Location) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 14 with IOrchestratorPlugin

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);
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 15 with IOrchestratorPlugin

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);
        }
    });
}
Also used : NodeOperationExecRequest(alien4cloud.paas.model.NodeOperationExecRequest) Map(java.util.Map) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Aggregations

IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)22 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)6 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)6 Deployment (alien4cloud.model.deployment.Deployment)5 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)5 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)5 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)5 Location (alien4cloud.model.orchestrators.locations.Location)4 OrchestratorConfiguration (alien4cloud.model.orchestrators.OrchestratorConfiguration)3 IPaaSCallback (alien4cloud.paas.IPaaSCallback)3 PaaSTopologyDeploymentContext (alien4cloud.paas.model.PaaSTopologyDeploymentContext)3 Map (java.util.Map)3 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2 Test (org.junit.Test)2 DeploymentCreatedEvent (alien4cloud.events.DeploymentCreatedEvent)1 LocationTemplateCreated (alien4cloud.events.LocationTemplateCreated)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 NotFoundException (alien4cloud.exception.NotFoundException)1 Usage (alien4cloud.model.common.Usage)1