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 URI stringToUri(String endPoint) { try { return new URI(endPoint); } catch (URISyntaxException e) { throw new CloudOperationException("Unable to parse Loggregator endpoint " + endPoint); } }
public CloudControllerException(CloudOperationException cloudOperationException) { super(cloudOperationException.getStatusCode(), cloudOperationException.getStatusText(), cloudOperationException.getDescription(), cloudOperationException); }
private boolean shouldIgnoreException(CloudOperationException e) { return e.getStatusCode() .equals(HttpStatus.FORBIDDEN); }
@Override public String getMessage() { return decorateExceptionMessage(super.getMessage()); }
if (e.getStatusCode() .equals(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE)) { return ""; throw new CloudOperationException(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE, "The starting position " + start + " is past the end of the file content.");
@Test public void testUpdateServicePlan3() { // Given: CloudControllerClient client = getMockedClient(); Mockito.when(client.getService(EXISTING_SERVICE_NAME)) .thenThrow(new CloudOperationException(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.getReasonPhrase(), "Service \"foo\" was not found!")); try { // When: serviceUpdater.updateServicePlan(client, EXISTING_SERVICE_NAME, "v3.0-small"); } catch (CloudOperationException e) { // Then: assertEquals("404 Not Found: Service \"foo\" was not found!", e.getMessage()); } }
public CloudOperationException(HttpStatus statusCode, String statusText, String description, Throwable cause) { super(getExceptionMessage(statusCode, statusText, description), cause); this.statusCode = statusCode; this.statusText = statusText; this.description = description; }
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); }
@Override public String getMessage() { return decorateExceptionMessage(super.getMessage()); }
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 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); }
public CloudServiceBrokerException(CloudOperationException cloudOperationException) { super(cloudOperationException.getStatusCode(), cloudOperationException.getStatusText(), cloudOperationException.getDescription(), cloudOperationException); }
private UUID getRequiredApplicationId(String applicationName) { UUID applicationId = getApplicationId(applicationName); if (applicationId == null) { throw new CloudOperationException(HttpStatus.NOT_FOUND, "Not Found", "Application '" + applicationName + "' not found."); } return applicationId; }
private MethodExecution<String> attemptToFindServiceOfferingAndCreateService(CloudControllerClient client, CloudServiceExtended service, String spaceId, List<String> validServiceOfferings) { for (String validServiceOffering : validServiceOfferings) { try { service.setLabel(validServiceOffering); return serviceCreator.createService(client, service, spaceId); } catch (CloudOperationException e) { if (!shouldIgnoreException(e)) { throw e; } userMessageLogger.warn("Service \"{0}\" creation with service offering \"{1}\" failed with \"{2}\"", service.getName(), validServiceOffering, e.getMessage()); } } throw new SLException(Messages.CANT_CREATE_SERVICE, service.getName(), validServiceOfferings); }
public <T> T executeWithRetry(Supplier<T> supplier, HttpStatus... httpStatusesToIgnore) { Set<HttpStatus> httpStatuses = new HashSet<>(); httpStatuses.addAll(Arrays.asList(httpStatusesToIgnore)); for (int i = 1; i < retryCount; i++) { try { return supplier.get(); } catch (ResourceAccessException e) { LOGGER.warn(e.getMessage(), e); } catch (CloudOperationException e) { if (!shouldIgnoreException(e, httpStatuses)) { throw e; } LOGGER.warn("Retrying failed request with status: " + e.getStatusCode() + " and message: " + e.getMessage()); } sleep(waitTimeBetweenRetriesInMillis); } return supplier.get(); }
private CloudSpace attemptToFindSpace(String spaceId) { try { return spaceGetter.getSpace(client, spaceId); } catch (CloudOperationException e) { // From our point of view 403 means the same as 404 - the user does not have access to a space, so it is like it does not exist // for him. if (e.getStatusCode() .equals(HttpStatus.FORBIDDEN)) { LOGGER.debug(MessageFormat.format("The user does not have access to space with ID {0}!", spaceId)); return null; } if (e.getStatusCode() .equals(HttpStatus.NOT_FOUND)) { LOGGER.debug(MessageFormat.format("Space with ID {0} does not exist!", spaceId)); return null; } throw e; } }
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; }
public CloudSpace getSpace(CloudControllerClient client, String spaceId) { return client.getSpaces() .stream() .filter(space -> isSameSpace(space, spaceId)) .findAny() .orElseThrow( () -> new CloudOperationException(HttpStatus.NOT_FOUND, MessageFormat.format("Space with ID {0} does not exist", spaceId))); }
@Test public void testUpdateServicePlan2() { // Given: CloudControllerClient client = getMockedClient(); Mockito.when(client.getService(EXISTING_SERVICE_NAME)) .thenReturn(EXISTING_SERVICE); try { // When: serviceUpdater.updateServicePlan(client, EXISTING_SERVICE_NAME, "v3.0-large"); } catch (CloudOperationException e) { // Then: assertEquals( "404 Not Found: Could not create service instance \"foo\". Service plan \"v3.0-large\" from service offering \"mongodb\" was not found.", e.getMessage()); } }