Search in sources :

Example 1 with SubmitJobResponse

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

the class JobClusterActor method onGetJobDefinitionUpdatedFromJobActorResponse.

public void onGetJobDefinitionUpdatedFromJobActorResponse(GetJobDefinitionUpdatedFromJobActorResponse request) {
    logger.info("Resuming job submission from job actor");
    // this request is returned by job actor but the response needs to be replied to the original job request sender (from API routes).
    ActorRef originalSender = request.getOriginalSender();
    if (request.responseCode == SERVER_ERROR || request.getJobDefinition() == null) {
        logger.error("Failed to retrieve job definition from job actor");
        numJobSubmissionFailures.increment();
        originalSender.tell(new SubmitJobResponse(request.requestId, SERVER_ERROR, request.message, empty()), getSelf());
        return;
    }
    try {
        JobDefinition resolvedJobDefn = request.getJobDefinition();
        // for quick submit the artifact version/name needs to be reset using the fork method below.
        if (request.isQuickSubmitMode()) {
            Optional<JobDefinition> jobDefinitionCloneO = cloneToNewJobDefinitionWithoutArtifactNameAndVersion(request.getJobDefinition());
            if (jobDefinitionCloneO.isPresent()) {
                resolvedJobDefn = jobDefinitionCloneO.get();
            }
        }
        resolvedJobDefn = this.jobDefinitionResolver.getResolvedJobDefinition(request.getUser(), resolvedJobDefn, this.jobClusterMetadata);
        eventPublisher.publishStatusEvent(new LifecycleEventsProto.JobClusterStatusEvent(LifecycleEventsProto.StatusEvent.StatusEventType.INFO, "Job submit request received", jobClusterMetadata.getJobClusterDefinition().getName()));
        resolvedJobDefn = LabelManager.insertSystemLabels(resolvedJobDefn, request.isAutoResubmit());
        submitJob(resolvedJobDefn, originalSender, request.getUser());
        numJobSubmissions.increment();
    } catch (PersistException pe) {
        logger.error("Exception submitting job {} from {}", this.name, request.getUser(), pe);
        numJobSubmissionFailures.increment();
        originalSender.tell(new SubmitJobResponse(request.requestId, SERVER_ERROR, pe.getMessage(), empty()), getSelf());
    } catch (Exception e) {
        logger.error("Exception submitting job {} from {}", this.name, request.getUser(), e);
        numJobSubmissionFailures.increment();
        originalSender.tell(new SubmitJobResponse(request.requestId, CLIENT_ERROR, e.getMessage(), empty()), getSelf());
    }
}
Also used : ActorRef(akka.actor.ActorRef) SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) 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 SubmitJobResponse

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

the class JobClusterActor method onJobSubmit.

@Override
public void onJobSubmit(final SubmitJobRequest request) {
    final ActorRef sender = getSender();
    // if the job is submitted with a userDefinedType check to see if such a job is already running. If so just reply with a reference to it.
    if (request.getJobDefinition().isPresent()) {
        String uniq = request.getJobDefinition().get().getJobSla().getUserProvidedType();
        if (uniq != null && !uniq.isEmpty()) {
            Optional<JobInfo> existingJob = jobManager.getJobInfoByUniqueId(uniq);
            if (existingJob.isPresent()) {
                logger.info("Job with unique {} already exists, returning its job Id {}", uniq, existingJob.get().jobId);
                sender.tell(new SubmitJobResponse(request.requestId, SUCCESS, existingJob.get().jobId.getId(), of(existingJob.get().jobId)), getSelf());
                return;
            }
        }
    }
    logger.info("Submitting job {}", request);
    try {
        if (requireJobActorProcess(request)) {
            logger.info("Sending job submit request to job actor for inheritance: {}", request.requestId);
            return;
        }
        JobDefinition resolvedJobDefn = getResolvedJobDefinition(request.getSubmitter(), request.getJobDefinition());
        eventPublisher.publishStatusEvent(new LifecycleEventsProto.JobClusterStatusEvent(LifecycleEventsProto.StatusEvent.StatusEventType.INFO, "Job submit request received", jobClusterMetadata.getJobClusterDefinition().getName()));
        resolvedJobDefn = LabelManager.insertSystemLabels(resolvedJobDefn, request.isAutoResubmit());
        submitJob(resolvedJobDefn, sender, request.getSubmitter());
        numJobSubmissions.increment();
    } catch (PersistException pe) {
        logger.error("Exception submitting job {} from {}", request.getClusterName(), request.getSubmitter(), pe);
        numJobSubmissionFailures.increment();
        sender.tell(new SubmitJobResponse(request.requestId, SERVER_ERROR, pe.getMessage(), empty()), getSelf());
    } catch (Exception e) {
        logger.error("Exception submitting job {} from {}", request.getClusterName(), request.getSubmitter(), e);
        numJobSubmissionFailures.increment();
        sender.tell(new SubmitJobResponse(request.requestId, CLIENT_ERROR, e.getMessage(), empty()), getSelf());
    }
}
Also used : ActorRef(akka.actor.ActorRef) SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) TriggerNotFoundException(com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException) SchedulerException(com.netflix.fenzo.triggers.exceptions.SchedulerException) JobClusterAlreadyExistsException(io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException)

