Search in sources :

Example 6 with ObserveJobsWithKeepAliveRequest

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

the class ObserveJobsSubscription method getLastKeepAliveEvent.

private KeepAliveRequest getLastKeepAliveEvent() {
    Pair<Long, ObserveJobsWithKeepAliveRequest> firstKeepAliveRequestPair = null;
    KeepAliveRequest lastKeepAliveRequest = null;
    int count = 0;
    Pair<Long, ObserveJobsWithKeepAliveRequest> eventPair;
    while ((eventPair = grpcClientEvents.peek()) != null) {
        ObserveJobsWithKeepAliveRequest event = eventPair.getRight();
        if (event.getKindCase() == ObserveJobsWithKeepAliveRequest.KindCase.KEEPALIVEREQUEST) {
            long requestTimestampNano = eventPair.getLeft();
            if (requestTimestampNano > lastCheckpointTimestampNano) {
                break;
            }
            lastKeepAliveRequest = event.getKeepAliveRequest();
            count++;
            if (firstKeepAliveRequestPair == null) {
                firstKeepAliveRequestPair = eventPair;
            }
        }
        grpcClientEvents.poll();
    }
    if (lastKeepAliveRequest != null && logger.isDebugEnabled()) {
        KeepAliveRequest firstKeepAliveRequest = firstKeepAliveRequestPair.getRight().getKeepAliveRequest();
        long internalSyncDelayMs = (System.nanoTime() - firstKeepAliveRequestPair.getLeft()) / 1_000_000;
        logger.debug("Acknowledging the keep alive request(s): count={}, requestId(first)={}, requestTimestamp={}, internalSyncDelayMs={}", count, firstKeepAliveRequest.getRequestId(), firstKeepAliveRequest.getTimestamp(), internalSyncDelayMs);
    }
    return lastKeepAliveRequest;
}
Also used : ObserveJobsWithKeepAliveRequest(com.netflix.titus.grpc.protogen.ObserveJobsWithKeepAliveRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) KeepAliveRequest(com.netflix.titus.grpc.protogen.KeepAliveRequest) ObserveJobsWithKeepAliveRequest(com.netflix.titus.grpc.protogen.ObserveJobsWithKeepAliveRequest)

Aggregations

ObserveJobsWithKeepAliveRequest (com.netflix.titus.grpc.protogen.ObserveJobsWithKeepAliveRequest)6 JobChangeNotification (com.netflix.titus.grpc.protogen.JobChangeNotification)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Task (com.netflix.titus.api.jobmanager.model.job.Task)1 KeepAliveRequest (com.netflix.titus.grpc.protogen.KeepAliveRequest)1 ObserveJobsQuery (com.netflix.titus.grpc.protogen.ObserveJobsQuery)1 ClientCallStreamObserver (io.grpc.stub.ClientCallStreamObserver)1 ClientResponseObserver (io.grpc.stub.ClientResponseObserver)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Disposable (reactor.core.Disposable)1