Search in sources :

Example 1 with UpdateJobClusterRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest 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)

Example 2 with UpdateJobClusterRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest in project mantis by Netflix.

the class JobClusterTest method testJobSubmitWithVersionAndNoSchedInfo.

@Test
public void testJobSubmitWithVersionAndNoSchedInfo() {
    TestKit probe = new TestKit(system);
    String clusterName = "testJobSubmitWithVersionAndNoSchedInfo";
    MantisScheduler schedulerMock = mock(MantisScheduler.class);
    MantisJobStore jobStoreMock = mock(MantisJobStore.class);
    final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
    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("myart2").withSchedulingInfo(TWO_WORKER_SCHED_INFO).withVersion("0.0.2").build();
    final JobClusterDefinitionImpl updatedFakeJobCluster = new JobClusterDefinitionImpl.Builder().withJobClusterConfig(clusterConfig).withName(clusterName).withParameters(Lists.newArrayList()).withUser(user).withIsReadyForJobMaster(true).withOwner(DEFAULT_JOB_OWNER).withMigrationConfig(WorkerMigrationConfig.DEFAULT).withSla(NO_OP_SLA).build();
    jobClusterActor.tell(new UpdateJobClusterRequest(updatedFakeJobCluster, "user"), probe.getRef());
    UpdateJobClusterResponse resp = probe.expectMsgClass(UpdateJobClusterResponse.class);
    jobClusterActor.tell(new GetJobClusterRequest(clusterName), probe.getRef());
    GetJobClusterResponse getJobClusterResponse = probe.expectMsgClass(GetJobClusterResponse.class);
    assertEquals(2, getJobClusterResponse.getJobCluster().get().getJars().size());
    try {
        final JobDefinition jobDefn = new JobDefinition.Builder().withName(clusterName).withParameters(Lists.newArrayList()).withUser("njoshi").withVersion("0.0.2").withSubscriptionTimeoutSecs(300).withJobSla(new JobSla(0, 0, JobSla.StreamSLAType.Lossy, MantisJobDurationType.Transient, "")).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);
        // make sure it inherits from cluster
        assertEquals("myart2", detailsResp.getJobMetadata().get().getArtifactName());
        // inherits cluster scheduling Info corresponding to the given artifact
        assertEquals(TWO_WORKER_SCHED_INFO, detailsResp.getJobMetadata().get().getSchedulingInfo());
        // Now submit with a different artifact and no scheduling Info
        final JobDefinition jobDefn2 = new JobDefinition.Builder().withName(clusterName).withParameters(Lists.newArrayList()).withUser("njoshi").withVersion("0.0.1").withSubscriptionTimeoutSecs(300).withJobSla(new JobSla(0, 0, JobSla.StreamSLAType.Lossy, MantisJobDurationType.Transient, "")).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);
        // make sure it inherits from cluster
        assertEquals("myart", detailsResp2.getJobMetadata().get().getArtifactName());
        // inherits cluster scheduling Info corresponding to the given artifact
        assertEquals(SINGLE_WORKER_SCHED_INFO, detailsResp2.getJobMetadata().get().getSchedulingInfo());
        JobTestHelper.killJobAndVerify(probe, clusterName, new JobId(clusterName, 2), jobClusterActor);
        verify(jobStoreMock, times(1)).createJobCluster(any());
        verify(jobStoreMock, times(3)).updateJobCluster(any());
    } 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) GetJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse) ActorRef(akka.actor.ActorRef) 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) UpdateJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) UpdateJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse) JobSla(io.mantisrx.runtime.JobSla) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) Test(org.junit.Test)

Example 3 with UpdateJobClusterRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest in project mantis by Netflix.

the class JobClusterProtoAdapter method toUpdateJobClusterRequest.

