Search in sources :

Example 1 with IPaaSCallback

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

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

use of alien4cloud.paas.IPaaSCallback in project alien4cloud by alien4cloud.

the class DeploymentRuntimeStateService method getDeploymentStatus.

/**
 * Get the current deployment status for a topology.
 *
 * @param deployment deployment for which we want the status.
 * @param callback that will be called when status is available
 * @return The status of the topology.
 * @throws alien4cloud.paas.exception.OrchestratorDisabledException In case the cloud selected for the topology is disabled.
 */
public void getDeploymentStatus(final Deployment deployment, final IPaaSCallback<DeploymentStatus> callback) throws OrchestratorDisabledException {
    deploymentLockService.doWithDeploymentReadLock(deployment.getOrchestratorDeploymentId(), () -> {
        if (deployment == null) {
            callback.onSuccess(DeploymentStatus.UNDEPLOYED);
            return null;
        }
        IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
        PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, getRuntimeTopology(deployment.getId()), null);
        IPaaSCallback<DeploymentStatus> esCallback = new IPaaSCallback<DeploymentStatus>() {

            @Override
            public void onSuccess(DeploymentStatus data) {
                callback.onSuccess(data);
            }

            @Override
            public void onFailure(Throwable throwable) {
                callback.onFailure(throwable);
            }
        };
        orchestratorPlugin.getStatus(deploymentContext, esCallback);
        return null;
    });
}
Also used : IPaaSCallback(alien4cloud.paas.IPaaSCallback) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Aggregations

IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)3 IPaaSCallback (alien4cloud.paas.IPaaSCallback)3 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)1 Location (alien4cloud.model.orchestrators.locations.Location)1 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)1 PaaSTopologyDeploymentContext (alien4cloud.paas.model.PaaSTopologyDeploymentContext)1 Capability (org.alien4cloud.tosca.model.templates.Capability)1