use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse 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()));
}
}
use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse in project mantis by Netflix.
the class JobClustersManagerActor method onGetLastSubmittedJobIdSubject.
@Override
public void onGetLastSubmittedJobIdSubject(GetLastSubmittedJobIdStreamRequest r) {
Optional<JobClusterInfo> jobClusterInfo = jobClusterInfoManager.getJobClusterInfo(r.getClusterName());
ActorRef sender = getSender();
if (jobClusterInfo.isPresent()) {
jobClusterInfo.get().jobClusterActor.forward(r, getContext());
} else {
sender.tell(new GetLastSubmittedJobIdStreamResponse(r.requestId, CLIENT_ERROR_NOT_FOUND, "No such Job cluster " + r.getClusterName(), empty()), getSelf());
}
}
use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse in project mantis by Netflix.
the class JobClusterManagerTest method testGetJobIdSubject.
@Test
public void testGetJobIdSubject() {
TestKit probe = new TestKit(system);
String clusterName = "testGetJobIdSubject";
final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, Lists.newArrayList());
jobClusterManagerActor.tell(new JobClusterManagerProto.CreateJobClusterRequest(fakeJobCluster, "user"), probe.getRef());
JobClusterManagerProto.CreateJobClusterResponse resp = probe.expectMsgClass(JobClusterManagerProto.CreateJobClusterResponse.class);
System.out.println("response----->" + resp);
assertEquals(SUCCESS_CREATED, resp.responseCode);
JobDefinition jobDefn;
try {
jobClusterManagerActor.tell(new GetLastSubmittedJobIdStreamRequest(clusterName), probe.getRef());
JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse getLastSubmittedJobIdStreamResponse = probe.expectMsgClass(JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse.class);
assertEquals(SUCCESS, getLastSubmittedJobIdStreamResponse.responseCode);
CountDownLatch jobIdLatch = new CountDownLatch(1);
assertTrue(getLastSubmittedJobIdStreamResponse.getjobIdBehaviorSubject().isPresent());
BehaviorSubject<JobId> jobIdBehaviorSubject = getLastSubmittedJobIdStreamResponse.getjobIdBehaviorSubject().get();
jobIdBehaviorSubject.subscribeOn(Schedulers.io()).subscribe((jId) -> {
System.out.println("Got Jid -> " + jId);
assertEquals(clusterName + "-1", jId.getId());
jobIdLatch.countDown();
});
jobDefn = createJob(clusterName);
jobClusterManagerActor.tell(new JobClusterManagerProto.SubmitJobRequest(clusterName, "me", of(jobDefn)), probe.getRef());
JobClusterManagerProto.SubmitJobResponse submitResp = probe.expectMsgClass(JobClusterManagerProto.SubmitJobResponse.class);
assertEquals(SUCCESS, submitResp.responseCode);
jobIdLatch.await(1, TimeUnit.SECONDS);
// try a non existent cluster
jobClusterManagerActor.tell(new GetLastSubmittedJobIdStreamRequest("randomC"), probe.getRef());
getLastSubmittedJobIdStreamResponse = probe.expectMsgClass(JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse.class);
assertEquals(CLIENT_ERROR_NOT_FOUND, getLastSubmittedJobIdStreamResponse.responseCode);
assertTrue(!getLastSubmittedJobIdStreamResponse.getjobIdBehaviorSubject().isPresent());
jobClusterManagerActor.tell(new JobClusterManagerProto.KillJobRequest(clusterName + "-1", "", clusterName), probe.getRef());
JobClusterManagerProto.KillJobResponse kill = probe.expectMsgClass(JobClusterManagerProto.KillJobResponse.class);
} catch (InvalidJobException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail();
} catch (InterruptedException e) {
e.printStackTrace();
}
// assertEquals(jobClusterManagerActor, probe.getLastSender().path());
}
use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse in project mantis by Netflix.
the class JobClusterManagerTest method testBootStrapJobClustersAndJobs.
@Test
public void testBootStrapJobClustersAndJobs() {
TestKit probe = new TestKit(system);
JobTestHelper.deleteAllFiles();
MantisJobStore jobStore = new MantisJobStore(new MantisStorageProviderAdapter(new io.mantisrx.server.master.store.SimpleCachedFileStorageProvider(), eventPublisher));
MantisJobStore jobStoreSpied = Mockito.spy(jobStore);
MantisScheduler schedulerMock = mock(MantisScheduler.class);
ActorRef jobClusterManagerActor = system.actorOf(JobClustersManagerActor.props(jobStoreSpied, eventPublisher));
jobClusterManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(schedulerMock, false), probe.getRef());
JobClustersManagerInitializeResponse iResponse = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), JobClustersManagerInitializeResponse.class);
List<String> clusterNames = Lists.newArrayList("testBootStrapJobClustersAndJobs1", "testBootStrapJobClustersAndJobs2", "testBootStrapJobClustersAndJobs3");
String clusterWithNoJob = "testBootStrapJobClusterWithNoJob";
createJobClusterAndAssert(jobClusterManagerActor, clusterWithNoJob);
WorkerMigrationConfig migrationConfig = new WorkerMigrationConfig(MigrationStrategyEnum.PERCENTAGE, "{\"percentToMove\":60, \"intervalMs\":30000}");
// Create 3 clusters and submit 1 job each
for (String cluster : clusterNames) {
createJobClusterAndAssert(jobClusterManagerActor, cluster, migrationConfig);
submitJobAndAssert(jobClusterManagerActor, cluster);
if (cluster.equals("testBootStrapJobClustersAndJobs1")) {
// send worker events for job 1 so it goes to started state
String jobId = "testBootStrapJobClustersAndJobs1-1";
WorkerId workerId = new WorkerId(jobId, 0, 1);
WorkerEvent launchedEvent = new WorkerLaunched(workerId, 0, "host1", "vm1", empty(), new WorkerPorts(Lists.newArrayList(8000, 9000, 9010, 9020, 9030)));
jobClusterManagerActor.tell(launchedEvent, probe.getRef());
WorkerEvent startInitEvent = new WorkerStatus(new Status(workerId.getJobId(), 1, workerId.getWorkerIndex(), workerId.getWorkerNum(), TYPE.INFO, "test START_INIT", MantisJobState.StartInitiated));
jobClusterManagerActor.tell(startInitEvent, probe.getRef());
WorkerEvent heartBeat = new WorkerHeartbeat(new Status(jobId, 1, workerId.getWorkerIndex(), workerId.getWorkerNum(), TYPE.HEARTBEAT, "", MantisJobState.Started));
jobClusterManagerActor.tell(heartBeat, probe.getRef());
// get Job status
jobClusterManagerActor.tell(new GetJobDetailsRequest("user", JobId.fromId(jobId).get()), probe.getRef());
GetJobDetailsResponse resp2 = probe.expectMsgClass(GetJobDetailsResponse.class);
// Ensure its launched
assertEquals(SUCCESS, resp2.responseCode);
assertEquals(JobState.Launched, resp2.getJobMetadata().get().getState());
}
}
// kill 1 of the jobs to test archive path
JobClusterManagerProto.KillJobRequest killRequest = new JobClusterManagerProto.KillJobRequest("testBootStrapJobClustersAndJobs2-1", JobCompletedReason.Killed.toString(), "njoshi");
jobClusterManagerActor.tell(killRequest, probe.getRef());
JobClusterManagerProto.KillJobResponse killJobResponse = probe.expectMsgClass(JobClusterManagerProto.KillJobResponse.class);
assertEquals(SUCCESS, killJobResponse.responseCode);
JobTestHelper.sendWorkerTerminatedEvent(probe, jobClusterManagerActor, "testBootStrapJobClustersAndJobs2-1", new WorkerId("testBootStrapJobClustersAndJobs2-1", 0, 1));
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Stop job cluster Manager Actor
system.stop(jobClusterManagerActor);
// create new instance
jobClusterManagerActor = system.actorOf(JobClustersManagerActor.props(jobStoreSpied, eventPublisher));
// initialize it
jobClusterManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(schedulerMock, true), probe.getRef());
JobClustersManagerInitializeResponse initializeResponse = probe.expectMsgClass(JobClustersManagerInitializeResponse.class);
// probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES),JobClusterManagerProto.JobClustersManagerInitializeResponse.class);
// probe.expectMsgClass(JobClusterManagerProto.JobClustersManagerInitializeResponse.class);
assertEquals(SUCCESS, initializeResponse.responseCode);
// Get Cluster Config
jobClusterManagerActor.tell(new GetJobClusterRequest("testBootStrapJobClustersAndJobs1"), probe.getRef());
GetJobClusterResponse clusterResponse = probe.expectMsgClass(GetJobClusterResponse.class);
assertEquals(SUCCESS, clusterResponse.responseCode);
assertTrue(clusterResponse.getJobCluster().isPresent());
WorkerMigrationConfig mConfig = clusterResponse.getJobCluster().get().getMigrationConfig();
assertEquals(migrationConfig.getStrategy(), mConfig.getStrategy());
assertEquals(migrationConfig.getConfigString(), migrationConfig.getConfigString());
// get Job status
jobClusterManagerActor.tell(new GetJobDetailsRequest("user", JobId.fromId("testBootStrapJobClustersAndJobs1-1").get()), probe.getRef());
GetJobDetailsResponse resp2 = probe.expectMsgClass(GetJobDetailsResponse.class);
// Ensure its launched
System.out.println("Resp2 -> " + resp2.message);
assertEquals(SUCCESS, resp2.responseCode);
assertEquals(JobState.Launched, resp2.getJobMetadata().get().getState());
// 1 jobs should be in completed state
jobClusterManagerActor.tell(new GetJobDetailsRequest("user", JobId.fromId("testBootStrapJobClustersAndJobs2-1").get()), probe.getRef());
resp2 = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), GetJobDetailsResponse.class);
// Ensure its completed
assertEquals(SUCCESS, resp2.responseCode);
assertEquals(JobState.Completed, resp2.getJobMetadata().get().getState());
jobClusterManagerActor.tell(new GetJobDetailsRequest("user", JobId.fromId("testBootStrapJobClustersAndJobs3-1").get()), probe.getRef());
resp2 = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), GetJobDetailsResponse.class);
// Ensure its Accepted
assertEquals(SUCCESS, resp2.responseCode);
assertEquals(JobState.Accepted, resp2.getJobMetadata().get().getState());
try {
Optional<JobWorker> workerByIndex = resp2.getJobMetadata().get().getWorkerByIndex(1, 0);
assertTrue(workerByIndex.isPresent());
Optional<IMantisStageMetadata> stageMetadata = resp2.getJobMetadata().get().getStageMetadata(1);
assertTrue(stageMetadata.isPresent());
JobWorker workerByIndex1 = stageMetadata.get().getWorkerByIndex(0);
System.out.println("Got worker by index : " + workerByIndex1);
Optional<JobWorker> worker = resp2.getJobMetadata().get().getWorkerByNumber(1);
assertTrue(worker.isPresent());
} catch (io.mantisrx.server.master.persistence.exceptions.InvalidJobException e) {
e.printStackTrace();
}
jobClusterManagerActor.tell(new GetLastSubmittedJobIdStreamRequest("testBootStrapJobClustersAndJobs1"), probe.getRef());
GetLastSubmittedJobIdStreamResponse lastSubmittedJobIdStreamResponse = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), GetLastSubmittedJobIdStreamResponse.class);
lastSubmittedJobIdStreamResponse.getjobIdBehaviorSubject().get().take(1).toBlocking().subscribe((jId) -> {
assertEquals(new JobId("testBootStrapJobClustersAndJobs1", 1), jId);
});
jobClusterManagerActor.tell(new GetJobClusterRequest(clusterWithNoJob), probe.getRef());
GetJobClusterResponse jobClusterResponse = probe.expectMsgClass(Duration.of(10, ChronoUnit.MINUTES), GetJobClusterResponse.class);
assertEquals(SUCCESS, jobClusterResponse.responseCode);
assertTrue(jobClusterResponse.getJobCluster().isPresent());
assertEquals(clusterWithNoJob, jobClusterResponse.getJobCluster().get().getName());
// 1 running worker
verify(schedulerMock, timeout(100_1000).times(1)).initializeRunningWorker(any(), any());
// 2 worker schedule requests
verify(schedulerMock, timeout(100_000).times(4)).scheduleWorker(any());
try {
Mockito.verify(jobStoreSpied).loadAllArchivedJobsAsync();
Mockito.verify(jobStoreSpied).loadAllActiveJobs();
Mockito.verify(jobStoreSpied).loadAllCompletedJobs();
Mockito.verify(jobStoreSpied).archiveWorker(any());
Mockito.verify(jobStoreSpied).archiveJob(any());
} catch (IOException e) {
e.printStackTrace();
fail();
}
}
use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse in project mantis by Netflix.
the class JobClusterTest method testGetLastSubmittedJobSubject.
// //////////////////////////////// JOB SUBMIT OPERATIONS END/////////////////////////////////////////////////////////////
// //////////////////////////////// OTHER JOB OPERATIONS //////////////////////////////////////////////////////////////
@Test
public void testGetLastSubmittedJobSubject() {
TestKit probe = new TestKit(system);
String clusterName = "testGetLastSubmittedJobSubject";
MantisScheduler schedulerMock = mock(MantisScheduler.class);
MantisJobStore jobStoreMock = mock(MantisJobStore.class);
final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreMock, schedulerMock, eventPublisher));
jobClusterActor.tell(new JobClusterProto.InitializeJobClusterRequest(fakeJobCluster, user, probe.getRef()), probe.getRef());
JobClusterProto.InitializeJobClusterResponse createResp = probe.expectMsgClass(JobClusterProto.InitializeJobClusterResponse.class);
assertEquals(SUCCESS, createResp.responseCode);
try {
jobClusterActor.tell(new GetLastSubmittedJobIdStreamRequest(clusterName), probe.getRef());
GetLastSubmittedJobIdStreamResponse getLastSubmittedJobIdStreamResponse = probe.expectMsgClass(GetLastSubmittedJobIdStreamResponse.class);
assertEquals(SUCCESS, getLastSubmittedJobIdStreamResponse.responseCode);
CountDownLatch jobIdLatch = new CountDownLatch(1);
assertTrue(getLastSubmittedJobIdStreamResponse.getjobIdBehaviorSubject().isPresent());
BehaviorSubject<JobId> jobIdBehaviorSubject = getLastSubmittedJobIdStreamResponse.getjobIdBehaviorSubject().get();
jobIdBehaviorSubject.subscribeOn(Schedulers.io()).subscribe((jId) -> {
System.out.println("Got Jid ------> " + jId);
String jIdStr = jId.getId();
assertEquals(clusterName + "-1", jIdStr);
jobIdLatch.countDown();
});
final JobDefinition jobDefn = createJob(clusterName, 1, MantisJobDurationType.Transient);
String jobId = clusterName + "-1";
JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
JobTestHelper.getJobDetailsAndVerify(probe, jobClusterActor, jobId, SUCCESS, JobState.Accepted);
jobIdLatch.await(1000, TimeUnit.SECONDS);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail();
}
// Mockito.doThrow(IOException.class).when(jobStoreMock).storeNewJob(any());
}
Aggregations