Java Code Examples for org.eclipse.microprofile.health.HealthCheckResponseBuilder#down()

The following examples show how to use org.eclipse.microprofile.health.HealthCheckResponseBuilder#down() . 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: SocketHealthCheck.java    From smallrye-health with Apache License 2.0 6 votes vote down vote up
@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder healthCheckResponseBuilder = HealthCheckResponse
            .named(name);
    healthCheckResponseBuilder.withData("host", String.format("%s:%d", this.host, this.port));
    try (Socket s = new Socket()) {
        final SocketAddress socketAddress = new InetSocketAddress(host, port);
        s.connect(socketAddress, timeout);
        healthCheckResponseBuilder.up();
    } catch (IOException ex) {
        HealthChecksLogging.log.socketHealthCheckError(ex);

        healthCheckResponseBuilder.withData("error", ex.getMessage());
        healthCheckResponseBuilder.down();
    }
    return healthCheckResponseBuilder.build();
}
 
Example 2
Source File: InetAddressHealthCheck.java    From smallrye-health with Apache License 2.0 6 votes vote down vote up
@Override
public HealthCheckResponse call() {
    final HealthCheckResponseBuilder healthCheckResponseBuilder = HealthCheckResponse.named(this.name);
    healthCheckResponseBuilder.withData("host", this.host);
    try {
        InetAddress addr = InetAddress.getByName(this.host);
        final boolean reachable = addr.isReachable(this.timeout);
        if (!reachable) {
            healthCheckResponseBuilder.withData("error", String.format("Host %s not reachable.", this.host));
        }

        healthCheckResponseBuilder.state(reachable);
    } catch (IOException e) {
        HealthChecksLogging.log.inetAddressHealthCheckError(e);

        healthCheckResponseBuilder.withData("error", e.getMessage());
        healthCheckResponseBuilder.down();
    }

    return healthCheckResponseBuilder.build();
}
 
Example 3
Source File: GrpcHealthCheck.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public HealthCheckResponse call() {
    ServingStatus servingStatus = healthService.getStatuses().get(GrpcHealthStorage.DEFAULT_SERVICE_NAME);

    HealthCheckResponseBuilder builder = HealthCheckResponse.named("gRPC Server health check").up();
    builder.name("gRPC Server");

    if (isUp(servingStatus)) {
        builder.up();
    } else {
        builder.down();
    }

    for (Map.Entry<String, ServingStatus> statusEntry : healthService.getStatuses().entrySet()) {
        String serviceName = statusEntry.getKey();
        if (!serviceName.equals(GrpcHealthStorage.DEFAULT_SERVICE_NAME)) {
            builder.withData(serviceName, isUp(statusEntry.getValue()));
        }
    }

    return builder.build();
}
 
Example 4
Source File: ReactiveMySQLDataSourceHealthCheck.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder builder = HealthCheckResponse.named("Reactive MySQL connection health check").up();

    try {
        CompletableFuture<Void> databaseConnectionAttempt = new CompletableFuture<>();
        mySQLPool.query("SELECT 1")
                .execute(ar -> {
                    if (ar.failed()) {
                        builder.down();
                    }
                    databaseConnectionAttempt.complete(null);
                });
        databaseConnectionAttempt.get(10, TimeUnit.SECONDS);
    } catch (Exception exception) {
        builder.down();
    }

    return builder.build();
}
 
Example 5
Source File: ReactivePgDataSourceHealthCheck.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder builder = HealthCheckResponse.named("Reactive PostgreSQL connection health check").up();

    try {
        CompletableFuture<Void> databaseConnectionAttempt = new CompletableFuture<>();
        pgPool.query("SELECT 1")
                .execute(ar -> {
                    if (ar.failed()) {
                        builder.down();
                    }
                    databaseConnectionAttempt.complete(null);
                });
        databaseConnectionAttempt.get(10, TimeUnit.SECONDS);
    } catch (Exception exception) {
        builder.down();
    }

    return builder.build();
}
 
