Search in sources :

Example 1 with Details

use of com.netflix.titus.grpc.protogen.HealthCheckResponse.Details in project titus-control-plane by Netflix.

the class DefaultHealthServiceGrpc method check.

@Override
public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) {
    Details details = healthService.getServerStatus();
    responseObserver.onNext(HealthCheckResponse.newBuilder().setStatus(details.getStatus()).addDetails(HealthCheckResponse.ServerStatus.newBuilder().setDetails(details).build()).build());
    responseObserver.onCompleted();
}
Also used : Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details)

Example 2 with Details

use of com.netflix.titus.grpc.protogen.HealthCheckResponse.Details in project titus-control-plane by Netflix.

the class DefaultHealthService method getServerStatus.

public Details getServerStatus() {
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
    Duration uptime = Durations.fromMillis(rb.getUptime());
    if (!leaderActivator.isLeader()) {
        return Details.newBuilder().setStatus(NOT_SERVING).setLeader(false).setActive(false).setUptime(uptime).build();
    }
    boolean active = leaderActivator.isActivated();
    List<ServiceActivation> serviceActivations = activationLifecycle.getServiceActionTimesMs().stream().sorted(Comparator.comparing(Pair::getRight)).map(pair -> ServiceActivation.newBuilder().setName(pair.getLeft()).setActivationTime(Durations.fromMillis(pair.getRight())).build()).collect(Collectors.toList());
    Details.Builder details = Details.newBuilder().setStatus(SERVING).setCell(cellInfoResolver.getCellName()).setLeader(true).setActive(active).setUptime(uptime).setElectionTimestamp(Timestamps.fromMillis(leaderActivator.getElectionTimestamp())).setActivationTimestamp(Timestamps.fromMillis(leaderActivator.getActivationEndTimestamp())).addAllServiceActivationTimes(serviceActivations);
    if (active) {
        details.setActivationTime(Durations.fromMillis(leaderActivator.getActivationTime()));
    }
    return details.build();
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean) LeaderActivator(com.netflix.titus.api.supervisor.service.LeaderActivator) NOT_SERVING(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.NOT_SERVING) ServiceActivation(com.netflix.titus.grpc.protogen.ServiceActivation) SERVING(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING) Timestamps(com.google.protobuf.util.Timestamps) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Durations(com.google.protobuf.util.Durations) Inject(javax.inject.Inject) List(java.util.List) Duration(com.google.protobuf.Duration) Pair(com.netflix.titus.common.util.tuple.Pair) ActivationLifecycle(com.netflix.titus.common.util.guice.ActivationLifecycle) CellInfoResolver(com.netflix.titus.master.config.CellInfoResolver) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) ManagementFactory(java.lang.management.ManagementFactory) Comparator(java.util.Comparator) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) Duration(com.google.protobuf.Duration) RuntimeMXBean(java.lang.management.RuntimeMXBean) ServiceActivation(com.netflix.titus.grpc.protogen.ServiceActivation)

Example 3 with Details

use of com.netflix.titus.grpc.protogen.HealthCheckResponse.Details in project titus-control-plane by Netflix.

the class ServerStatusResource method getServerStatus.

@GET
public ServerStatusRepresentation getServerStatus() {
    Details details = healthService.getServerStatus();
    if (details.getStatus() != ServingStatus.SERVING) {
        return new ServerStatusRepresentation(false, false, DateTimeExt.toTimeUnitString(details.getUptime()), NOT_APPLICABLE, NOT_APPLICABLE, NOT_APPLICABLE, Collections.emptyList(), Collections.emptyList());
    }
    List<ServerStatusRepresentation.ServiceActivation> sortedByActivationTime = details.getServiceActivationTimesList().stream().sorted(Comparator.comparing(ServiceActivation::getActivationTime, Durations.comparator())).map(s -> new ServerStatusRepresentation.ServiceActivation(s.getName(), DateTimeExt.toTimeUnitString(s.getActivationTime()))).collect(Collectors.toList());
    List<String> namesSortedByActivationTimestamp = details.getServiceActivationTimesList().stream().map(ServiceActivation::getName).collect(Collectors.toList());
    return new ServerStatusRepresentation(details.getLeader(), details.getActive(), DateTimeExt.toTimeUnitString(details.getUptime()), Timestamps.toString(details.getElectionTimestamp()), Timestamps.toString(details.getActivationTimestamp()), details.getActive() ? DateTimeExt.toTimeUnitString(details.getActivationTime()) : NOT_APPLICABLE, sortedByActivationTime, namesSortedByActivationTimestamp);
}
Also used : HealthService(com.netflix.titus.master.health.service.HealthService) DateTimeExt(com.netflix.titus.common.util.DateTimeExt) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ServerStatusRepresentation(com.netflix.titus.api.endpoint.v2.rest.representation.ServerStatusRepresentation) ServiceActivation(com.netflix.titus.grpc.protogen.ServiceActivation) Path(javax.ws.rs.Path) Timestamps(com.google.protobuf.util.Timestamps) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Durations(com.google.protobuf.util.Durations) Inject(javax.inject.Inject) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) ServingStatus(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) Comparator(java.util.Comparator) Collections(java.util.Collections) ServerStatusRepresentation(com.netflix.titus.api.endpoint.v2.rest.representation.ServerStatusRepresentation) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) ServiceActivation(com.netflix.titus.grpc.protogen.ServiceActivation) GET(javax.ws.rs.GET)

Aggregations

Details (com.netflix.titus.grpc.protogen.HealthCheckResponse.Details)3 Durations (com.google.protobuf.util.Durations)2 Timestamps (com.google.protobuf.util.Timestamps)2 ServiceActivation (com.netflix.titus.grpc.protogen.ServiceActivation)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 Duration (com.google.protobuf.Duration)1 ServerStatusRepresentation (com.netflix.titus.api.endpoint.v2.rest.representation.ServerStatusRepresentation)1 LeaderActivator (com.netflix.titus.api.supervisor.service.LeaderActivator)1 DateTimeExt (com.netflix.titus.common.util.DateTimeExt)1 ActivationLifecycle (com.netflix.titus.common.util.guice.ActivationLifecycle)1 Pair (com.netflix.titus.common.util.tuple.Pair)1 ServingStatus (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus)1 NOT_SERVING (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.NOT_SERVING)1 SERVING (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING)1 CellInfoResolver (com.netflix.titus.master.config.CellInfoResolver)1 HealthService (com.netflix.titus.master.health.service.HealthService)1