Search in sources :

Example 1 with JOB_CLUSTER_INFO_HB_INSTANCE

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()));
    }
}
Also used : JobId(io.mantisrx.server.master.domain.JobId) JobClusterInfo(io.mantisrx.master.api.akka.route.proto.JobClusterInfo) GetJobSchedInfoRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoRequest) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) JOB_CLUSTER_INFO_HB_INSTANCE(io.mantisrx.master.api.akka.route.utils.JobDiscoveryHeartbeats.JOB_CLUSTER_INFO_HB_INSTANCE) JobDiscoveryRouteProto(io.mantisrx.master.api.akka.route.proto.JobDiscoveryRouteProto) GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) Observable(rx.Observable) ActorRef(akka.actor.ActorRef) Duration(java.time.Duration) Metrics(io.mantisrx.common.metrics.Metrics) GetLastSubmittedJobIdStreamRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamRequest) Counter(io.mantisrx.common.metrics.Counter) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) SCHED_INFO_HB_INSTANCE(io.mantisrx.master.api.akka.route.utils.JobDiscoveryHeartbeats.SCHED_INFO_HB_INSTANCE) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) BaseResponse(io.mantisrx.master.jobcluster.proto.BaseResponse) GetJobSchedInfoResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse) TimeUnit(java.util.concurrent.TimeUnit) AsyncLoadingCache(com.github.benmanes.caffeine.cache.AsyncLoadingCache) CompletionStage(java.util.concurrent.CompletionStage) PatternsCS.ask(akka.pattern.PatternsCS.ask) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) BehaviorSubject(rx.subjects.BehaviorSubject) Optional(java.util.Optional) BehaviorSubject(rx.subjects.BehaviorSubject) GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) JobClusterInfo(io.mantisrx.master.api.akka.route.proto.JobClusterInfo)

Aggregations

ActorRef (akka.actor.ActorRef)1 PatternsCS.ask (akka.pattern.PatternsCS.ask)1 AsyncLoadingCache (com.github.benmanes.caffeine.cache.AsyncLoadingCache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 Counter (io.mantisrx.common.metrics.Counter)1 Metrics (io.mantisrx.common.metrics.Metrics)1 JobClusterInfo (io.mantisrx.master.api.akka.route.proto.JobClusterInfo)1 JobDiscoveryRouteProto (io.mantisrx.master.api.akka.route.proto.JobDiscoveryRouteProto)1 JOB_CLUSTER_INFO_HB_INSTANCE (io.mantisrx.master.api.akka.route.utils.JobDiscoveryHeartbeats.JOB_CLUSTER_INFO_HB_INSTANCE)1 SCHED_INFO_HB_INSTANCE (io.mantisrx.master.api.akka.route.utils.JobDiscoveryHeartbeats.SCHED_INFO_HB_INSTANCE)1 BaseResponse (io.mantisrx.master.jobcluster.proto.BaseResponse)1 GetJobSchedInfoRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoRequest)1 GetJobSchedInfoResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse)1 GetLastSubmittedJobIdStreamRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamRequest)1 GetLastSubmittedJobIdStreamResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse)1 JobSchedulingInfo (io.mantisrx.server.core.JobSchedulingInfo)1 ConfigurationProvider (io.mantisrx.server.master.config.ConfigurationProvider)1 JobId (io.mantisrx.server.master.domain.JobId)1 Duration (java.time.Duration)1 HashMap (java.util.HashMap)1