use of io.mantisrx.master.api.akka.route.utils.JobDiscoveryHeartbeats.JOB_CLUSTER_INFO_HB_INSTANCE in project mantis by Netflix.
the class JobDiscoveryRouteHandlerAkkaImpl method lastSubmittedJobIdStream.
@Override
public CompletionStage<JobDiscoveryRouteProto.JobClusterInfoResponse> lastSubmittedJobIdStream(final GetLastSubmittedJobIdStreamRequest request, final boolean sendHeartbeats) {
CompletionStage<GetLastSubmittedJobIdStreamResponse> response = lastSubmittedJobIdStreamRespCache.get(request);
try {
return response.thenApply(lastSubmittedJobIdResp -> {
Optional<BehaviorSubject<JobId>> jobIdSubjectO = lastSubmittedJobIdResp.getjobIdBehaviorSubject();
if (lastSubmittedJobIdResp.responseCode.equals(BaseResponse.ResponseCode.SUCCESS) && jobIdSubjectO.isPresent()) {
Observable<JobClusterInfo> jobClusterInfoObs = jobIdSubjectO.get().map(jobId -> new JobClusterInfo(jobId.getCluster(), jobId.getId()));
Observable<JobClusterInfo> heartbeats = Observable.interval(5, serverIdleConnectionTimeout.getSeconds() - 1, TimeUnit.SECONDS).map(x -> JOB_CLUSTER_INFO_HB_INSTANCE).takeWhile(x -> sendHeartbeats == true);
Observable<JobClusterInfo> jobClusterInfoWithHB = Observable.merge(jobClusterInfoObs, heartbeats);
return new JobDiscoveryRouteProto.JobClusterInfoResponse(lastSubmittedJobIdResp.requestId, lastSubmittedJobIdResp.responseCode, lastSubmittedJobIdResp.message, jobClusterInfoWithHB);
} else {
logger.info("Failed to get lastSubmittedJobId stream for job cluster {}", request.getClusterName());
lastSubmittedJobIdStreamErrors.increment();
return new JobDiscoveryRouteProto.JobClusterInfoResponse(lastSubmittedJobIdResp.requestId, lastSubmittedJobIdResp.responseCode, lastSubmittedJobIdResp.message);
}
});
} catch (Exception e) {
logger.error("caught exception fetching lastSubmittedJobId stream for {}", request.getClusterName(), e);
lastSubmittedJobIdStreamErrors.increment();
return CompletableFuture.completedFuture(new JobDiscoveryRouteProto.JobClusterInfoResponse(0, BaseResponse.ResponseCode.SERVER_ERROR, "Failed to get last submitted jobId stream for " + request.getClusterName() + " error: " + e.getMessage()));
}
}
Aggregations