private RuntimeException handleException(RuntimeException e) { Throwable cause = e.getCause(); if (cause != null && cause instanceof TException) { throw new ServiceUnavailableException(Constants.Service.TRANSACTION, cause); } throw e; } }
private RuntimeException handleException(RuntimeException e) { Throwable cause = e.getCause(); if (cause != null && cause instanceof TException) { throw new ServiceUnavailableException(Constants.Service.TRANSACTION, cause); } throw e; } }
/** * Handles error response based on the given response code. */ private void handleError(int responseCode, Supplier<String> responseBodySupplier, String errorPrefix) throws IOException { switch (responseCode) { case HttpURLConnection.HTTP_OK: return; case HttpURLConnection.HTTP_BAD_REQUEST: throw new IllegalArgumentException(errorPrefix + ". Reason: " + responseBodySupplier.get()); case HttpURLConnection.HTTP_UNAVAILABLE: throw new ServiceUnavailableException(Constants.Service.MESSAGING_SERVICE); default: throw new IOException(errorPrefix + ". Reason: " + responseBodySupplier.get()); } }
/** * Handles error response based on the given response code. */ private void handleError(int responseCode, Supplier<String> responseBodySupplier, String errorPrefix) throws IOException { switch (responseCode) { case HttpURLConnection.HTTP_OK: return; case HttpURLConnection.HTTP_BAD_REQUEST: throw new IllegalArgumentException(errorPrefix + ". Reason: " + responseBodySupplier.get()); case HttpURLConnection.HTTP_UNAVAILABLE: throw new ServiceUnavailableException(Constants.Service.MESSAGING_SERVICE); default: throw new IOException(errorPrefix + ". Reason: " + responseBodySupplier.get()); } }
/** * Checks if the scheduler started completely and is functional. * * @throws ServiceUnavailableException if the scheduler is not yet functional */ private void checkStarted() { if (!Uninterruptibles.awaitUninterruptibly(startedLatch, 0, TimeUnit.SECONDS)) { throw new ServiceUnavailableException("Core scheduler"); } }
/** * Checks if the scheduler started completely and is functional. * * @throws ServiceUnavailableException if the scheduler is not yet functional */ private void checkStarted() { if (!Uninterruptibles.awaitUninterruptibly(startedLatch, 0, TimeUnit.SECONDS)) { throw new ServiceUnavailableException("Core scheduler"); } }
@Override protected InetSocketAddress getExploreServiceAddress() { Discoverable discoverable = endpointStrategySupplier.get().pick(3L, TimeUnit.SECONDS); if (discoverable != null) { return discoverable.getSocketAddress(); } throw new ServiceUnavailableException(Service.EXPLORE_HTTP_USER_SERVICE); }
@Override protected InetSocketAddress getExploreServiceAddress() { Discoverable discoverable = endpointStrategySupplier.get().pick(3L, TimeUnit.SECONDS); if (discoverable != null) { return discoverable.getSocketAddress(); } throw new ServiceUnavailableException(Service.EXPLORE_HTTP_USER_SERVICE); }
/** * Throws exception if the given response code is not 200 OK. */ private void throwIfNotOK(int responseCode, HttpURLConnection urlConn) throws IOException { switch (responseCode) { case HttpURLConnection.HTTP_OK: return; case HttpURLConnection.HTTP_BAD_REQUEST: throw new IllegalArgumentException(readError(urlConn)); case HttpURLConnection.HTTP_UNAVAILABLE: throw new ServiceUnavailableException("runtime.monitor", readError(urlConn)); default: throw new IOException("Failed to talk to runtime monitor. Response code is " + responseCode + ". Error is " + readError(urlConn)); } }
/** * Requests graceful termination of the running program. * * @throws IOException if failed to issue the command to the server * @throws IllegalArgumentException if server responded with 400 Bad Request * @throws ServiceUnavailableException if the runtime monitor server is not available */ void requestStop() throws IOException { HttpURLConnection urlConn = connect("runtime/kill"); try { urlConn.setRequestMethod("POST"); throwIfNotOK(urlConn.getResponseCode(), urlConn); } catch (ConnectException e) { throw new ServiceUnavailableException("runtime.monitor", e); } finally { releaseConnection(urlConn); } }
/** * Requests graceful termination of the running program. * * @throws IOException if failed to issue the command to the server * @throws IllegalArgumentException if server responded with 400 Bad Request * @throws ServiceUnavailableException if the runtime monitor server is not available */ void requestStop() throws IOException { HttpURLConnection urlConn = connect("runtime/kill"); try { urlConn.setRequestMethod("POST"); throwIfNotOK(urlConn.getResponseCode(), urlConn); } catch (ConnectException e) { throw new ServiceUnavailableException("runtime.monitor", e); } finally { releaseConnection(urlConn); } }
/** * Throws exception if the given response code is not 200 OK. */ private void throwIfNotOK(int responseCode, HttpURLConnection urlConn) throws IOException { switch (responseCode) { case HttpURLConnection.HTTP_OK: return; case HttpURLConnection.HTTP_BAD_REQUEST: throw new IllegalArgumentException(readError(urlConn)); case HttpURLConnection.HTTP_UNAVAILABLE: throw new ServiceUnavailableException("runtime.monitor", readError(urlConn)); default: throw new IOException("Failed to talk to runtime monitor. Response code is " + responseCode + ". Error is " + readError(urlConn)); } }
/** * Requests the runtime monitor server to shutdown. * * @throws IOException if failed to issue the command to the server * @throws IllegalArgumentException if server responded with 400 Bad Request * @throws ServiceUnavailableException if the runtime monitor server is not available */ void requestShutdown() throws IOException { HttpURLConnection urlConn = connect("runtime/shutdown"); try { urlConn.setRequestMethod("POST"); throwIfNotOK(urlConn.getResponseCode(), urlConn); } catch (ConnectException e) { throw new ServiceUnavailableException("runtime.monitor", e); } finally { releaseConnection(urlConn); } }
/** * Requests the runtime monitor server to shutdown. * * @throws IOException if failed to issue the command to the server * @throws IllegalArgumentException if server responded with 400 Bad Request * @throws ServiceUnavailableException if the runtime monitor server is not available */ void requestShutdown() throws IOException { HttpURLConnection urlConn = connect("runtime/shutdown"); try { urlConn.setRequestMethod("POST"); throwIfNotOK(urlConn.getResponseCode(), urlConn); } catch (ConnectException e) { throw new ServiceUnavailableException("runtime.monitor", e); } finally { releaseConnection(urlConn); } }
private MessagingService getMessagingService() { DelegateService delegateService = delegate.getReference(); if (delegateService == null || !delegate.isMarked()) { throw new ServiceUnavailableException(Constants.Service.MESSAGING_SERVICE, "Messaging service is temporarily unavailable due to leader transition"); } return delegateService.getMessagingService(); }
private MessagingService getMessagingService() { DelegateService delegateService = delegate.getReference(); if (delegateService == null || !delegate.isMarked()) { throw new ServiceUnavailableException(Constants.Service.MESSAGING_SERVICE, "Messaging service is temporarily unavailable due to leader transition"); } return delegateService.getMessagingService(); }
private void checkWriteAllowed(MetadataScope scope, MetadataEntity metadataEntity) { if (isMigrationCompleted()) { return; } // we do not support writes to V1 tables during migration. So throw an error if we are trying to update // an existing entity if ((scope.equals(MetadataScope.SYSTEM) ? hasV1SystemDs : hasV1BusinessDs) && hasEntityInV1(scope, metadataEntity)) { throw new ServiceUnavailableException("metadata-service", "Metadata migration is in progress. Please retry the same operation " + "once metadata is migrated."); } }
public void ping() throws UnauthenticatedException, ServiceUnavailableException, ExploreException { HttpResponse response = doGet("explore/status"); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return; } if (response.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new UnauthenticatedException(response.getResponseBodyAsString()); } if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) { throw new ServiceUnavailableException(Constants.Service.EXPLORE_HTTP_USER_SERVICE); } throw new ExploreException(String.format("Unexpected response while checking explore status. " + "Received code '%s' and response message '%s'.", response.getResponseCode(), response.getResponseBodyAsString())); }
public void ping() throws UnauthenticatedException, ServiceUnavailableException, ExploreException { HttpResponse response = doGet("explore/status"); if (response.getResponseCode() == HttpURLConnection.HTTP_OK) { return; } if (response.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new UnauthenticatedException(response.getResponseBodyAsString()); } if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) { throw new ServiceUnavailableException(Constants.Service.EXPLORE_HTTP_USER_SERVICE); } throw new ExploreException(String.format("Unexpected response while checking explore status. " + "Received code '%s' and response message '%s'.", response.getResponseCode(), response.getResponseBodyAsString())); }
/** * Checks if a user service is available by hitting the availability endpoint. */ private void checkAvailability() throws IOException, UnauthenticatedException, NotFoundException { URL url = clientConfig.resolveNamespacedURLV3(programId.getNamespaceId(), String.format("apps/%s/versions/%s/%s/%s/available", programId.getApplication(), programId.getVersion(), programId.getType().getCategoryName(), programId.getProgram())); HttpResponse response = restClient.execute(HttpMethod.GET, url, clientConfig.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_UNAVAILABLE); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(programId); } if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) { throw new ServiceUnavailableException(programId.toString()); } } }