io.grpc.services.HealthStatusManager Java Examples

The following examples show how to use io.grpc.services.HealthStatusManager. 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: PubsubEmulatorServer.java    From kafka-pubsub-emulator with Apache License 2.0 6 votes vote down vote up
@Inject
public PubsubEmulatorServer(
    ConfigurationManager configurationManager,
    PublisherService publisher,
    SubscriberService subscriber,
    AdminService admin,
    HealthStatusManager healthStatusManager) {
  this.publisher = publisher;
  this.subscriber = subscriber;
  this.healthStatusManager = healthStatusManager;

  ServerBuilder builder =
      ServerBuilder.forPort(configurationManager.getServer().getPort())
          .addService(publisher)
          .addService(subscriber)
          .addService(admin)
          .addService(healthStatusManager.getHealthService())
          .maxInboundMessageSize(MAX_MESSAGE_SIZE);
  if (configurationManager.getServer().hasSecurity()) {
    builder.useTransportSecurity(
        new File(configurationManager.getServer().getSecurity().getCertificateChainFile()),
        new File(configurationManager.getServer().getSecurity().getPrivateKeyFile()));
  }
  server = builder.build();
}
 
Example #2
Source File: GrpcServerMetricAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 6 votes vote down vote up
@Bean
@Lazy
InfoContributor grpcInfoContributor(final GrpcServerProperties properties,
        final Collection<BindableService> grpcServices, final HealthStatusManager healthStatusManager) {
    final Map<String, Object> details = new LinkedHashMap<>();
    details.put("port", properties.getPort());

    if (properties.isReflectionServiceEnabled()) {
        // Only expose services via web-info if we do the same via grpc.
        final Map<String, List<String>> services = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        details.put("services", services);
        final List<BindableService> mutableGrpcServiceList = new ArrayList<>(grpcServices);
        mutableGrpcServiceList.add(ProtoReflectionService.newInstance());
        if (properties.isHealthServiceEnabled()) {
            mutableGrpcServiceList.add(healthStatusManager.getHealthService());
        }
        for (final BindableService grpcService : mutableGrpcServiceList) {
            final ServiceDescriptor serviceDescriptor = grpcService.bindService().getServiceDescriptor();

            final List<String> methods = collectMethodNamesForService(serviceDescriptor);
            services.put(serviceDescriptor.getName(), methods);
        }
    }

    return new SimpleInfoContributor("grpc.server", details);
}
 
Example #3
Source File: GrpcServerMetricAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 6 votes vote down vote up
@Bean
@Lazy
InfoContributor grpcInfoContributor(final GrpcServerProperties properties,
        final Collection<BindableService> grpcServices, final HealthStatusManager healthStatusManager) {
    final Map<String, Object> details = new LinkedHashMap<>();
    details.put("port", properties.getPort());

    if (properties.isReflectionServiceEnabled()) {
        // Only expose services via web-info if we do the same via grpc.
        final Map<String, List<String>> services = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        details.put("services", services);
        final List<BindableService> mutableGrpcServiceList = new ArrayList<>(grpcServices);
        mutableGrpcServiceList.add(ProtoReflectionService.newInstance());
        if (properties.isHealthServiceEnabled()) {
            mutableGrpcServiceList.add(healthStatusManager.getHealthService());
        }
        for (final BindableService grpcService : mutableGrpcServiceList) {
            final ServiceDescriptor serviceDescriptor = grpcService.bindService().getServiceDescriptor();

            final List<String> methods = collectMethodNamesForService(serviceDescriptor);
            services.put(serviceDescriptor.getName(), methods);
        }
    }

    return new SimpleInfoContributor("grpc.server", details);
}
 
Example #4
Source File: GrpcConfiguration.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
@Bean
CompositeHealthContributor grpcServices(GrpcServiceDiscoverer grpcServiceDiscoverer,
                                        HealthStatusManager healthStatusManager) {

    Map<String, HealthIndicator> healthIndicators = new LinkedHashMap<>();

    for (GrpcServiceDefinition grpcService : grpcServiceDiscoverer.findGrpcServices()) {
        String serviceName = grpcService.getDefinition().getServiceDescriptor().getName();
        healthIndicators.put(serviceName, new GrpcHealthIndicator(healthStatusManager, serviceName));
    }

    return CompositeHealthContributor.fromMap(healthIndicators);
}
 
Example #5
Source File: DefaultModule.java    From kafka-pubsub-emulator with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  bind(KafkaClientFactory.class).to(DefaultKafkaClientFactory.class);
  bind(Clock.class).toInstance(Clock.systemUTC());

  bind(ConfigurationManager.class);
  bind(SubscriptionManagerFactory.class);
  bind(PublisherService.class);
  bind(SubscriberService.class);
  bind(AdminService.class);
  bind(StatisticsManager.class);
  bind(HealthStatusManager.class);
  bind(PubsubEmulatorServer.class);
}
 
