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());
}
}
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;
}
}
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());
}
}
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());
}
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());
}
Aggregations