All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.grpc.runtime.health.GrpcHealthCheck Maven / Gradle / Ivy

There is a newer version: 3.15.1
Show newest version
package io.quarkus.grpc.runtime.health;

import java.util.Map;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.HealthCheckResponseBuilder;
import org.eclipse.microprofile.health.Readiness;

import grpc.health.v1.HealthOuterClass.HealthCheckResponse.ServingStatus;

/**
 * Eclipse MicroProfile Health Check
 */
@Readiness
@ApplicationScoped
public class GrpcHealthCheck implements HealthCheck {

    @Inject
    GrpcHealthStorage healthService;

    @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 statusEntry : healthService.getStatuses().entrySet()) {
            String serviceName = statusEntry.getKey();
            if (!serviceName.equals(GrpcHealthStorage.DEFAULT_SERVICE_NAME)) {
                builder.withData(serviceName, isUp(statusEntry.getValue()));
            }
        }

        return builder.build();
    }

    private boolean isUp(ServingStatus value) {
        return value == ServingStatus.SERVING;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy