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();
}
}
Aggregations