Example 3 with SubmitJobResponse

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

the class JobClusterTest method testJobSubmitFails.

@Test
public void testJobSubmitFails() {
    TestKit probe = new TestKit(system);
    try {
        String clusterName = "testJobSubmitFails";
        MantisScheduler schedulerMock = mock(MantisScheduler.class);
        MantisJobStore jobStoreMock = mock(MantisJobStore.class);
        final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName);
        Mockito.doThrow(Exception.class).when(jobStoreMock).storeNewJob(any());
        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);
        final JobDefinition jobDefn = createJob(clusterName, 1, MantisJobDurationType.Transient);
        String jobId = clusterName + "-1";
        jobClusterActor.tell(new SubmitJobRequest(clusterName, "user", Optional.ofNullable(jobDefn)), probe.getRef());
        SubmitJobResponse submitResponse = probe.expectMsgClass(SubmitJobResponse.class);
        assertEquals(SERVER_ERROR, submitResponse.responseCode);
        verify(jobStoreMock, times(1)).createJobCluster(any());
        verify(jobStoreMock, times(1)).updateJobCluster(any());
        verify(jobStoreMock, times(0)).storeNewWorker(any());
        verify(jobStoreMock, times(0)).storeNewWorkers(any(), any());
    } catch (Exception e) {
        fail();
    }
}
Also used : JobClusterProto(io.mantisrx.master.jobcluster.proto.JobClusterProto) ActorRef(akka.actor.ActorRef) SubmitJobRequest(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobRequest) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) TestKit(akka.testkit.javadsl.TestKit) Matchers.anyString(org.mockito.Matchers.anyString) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse) Test(org.junit.Test)

Example 4 with SubmitJobResponse

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

the class JobClustersManagerActor method onJobSubmit.

// ////////////////// JOB OPERATIONS ////////////////////////////////////////////////
@Override
public void onJobSubmit(final SubmitJobRequest request) {
    logger.info("Submitting job " + request);
    Optional<JobClusterInfo> jobClusterInfo = jobClusterInfoManager.getJobClusterInfo(request.getClusterName());
    ActorRef sender = getSender();
    if (jobClusterInfo.isPresent()) {
        jobClusterInfo.get().jobClusterActor.forward(request, getContext());
    } else {
        sender.tell(new SubmitJobResponse(request.requestId, CLIENT_ERROR_NOT_FOUND, "Job Cluster " + request.getClusterName() + " doesn't exist", empty()), getSelf());
    }
}
Also used : ActorRef(akka.actor.ActorRef) SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse)

Example 5 with SubmitJobResponse

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

the class JobClusterActor method onJobInitialized.

@Override
public void onJobInitialized(JobProto.JobInitialized jobInited) {
    if (logger.isTraceEnabled()) {
        logger.trace("Enter onJobInitialized");
    }
    jobManager.markJobInitialized(jobInited.jobId, System.currentTimeMillis());
    if (jobInited.responseCode == SUCCESS) {
        jobInited.requestor.tell(new SubmitJobResponse(jobInited.requestId, SUCCESS, jobInited.jobId.getId(), of(jobInited.jobId)), getSelf());
        numJobsInitialized.increment();
    } else {
        logger.warn("Job was not initialized {}", jobInited);
        Optional<JobInfo> jobInfo = jobManager.getJobInfoForNonTerminalJob(jobInited.jobId);
        if (jobInfo.isPresent()) {
            cleanUpOnJobSubmitFailure(jobInfo.get().jobId);
            // if this is not a cron submission inform the caller
            if (jobInited.requestor != null)
                jobInited.requestor.tell(new SubmitJobResponse(jobInited.requestId, jobInited.responseCode, "Job " + jobInited.jobId + " submission failed", ofNullable(jobInited.jobId)), getSelf());
        } else {
            logger.warn("No such job found {}", jobInited.jobId);
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Exit onJobInitialized");
    }
}
Also used : SubmitJobResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse)

Aggregations

SubmitJobResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobResponse)8 ActorRef (akka.actor.ActorRef)7 TestKit (akka.testkit.javadsl.TestKit)4 SubmitJobRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.SubmitJobRequest)4 JobClusterProto (io.mantisrx.master.jobcluster.proto.JobClusterProto)4 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)4 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)4 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)4 Test (org.junit.Test)4 Matchers.anyString (org.mockito.Matchers.anyString)4 WorkerId (io.mantisrx.server.core.domain.WorkerId)3 SchedulerException (com.netflix.fenzo.triggers.exceptions.SchedulerException)2 TriggerNotFoundException (com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException)2 LifecycleEventsProto (io.mantisrx.master.events.LifecycleEventsProto)2 JobDefinition (io.mantisrx.server.master.domain.JobDefinition)2 JobClusterAlreadyExistsException (io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException)2 GetJobDetailsRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsRequest)1 GetJobDetailsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse)1 ScaleStageRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageRequest)1 ScaleStageResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.ScaleStageResponse)1