use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse in project mantis by Netflix.
the class JobActor method onGetJobStatusSubject.
/**
* Return a BehaviorSubject that streams worker lifecycle events to the user.
*
* @param r
*/
@Override
public void onGetJobStatusSubject(GetJobSchedInfoRequest r) {
LOGGER.trace("Entering onGetJobStatusSubject {}", r);
ActorRef sender = getSender();
if (r.getJobId().equals(this.jobId)) {
sender.tell(new GetJobSchedInfoResponse(r.requestId, SUCCESS, "", of(workerManager.getJobStatusSubject())), getSelf());
} else {
String msg = "JobId in the request " + r.getJobId() + " does not match Job Actors job Id " + this.jobId;
LOGGER.warn(msg);
sender.tell(new GetJobSchedInfoResponse(r.requestId, CLIENT_ERROR, msg, empty()), getSelf());
}
}
use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse in project mantis by Netflix.
the class JobDiscoveryRouteHandlerAkkaImpl method schedulingInfoStream.
@Override
public CompletionStage<JobDiscoveryRouteProto.SchedInfoResponse> schedulingInfoStream(final GetJobSchedInfoRequest request, final boolean sendHeartbeats) {
CompletionStage<GetJobSchedInfoResponse> response = schedInfoCache.get(request);
try {
AtomicBoolean isJobCompleted = new AtomicBoolean(false);
final String jobId = request.getJobId().getId();
final JobSchedulingInfo completedJobSchedulingInfo = new JobSchedulingInfo(jobId, new HashMap<>());
CompletionStage<JobDiscoveryRouteProto.SchedInfoResponse> jobSchedInfoObsCS = response.thenApply(getJobSchedInfoResp -> {
Optional<BehaviorSubject<JobSchedulingInfo>> jobStatusSubjectO = getJobSchedInfoResp.getJobSchedInfoSubject();
if (getJobSchedInfoResp.responseCode.equals(BaseResponse.ResponseCode.SUCCESS) && jobStatusSubjectO.isPresent()) {
BehaviorSubject<JobSchedulingInfo> jobSchedulingInfoObs = jobStatusSubjectO.get();
Observable<JobSchedulingInfo> heartbeats = Observable.interval(5, serverIdleConnectionTimeout.getSeconds() - 1, TimeUnit.SECONDS).map(x -> {
if (!isJobCompleted.get()) {
return SCHED_INFO_HB_INSTANCE;
} else {
return completedJobSchedulingInfo;
}
}).takeWhile(x -> sendHeartbeats == true);
// Job SchedulingInfo obs completes on job shutdown. Use the do On completed as a signal to inform the user that there are no workers to connect to.
// TODO For future a more explicit key in the payload saying the job is completed.
Observable<JobSchedulingInfo> jobSchedulingInfoWithHBObs = Observable.merge(jobSchedulingInfoObs.doOnCompleted(() -> isJobCompleted.set(true)), heartbeats);
return new JobDiscoveryRouteProto.SchedInfoResponse(getJobSchedInfoResp.requestId, getJobSchedInfoResp.responseCode, getJobSchedInfoResp.message, jobSchedulingInfoWithHBObs);
} else {
logger.info("Failed to get Sched info stream for {}", request.getJobId().getId());
schedInfoStreamErrors.increment();
return new JobDiscoveryRouteProto.SchedInfoResponse(getJobSchedInfoResp.requestId, getJobSchedInfoResp.responseCode, getJobSchedInfoResp.message);
}
});
return jobSchedInfoObsCS;
} catch (Exception e) {
logger.error("caught exception fetching sched info stream for {}", request.getJobId().getId(), e);
schedInfoStreamErrors.increment();
return CompletableFuture.completedFuture(new JobDiscoveryRouteProto.SchedInfoResponse(0, BaseResponse.ResponseCode.SERVER_ERROR, "Failed to get SchedulingInfo stream for jobId " + request.getJobId().getId() + " error: " + e.getMessage()));
}
}
use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse in project mantis by Netflix.
the class JobClustersManagerActor method onGetJobStatusSubject.
@Override
public void onGetJobStatusSubject(GetJobSchedInfoRequest request) {
Optional<JobClusterInfo> jobClusterInfo = jobClusterInfoManager.getJobClusterInfo(request.getJobId().getCluster());
ActorRef sender = getSender();
if (jobClusterInfo.isPresent()) {
jobClusterInfo.get().jobClusterActor.forward(request, getContext());
} else {
sender.tell(new GetJobSchedInfoResponse(request.requestId, CLIENT_ERROR_NOT_FOUND, "JobCluster " + request.getJobId().getCluster() + " doesn't exist", Optional.empty()), getSelf());
}
}
use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobSchedInfoResponse in project mantis by Netflix.
the class JobClusterActor method onGetJobStatusSubject.
@Override
public void onGetJobStatusSubject(GetJobSchedInfoRequest request) {
if (logger.isTraceEnabled()) {
logger.trace("Enter onGetJobStatusSubject {}", request);
}
Optional<JobInfo> jInfo = jobManager.getJobInfoForNonTerminalJob(request.getJobId());
if (jInfo.isPresent()) {
if (logger.isDebugEnabled()) {
logger.debug("Forwarding getJobDetails to job actor for {}", request.getJobId());
}
jInfo.get().jobActor.forward(request, getContext());
} else {
// Could be a terminated job
GetJobSchedInfoResponse response = new GetJobSchedInfoResponse(request.requestId, CLIENT_ERROR, "Job " + request.getJobId() + " not found or not active", empty());
getSender().tell(response, getSelf());
}
if (logger.isTraceEnabled()) {
logger.trace("Exit onGetJobStatusSubject ");
}
}
Aggregations