@Override public String getMessage() { return decorateExceptionMessage(super.getMessage()); }
@Override public String getMessage() { return decorateExceptionMessage(super.getMessage()); }
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(); }
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 Map<String, Object> getInstanceInfoForApp(UUID appId, String path) { try { String url = getUrl("/v2/apps/{guid}/" + path); Map<String, Object> urlVars = new HashMap<String, Object>(); urlVars.put("guid", appId); String resp = getRestTemplate().getForObject(url, String.class, urlVars); return JsonUtil.convertJsonToMap(resp); } catch (CloudOperationException e) { if (HttpStatus.BAD_REQUEST.equals(e.getStatusCode())) { // Application has been stopped before we could get the instance info logger.warn(e.getMessage(), e); return null; } throw e; } }
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; } }
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 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 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); }
@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()); } }
protected void bindService(ExecutionWrapper execution, CloudControllerClient client, String appName, String serviceName, Map<String, Object> bindingParameters) { try { bindServiceToApplication(execution, client, appName, serviceName, bindingParameters); } catch (CloudOperationException e) { List<CloudServiceExtended> servicesToBind = StepsUtil.getServicesToBind(execution.getContext()); CloudServiceExtended serviceToBind = findServiceCloudModel(servicesToBind, serviceName); if (serviceToBind != null && serviceToBind.isOptional()) { getStepLogger().warn(e, Messages.COULD_NOT_BIND_APP_TO_OPTIONAL_SERVICE, appName, serviceName); return; } throw new SLException(e, Messages.COULD_NOT_BIND_APP_TO_SERVICE, appName, serviceName, e.getMessage()); } }
protected void bindService(ExecutionWrapper execution, CloudControllerClient client, String appName, String serviceName, Map<String, Object> bindingParameters) { try { bindServiceToApplication(execution, client, appName, serviceName, bindingParameters); } catch (CloudOperationException e) { List<CloudServiceExtended> servicesToBind = StepsUtil.getServicesToBind(execution.getContext()); CloudServiceExtended serviceToBind = findServiceCloudModel(servicesToBind, serviceName); if (serviceToBind != null && serviceToBind.isOptional()) { getStepLogger().warn(e, Messages.COULD_NOT_BIND_APP_TO_OPTIONAL_SERVICE, appName, serviceName); return; } throw new SLException(e, Messages.COULD_NOT_BIND_APP_TO_SERVICE, appName, serviceName, e.getMessage()); } }
@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()); } }