Search in sources :

Example 11 with DeploymentTopology

use of alien4cloud.model.deployment.DeploymentTopology 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 12 with DeploymentTopology

use of alien4cloud.model.deployment.DeploymentTopology 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 DeploymentTopology

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

the class ManagedServiceResourceEventService method updateRunningService.

private void updateRunningService(ServiceResource serviceResource, String deploymentId, String state) {
    Deployment deployment = deploymentService.get(deploymentId);
    if (deployment == null) {
        log.error("Unable to update service [ {} ] as deployment [ {} ] cannot be found.", serviceResource.getId(), deploymentId);
        resetRunningServiceResource(serviceResource);
        return;
    }
    DeploymentTopology topology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
    updateRunningService(topology, serviceResource, deployment, state);
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment)

Example 14 with DeploymentTopology

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

the class ManagedServiceResourceService method create.

/**
 * Create a Service resource associated with the given environment.
 *
 * @param environmentId The environment to create a service for, the service version will be the one of the environment current associated version.
 * @param serviceName The name of the service as it should appears.
 * @param fromRuntime If we should try to create the service from the runtime topology related to the environment.
 * @return the id of the created service
 *
 * @throws AlreadyExistException if a service with the given name, or related to the given environment already exists
 * @throws alien4cloud.exception.NotFoundException if <b>fromRuntime</b> is set to true, but the environment is not deployed
 * @throws MissingSubstitutionException if topology related to the environment doesn't define a substitution type
 */
public synchronized String create(String serviceName, String environmentId, boolean fromRuntime) {
    ApplicationEnvironment environment = checkAndGetApplicationEnvironment(environmentId);
    // check that the service does not exists already for this environment
    if (alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("environmentId", environmentId)).count() > 0) {
        throw new AlreadyExistException("A service resource for environment <" + environmentId + "> and version <" + environment.getTopologyVersion() + "> already exists.");
    }
    Topology topology;
    String state = ToscaNodeLifecycleConstants.INITIAL;
    Deployment deployment = null;
    if (fromRuntime) {
        deployment = deploymentService.getActiveDeploymentOrFail(environmentId);
        topology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
        DeploymentStatus currentStatus = deploymentRuntimeStateService.getDeploymentStatus(deployment);
        state = managedServiceResourceEventService.getInstanceStateFromDeploymentStatus(currentStatus);
        if (state == null) {
            // We need a valid deployment state to expose as service.
            throw new InvalidDeploymentStatusException("Creating a service out of a running deployment is possible only when it's status is one of [DEPLOYED, FAILURE, UNDEPLOYED] current was <" + currentStatus + ">", currentStatus);
        }
    } else {
        topology = topologyServiceCore.getOrFail(Csar.createId(environment.getApplicationId(), environment.getTopologyVersion()));
    }
    if (topology.getSubstitutionMapping() == null) {
        throw new MissingSubstitutionException("Substitution is required to expose a topology.");
    }
    // The elementId of the type created out of the substitution is currently the archive name.
    String serviceId = serviceResourceService.create(serviceName, environment.getTopologyVersion(), topology.getArchiveName(), environment.getTopologyVersion(), environmentId);
    // Update the service relationships definition from the topology substitution
    updateServiceRelationship(serviceId, topology);
    if (fromRuntime) {
        managedServiceResourceEventService.updateRunningService((DeploymentTopology) topology, serviceResourceService.getOrFail(serviceId), deployment, state);
    }
    ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
    // trigger a ManagedServiceCreatedEvent
    publisher.publishEvent(new ManagedServiceCreatedEvent(this, serviceResource));
    return serviceId;
}
Also used : MissingSubstitutionException(org.alien4cloud.alm.service.exceptions.MissingSubstitutionException) InvalidDeploymentStatusException(org.alien4cloud.alm.service.exceptions.InvalidDeploymentStatusException) Deployment(alien4cloud.model.deployment.Deployment) ServiceResource(alien4cloud.model.service.ServiceResource) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) AlreadyExistException(alien4cloud.exception.AlreadyExistException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ManagedServiceCreatedEvent(org.alien4cloud.alm.events.ManagedServiceCreatedEvent) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus)

Example 15 with DeploymentTopology

use of alien4cloud.model.deployment.DeploymentTopology 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)

Aggregations

DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)22 Deployment (alien4cloud.model.deployment.Deployment)11 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)6 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)5 Location (alien4cloud.model.orchestrators.locations.Location)5 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)4 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Map (java.util.Map)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 NotFoundException (alien4cloud.exception.NotFoundException)2 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)2 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)2 PaaSTopology (alien4cloud.paas.model.PaaSTopology)2 PaaSTopologyDeploymentContext (alien4cloud.paas.model.PaaSTopologyDeploymentContext)2 TopologyDTO (alien4cloud.topology.TopologyDTO)2 ParsingException (alien4cloud.tosca.parser.ParsingException)2 IOException (java.io.IOException)2 ZipException (java.util.zip.ZipException)2