use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.
the class JobClusterTest method testLostWorkerGetsReplaced.
@Test
public void testLostWorkerGetsReplaced() {
TestKit probe = new TestKit(system);
String clusterName = "testLostWorkerGetsReplaced";
MantisScheduler schedulerMock = mock(MantisScheduler.class);
// MantisJobStore jobStoreMock = mock(MantisJobStore.class);
MantisJobStore jobStoreSpied = Mockito.spy(jobStore);
final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
ActorRef jobClusterActor = system.actorOf(props(clusterName, jobStoreSpied, 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 {
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);
// JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 1), jobClusterActor);
verify(jobStoreSpied, times(1)).createJobCluster(any());
verify(jobStoreSpied, times(1)).updateJobCluster(any());
int stageNo = 1;
// send launched event
WorkerId workerId = new WorkerId(jobId, 0, 1);
// send heartbeat
JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId, stageNo, workerId);
// check job status again
jobClusterActor.tell(new GetJobDetailsRequest("nj", jobId), probe.getRef());
// jobActor.tell(new JobProto.InitJob(probe.getRef()), probe.getRef());
GetJobDetailsResponse resp2 = probe.expectMsgClass(GetJobDetailsResponse.class);
System.out.println("resp " + resp2 + " msg " + resp2.message);
assertEquals(SUCCESS, resp2.responseCode);
// Job started
assertEquals(JobState.Launched, resp2.getJobMetadata().get().getState());
// send launched event
// worker 2 gets terminated abnormally
JobTestHelper.sendWorkerTerminatedEvent(probe, jobClusterActor, jobId, workerId);
// replaced worker comes up and sends events
WorkerId workerId2_replaced = new WorkerId(jobId, 0, 2);
JobTestHelper.sendLaunchedInitiatedStartedEventsToWorker(probe, jobClusterActor, jobId, stageNo, workerId2_replaced);
jobClusterActor.tell(new GetJobDetailsRequest("nj", jobId), probe.getRef());
GetJobDetailsResponse resp4 = probe.expectMsgClass(GetJobDetailsResponse.class);
IMantisJobMetadata jobMeta = resp4.getJobMetadata().get();
Map<Integer, ? extends IMantisStageMetadata> stageMetadata = jobMeta.getStageMetadata();
IMantisStageMetadata stage = stageMetadata.get(1);
for (JobWorker worker : stage.getAllWorkers()) {
System.out.println("worker -> " + worker.getMetadata());
}
// 2 initial schedules and 1 replacement
verify(schedulerMock, timeout(1_000).times(2)).scheduleWorker(any());
// archive worker should get called once for the dead worker
// verify(jobStoreMock, timeout(1_000).times(1)).archiveWorker(any());
Mockito.verify(jobStoreSpied).archiveWorker(any());
jobClusterActor.tell(new ListJobsRequest(), probe.getRef());
ListJobsResponse listResp2 = probe.expectMsgClass(ListJobsResponse.class);
assertEquals(SUCCESS, listResp2.responseCode);
assertEquals(1, listResp2.getJobList().size());
for (MantisJobMetadataView jb : listResp2.getJobList()) {
System.out.println("Jb -> " + jb);
}
// assertEquals(jobActor, probe.getLastSender());
} catch (InvalidJobException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail();
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
system.stop(jobClusterActor);
}
}
use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.
the class LabelManagerTest method insertVersionLabelTest.
@Test
public void insertVersionLabelTest() throws InvalidJobException {
String artifactName = "art.zip";
JobDefinition jobDefinition = generateJobDefinition("insertVersionLabelTest", new ArrayList<>(), artifactName, "1.0");
JobDefinition updatedJobDefn = LabelManager.insertSystemLabels(jobDefinition, false);
assertEquals(2, updatedJobDefn.getLabels().size());
List<Label> labels = updatedJobDefn.getLabels().stream().filter(label -> label.getName().equals(MANTIS_VERSION_LABEL.label)).collect(Collectors.toList());
Label label = labels.get(0);
assertEquals(MANTIS_VERSION_LABEL.label, label.getName());
assertEquals("1.0", label.getValue());
}
use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.
the class JobClusterManagerTest method testJobSubmit.
@Test
public void testJobSubmit() {
TestKit probe = new TestKit(system);
String clusterName = "testJobSubmit";
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 {
jobDefn = createJob(clusterName);
jobClusterManagerActor.tell(new JobClusterManagerProto.SubmitJobRequest(clusterName, "me", Optional.ofNullable(jobDefn)), probe.getRef());
JobClusterManagerProto.SubmitJobResponse submitResp = probe.expectMsgClass(JobClusterManagerProto.SubmitJobResponse.class);
assertEquals(SUCCESS, submitResp.responseCode);
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();
}
// assertEquals(jobClusterManagerActor, probe.getLastSender().path());
}
use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.
the class JobTestLifecycle method testJobSubmitInitalizationFails.
@Test
public void testJobSubmitInitalizationFails() {
final TestKit probe = new TestKit(system);
String clusterName = "testJobSubmitPersistenceFails";
IJobClusterDefinition jobClusterDefn = JobTestHelper.generateJobClusterDefinition(clusterName);
JobDefinition jobDefn;
try {
jobDefn = JobTestHelper.generateJobDefinition(clusterName);
MantisScheduler schedulerMock = mock(MantisScheduler.class);
MantisJobStore jobStoreMock = mock(MantisJobStore.class);
Mockito.doThrow(IOException.class).when(jobStoreMock).storeNewJob(any());
MantisJobMetadataImpl mantisJobMetaData = new MantisJobMetadataImpl.Builder().withJobId(new JobId(clusterName, 1)).withSubmittedAt(Instant.now()).withJobState(JobState.Accepted).withNextWorkerNumToUse(1).withJobDefinition(jobDefn).build();
final ActorRef jobActor = system.actorOf(JobActor.props(jobClusterDefn, mantisJobMetaData, jobStoreMock, schedulerMock, eventPublisher));
jobActor.tell(new JobProto.InitJob(probe.getRef()), probe.getRef());
JobProto.JobInitialized initMsg = probe.expectMsgClass(JobProto.JobInitialized.class);
assertEquals(SERVER_ERROR, initMsg.responseCode);
System.out.println(initMsg.message);
String jobId = clusterName + "-1";
jobActor.tell(new JobClusterManagerProto.GetJobDetailsRequest("nj", jobId), probe.getRef());
// jobActor.tell(new JobProto.InitJob(probe.getRef()), probe.getRef());
GetJobDetailsResponse resp = probe.expectMsgClass(GetJobDetailsResponse.class);
System.out.println("resp " + resp + " msg " + resp.message);
assertEquals(CLIENT_ERROR, resp.responseCode);
} catch (InvalidJobException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.
the class JobDefinitionResolverTest method versionSchedPresentTest.
@Test
public void versionSchedPresentTest() {
String clusterName = "versionSchedPresentTest";
List<Label> labels = new ArrayList<>();
Label label = new Label("l1", "lv1");
labels.add(label);
List<Parameter> parameters = new ArrayList<>();
Parameter parameter = new Parameter("paramName", "paramValue");
parameters.add(parameter);
final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, labels, parameters);
IJobClusterMetadata jobClusterMetadata = new JobClusterMetadataImpl(fakeJobCluster, 1, false);
String version = "0.0.1";
JobConstraints softConstraints = JobConstraints.ExclusiveHost;
List<JobConstraints> constraintsList = new ArrayList<>();
constraintsList.add(softConstraints);
SchedulingInfo schedulingInfo = new SchedulingInfo.Builder().numberOfStages(1).singleWorkerStageWithConstraints(DEFAULT_MACHINE_DEFINITION, Lists.newArrayList(), constraintsList).build();
try {
JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).withSchedulingInfo(schedulingInfo).withVersion(version).build();
JobDefinitionResolver resolver = new JobDefinitionResolver();
JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
// artifact will get populated using the given version.
assertEquals(DEFAULT_ARTIFACT_NAME, resolvedJobDefinition.getArtifactName());
// scheduling info will be the one specified by us
assertEquals(schedulingInfo, resolvedJobDefinition.getSchedulingInfo());
// version should match what we set.
assertEquals(version, resolvedJobDefinition.getVersion());
// assert the parameters and labels are inherited since they were not specified
assertEquals(1, resolvedJobDefinition.getLabels().size());
assertEquals(label, resolvedJobDefinition.getLabels().get(0));
assertEquals(1, resolvedJobDefinition.getParameters().size());
assertEquals(parameter, resolvedJobDefinition.getParameters().get(0));
} catch (InvalidJobException e) {
e.printStackTrace();
fail();
} catch (Exception e) {
e.printStackTrace();
fail();
}
// Only version is specified
try {
JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).withVersion(version).build();
JobDefinitionResolver resolver = new JobDefinitionResolver();
JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
// assert the artifact is inherited
assertEquals(DEFAULT_ARTIFACT_NAME, resolvedJobDefinition.getArtifactName());
// assert the scheduling info is inherited
assertEquals(SINGLE_WORKER_SCHED_INFO, resolvedJobDefinition.getSchedulingInfo());
// assert a version is the one we gave
assertEquals(version, resolvedJobDefinition.getVersion());
// assert the parameters and labels are inherited since they were not specified
assertEquals(1, resolvedJobDefinition.getLabels().size());
assertEquals(label, resolvedJobDefinition.getLabels().get(0));
assertEquals(1, resolvedJobDefinition.getParameters().size());
assertEquals(parameter, resolvedJobDefinition.getParameters().get(0));
} catch (InvalidJobException e) {
e.printStackTrace();
fail();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations