use of io.helidon.health.HealthSupport in project helidon by oracle.
the class ApplMain method startServer.
private static WebServer startServer(final String configFile) {
final Config config = Config.create(ConfigSources.classpath(configFile));
final Config dbConfig = config.get("db");
// Client services are added through a service loader - see mongoDB example for explicit services
final DbClient dbClient = DbClient.builder(dbConfig).addService(DbClientMetrics.counter().statementNames("select-pokemon-named-arg", "select-pokemon-order-arg", "insert-pokemon")).addService(DbClientMetrics.timer().statementTypes(DbStatementType.GET)).build();
final HealthSupport health = HealthSupport.builder().addLiveness(DbClientHealthCheck.builder(dbClient).statementName("ping").build()).build();
final Map<String, String> statements = dbConfig.get("statements").detach().asMap().get();
final ExitService exitResource = new ExitService();
final DbClientService interceptorTestService = new InterceptorService.TestClientService();
final Routing routing = Routing.builder().register(// Metrics at "/metrics"
MetricsSupport.create()).register(// Health at "/health"
health).register("/Init", new InitService(dbClient, dbConfig)).register("/Exit", exitResource).register("/Verify", new VerifyService(dbClient, config)).register("/SimpleGet", new SimpleGetService(dbClient, statements)).register("/SimpleQuery", new SimpleQueryService(dbClient, statements)).register("/SimpleUpdate", new SimpleUpdateService(dbClient, statements)).register("/SimpleInsert", new SimpleInsertService(dbClient, statements)).register("/SimpleDelete", new SimpleDeleteService(dbClient, statements)).register("/TransactionGet", new TransactionGetService(dbClient, statements)).register("/TransactionQueries", new TransactionQueriesService(dbClient, statements)).register("/TransactionUpdate", new TransactionUpdateService(dbClient, statements)).register("/TransactionInsert", new TransactionInsertService(dbClient, statements)).register("/TransactionDelete", new TransactionDeleteService(dbClient, statements)).register("/DmlStatement", new DmlStatementService(dbClient, statements)).register("/GetStatement", new GetStatementService(dbClient, statements)).register("/QueryStatement", new QueryStatementService(dbClient, statements)).register("/FlowControl", new FlowControlService(dbClient, statements)).register("/Mapper", new MapperService(dbClient, statements)).register("/Interceptor", new InterceptorService(DbClient.builder(dbConfig).addService(interceptorTestService).build(), statements, interceptorTestService)).register("/HealthCheck", new HealthCheckService(dbClient, dbConfig, statements)).build();
// Prepare routing for the server
final WebServer.Builder serverBuilder = WebServer.builder().routing(routing).config(config.get("server"));
final WebServer server = serverBuilder.addMediaSupport(JsonpSupport.create()).addMediaSupport(JsonbSupport.create()).build();
exitResource.setServer(server);
// Start the server and print some info.
server.start().thenAccept(ws -> {
System.out.println("WEB server is up! http://localhost:" + ws.port() + "/");
});
// Server threads are not daemon. NO need to block. Just react.
server.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
return server;
}
use of io.helidon.health.HealthSupport in project helidon by oracle.
the class ServerHealthCheckIT method createRouting.
private static Routing createRouting() {
HealthCheck check = DbClientHealthCheck.create(DB_CLIENT, CONFIG.get("db.health-check"));
final HealthSupport health = HealthSupport.builder().addLiveness(check).build();
return Routing.builder().register(// Health at "/health"
health).build();
}
use of io.helidon.health.HealthSupport in project helidon by oracle.
the class Main method createRouting.
/**
* Creates new {@link Routing}.
*
* @return routing configured with JSON support, a health check, and a service
* @param config configuration of this server
*/
private static Routing createRouting(Config config) {
MetricsSupport metrics = MetricsSupport.create();
GreetService greetService = new GreetService(config);
HealthSupport health = HealthSupport.builder().addLiveness(// Adds a convenient set of checks
HealthChecks.healthChecks()).build();
return Routing.builder().register(// Health at "/health"
health).register(// Metrics at "/metrics"
metrics).register("/greet", greetService).build();
}
use of io.helidon.health.HealthSupport in project helidon by oracle.
the class OciVaultMain 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 vaultConfig = config.get("oci.vault");
// the following three parameters are required
String vaultOcid = vaultConfig.get("vault-ocid").asString().get();
String compartmentOcid = vaultConfig.get("compartment-ocid").asString().get();
String encryptionKey = vaultConfig.get("encryption-key-ocid").asString().get();
String signatureKey = vaultConfig.get("signature-key-ocid").asString().get();
// this requires OCI configuration in the usual place
// ~/.oci/config
OciVaultRx ociVault = OciVaultRx.create(config.get("oci"));
// setup vault health check
HealthSupport health = HealthSupport.builder().addLiveness(OciVaultHealthCheck.builder().addVaultId(vaultOcid).ociVault(ociVault).build()).build();
WebServer.builder().config(config.get("server")).routing(Routing.builder().register(health).register("/vault", new VaultService(ociVault, vaultOcid, compartmentOcid, encryptionKey, signatureKey))).build().start().await();
}
use of io.helidon.health.HealthSupport in project helidon by oracle.
the class Se1Main method createRouting.
/**
* Creates new {@link io.helidon.webserver.Routing}.
*
* @return routing configured with JSON support, a health check, and a service
* @param config configuration of this server
*/
private static Routing createRouting(Config config) {
MetricsSupport metrics = MetricsSupport.create();
GreetService greetService = new GreetService(config);
MockZipkinService zipkinService = new MockZipkinService(Set.of("helidon-webclient"));
WebClientService webClientService = new WebClientService(config, zipkinService);
HealthSupport health = HealthSupport.builder().addLiveness(// Adds a convenient set of checks
HealthChecks.healthChecks()).addLiveness(() -> // a custom health check
HealthCheckResponse.named("custom").up().withData("timestamp", System.currentTimeMillis()).build()).build();
return Routing.builder().register("/static/path", StaticContentSupport.create(Paths.get("web"))).register("/static/classpath", StaticContentSupport.create("web")).register("/static/jar", StaticContentSupport.create("web-jar")).register(WebSecurity.create(config.get("security"))).register(// Health at "/health"
health).register(// Metrics at "/metrics"
metrics).register("/greet", greetService).register("/wc", webClientService).register("/zipkin", zipkinService).register("/ws", TyrusSupport.builder().register(ServerEndpointConfig.Builder.create(WebSocketEndpoint.class, "/messages").build()).build()).build();
}
Aggregations