Java Code Examples for org.springframework.boot.actuate.health.Status#UP

The following examples show how to use org.springframework.boot.actuate.health.Status#UP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSolrHealthIndicator.java    From ambari-logsearch with Apache License 2.0 9 votes vote down vote up
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
  Status status = Status.DOWN;
  String errorDetails = null;
  if (getSolrTemplate() != null && getSolrTemplate().getSolrClient() != null) {
    try {
      SolrClient solrClient = getSolrTemplate().getSolrClient();
      SolrQuery q = new SolrQuery("*:*");
      q.setRows(0);
      QueryResponse response = solrClient.query(q);
      if (response.getStatus() == 0) {
        status = Status.UP;
        if (response.getResults() != null) {
          builder.withDetail("numDocs", response.getResults().getNumFound());
        }
      }
    } catch (Exception e) {
      errorDetails = e.getMessage();
    }
  }
  builder.status(status);
  if (errorDetails != null) {
    builder.withDetail("error", errorDetails);
  }
}
 
Example 2
Source File: PipelineController.java    From kayenta with Apache License 2.0 6 votes vote down vote up
@Scheduled(initialDelay = 10000, fixedDelay = 5000)
void startOrcaQueueProcessing() {
  if (!upAtLeastOnce) {
    Health health = healthIndicator.health();
    if (health.getStatus() == Status.UP) {
      upAtLeastOnce = true;
      context.publishEvent(new RemoteStatusChangedEvent(new StatusChangeEvent(STARTING, UP)));
      // Cancel the scheduled task.
      postProcessor.postProcessBeforeDestruction(this, null);
      log.info("Health indicators are all reporting UP; starting orca queue processing");
    } else {
      log.warn(
          "Health indicators are still reporting DOWN; not starting orca queue processing yet: {}",
          health);
    }
  }
}
 
Example 3
Source File: RabbitMQCheck.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
@Override
protected void doHealthCheck(Health.Builder builder) {
    Map<String, Object> properties = connection.getServerProperties();
    Status status = connection.isOpen() ? Status.UP : Status.DOWN;
    builder.status(status)
            .withDetail("address", connection.getAddress())
            .withDetail("version", properties.get("version").toString());
}
 
Example 4
Source File: ApiCatalogHealthIndicator.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doHealthCheck(Health.Builder builder) {
    String gatewayServiceId = CoreService.GATEWAY.getServiceId();

    boolean gatewayUp = !this.discoveryClient.getInstances(gatewayServiceId).isEmpty();
    Status healthStatus = gatewayUp ? Status.UP : Status.DOWN;

    builder
        .status(healthStatus)
        .withDetail(gatewayServiceId, healthStatus.getCode());
}
 
Example 5
Source File: RabbitMQCheck.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
@Override
protected void doHealthCheck(Health.Builder builder) {
    Map<String, Object> properties = connection.getServerProperties();
    Status status = connection.isOpen() ? Status.UP : Status.DOWN;
    builder.status(status)
            .withDetail("address", connection.getAddress())
            .withDetail("version", properties.get("version").toString());
}
 
Example 6
Source File: KafkaStreamsBinderHealthIndicatorTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
private static boolean waitFor(Status status, Map<String, Object> details) {
	if (status == Status.UP) {
		String threadState = (String) details.get("threadState");
		return threadState != null
				&& (threadState.equalsIgnoreCase(KafkaStreams.State.REBALANCING.name())
						|| threadState.equalsIgnoreCase("PARTITIONS_REVOKED")
						|| threadState.equalsIgnoreCase("PARTITIONS_ASSIGNED")
						|| threadState.equalsIgnoreCase(
								KafkaStreams.State.PENDING_SHUTDOWN.name()));
	}
	return false;
}
 
Example 7
Source File: ApplicationInstanceServiceTests.java    From microservices-dashboard with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUpdateTheHealthOfAnApplicationInstance() {
	when(this.repository.getById("a-1")).thenReturn(ApplicationInstanceMother.instance("a-1", "a"));
	when(this.repository.save(any(ApplicationInstance.class)))
			.thenAnswer((Answer<ApplicationInstance>) invocation -> invocation.getArgument(0));

	UpdateApplicationInstanceHealth command = new UpdateApplicationInstanceHealth("a-1", Status.UP);
	this.service.updateApplicationInstanceHealth(command);

	verify(this.repository).save(this.applicationInstanceArgumentCaptor.capture());
	ApplicationInstance applicationInstance = this.applicationInstanceArgumentCaptor.getValue();
	assertThat(applicationInstance.getId()).isEqualTo("a-1");
}
 
Example 8
Source File: MonitoredPollerHealth.java    From echo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doHealthCheck(Health.Builder builder) {
  if (!poller.isRunning()) {
    log.warn("Poller {} is not currently running", poller);
  }

  // status is initially DOWN and can only flicked to UP (when the poller
  // has completed one cycle successfully), never back to DOWN
  // if poller staleness is a concern (i.e. poller.getLastPollTimestamp() is
  // significantly old), rely on monitoring and alerting instead
  if (status != Status.UP && poller.isInitialized()) {
    status = Status.UP;
  }

  Instant lastPollTimestamp = poller.getLastPollTimestamp();
  if (lastPollTimestamp != null) {
    val timeSinceLastPoll = Duration.between(lastPollTimestamp, now());
    builder
        .withDetail(
            "last.polled", formatDurationWords(timeSinceLastPoll.toMillis(), true, true) + " ago")
        .withDetail(
            "last.polled.at",
            ISO_LOCAL_DATE_TIME.format(lastPollTimestamp.atZone(ZoneId.systemDefault())));
  }

  builder.status(status);
}
 
Example 9
Source File: VirtualService.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
public Status getStatus() {
    return up ? Status.UP : Status.DOWN;
}
 
Example 10
Source File: UserRolesSyncer.java    From fiat with Apache License 2.0 4 votes vote down vote up
private boolean isServerHealthy() {
  return healthIndicator.health().getStatus() == Status.UP;
}