// public static final JobSla toJobSla(final io.mantisrx.master.core.proto.JobSla protoSla) {
// return new JobSla(protoSla.getRuntimeLimitSecs(),
// protoSla.getMinRuntimeSecs(),
// JobSla.StreamSLAType.valueOf(protoSla.getSlaType().name()),
// MantisJobDurationType.valueOf(protoSla.getDurationType().name()),
// protoSla.getUserProvidedType());
// }
// 
// public static final MachineDefinition toMachineDefinition(final io.mantisrx.master.core.proto.MachineDefinition md) {
// return new MachineDefinition(md.getCpuCores(),
// md.getMemoryMB(), md.getNetworkMbps(), md.getDiskMB(), md.getNumPorts());
// }
// public static final StageScalingPolicy.Strategy toStageScalingStrategy(final io.mantisrx.master.core.proto.StageScalingPolicy.Strategy s) {
// return new StageScalingPolicy.Strategy(
// StageScalingPolicy.ScalingReason.valueOf(s.getReason().name()),
// s.getScaleDownBelowPct(),
// s.getScaleUpAbovePct(),
// s.hasRollingCount() ?
// new StageScalingPolicy.RollingCount(
// s.getRollingCount().getCount(),
// s.getRollingCount().getOf()) :
// null
// );
// }
// public static final StageScalingPolicy toStageScalingPolicy(final io.mantisrx.master.core.proto.StageScalingPolicy p) {
// return new StageScalingPolicy(
// p.getStage(),
// p.getMin(),
// p.getMax(),
// p.getIncrement(),
// p.getDecrement(),
// p.getCoolDownSecs(),
// p.getStrategiesMap().entrySet().stream().collect(
// Collectors.toMap(
// e -> StageScalingPolicy.ScalingReason.valueOf(e.getKey()),
// e -> toStageScalingStrategy(e.getValue())
// )
// )
// );
// }
// 
// private static final StageSchedulingInfo toStageSchedulingInfo(final io.mantisrx.master.core.proto.SchedulingInfo.StageSchedulingInfo s) {
// return new StageSchedulingInfo(
// s.getNumberOfInstances(),
// toMachineDefinition(s.getMachineDefinition()),
// s.getHardConstraintsList().stream().map(c -> JobConstraints.valueOf(c.name())).collect(Collectors.toList()),
// s.getSoftConstraintsList().stream().map(c -> JobConstraints.valueOf(c.name())).collect(Collectors.toList()),
// s.hasScalingPolicy() ? toStageScalingPolicy(s.getScalingPolicy()) : null,
// s.getScalable()
// );
// }
// private static final SchedulingInfo toSchedulingInfo(final io.mantisrx.master.core.proto.SchedulingInfo s) {
// 
// return new SchedulingInfo(
// s.getStagesMap().entrySet().stream()
// .collect(Collectors.toMap(e -> e.getKey(),
// e -> toStageSchedulingInfo(e.getValue())))
// );
// }
// private static final WorkerMigrationConfig toMigrationConfig(final io.mantisrx.master.core.proto.WorkerMigrationConfig cfg) {
// return new WorkerMigrationConfig(
// WorkerMigrationConfig.MigrationStrategyEnum.valueOf(cfg.getStrategy().name()),
// cfg.getConfigString()
// );
// }
// public static final MantisJobDefinition toMantisJobDefinition(final JobSubmitRequest jsr) throws MalformedURLException {
// 
// return new MantisJobDefinition(jsr.getName(),
// jsr.getUser(),
// new URL(jsr.getUrl()),
// jsr.getVersion(),
// jsr.getParametersList().stream().map(p -> new Parameter(p.getName(), p.getValue())).collect(Collectors.toList()),
// jsr.hasJobSla() ? toJobSla(jsr.getJobSla()) : null,
// jsr.getSubscriptionTimeoutSecs(),
// jsr.hasSchedulingInfo() ? toSchedulingInfo(jsr.getSchedulingInfo()) : null,
// jsr.getSlaMin(),
// jsr.getSlaMax(),
// jsr.getCronSpec(),
// NamedJobDefinition.CronPolicy.valueOf(jsr.getCronPolicy().name()),
// true,
// jsr.hasMigrationConfig() ? toMigrationConfig(jsr.getMigrationConfig()) : WorkerMigrationConfig.DEFAULT,
// jsr.getLabelsList().stream().map(l -> new Label(l.getName(), l.getValue())).collect(Collectors.toList())
// );
// }
public static final UpdateJobClusterRequest toUpdateJobClusterRequest(final NamedJobDefinition njd) {
    MantisJobDefinition jd = njd.getJobDefinition();
    final UpdateJobClusterRequest request = new UpdateJobClusterRequest(new JobClusterDefinitionImpl(jd.getName(), Arrays.asList(new JobClusterConfig(jd.getJobJarFileLocation().toString(), System.currentTimeMillis(), jd.getVersion(), jd.getSchedulingInfo())), njd.getOwner(), jd.getUser(), new SLA(jd.getSlaMin(), jd.getSlaMax(), jd.getCronSpec(), jd.getCronPolicy() == NamedJobDefinition.CronPolicy.KEEP_EXISTING ? IJobClusterDefinition.CronPolicy.KEEP_EXISTING : IJobClusterDefinition.CronPolicy.KEEP_NEW), jd.getMigrationConfig(), jd.getIsReadyForJobMaster(), jd.getParameters(), jd.getLabels()), "user");
    return request;
}
Also used : UpdateJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest) MantisJobDefinition(io.mantisrx.runtime.MantisJobDefinition)

Example 4 with UpdateJobClusterRequest

use of io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest in project mantis by Netflix.

the class JobClusterTest method testJobClusterUpdateFailsIfArtifactNotUnique.

@Test
public void testJobClusterUpdateFailsIfArtifactNotUnique() throws Exception {
    TestKit probe = new TestKit(system);
    List<Label> labels = Lists.newLinkedList();
    Label l = new Label("labelname", "labelvalue");
    labels.add(l);
    String clusterName = "testJobClusterUpdateFailsIfArtifactNotUnique";
    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);
    jobClusterActor.tell(new UpdateJobClusterRequest(fakeJobCluster, "user"), probe.getRef());
    UpdateJobClusterResponse resp = probe.expectMsgClass(UpdateJobClusterResponse.class);
    assertEquals(CLIENT_ERROR, resp.responseCode);
    assertEquals(jobClusterActor, probe.getLastSender());
    verify(jobStoreMock, times(1)).createJobCluster(any());
    verify(jobStoreMock, times(0)).updateJobCluster(any());
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) 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) Test(org.junit.Test)

Aggregations

UpdateJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterRequest)4 ActorRef (akka.actor.ActorRef)3 TestKit (akka.testkit.javadsl.TestKit)3 UpdateJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterResponse)3 JobClusterProto (io.mantisrx.master.jobcluster.proto.JobClusterProto)3 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)3 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)3 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Label (io.mantisrx.common.Label)2 GetJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest)2 GetJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse)2 GetJobDetailsRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest)1 GetJobDetailsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse)1 JobSla (io.mantisrx.runtime.JobSla)1 MantisJobDefinition (io.mantisrx.runtime.MantisJobDefinition)1 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)1