Search in sources :

Example 6 with Label

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

Example 7 with Label

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

Example 8 with Label

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;
    }
}
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 9 with Label

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());
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) GetJobDetailsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) GetJobDetailsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.junit.Test)

Example 10 with Label

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);
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) ActorRef(akka.actor.ActorRef) Label(io.mantisrx.common.Label) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) UpdateJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) UpdateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) Test(org.junit.Test)

Aggregations

Label (io.mantisrx.common.Label)47 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)30 JobDefinition (io.mantisrx.server.master.domain.JobDefinition)15 TestKit (akka.testkit.javadsl.TestKit)14 JobClusterDefinitionImpl (io.mantisrx.server.master.domain.JobClusterDefinitionImpl)13 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)11 GetJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest)8 GetJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse)8 Parameter (io.mantisrx.runtime.parameter.Parameter)8 ActorRef (akka.actor.ActorRef)7 JobClusterManagerProto (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)7 JobClusterProto (io.mantisrx.master.jobcluster.proto.JobClusterProto)7 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)7 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)7 Matchers.anyString (org.mockito.Matchers.anyString)7 JobId (io.mantisrx.server.master.domain.JobId)6 SchedulingInfo (io.mantisrx.runtime.descriptor.SchedulingInfo)4 DisableJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest)3 JobSla (io.mantisrx.runtime.JobSla)3