Search in sources :

Example 61 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method getApplicationsStatuses.

@ApiOperation(value = "Deprecated Get the deployment status for the environements that the current user is allowed to see for a given application.", notes = "Returns the current status of an application list from the PaaS it is deployed on for all environments.")
@RequestMapping(value = "/statuses", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Deprecated
public RestResponse<Map<String, Map<String, EnvironmentStatusDTO>>> getApplicationsStatuses(@RequestBody List<String> applicationIds) {
    Map<String, Map<String, EnvironmentStatusDTO>> statuses = Maps.newHashMap();
    for (String applicationId : applicationIds) {
        Map<String, EnvironmentStatusDTO> environmentStatuses = Maps.newHashMap();
        Application application = applicationService.checkAndGetApplication(applicationId);
        // get all environments status for the current application
        ApplicationEnvironment[] environments = applicationEnvironmentService.getByApplicationId(application.getId());
        for (ApplicationEnvironment env : environments) {
            if (AuthorizationUtil.hasAuthorizationForEnvironment(application, env, ApplicationEnvironmentRole.values())) {
                DeploymentStatus status = DeploymentStatus.UNKNOWN;
                try {
                    status = applicationEnvironmentService.getStatus(env);
                } catch (Exception e) {
                    log.debug("Getting status for the environment <" + env.getId() + "> failed because the associated orchestrator seems disabled. Returned status is UNKNOWN.", e);
                }
                // TODO: include environment roles in the DTO to help display on ui
                environmentStatuses.put(env.getId(), new EnvironmentStatusDTO(env.getName(), status));
            }
        }
        statuses.put(applicationId, environmentStatuses);
    }
    return RestResponseBuilder.<Map<String, Map<String, EnvironmentStatusDTO>>>builder().data(statuses).build();
}
Also used : EnvironmentStatusDTO(alien4cloud.rest.application.model.EnvironmentStatusDTO) Map(java.util.Map) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) PaaSDeploymentException(alien4cloud.paas.exception.PaaSDeploymentException) MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) NotFoundException(alien4cloud.exception.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 62 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method getActiveDeployment.

/**
 * Get only the active deployment for the given application on the given cloud
 *
 * @param applicationId id of the topology
 * @return the active deployment
 */
@ApiOperation(value = "Get active deployment for the given application on the given cloud.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/active-deployment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<Deployment> getActiveDeployment(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
    Application application = applicationService.checkAndGetApplication(applicationId);
    // get the topology from the version and the cloud from the environment
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(application.getId(), applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.APPLICATION_USER);
    Deployment deployment = deploymentService.getActiveDeployment(environment.getId());
    return RestResponseBuilder.<Deployment>builder().data(deployment).build();
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 63 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method doUndeploy.

private RestResponse<Void> doUndeploy(String applicationId, String applicationEnvironmentId, SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, applicationEnvironmentId);
    Application application = applicationService.checkAndGetApplication(applicationId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    try {
        undeployService.undeployEnvironment(secretProviderConfigurationAndCredentials, applicationEnvironmentId);
    } catch (OrchestratorDisabledException e) {
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build();
    }
    return RestResponseBuilder.<Void>builder().build();
}
Also used : OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) RestError(alien4cloud.rest.model.RestError) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Application(alien4cloud.model.application.Application)

Example 64 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method updateTopologyVersion.

/**
 * Use new topology version for environment
 *
 * @param applicationEnvironmentId environment's id
 * @param applicationId application's id
 * @param request request for new topology's version
 */
@ApiOperation(value = "Use new topology version for the given application environment", notes = "The logged-in user must have the application manager role for this application. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}/topology-version", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<Void> updateTopologyVersion(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId, @RequestBody UpdateTopologyVersionForEnvironmentRequest request) throws OrchestratorDisabledException {
    // Only APPLICATION_MANAGER & DEPLOYMENT_MANAGER on the underlying application can update an application environment
    ApplicationEnvironment applicationEnvironment = applicationEnvironmentService.checkAndGetApplicationEnvironment(applicationEnvironmentId, ApplicationRole.APPLICATION_MANAGER, ApplicationEnvironmentRole.DEPLOYMENT_MANAGER);
    if (applicationEnvironment == null) {
        return RestResponseBuilder.<Void>builder().data(null).error(RestErrorBuilder.builder(RestErrorCode.APPLICATION_ENVIRONMENT_ERROR).message("Application environment with id <" + applicationEnvironmentId + "> does not exist").build()).build();
    }
    // update the version of the environment
    ApplicationVersion newApplicationVersion = applicationVersionService.getOrFailByArchiveId(Csar.createId(applicationEnvironment.getApplicationId(), request.getNewTopologyVersion()));
    String oldVersion = applicationEnvironment.getVersion();
    String oldTopologyVersion = applicationEnvironment.getTopologyVersion();
    String newVersion = newApplicationVersion.getVersion();
    String newTopologyVersion = request.getNewTopologyVersion();
    if (!Objects.equals(newVersion, oldVersion) || !Objects.equals(newTopologyVersion, oldTopologyVersion)) {
        // Only process if something has changed
        applicationEnvironmentService.updateTopologyVersion(applicationEnvironment, oldTopologyVersion, newVersion, newTopologyVersion, request.getEnvironmentToCopyInput());
    }
    return RestResponseBuilder.<Void>builder().build();
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 65 with ApplicationEnvironment

use of alien4cloud.model.application.ApplicationEnvironment in project alien4cloud by alien4cloud.

the class ApplicationEnvironmentController method getApplicationEnvironmentStatus.

/**
 * Get the current status of the environment for the given application.
 *
 * @param applicationId the id of the application to be deployed.
 * @param applicationEnvironmentId the environment for which to get the status
 * @return A {@link RestResponse} that contains the application's current {@link DeploymentStatus}.
 * @throws Exception
 */
@ApiOperation(value = "Get an application environment from its id", notes = "Returns the application environment. Application role required [ APPLICATION_USER | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationEnvironmentId:.+}/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<DeploymentStatus> getApplicationEnvironmentStatus(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) throws ExecutionException, InterruptedException {
    Application application = applicationService.checkAndGetApplication(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getOrFail(applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.values());
    DeploymentStatus status = applicationEnvironmentService.getStatus(environment);
    return RestResponseBuilder.<DeploymentStatus>builder().data(status).build();
}
Also used : Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)82 ApiOperation (io.swagger.annotations.ApiOperation)42 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 Application (alien4cloud.model.application.Application)40 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)35 Audit (alien4cloud.audit.annotation.Audit)27 List (java.util.List)17 Collectors (java.util.stream.Collectors)16 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)15 RestResponse (alien4cloud.rest.model.RestResponse)15 Topology (org.alien4cloud.tosca.model.templates.Topology)15 Set (java.util.Set)14 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)13 NotFoundException (alien4cloud.exception.NotFoundException)13 Map (java.util.Map)13 Resource (javax.annotation.Resource)12 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)11 Deployment (alien4cloud.model.deployment.Deployment)11 Arrays (java.util.Arrays)11 Location (alien4cloud.model.orchestrators.locations.Location)10