Search in sources :

Example 1 with PaaSDeploymentContext

use of alien4cloud.paas.model.PaaSDeploymentContext 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 2 with PaaSDeploymentContext

use of alien4cloud.paas.model.PaaSDeploymentContext 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 3 with PaaSDeploymentContext

use of alien4cloud.paas.model.PaaSDeploymentContext 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 4 with PaaSDeploymentContext

use of alien4cloud.paas.model.PaaSDeploymentContext in project alien4cloud by alien4cloud.

the class DeploymentRuntimeService method doScaleNode.

private void doScaleNode(final String nodeTemplateId, final int instances, final IPaaSCallback<Object> callback, final Deployment deployment, final DeploymentTopology topology, NodeTemplate nodeTemplate, SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
    final Capability capability = NodeTemplateUtils.getCapabilityByTypeOrFail(nodeTemplate, NormativeCapabilityTypes.SCALABLE);
    final int previousInitialInstances = TopologyUtils.getScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, capability);
    final int newInitialInstances = previousInitialInstances + instances;
    log.info("Scaling [ {} ] node from [ {} ] to [ {} ]. Updating runtime topology...", nodeTemplateId, previousInitialInstances, newInitialInstances);
    TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, newInitialInstances, capability);
    alienMonitorDao.save(topology);
    IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
    PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, topology, secretProviderConfigurationAndCredentials);
    orchestratorPlugin.scale(deploymentContext, nodeTemplateId, instances, new IPaaSCallback() {

        @Override
        public void onFailure(Throwable throwable) {
            log.info("Failed to scale [ {} ] node from [ {} ] to [ {} ]. rolling back to {}...", nodeTemplateId, previousInitialInstances, newInitialInstances, previousInitialInstances);
            TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, previousInitialInstances, capability);
            alienMonitorDao.save(topology);
            callback.onFailure(throwable);
        }

        @Override
        public void onSuccess(Object data) {
            callback.onSuccess(data);
        }
    });
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) IPaaSCallback(alien4cloud.paas.IPaaSCallback) Capability(org.alien4cloud.tosca.model.templates.Capability) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 5 with PaaSDeploymentContext

use of alien4cloud.paas.model.PaaSDeploymentContext in project alien4cloud by alien4cloud.

the class UndeployService method undeploy.

private void undeploy(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, final Deployment deployment) {
    deploymentLockService.doWithDeploymentWriteLock(deployment.getOrchestratorDeploymentId(), () -> {
        log.info("Un-deploying deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
        IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
        DeploymentTopology deployedTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
        Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deployedTopology);
        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, deployedTopology, authResponse);
        orchestratorPlugin.undeploy(deploymentContext, new IPaaSCallback<ResponseEntity>() {

            @Override
            public void onSuccess(ResponseEntity data) {
                deploymentService.markUndeployed(deployment);
                log.info("Un-deployed deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
            }

            @Override
            public void onFailure(Throwable throwable) {
                log.warn("Fail while Undeploying deployment [{}] on orchestrator [{}]", deployment.getId(), deployment.getOrchestratorId());
            }
        });
        return null;
    });
}
Also used : PaaSDeploymentContext(alien4cloud.paas.model.PaaSDeploymentContext) ResponseEntity(org.springframework.http.ResponseEntity) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) SecretProviderConfigurationAndCredentials(alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)5 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)5 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)4 Deployment (alien4cloud.model.deployment.Deployment)3 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)2 Location (alien4cloud.model.orchestrators.locations.Location)2 IPaaSCallback (alien4cloud.paas.IPaaSCallback)1 Capability (org.alien4cloud.tosca.model.templates.Capability)1 ResponseEntity (org.springframework.http.ResponseEntity)1