@Override public void reportUnhealthy(final String message) { // If there has already been an unhealthy report then discard this new one (i.e. we assume it is better to return the original) if (healthResult != null) { return; } // Construct the new health result healthResult = new HealthResult(HealthStatus.UNHEALTHY, message); }
/** * Try a trivial connection to the HTTP endpoint. * @return whether a connection to the Marathon host works or not */ @Override public HealthResult healthCheck() { try ( Socket socket = new Socket()) { socket.connect(new InetSocketAddress(url.getHost(), url.getPort()), 5000); return HealthResult.RESULT_HEALTHY; } catch (IOException e) { LOG.warn("Connection failure to HTTP endpoint", e); return new HealthResult(HealthStatus.UNHEALTHY, "Cannot connect to REST endpoint: " + url); } } }
/** * Try a trivial connection to the HTTP endpoint. * @return whether a connection to the Marathon host works or not */ @Override public HealthResult healthCheck() { try ( Socket socket = new Socket()) { socket.connect(new InetSocketAddress(url.getHost(), url.getPort()), 5000); return HealthResult.RESULT_HEALTHY; } catch (IOException e) { LOG.warn("Connection failure to HTTP endpoint", e); return new HealthResult(HealthStatus.UNHEALTHY, "Cannot connect to REST endpoint: " + url); } } }
@Override public HealthResult healthCheck() { try { LOG.debug("Received healthcheck request for storage service."); StorageServiceInfo status = callStorageService(c -> c.getStorageServiceStatus()); LOG.debug("Storage service healthcheck status received. Storage service version: " + status.getVersion() + ", status: " + status.getStatus()); if (status.getStatus() != StorageServiceStatus.HEALTHY) { return new HealthResult(HealthStatus.UNHEALTHY, "Storage service returned " + status.getStatus() + " status."); } } catch (StorageServiceException e) { LOG.warn("Health check failed", e); return new HealthResult(HealthStatus.UNHEALTHY, "Error from Storage service: " + e.getResponseErrorMessage()); } catch (StorageServiceConnectException | StorageClientException e) { LOG.warn("Health check failed", e); return new HealthResult(HealthStatus.UNHEALTHY, "Failed to connect to Storage service"); } catch (IOException e) { LOG.warn("Health check failed", e); return new HealthResult(HealthStatus.UNHEALTHY, "Failed to request access token: " + e.getMessage()); } return HealthResult.RESULT_HEALTHY; }
/** * This method checks if any entry in the Transient Exception Registry is newer than the time now, minus the elapsed time interval. If * an entry is found within the range the health check returns Unhealthy. If the Transient Exception Registry is empty or no entries * are found within the range the health check returns Healthy. * * @return HealthResult the result of the Transient Health Check, Healthy or Unhealthy */ @Override public HealthResult healthCheck() { LOG.debug("Transient Health Check executing"); HealthResult healthResult = HealthResult.RESULT_HEALTHY; synchronized (transientExceptionRegistryLock) { for (Map.Entry<String, LocalDateTime> entry : transientExceptionRegistry.entrySet()) { if (entry.getValue().toEpochSecond(ZoneOffset.UTC) < LocalDateTime.now().minusSeconds(elapsedTime).toEpochSecond(ZoneOffset.UTC)) { healthResult = HealthResult.RESULT_HEALTHY; } else { healthResult = new HealthResult(HealthStatus.UNHEALTHY); break; } } if (healthResult.equals(HealthResult.RESULT_HEALTHY)) { LOG.debug("Transient Health Check is currently Healthy, therefore clearing the Transient Exception Registry"); transientExceptionRegistry.clear(); } LOG.debug("Transient Health Check is currently [{}]", healthResult.getStatus().toString()); return healthResult; } }
@Override public HealthResult healthCheck() { HealthStatus status; if (applicationContext.getBean(ElasticsearchProperties.class).isElasticsearchDisabled()) { status = HealthStatus.HEALTHY; } else { BooleanAgentServices booleanAgentServices = applicationContext.getBean(BooleanAgentServices.class); if (booleanAgentServices.canConnect()) { status = HealthStatus.HEALTHY; } else { status = HealthStatus.UNHEALTHY; } } return new HealthResult(status); }