Search in sources :

Example 1 with InvalidJobException

use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.

the class MantisJobDefinition method validateSchedulingInfo.

private void validateSchedulingInfo(boolean schedulingInfoOptional) throws InvalidJobException {
    if (schedulingInfoOptional && schedulingInfo == null)
        return;
    if (schedulingInfo == null)
        throw new InvalidJobException("No scheduling info provided");
    if (schedulingInfo.getStages() == null)
        throw new InvalidJobException("No stages defined in scheduling info");
    int numStages = schedulingInfo.getStages().size();
    int startingIdx = 1;
    if (schedulingInfo.forStage(0) != null) {
        // jobMaster stage 0 definition exists, adjust index range
        startingIdx = 0;
        numStages--;
    }
    for (int i = startingIdx; i <= numStages; i++) {
        StageSchedulingInfo stage = schedulingInfo.getStages().get(i);
        if (stage == null)
            throw new InvalidJobException("No definition for stage " + i + " in scheduling info for " + numStages + " stage job");
        if (stage.getNumberOfInstances() < 1)
            throw new InvalidJobException("Number of instance for stage " + i + " must be >0, not " + stage.getNumberOfInstances());
        MachineDefinition machineDefinition = stage.getMachineDefinition();
        if (machineDefinition.getCpuCores() <= 0)
            throw new InvalidJobException("cpuCores must be >0.0, not " + machineDefinition.getCpuCores());
        if (machineDefinition.getMemoryMB() <= 0)
            throw new InvalidJobException("memory must be <0.0, not " + machineDefinition.getMemoryMB());
        if (machineDefinition.getDiskMB() < 0)
            throw new InvalidJobException("disk must be >=0, not " + machineDefinition.getDiskMB());
        if (machineDefinition.getNumPorts() < 0)
            throw new InvalidJobException("numPorts must be >=0, not " + machineDefinition.getNumPorts());
    }
}
Also used : StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException)

Example 2 with InvalidJobException

use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.

the class LabelManager method insertAutoResubmitLabel.

static JobDefinition insertAutoResubmitLabel(JobDefinition resolvedJobDefn) {
    List<Label> labels = resolvedJobDefn.getLabels();
    boolean alreadyHasResubmitLabel = labels.stream().anyMatch(label -> label.getName().equals(SystemLabels.MANTIS_IS_RESUBMIT_LABEL.label));
    if (!alreadyHasResubmitLabel) {
        List<Label> updatedLabels = new ArrayList<>(labels);
        updatedLabels.add(new Label(SystemLabels.MANTIS_IS_RESUBMIT_LABEL.label, "true"));
        try {
            JobDefinition updatedJobDefn = new JobDefinition.Builder().from(resolvedJobDefn).withLabels(updatedLabels).build();
            logger.debug("Added isResubmit label");
            return updatedJobDefn;
        } catch (InvalidJobException e) {
            logger.error(e.getMessage());
            return resolvedJobDefn;
        }
    } else {
        logger.debug("Job " + resolvedJobDefn.getName() + " already has isResubmit label. Don't add new");
        return resolvedJobDefn;
    }
}
Also used : Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) JobDefinition(io.mantisrx.server.master.domain.JobDefinition)

Example 3 with InvalidJobException

use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.

the class JobDefinition method validateSchedulingInfo.

private void validateSchedulingInfo(boolean schedulingInfoOptional) throws InvalidJobException {
    if (schedulingInfoOptional && schedulingInfo == null)
        return;
    if (schedulingInfo == null)
        throw new InvalidJobException("No scheduling info provided");
    if (schedulingInfo.getStages() == null)
        throw new InvalidJobException("No stages defined in scheduling info");
    int withNumberOfStages = schedulingInfo.getStages().size();
    int startingIdx = 1;
    if (schedulingInfo.forStage(0) != null) {
        // jobMaster stage 0 definition exists, adjust index range
        startingIdx = 0;
        withNumberOfStages--;
    }
    for (int i = startingIdx; i <= withNumberOfStages; i++) {
        StageSchedulingInfo stage = schedulingInfo.getStages().get(i);
        if (stage == null)
            throw new InvalidJobException("No definition for stage " + i + " in scheduling info for " + withNumberOfStages + " stage job");
        if (stage.getNumberOfInstances() < 1)
            throw new InvalidJobException("Number of instance for stage " + i + " must be >0, not " + stage.getNumberOfInstances());
        MachineDefinition machineDefinition = stage.getMachineDefinition();
        if (machineDefinition.getCpuCores() <= 0)
            throw new InvalidJobException("cpuCores must be >0.0, not " + machineDefinition.getCpuCores());
        if (machineDefinition.getMemoryMB() <= 0)
            throw new InvalidJobException("memory must be <0.0, not " + machineDefinition.getMemoryMB());
        if (machineDefinition.getDiskMB() < 0)
            throw new InvalidJobException("disk must be >=0, not " + machineDefinition.getDiskMB());
        if (machineDefinition.getNumPorts() < 0)
            throw new InvalidJobException("numPorts must be >=0, not " + machineDefinition.getNumPorts());
    }
}
Also used : MachineDefinition(io.mantisrx.runtime.MachineDefinition) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException)

Example 4 with InvalidJobException

use of io.mantisrx.runtime.command.InvalidJobException in project mantis by Netflix.

the class JobClusterManagerTest method testWorkerList.

@Test
public void testWorkerList() {
    TestKit probe = new TestKit(system);
    String clusterName = "testWorkerList";
    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.ListWorkersRequest(new JobId(clusterName, 1)), probe.getRef());
        JobClusterManagerProto.ListWorkersResponse listWorkersResponse = probe.expectMsgClass(JobClusterManagerProto.ListWorkersResponse.class);
        assertEquals(SUCCESS, listWorkersResponse.responseCode);
        assertEquals(1, listWorkersResponse.getWorkerMetadata().size());
        // send list workers request to non existent cluster
        jobClusterManagerActor.tell(new JobClusterManagerProto.ListWorkersRequest(new JobId("randomCluster", 1)), probe.getRef());
        JobClusterManagerProto.ListWorkersResponse listWorkersResponse2 = probe.expectMsgClass(JobClusterManagerProto.ListWorkersResponse.class);
        assertEquals(CLIENT_ERROR, listWorkersResponse2.responseCode);
        assertEquals(0, listWorkersResponse2.getWorkerMetadata().size());
        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) TestKit(akka.testkit.javadsl.TestKit) 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 5 with InvalidJobException

use of io.mantisrx.runtime.command.InvalidJobException 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());
}
Also used : GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) TestKit(akka.testkit.javadsl.TestKit) CountDownLatch(java.util.concurrent.CountDownLatch) GetLastSubmittedJobIdStreamResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamResponse) GetLastSubmittedJobIdStreamRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetLastSubmittedJobIdStreamRequest) 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)

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