Search in sources :

Example 11 with HealthSupport

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;
}
Also used : TransactionGetService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionGetService) LogConfig(io.helidon.common.LogConfig) Config(io.helidon.config.Config) HealthSupport(io.helidon.health.HealthSupport) TransactionQueriesService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionQueriesService) DmlStatementService(io.helidon.tests.integration.dbclient.appl.statement.DmlStatementService) TransactionUpdateService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionUpdateService) SimpleQueryService(io.helidon.tests.integration.dbclient.appl.simple.SimpleQueryService) TransactionInsertService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionInsertService) GetStatementService(io.helidon.tests.integration.dbclient.appl.statement.GetStatementService) QueryStatementService(io.helidon.tests.integration.dbclient.appl.statement.QueryStatementService) DbClient(io.helidon.dbclient.DbClient) HealthCheckService(io.helidon.tests.integration.dbclient.appl.health.HealthCheckService) SimpleInsertService(io.helidon.tests.integration.dbclient.appl.simple.SimpleInsertService) Routing(io.helidon.webserver.Routing) SimpleGetService(io.helidon.tests.integration.dbclient.appl.simple.SimpleGetService) SimpleDeleteService(io.helidon.tests.integration.dbclient.appl.simple.SimpleDeleteService) ExitService(io.helidon.tests.integration.dbclient.appl.tools.ExitService) DbClientService(io.helidon.dbclient.DbClientService) WebServer(io.helidon.webserver.WebServer) TransactionDeleteService(io.helidon.tests.integration.dbclient.appl.transaction.TransactionDeleteService) InterceptorService(io.helidon.tests.integration.dbclient.appl.interceptor.InterceptorService) SimpleUpdateService(io.helidon.tests.integration.dbclient.appl.simple.SimpleUpdateService) FlowControlService(io.helidon.tests.integration.dbclient.appl.result.FlowControlService) MapperService(io.helidon.tests.integration.dbclient.appl.mapping.MapperService)

Example 12 with HealthSupport

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();
}
Also used : DbClientHealthCheck(io.helidon.dbclient.health.DbClientHealthCheck) HealthCheck(org.eclipse.microprofile.health.HealthCheck) HealthSupport(io.helidon.health.HealthSupport)

Example 13 with HealthSupport

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();
}
Also used : HealthSupport(io.helidon.health.HealthSupport) MetricsSupport(io.helidon.metrics.MetricsSupport)

Example 14 with HealthSupport

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();
}
Also used : Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) HealthSupport(io.helidon.health.HealthSupport) OciVaultRx(io.helidon.integrations.oci.vault.OciVaultRx)

Example 15 with HealthSupport

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();
}
Also used : HealthSupport(io.helidon.health.HealthSupport) MetricsSupport(io.helidon.metrics.MetricsSupport)

Aggregations

HealthSupport (io.helidon.health.HealthSupport)20 MetricsSupport (io.helidon.metrics.MetricsSupport)10 LogConfig (io.helidon.common.LogConfig)7 Config (io.helidon.config.Config)7 DbClient (io.helidon.dbclient.DbClient)4 WebServer (io.helidon.webserver.WebServer)4 Routing (io.helidon.webserver.Routing)3 HealthChecks (io.helidon.health.checks.HealthChecks)2 DbClientService (io.helidon.dbclient.DbClientService)1 DbClientHealthCheck (io.helidon.dbclient.health.DbClientHealthCheck)1 MovieRepository (io.helidon.examples.integrations.neo4j.se.domain.MovieRepository)1 GreetService (io.helidon.grpc.examples.common.GreetService)1 GreetServiceJava (io.helidon.grpc.examples.common.GreetServiceJava)1 StringService (io.helidon.grpc.examples.common.StringService)1 GrpcRouting (io.helidon.grpc.server.GrpcRouting)1 GrpcServer (io.helidon.grpc.server.GrpcServer)1 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)1 Neo4j (io.helidon.integrations.neo4j.Neo4j)1 Neo4jHealthCheck (io.helidon.integrations.neo4j.health.Neo4jHealthCheck)1 Neo4jMetricsSupport (io.helidon.integrations.neo4j.metrics.Neo4jMetricsSupport)1