Example 6
Source File: LivenessProbe.java    From trader with Apache License 2.0 6 votes vote down vote up
public HealthCheckResponse call() {
	HealthCheckResponse response = null;
	String message = "Live";
	try {
		HealthCheckResponseBuilder builder = HealthCheckResponse.named("Trader");

		if (Summary.error) { //can't run without these env vars
			builder = builder.down();
			message = Summary.message;
			logger.warning("Returning NOT live!");
		} else {
			builder = builder.up();
			logger.fine("Returning live!");
		}

		builder = builder.withData("message", message);

		response = builder.build(); 
	} catch (Throwable t) {
		logger.warning("Exception occurred during health check: "+t.getMessage());
		logException(t);
		throw t;
	}

	return response;
}
 
Example 7
Source File: ReadinessProbe.java    From trader with Apache License 2.0 6 votes vote down vote up
public HealthCheckResponse call() {
	HealthCheckResponse response = null;
	String message = "Ready";
	try {
		HealthCheckResponseBuilder builder = HealthCheckResponse.named("Trader");

		if ((jwtAudience==null) || (jwtIssuer==null)) { //can't run without these env vars
			builder = builder.down();
			message = "JWT environment variables not set!";
			logger.warning("Returning NOT ready!");
		} else {
			builder = builder.up();
			logger.fine("Returning ready!");
		}

		builder = builder.withData("message", message);

		response = builder.build(); 
	} catch (Throwable t) {
		logger.warning("Exception occurred during health check: "+t.getMessage());
		logException(t);
		throw t;
	}

	return response;
}
 
Example 8
Source File: CamelUptimeHealthCheck.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder builder = HealthCheckResponse.named("Uptime readiness check");

    if (camelContext.getUptimeMillis() > 0) {
        builder.up();
    } else {
        builder.down();
    }

    return builder.build();
}
 
Example 9
Source File: UrlHealthCheck.java    From smallrye-health with Apache License 2.0 5 votes vote down vote up
@Override
public HealthCheckResponse call() {
    final HealthCheckResponseBuilder healthCheckResponseBuilder = HealthCheckResponse
            .named(name);
    healthCheckResponseBuilder.withData("host", String.format("%s %s", this.requestMethod, this.url));
    try {
        final HttpURLConnection httpUrlConn = (HttpURLConnection) new URL(this.url)
                .openConnection();

        httpUrlConn.setRequestMethod(requestMethod);

        httpUrlConn.setConnectTimeout(timeout);
        httpUrlConn.setReadTimeout(timeout);

        final boolean isUp = httpUrlConn.getResponseCode() == statusCode;

        if (!isUp) {
            healthCheckResponseBuilder.withData("error", String.format("Expected response code %d but actual is %d",
                    statusCode, httpUrlConn.getResponseCode()));
        }

        healthCheckResponseBuilder.state(isUp);

    } catch (Exception e) {
        HealthChecksLogging.log.urlHealthCheckError(e);

        healthCheckResponseBuilder.withData("error",
                String.format("%s: %s", e.getClass().getCanonicalName(), e.getMessage()));
        healthCheckResponseBuilder.down();
    }

    return healthCheckResponseBuilder.build();
}
 
Example 10
Source File: ReactiveDB2DataSourceHealthCheck.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder builder = HealthCheckResponse.named("Reactive DB2 connection health check").up();

    try {
        db2Pool.query("SELECT 1 FROM SYSIBM.SYSDUMMY1")
                .execute()
                .await().atMost(Duration.ofSeconds(10));
    } catch (Exception exception) {
        builder.down();
    }

    return builder.build();
}
 
Example 11
Source File: ConnectionFactoryHealthCheck.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder builder = HealthCheckResponse.named("Artemis JMS health check");
    try (Connection connection = connectionFactory.createConnection()) {
        builder.up();
    } catch (Exception e) {
        builder.down();
    }
    return builder.build();
}
 
Example 12
Source File: ServerLocatorHealthCheck.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder builder = HealthCheckResponse.named("Artemis Core health check");
    try (ClientSessionFactory factory = serverLocator.createSessionFactory()) {
        builder.up();
    } catch (Exception e) {
        builder.down();
    }
    return builder.build();
}