Search in sources :

Example 16 with Deployment

use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.

the class DeployService method deploy.

/**
 * Deploy a topology and return the deployment ID.
 *
 * @param deploymentTopology Location aware and matched topology.
 * @param deploymentSource Application to be deployed or the Csar that contains test toplogy to be deployed
 * @return The id of the generated deployment.
 */
public String deploy(final User deployer, final SecretProviderCredentials secretProviderCredentials, final DeploymentTopology deploymentTopology, IDeploymentSource deploymentSource) {
    Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deploymentTopology);
    Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
    final Location firstLocation = locations.values().iterator().next();
    String deploymentPaaSId = generateOrchestratorDeploymentId(deploymentTopology.getEnvironmentId(), firstLocation.getOrchestratorId());
    return deploymentLockService.doWithDeploymentWriteLock(deploymentPaaSId, () -> {
        // Get the orchestrator that will perform the deployment
        IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(firstLocation.getOrchestratorId());
        // Create a deployment object to be kept in ES.
        final Deployment deployment = new Deployment();
        deployment.setId(UUID.randomUUID().toString());
        deployment.setOrchestratorId(firstLocation.getOrchestratorId());
        deployment.setLocationIds(locationIds.values().toArray(new String[locationIds.size()]));
        deployment.setOrchestratorDeploymentId(deploymentPaaSId);
        deployment.setSourceId(deploymentSource.getId());
        deployment.setDeployerUsername(deployer.getUsername());
        String sourceName;
        if (deploymentSource.getName() == null) {
            sourceName = UUID.randomUUID().toString();
        } else {
            sourceName = deploymentSource.getName();
        }
        deployment.setSourceName(sourceName);
        deployment.setSourceType(DeploymentSourceType.fromSourceType(deploymentSource.getClass()));
        // mandatory for the moment since we could have deployment with no environment (csar test)
        deployment.setEnvironmentId(deploymentTopology.getEnvironmentId());
        deployment.setVersionId(deploymentTopology.getVersionId());
        deployment.setStartDate(new Date());
        setUsedServicesResourcesIds(deploymentTopology, deployment);
        alienDao.save(deployment);
        // publish an event for the eventual managed service
        eventPublisher.publishEvent(new DeploymentCreatedEvent(this, deployment.getId()));
        PaaSTopologyDeploymentContext deploymentContext = saveDeploymentTopologyAndGenerateDeploymentContext(secretProviderCredentials, deploymentTopology, deployment, locations);
        // Build the context for deployment and deploy
        orchestratorPlugin.deploy(deploymentContext, new IPaaSCallback<Object>() {

            @Override
            public void onSuccess(Object data) {
                log.debug("Deployed topology [{}] on location [{}], generated deployment with id [{}]", deploymentTopology.getInitialTopologyId(), firstLocation.getId(), deployment.getId());
            }

            @Override
            public void onFailure(Throwable t) {
                log.error("Deployment failed with cause", t);
                log(deployment, t);
            }
        });
        log.debug("Triggered deployment of topology [{}] on location [{}], generated deployment with id [{}]", deploymentTopology.getInitialTopologyId(), firstLocation.getId(), deployment.getId());
        return deployment.getId();
    });
}
Also used : DeploymentCreatedEvent(alien4cloud.events.DeploymentCreatedEvent) PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext) Deployment(alien4cloud.model.deployment.Deployment) Date(java.util.Date) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin) Location(alien4cloud.model.orchestrators.locations.Location)

Example 17 with Deployment

use of alien4cloud.model.deployment.Deployment 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 18 with Deployment

use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.

the class DeploymentRuntimeService method scale.

/**
 * Scale up/down a node in a topology
 *
 * @param applicationEnvironmentId id of the targeted environment
 * @param nodeTemplateId id of the compute node to scale up
 * @param instances the number of instances to be added (if positive) or removed (if negative)
 */
public void scale(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, String applicationEnvironmentId, final String nodeTemplateId, int instances, final IPaaSCallback<Object> callback) throws OrchestratorDisabledException {
    Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
    final DeploymentTopology topology = alienMonitorDao.findById(DeploymentTopology.class, deployment.getId());
    toscaContextualAspect.execInToscaContext(() -> {
        doScale(nodeTemplateId, instances, callback, deployment, topology, secretProviderConfigurationAndCredentials);
        return null;
    }, false, topology);
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment)

Example 19 with Deployment

use of alien4cloud.model.deployment.Deployment 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 20 with Deployment

use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.

the class UndeployService method undeploy.

/**
 * Un-deploy a deployment object
 *
 * @param deploymentId deployment id to deploy
 */
public void undeploy(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, String deploymentId) {
    Deployment deployment = deploymentService.getOrfail(deploymentId);
    undeploy(secretProviderConfigurationAndCredentials, deployment);
}
Also used : Deployment(alien4cloud.model.deployment.Deployment)

Aggregations

Deployment (alien4cloud.model.deployment.Deployment)43 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)13 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)11 ApiOperation (io.swagger.annotations.ApiOperation)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 NotFoundException (alien4cloud.exception.NotFoundException)6 Application (alien4cloud.model.application.Application)6 Location (alien4cloud.model.orchestrators.locations.Location)6 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)5 ApplicationVersion (alien4cloud.model.application.ApplicationVersion)3 Usage (alien4cloud.model.common.Usage)3 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)3 Date (java.util.Date)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 ServiceResource (alien4cloud.model.service.ServiceResource)2 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)2 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)2