use of io.mantisrx.common.Label in project mantis by Netflix.
the class JobDefinitionResolverTest method artifactPresentButSchedAbsentFailsTest.
@Test
public void artifactPresentButSchedAbsentFailsTest() {
String clusterName = "artifactPresentButSchedAbsentFailsTest";
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.2";
String artifactName = "myArt2";
// Only new artifact and version is specified
try {
JobDefinition givenJobDefn = new JobDefinition.Builder().withArtifactName(artifactName).withName(clusterName).withVersion(version).build();
JobDefinitionResolver resolver = new JobDefinitionResolver();
JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
fail();
} catch (Exception e) {
e.printStackTrace();
}
// Only new artifact is specified
try {
JobDefinition givenJobDefn = new JobDefinition.Builder().withArtifactName(artifactName).withName(clusterName).build();
JobDefinitionResolver resolver = new JobDefinitionResolver();
JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
fail();
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.mantisrx.common.Label in project mantis by Netflix.
the class JobDefinitionResolverTest method versionNotFoundTest.
@Test
public void versionNotFoundTest() {
String clusterName = "versionNotFoundTest";
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.2";
try {
JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).withVersion(version).build();
JobDefinitionResolver resolver = new JobDefinitionResolver();
JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
fail();
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.mantisrx.common.Label 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.common.Label in project mantis by Netflix.
the class JobClusterTest method testJobSubmitWithNoSchedInfoUsesJobClusterValues.
@Test
public void testJobSubmitWithNoSchedInfoUsesJobClusterValues() {
TestKit probe = new TestKit(system);
String clusterName = "testJobSubmitWithNoSchedInfoUsesJobClusterValues";
MantisScheduler schedulerMock = mock(MantisScheduler.class);
MantisJobStore jobStoreMock = mock(MantisJobStore.class);
List<Label> clusterLabels = new ArrayList<>();
Label label = new Label("clabelName", "cLabelValue");
clusterLabels.add(label);
final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, clusterLabels);
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 {
final JobDefinition jobDefn = new JobDefinition.Builder().withName(clusterName).withVersion("0.0.1").withSubscriptionTimeoutSecs(0).withUser("njoshi").build();
String jobId = clusterName + "-1";
JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn, jobId);
jobClusterActor.tell(new GetJobDetailsRequest("nj", JobId.fromId(jobId).get()), probe.getRef());
GetJobDetailsResponse detailsResp = probe.expectMsgClass(GetJobDetailsResponse.class);
assertEquals(SUCCESS, detailsResp.responseCode);
assertEquals(JobState.Accepted, detailsResp.getJobMetadata().get().getState());
//
assertEquals(clusterLabels.size() + LabelManager.numberOfMandatoryLabels(), detailsResp.getJobMetadata().get().getLabels().size());
// confirm that the clusters labels got inherited
assertEquals(1, detailsResp.getJobMetadata().get().getLabels().stream().filter(l -> l.getName().equals("clabelName")).count());
// assertEquals(label, detailsResp.getJobMetadata().get().getLabels().get(0));
// Now submit another one with labels, it should not inherit cluster labels
Label jobLabel = new Label("jobLabel", "jobValue");
List<Label> jobLabelList = new ArrayList<>();
jobLabelList.add(jobLabel);
final JobDefinition jobDefn2 = new JobDefinition.Builder().withName(clusterName).withVersion("0.0.1").withLabels(jobLabelList).withSubscriptionTimeoutSecs(0).withUser("njoshi").build();
String jobId2 = clusterName + "-2";
JobTestHelper.submitJobAndVerifySuccess(probe, clusterName, jobClusterActor, jobDefn2, jobId2);
jobClusterActor.tell(new GetJobDetailsRequest("nj", JobId.fromId(jobId2).get()), probe.getRef());
GetJobDetailsResponse detailsResp2 = probe.expectMsgClass(GetJobDetailsResponse.class);
assertEquals(SUCCESS, detailsResp2.responseCode);
assertEquals(JobState.Accepted, detailsResp2.getJobMetadata().get().getState());
assertEquals(clusterLabels.size() + 2, detailsResp2.getJobMetadata().get().getLabels().size());
// confirm that the clusters labels got inherited
// assertEquals(jobLabel, detailsResp2.getJobMetadata().get().getLabels().get(0));
assertEquals(1, detailsResp2.getJobMetadata().get().getLabels().stream().filter(l -> l.getName().equals(jobLabel.getName())).count());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail();
}
// Mockito.doThrow(IOException.class).when(jobStoreMock).storeNewJob(any());
}
use of io.mantisrx.common.Label in project mantis by Netflix.
the class JobClusterTest method testJobClusterUpdateAndDelete.
@Test
public void testJobClusterUpdateAndDelete() throws Exception {
TestKit probe = new TestKit(system);
List<Label> labels = Lists.newLinkedList();
Label l = new Label("labelname", "labelvalue");
labels.add(l);
String clusterName = "testJobClusterUpdateAndDelete";
MantisScheduler schedulerMock = mock(MantisScheduler.class);
MantisJobStore jobStoreMock = mock(MantisJobStore.class);
final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, labels);
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);
JobClusterConfig clusterConfig = new JobClusterConfig.Builder().withArtifactName("myart").withSchedulingInfo(SINGLE_WORKER_SCHED_INFO).withVersion("0.0.2").build();
final JobClusterDefinitionImpl updatedJobCluster = new JobClusterDefinitionImpl.Builder().withJobClusterConfig(clusterConfig).withName(clusterName).withParameters(Lists.newArrayList()).withLabels(labels).withUser(user).withIsReadyForJobMaster(true).withOwner(DEFAULT_JOB_OWNER).withMigrationConfig(WorkerMigrationConfig.DEFAULT).withSla(NO_OP_SLA).build();
jobClusterActor.tell(new UpdateJobClusterRequest(updatedJobCluster, "user"), probe.getRef());
UpdateJobClusterResponse resp = probe.expectMsgClass(UpdateJobClusterResponse.class);
assertEquals(SUCCESS, resp.responseCode);
assertEquals(jobClusterActor, probe.getLastSender());
jobClusterActor.tell(new GetJobClusterRequest(clusterName), probe.getRef());
GetJobClusterResponse resp3 = probe.expectMsgClass(GetJobClusterResponse.class);
assertEquals(SUCCESS, resp3.responseCode);
assertTrue(resp3.getJobCluster() != null);
System.out.println("Job cluster " + resp3.getJobCluster());
assertEquals(clusterName, resp3.getJobCluster().get().getName());
System.out.println("Updated job cluster " + resp3.getJobCluster());
assertEquals(1, resp3.getJobCluster().get().getLabels().size());
assertEquals("labelname", resp3.getJobCluster().get().getLabels().get(0).getName());
jobClusterActor.tell(new JobClusterProto.DeleteJobClusterRequest(user, clusterName, probe.getRef()), probe.getRef());
JobClusterProto.DeleteJobClusterResponse resp4 = probe.expectMsgClass(JobClusterProto.DeleteJobClusterResponse.class);
assertEquals(SUCCESS, resp4.responseCode);
assertEquals(jobClusterActor, probe.getLastSender());
verify(jobStoreMock, times(1)).createJobCluster(any());
verify(jobStoreMock, times(1)).updateJobCluster(any());
verify(jobStoreMock, times(1)).deleteJobCluster(clusterName);
}
Aggregations