private boolean shouldIgnoreException(CloudOperationException e) { return e.getStatusCode() .equals(HttpStatus.FORBIDDEN); }
private boolean shouldIgnoreException(CloudOperationException e, Set<HttpStatus> httpStatusesToIgnore) { for (HttpStatus status : httpStatusesToIgnore) { if (e.getStatusCode() .equals(status)) { return true; } } return e.getStatusCode() .equals(HttpStatus.INTERNAL_SERVER_ERROR) || e.getStatusCode() .equals(HttpStatus.BAD_GATEWAY) || e.getStatusCode() .equals(HttpStatus.SERVICE_UNAVAILABLE); }
private boolean shouldIgnoreException(CloudOperationException e, Set<HttpStatus> httpStatusesToIgnore) { for (HttpStatus status : httpStatusesToIgnore) { if (e.getStatusCode() .equals(status)) { return true; } } return e.getStatusCode() .equals(HttpStatus.INTERNAL_SERVER_ERROR) || e.getStatusCode() .equals(HttpStatus.BAD_GATEWAY) || e.getStatusCode() .equals(HttpStatus.SERVICE_UNAVAILABLE); }
private <T> T ignoreBadGatewayErrors(Supplier<T> supplier) { try { return supplier.get(); } catch (CloudOperationException e) { if (!e.getStatusCode() .equals(HttpStatus.BAD_GATEWAY)) { throw e; } LOGGER.warn(MessageFormat.format("Controller operation failed. Status Code: {0}, Status Text: {1}, Description: {2}", e.getStatusCode(), e.getStatusText(), e.getDescription())); } return null; }
private CloudOperationException evaluateCloudOperationException(CloudOperationException e, String serviceName) { if (e.getStatusCode() == HttpStatus.NOT_FOUND) { getStepLogger().warn(e, Messages.COULD_NOT_DELETE_SERVICE, serviceName); return null; } if (e.getStatusCode() == HttpStatus.BAD_GATEWAY) { return new CloudServiceBrokerException(e); } return new CloudControllerException(e); }
private CloudOperationException evaluateCloudOperationException(CloudOperationException e, String serviceName) { if (e.getStatusCode() == HttpStatus.NOT_FOUND) { getStepLogger().warn(e, Messages.COULD_NOT_DELETE_SERVICE, serviceName); return null; } if (e.getStatusCode() == HttpStatus.BAD_GATEWAY) { return new CloudServiceBrokerException(e); } return new CloudControllerException(e); }
public CloudControllerException(CloudOperationException cloudOperationException) { super(cloudOperationException.getStatusCode(), cloudOperationException.getStatusText(), cloudOperationException.getDescription(), cloudOperationException); }
public CloudServiceBrokerException(CloudOperationException cloudOperationException) { super(cloudOperationException.getStatusCode(), cloudOperationException.getStatusText(), cloudOperationException.getDescription(), cloudOperationException); }
private Map<String, Object> processApplicationResource(Map<String, Object> resource, boolean fetchServiceInfo) { try { if (fetchServiceInfo) { fillInEmbeddedResource(resource, "service_bindings", "service_instance"); } fillInEmbeddedResource(resource, "stack"); return resource; } catch (CloudOperationException e) { if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { // Application has been deleted before we could fetch the embedded resource logger.warn(e.getMessage(), e); return null; } throw e; } }
public <T> T executeServiceOperation(CloudServiceExtended service, Supplier<T> serviceOperation, StepLogger stepLogger) { try { return serviceOperation.get(); } catch (CloudOperationException e) { if (!service.isOptional()) { if (e.getStatusCode() == HttpStatus.BAD_GATEWAY) { throw new CloudServiceBrokerException(e); } throw new CloudControllerException(e); } stepLogger.warn(e, Messages.COULD_NOT_EXECUTE_OPERATION_OVER_OPTIONAL_SERVICE, service.getName()); return null; } }
private StagingState getStagingStateIfExceptionHasOccurred(CloudOperationException e) { // "400 Bad Request" might mean that staging had already finished if (e.getStatusCode() .equals(HttpStatus.BAD_REQUEST)) { return new StagingState(PackageState.STAGED, null); } else { return new StagingState(PackageState.FAILED, e.getMessage()); } }
private boolean isStarted(CloudControllerClient client, String appName) { try { CloudApplication app = client.getApplication(appName); return app.getState() .equals(AppState.STARTED); } catch (CloudOperationException e) { if (e.getStatusCode() .equals(HttpStatus.INTERNAL_SERVER_ERROR)) { logger.warn(e.getMessage(), e); return false; } throw e; } }
private StagingState getStagingStateIfExceptionHasOccurred(CloudOperationException e) { // "400 Bad Request" might mean that staging had already finished if (e.getStatusCode() .equals(HttpStatus.BAD_REQUEST)) { return new StagingState(PackageState.STAGED, null); } else { return new StagingState(PackageState.FAILED, e.getMessage()); } }
private boolean isStarted(CloudControllerClient client, String appName) { try { CloudApplication app = client.getApplication(appName); return app.getState() .equals(AppState.STARTED); } catch (CloudOperationException e) { if (e.getStatusCode() .equals(HttpStatus.INTERNAL_SERVER_ERROR)) { logger.warn(e.getMessage(), e); return false; } throw e; } }
private void testGetSpaceWithHttpErrorCode(HttpStatus status) { Map<String, Object> urlVariables = new HashMap<>(); urlVariables.put("id", "1"); when(restTemplate.getForObject(GET_SPACE_ENDPOINT, String.class, urlVariables)).thenThrow(new HttpClientErrorException(status)); try { spaceGetter.getSpace(client, "1"); } catch (CloudOperationException e) { assertEquals(e.getStatusCode(), status); return; } fail(); }
private void processServiceCreationFailure(CloudServiceExtended service, CloudOperationException e) { if (!service.isOptional()) { if (e.getStatusCode() == HttpStatus.BAD_GATEWAY) { throw new CloudServiceBrokerException(e); } throw new CloudControllerException(e); } getStepLogger().warn(e, Messages.COULD_NOT_EXECUTE_OPERATION_OVER_OPTIONAL_SERVICE, service.getName()); }
private void deleteRoute(String uri, boolean portBasedRouting, CloudControllerClient client) { try { boolean portRoute = portBasedRouting || UriUtil.isTcpOrTcpsUri(uri); new ClientHelper(client, spaceGetter).deleteRoute(uri, portRoute); } catch (CloudOperationException e) { if (!e.getStatusCode() .equals(HttpStatus.CONFLICT)) { throw e; } getStepLogger().info(Messages.ROUTE_NOT_DELETED, uri); } }
private void processServiceCreationFailure(CloudServiceExtended service, CloudOperationException e) { if (!service.isOptional()) { if (e.getStatusCode() == HttpStatus.BAD_GATEWAY) { throw new CloudServiceBrokerException(e); } throw new CloudControllerException(e); } getStepLogger().warn(e, Messages.COULD_NOT_EXECUTE_OPERATION_OVER_OPTIONAL_SERVICE, service.getName()); }
private void deleteRoute(String uri, boolean portBasedRouting, CloudControllerClient client) { try { boolean portRoute = portBasedRouting || UriUtil.isTcpOrTcpsUri(uri); new ClientHelper(client, spaceGetter).deleteRoute(uri, portRoute); } catch (CloudOperationException e) { if (!e.getStatusCode() .equals(HttpStatus.CONFLICT)) { throw e; } getStepLogger().info(Messages.ROUTE_NOT_DELETED, uri); } }
@Test public void testHandleErrorsWithRightExceptionType() { try { new CustomControllerClientErrorHandler(NULL_RETRIER).handleErrors(() -> { throw exceptionToThrow; }); } catch (CloudOperationException result) { assertEquals(expected.getStatusCode(), result.getStatusCode()); assertEquals(expected.getStatusText(), result.getStatusText()); assertEquals(expected.getDescription(), result.getDescription()); return; } fail(); }