Search in sources :

Example 1 with PaaSTechnicalException

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

Aggregations

Deployment (alien4cloud.model.deployment.Deployment)1 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)1 PaaSTechnicalException (alien4cloud.paas.exception.PaaSTechnicalException)1 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1 RestError (alien4cloud.rest.model.RestError)1 ApiOperation (io.swagger.annotations.ApiOperation)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1