Search in sources :

Example 6 with InvalidJobException

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);
    }
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) ListJobsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsResponse) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) WorkerId(io.mantisrx.server.core.domain.WorkerId) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) JobWorker(io.mantisrx.master.jobcluster.job.worker.JobWorker) ListJobsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ListJobsRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) MantisJobMetadataView(io.mantisrx.master.jobcluster.job.MantisJobMetadataView) IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) Test(org.junit.Test)

Example 7 with InvalidJobException

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());
}
Also used : List(java.util.List) Lists(io.mantisrx.shaded.com.google.common.collect.Lists) Label(io.mantisrx.common.Label) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) JobSla(io.mantisrx.runtime.JobSla) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SystemLabels(io.mantisrx.master.jobcluster.LabelManager.SystemLabels) Assert.assertEquals(org.junit.Assert.assertEquals) ArrayList(java.util.ArrayList) Label(io.mantisrx.common.Label) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) Test(org.junit.Test)

Example 8 with InvalidJobException

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());
}
Also used : JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) TestKit(akka.testkit.javadsl.TestKit) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) Test(org.junit.Test)

Example 9 with InvalidJobException

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();
    }
}
Also used : ActorRef(akka.actor.ActorRef) JobProto(io.mantisrx.master.jobcluster.proto.JobProto) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) IOException(java.io.IOException) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) IJobClusterDefinition(io.mantisrx.server.master.domain.IJobClusterDefinition) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) JobId(io.mantisrx.server.master.domain.JobId) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) Test(org.junit.Test)

Example 10 with InvalidJobException

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();
    }
}
Also used : SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) JobConstraints(io.mantisrx.runtime.JobConstraints) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) Parameter(io.mantisrx.runtime.parameter.Parameter) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) Test(org.junit.Test)

Aggregations

InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)25 JobDefinition (io.mantisrx.server.master.domain.JobDefinition)21 Test (org.junit.Test)20 TestKit (akka.testkit.javadsl.TestKit)16 JobClusterManagerProto (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)14 ActorRef (akka.actor.ActorRef)11 JobId (io.mantisrx.server.master.domain.JobId)11 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)11 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)11 GetJobDetailsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse)10 SchedulingInfo (io.mantisrx.runtime.descriptor.SchedulingInfo)10 WorkerId (io.mantisrx.server.core.domain.WorkerId)10 JobProto (io.mantisrx.master.jobcluster.proto.JobProto)9 IJobClusterDefinition (io.mantisrx.server.master.domain.IJobClusterDefinition)9 MachineDefinition (io.mantisrx.runtime.MachineDefinition)8 StageSchedulingInfo (io.mantisrx.runtime.descriptor.StageSchedulingInfo)8 IOException (java.io.IOException)8 Label (io.mantisrx.common.Label)7 ArrayList (java.util.ArrayList)7 JobClusterDefinitionImpl (io.mantisrx.server.master.domain.JobClusterDefinitionImpl)6