Search in sources :

Example 21 with Deployment

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

the class UndeployService method undeploy.

/**
 * Un-deploy from a deployment setup.
 *
 * @param deploymentTopology setup object containing information to deploy
 */
public void undeploy(SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials, DeploymentTopology deploymentTopology) {
    Deployment activeDeployment = deploymentService.getActiveDeploymentOrFail(deploymentTopology.getEnvironmentId());
    undeploy(secretProviderConfigurationAndCredentials, activeDeployment);
}
Also used : Deployment(alien4cloud.model.deployment.Deployment)

Example 22 with Deployment

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

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

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

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

the class DeploymentRuntimeService method buildPaaSTopologyDeploymentContext.

/**
 * Build the deployment context from an operation execution request
 *
 * @param request the operation execution request
 * @return the deployment context
 */
public PaaSTopologyDeploymentContext buildPaaSTopologyDeploymentContext(OperationExecRequest request) {
    Deployment deployment = deploymentService.getActiveDeploymentOrFail(request.getApplicationEnvironmentId());
    DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(deployment.getEnvironmentId());
    Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(deploymentTopology);
    Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
    SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials = secretProviderService.generateToken(locations, request.getSecretProviderPluginName(), request.getSecretProviderCredentials());
    return deploymentContextService.buildTopologyDeploymentContext(secretProviderConfigurationAndCredentials, deployment, deploymentTopologyService.getLocations(deploymentTopology), deploymentTopology);
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment) SecretProviderConfigurationAndCredentials(alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials) Location(alien4cloud.model.orchestrators.locations.Location)

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