Example #6
Source File: BuildFarmServer.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
public void start() throws IOException {
  actionCacheRequestCounter.start();
  instances.start();
  server.start();
  healthStatusManager.setStatus(
      HealthStatusManager.SERVICE_NAME_ALL_SERVICES, ServingStatus.SERVING);
}
 
Example #7
Source File: BuildFarmServer.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
public void stop() {
  synchronized (this) {
    if (stopping) {
      return;
    }
    stopping = true;
  }
  healthStatusManager.setStatus(
      HealthStatusManager.SERVICE_NAME_ALL_SERVICES, ServingStatus.NOT_SERVING);
  try {
    if (server != null) {
      server.shutdown();
    }
    instances.stop();
    server.awaitTermination(10, TimeUnit.SECONDS);
  } catch (InterruptedException e) {
    if (server != null) {
      server.shutdownNow();
    }
  }
  if (!shutdownAndAwaitTermination(keepaliveScheduler, 10, TimeUnit.SECONDS)) {
    logger.log(Level.WARNING, "could not shut down keepalive scheduler");
  }
  if (!actionCacheRequestCounter.stop()) {
    logger.log(Level.WARNING, "count not shut down action cache request counter");
  }
}
 
Example #8
Source File: XdsTestServer.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private void start() throws Exception {
  health = new HealthStatusManager();
  server =
      NettyServerBuilder.forPort(port)
          .addService(new TestServiceImpl(serverId))
          .addService(new XdsUpdateHealthServiceImpl(health))
          .addService(health.getHealthService())
          .addService(ProtoReflectionService.newInstance())
          .build()
          .start();
  health.setStatus("", ServingStatus.SERVING);
}
 
Example #9
Source File: GrpcServerAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 4 votes vote down vote up
@ConditionalOnMissingBean
@Bean
public HealthStatusManager healthStatusManager() {
    return new HealthStatusManager();
}
 
Example #10
Source File: BuildFarmServer.java    From bazel-buildfarm with Apache License 2.0 4 votes vote down vote up
public BuildFarmServer(
    String session, ServerBuilder<?> serverBuilder, BuildFarmServerConfig config)
    throws InterruptedException, ConfigurationException {
  super("BuildFarmServer");
  String defaultInstanceName = config.getDefaultInstanceName();
  instances =
      new BuildFarmInstances(session, config.getInstancesList(), defaultInstanceName, this::stop);

  healthStatusManager = new HealthStatusManager();
  actionCacheRequestCounter =
      new ActionCacheRequestCounter(ActionCacheService.logger, Duration.ofSeconds(10));

  ServerInterceptor headersInterceptor = new ServerHeadersInterceptor();

  server =
      serverBuilder
          .addService(healthStatusManager.getHealthService())
          .addService(new ActionCacheService(instances, actionCacheRequestCounter::increment))
          .addService(new CapabilitiesService(instances))
          .addService(
              new ContentAddressableStorageService(
                  instances,
                  /* deadlineAfter=*/ 1,
                  TimeUnit.DAYS,
                  /* requestLogLevel=*/ Level.INFO))
          .addService(new ByteStreamService(instances, /* writeDeadlineAfter=*/ 1, TimeUnit.DAYS))
          .addService(
              new ExecutionService(
                  instances,
                  config.getExecuteKeepaliveAfterSeconds(),
                  TimeUnit.SECONDS,
                  keepaliveScheduler,
                  getMetricsPublisher(config.getMetricsConfig())))
          .addService(new OperationQueueService(instances))
          .addService(new OperationsService(instances))
          .intercept(TransmitStatusRuntimeExceptionInterceptor.instance())
          .intercept(headersInterceptor)
          .build();

  logger.log(Level.INFO, String.format("%s initialized", session));
}
 
Example #11
Source File: GRpcAutoConfiguration.java    From grpc-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@Bean
public HealthStatusManager healthStatusManager() {
    return new HealthStatusManager();
}
 
Example #12
Source File: GrpcServerAutoConfiguration.java    From grpc-spring-boot-starter with MIT License 4 votes vote down vote up
@ConditionalOnMissingBean
@Bean
public HealthStatusManager healthStatusManager() {
    return new HealthStatusManager();
}
 
Example #13
Source File: XdsTestServer.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
private XdsUpdateHealthServiceImpl(HealthStatusManager health) {
  this.health = health;
}