Search in sources :

Example 1 with UpdateJobClusterLabelsResponse

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

the class JobClusterActor method onJobClusterUpdateLabels.

@Override
public void onJobClusterUpdateLabels(UpdateJobClusterLabelsRequest labelRequest) {
    if (logger.isTraceEnabled()) {
        logger.trace("Enter onJobClusterUpdateLabels {}", labelRequest);
    }
    ActorRef sender = getSender();
    try {
        JobClusterConfig newConfig = new JobClusterConfig.Builder().from(jobClusterMetadata.getJobClusterDefinition().getJobClusterConfig()).build();
        JobClusterDefinitionImpl updatedDefn = new JobClusterDefinitionImpl.Builder().from(jobClusterMetadata.getJobClusterDefinition()).withJobClusterConfig(newConfig).withLabels(labelRequest.getLabels()).build();
        IJobClusterMetadata jobCluster = new JobClusterMetadataImpl.Builder().withIsDisabled(jobClusterMetadata.isDisabled()).withLastJobCount(jobClusterMetadata.getLastJobCount()).withJobClusterDefinition(updatedDefn).build();
        updateAndSaveJobCluster(jobCluster);
        sender.tell(new UpdateJobClusterLabelsResponse(labelRequest.requestId, SUCCESS, name + " labels updated"), getSelf());
        eventPublisher.publishAuditEvent(new LifecycleEventsProto.AuditEvent(LifecycleEventsProto.AuditEvent.AuditEventType.JOB_CLUSTER_UPDATE, jobClusterMetadata.getJobClusterDefinition().getName(), name + " update labels"));
    } catch (Exception e) {
        logger.error("job cluster labels not updated ", e);
        sender.tell(new UpdateJobClusterLabelsResponse(labelRequest.requestId, SERVER_ERROR, name + " labels updation failed " + e.getMessage()), getSelf());
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Exit onJobClusterUpdateLabels {}", labelRequest);
    }
}
Also used : ActorRef(akka.actor.ActorRef) JobClusterConfig(io.mantisrx.server.master.domain.JobClusterConfig) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto) UpdateJobClusterLabelsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse) TriggerNotFoundException(com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException) SchedulerException(com.netflix.fenzo.triggers.exceptions.SchedulerException) JobClusterAlreadyExistsException(io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException)

Example 2 with UpdateJobClusterLabelsResponse

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

the class JobClustersManagerActor method onJobClusterUpdateLabels.

@Override
public void onJobClusterUpdateLabels(UpdateJobClusterLabelsRequest request) {
    Optional<JobClusterInfo> jobClusterInfo = jobClusterInfoManager.getJobClusterInfo(request.getClusterName());
    ActorRef sender = getSender();
    if (jobClusterInfo.isPresent()) {
        jobClusterInfo.get().jobClusterActor.forward(request, getContext());
    } else {
        sender.tell(new UpdateJobClusterLabelsResponse(request.requestId, CLIENT_ERROR_NOT_FOUND, "JobCluster " + request.getClusterName() + " doesn't exist"), getSelf());
    }
}
Also used : ActorRef(akka.actor.ActorRef) UpdateJobClusterLabelsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse)

Example 3 with UpdateJobClusterLabelsResponse

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

the class JobClusterTest method testJobClusterLabelsUpdate.

@Test
public void testJobClusterLabelsUpdate() throws Exception {
    TestKit probe = new TestKit(system);
    String clusterName = "testJobClusterLabelsUpdate";
    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);
    // assert initially no labels
    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(0, resp3.getJobCluster().get().getLabels().size());
    // new labels
    List<Label> labels = Lists.newLinkedList();
    Label l = new Label("labelname", "labelvalue");
    labels.add(l);
    UpdateJobClusterLabelsRequest updateLabelsReq = new UpdateJobClusterLabelsRequest(clusterName, labels, "user");
    jobClusterActor.tell(updateLabelsReq, probe.getRef());
    UpdateJobClusterLabelsResponse resp = probe.expectMsgClass(UpdateJobClusterLabelsResponse.class);
    assertEquals(SUCCESS, resp.responseCode);
    assertEquals(jobClusterActor, probe.getLastSender());
    // get job cluster details
    jobClusterActor.tell(new GetJobClusterRequest(clusterName), probe.getRef());
    resp3 = probe.expectMsgClass(GetJobClusterResponse.class);
    assertEquals(SUCCESS, resp3.responseCode);
    assertTrue(resp3.getJobCluster() != null);
    assertEquals(clusterName, resp3.getJobCluster().get().getName());
    // assert label list is of size 1
    assertEquals(1, resp3.getJobCluster().get().getLabels().size());
    assertEquals(l, resp3.getJobCluster().get().getLabels().get(0));
    verify(jobStoreMock, times(1)).createJobCluster(any());
    verify(jobStoreMock, times(1)).updateJobCluster(any());
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) UpdateJobClusterLabelsRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest) 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) UpdateJobClusterLabelsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) GetJobClusterRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)3 UpdateJobClusterLabelsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse)3 TestKit (akka.testkit.javadsl.TestKit)1 SchedulerException (com.netflix.fenzo.triggers.exceptions.SchedulerException)1 TriggerNotFoundException (com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException)1 Label (io.mantisrx.common.Label)1 LifecycleEventsProto (io.mantisrx.master.events.LifecycleEventsProto)1 GetJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest)1 GetJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse)1 UpdateJobClusterLabelsRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsRequest)1 JobClusterProto (io.mantisrx.master.jobcluster.proto.JobClusterProto)1 JobClusterConfig (io.mantisrx.server.master.domain.JobClusterConfig)1 JobClusterDefinitionImpl (io.mantisrx.server.master.domain.JobClusterDefinitionImpl)1 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)1 JobClusterAlreadyExistsException (io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException)1 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1