use of io.helidon.health.HealthSupport in project helidon by oracle.
the class Main method main.
/**
* Start the example. Prints endpoints to standard output.
*
* @param args not used
*/
public static void main(String[] args) {
serverStartTime = System.currentTimeMillis();
HealthSupport health = HealthSupport.builder().addLiveness(HealthChecks.healthChecks()).addReadiness(() -> HealthCheckResponse.named("exampleHealthCheck").up().withData("time", System.currentTimeMillis()).build()).addStartup(() -> HealthCheckResponse.named("exampleStartCheck").status(isStarted()).withData("time", System.currentTimeMillis()).build()).build();
Routing routing = Routing.builder().register(health).get("/hello", (req, res) -> res.send("Hello World!")).build();
WebServer ws = WebServer.create(routing);
ws.start().thenApply(webServer -> {
String endpoint = "http://localhost:" + webServer.port();
System.out.println("Hello World started on " + endpoint + "/hello");
System.out.println("Health checks available on " + endpoint + "/health");
return null;
});
}
use of io.helidon.health.HealthSupport in project helidon by oracle.
the class ConfigTest method runWithConfig.
private JsonObject runWithConfig(String configKey, int expectedStatus) throws InterruptedException, ExecutionException, TimeoutException {
HealthSupport healthSupport = HealthSupport.builder().addLiveness(HealthChecks.healthChecks(testConfig.get(configKey + ".helidon.health"))).build();
WebServer webServer = null;
try {
webServer = startServer(healthSupport);
WebClientResponse response = webClientBuilder(webServer).build().get().accept(MediaType.APPLICATION_JSON).path("health/live").submit().await();
assertThat("Normal health URL HTTP response", response.status().code(), is(expectedStatus));
return response.content().as(JsonObject.class).await();
} finally {
if (webServer != null) {
shutdownServer(webServer);
}
}
}
use of io.helidon.health.HealthSupport in project helidon by oracle.
the class Server method main.
/**
* The main program entry point.
*
* @param args the program arguments
*/
public static void main(String[] args) {
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
// load logging configuration
LogConfig.configureRuntime();
// Get gRPC server config from the "grpc" section of application.yaml
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder(config.get("grpc")).build();
GrpcServer grpcServer = GrpcServer.create(serverConfig, createRouting(config));
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
grpcServer.start().thenAccept(s -> {
System.out.println("gRPC server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
// add support for standard and gRPC health checks
HealthSupport health = HealthSupport.builder().addLiveness(HealthChecks.healthChecks()).addLiveness(grpcServer.healthChecks()).build();
// start web server with health endpoint
Routing routing = Routing.builder().register(health).build();
WebServer.create(routing, config.get("webserver")).start().thenAccept(s -> {
System.out.println("HTTP server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("HTTP server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
}
use of io.helidon.health.HealthSupport in project helidon by oracle.
the class PokemonMain method createRouting.
/**
* Creates new {@link io.helidon.webserver.Routing}.
*
* @param config configuration of this server
* @return routing configured with JSON support, a health check, and a service
*/
private static Routing createRouting(Config config) {
Config dbConfig = config.get("db");
// Client services are added through a service loader - see mongoDB example for explicit services
DbClient dbClient = DbClient.builder(dbConfig).build();
// Some relational databases do not support DML statement as ping so using query which works for all of them
HealthSupport health = HealthSupport.builder().addLiveness(DbClientHealthCheck.create(dbClient, dbConfig.get("health-check"))).build();
// Initialize database schema
InitializeDb.init(dbClient);
return Routing.builder().register(// Health at "/health"
health).register(// Metrics at "/metrics"
MetricsSupport.create()).register("/db", new PokemonService(dbClient)).build();
}
use of io.helidon.health.HealthSupport in project helidon by oracle.
the class OciObjectStorageMain method main.
/**
* Main method.
*
* @param args ignored
*/
public static void main(String[] args) {
LogConfig.configureRuntime();
// as I cannot share my configuration of OCI, let's combine the configuration
// from my home directory with the one compiled into the jar
// when running this example, you can either update the application.yaml in resources directory
// or use the same approach
Config config = buildConfig();
Config ociConfig = config.get("oci");
// this requires OCI configuration in the usual place
// ~/.oci/config
OciObjectStorageRx ociObjectStorage = OciObjectStorageRx.create(ociConfig);
// the following parameters are required
String bucketName = ociConfig.get("objectstorage").get("bucket").asString().get();
String namespace = ociConfig.get("objectstorage").get("namespace").asString().get();
// setup ObjectStorage health check
HealthSupport health = HealthSupport.builder().addLiveness(OciObjectStorageHealthCheck.builder().ociObjectStorage(ociObjectStorage).addBucket(bucketName).namespace(namespace).build()).build();
WebServer.builder().config(config.get("server")).routing(Routing.builder().register(health).register("/files", new ObjectStorageService(ociObjectStorage, bucketName))).build().start().await();
}
Aggregations