Search in sources :

Example 6 with OrchestratorDisabledException

use of alien4cloud.paas.exception.OrchestratorDisabledException in project alien4cloud by alien4cloud.

the class DeploymentController method getDeploymentStatus.

@ApiOperation(value = "Get deployment status from its id.", authorizations = { @Authorization("ADMIN"), @Authorization("APPLICATION_MANAGER") })
@RequestMapping(value = "/{deploymentId}/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<DeploymentStatus> getDeploymentStatus(@ApiParam(value = "Deployment id.", required = true) @Valid @NotBlank @PathVariable String deploymentId) {
    Deployment deployment = alienDAO.findById(Deployment.class, deploymentId);
    if (deployment != null) {
        try {
            return deploymentLockService.doWithDeploymentReadLock(deployment.getOrchestratorDeploymentId(), () -> {
                final SettableFuture<DeploymentStatus> statusSettableFuture = SettableFuture.create();
                deploymentRuntimeStateService.getDeploymentStatus(deployment, new IPaaSCallback<DeploymentStatus>() {

                    @Override
                    public void onSuccess(DeploymentStatus result) {
                        statusSettableFuture.set(result);
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        statusSettableFuture.setException(t);
                    }
                });
                try {
                    DeploymentStatus currentStatus = statusSettableFuture.get();
                    if (DeploymentStatus.UNDEPLOYED.equals(currentStatus)) {
                        deploymentService.markUndeployed(deployment);
                    }
                    return RestResponseBuilder.<DeploymentStatus>builder().data(currentStatus).build();
                } catch (Exception e) {
                    throw new PaaSTechnicalException("Could not retrieve status from PaaS", e);
                }
            });
        } catch (OrchestratorDisabledException e) {
            return RestResponseBuilder.<DeploymentStatus>builder().data(null).error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build();
        }
    } else {
        return RestResponseBuilder.<DeploymentStatus>builder().data(null).error(new RestError(RestErrorCode.NOT_FOUND_ERROR.getCode(), "Deployment with id <" + deploymentId + "> was not found.")).build();
    }
}
Also used : OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) PaaSTechnicalException(alien4cloud.paas.exception.PaaSTechnicalException) RestError(alien4cloud.rest.model.RestError) Deployment(alien4cloud.model.deployment.Deployment) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) PaaSTechnicalException(alien4cloud.paas.exception.PaaSTechnicalException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with OrchestratorDisabledException

use of alien4cloud.paas.exception.OrchestratorDisabledException 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)

Aggregations

OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)7 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)5 RestError (alien4cloud.rest.model.RestError)5 ApiOperation (io.swagger.annotations.ApiOperation)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 RestResponse (alien4cloud.rest.model.RestResponse)4 DeferredResult (org.springframework.web.context.request.async.DeferredResult)4 Audit (alien4cloud.audit.annotation.Audit)3 Application (alien4cloud.model.application.Application)3 Deployment (alien4cloud.model.deployment.Deployment)2 PaaSDeploymentException (alien4cloud.paas.exception.PaaSDeploymentException)2 Map (java.util.Map)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)1 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)1 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)1 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)1 OperationExecutionException (alien4cloud.paas.exception.OperationExecutionException)1 PaaSTechnicalException (alien4cloud.paas.exception.PaaSTechnicalException)1 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1