Search in sources :

Example 1 with JobDefinition

use of io.mantisrx.server.master.domain.JobDefinition 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 2 with JobDefinition

use of io.mantisrx.server.master.domain.JobDefinition 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 3 with JobDefinition

use of io.mantisrx.server.master.domain.JobDefinition in project mantis by Netflix.

the class TestHelpers method createFakeScheduleRequest.

public static ScheduleRequest createFakeScheduleRequest(final WorkerId workerId, final int stageNum, final int numStages, final MachineDefinition machineDefinition) {
    try {
        JobDefinition jobDefinition = new JobDefinition.Builder().withArtifactName("jar").withSchedulingInfo(new SchedulingInfo(Collections.singletonMap(0, StageSchedulingInfo.builder().numberOfInstances(1).machineDefinition(machineDefinition).hardConstraints(Collections.emptyList()).softConstraints(Collections.emptyList()).build()))).withJobSla(new JobSla(0, 0, null, MantisJobDurationType.Perpetual, null)).build();
        IMantisJobMetadata mantisJobMetadata = new MantisJobMetadataImpl.Builder().withJobId(JobId.fromId(workerId.getJobId()).get()).withJobDefinition(jobDefinition).build();
        return new ScheduleRequest(workerId, stageNum, numStages, new JobMetadata(mantisJobMetadata.getJobId().getId(), mantisJobMetadata.getJobJarUrl(), mantisJobMetadata.getTotalStages(), mantisJobMetadata.getUser(), mantisJobMetadata.getSchedulingInfo(), mantisJobMetadata.getParameters(), mantisJobMetadata.getSubscriptionTimeoutSecs(), mantisJobMetadata.getMinRuntimeSecs()), mantisJobMetadata.getSla().get().getDurationType(), machineDefinition, Collections.emptyList(), Collections.emptyList(), 0, Optional.empty());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : JobMetadata(io.mantisrx.server.core.domain.JobMetadata) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) ScheduleRequest(io.mantisrx.server.master.scheduler.ScheduleRequest) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) JobSla(io.mantisrx.runtime.JobSla) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) JobDefinition(io.mantisrx.server.master.domain.JobDefinition)

Example 4 with JobDefinition

use of io.mantisrx.server.master.domain.JobDefinition 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 5 with JobDefinition

use of io.mantisrx.server.master.domain.JobDefinition in project mantis by Netflix.

the class JobClusterActor method getResolvedJobDefinition.

/**
 * Two cases
 * 1. JobDefinition provided by user: In this case check if labels / parameters or schedulingInfo was not provided
 * if that is the case inherit from the Cluster
 * 2. If JobDefinition is not provided, find the last submitted job and use its config (quick submit)
 * @param user submitter
 * @param givenJobDefnOp job defn provided by user in job submit
 * @return job definition to be used by the actual submit
 * @throws Exception If jobDefinition could not be resolved
 */
private JobDefinition getResolvedJobDefinition(final String user, final Optional<JobDefinition> givenJobDefnOp) throws Exception {
    JobDefinition resolvedJobDefn;
    if (givenJobDefnOp.isPresent()) {
        if (givenJobDefnOp.get().getSchedulingInfo() != null && givenJobDefnOp.get().requireInheritInstanceCheck()) {
            logger.warn("Job requires inheriting instance count but has no active non-terminal job.");
        }
        resolvedJobDefn = givenJobDefnOp.get();
    } else {
        // no job definition specified , this is quick submit which is supposed to inherit from last job submitted
        // for request inheriting from non-terminal jobs, it has been sent to job actor instead.
        Optional<JobDefinition> jobDefnOp = cloneJobDefinitionForQuickSubmitFromArchivedJobs(jobManager.getCompletedJobsList(), empty(), jobStore);
        if (jobDefnOp.isPresent()) {
            logger.info("Inherited scheduling Info and parameters from previous job");
            resolvedJobDefn = jobDefnOp.get();
        } else if (this.jobClusterMetadata != null && this.jobClusterMetadata.getJobClusterDefinition() != null && this.jobClusterMetadata.getJobClusterDefinition().getJobClusterConfig() != null) {
            logger.info("No previous job definition found. Fall back to cluster definition: {}", this.name);
            IJobClusterDefinition clusterDefinition = this.jobClusterMetadata.getJobClusterDefinition();
            JobClusterConfig clusterConfig = this.jobClusterMetadata.getJobClusterDefinition().getJobClusterConfig();
            resolvedJobDefn = new JobDefinition.Builder().withJobSla(new JobSla.Builder().build()).withArtifactName(clusterConfig.getArtifactName()).withVersion(clusterConfig.getVersion()).withLabels(clusterDefinition.getLabels()).withName(this.name).withParameters(clusterDefinition.getParameters()).withSchedulingInfo(clusterConfig.getSchedulingInfo()).withUser(user).build();
            logger.info("Built job definition from cluster definition: {}", resolvedJobDefn);
        } else {
            throw new Exception("Job Definition could not retrieved from a previous submission (There may " + "not be a previous submission)");
        }
    }
    logger.info("Resolved JobDefn {}", resolvedJobDefn);
    return this.jobDefinitionResolver.getResolvedJobDefinition(user, resolvedJobDefn, this.jobClusterMetadata);
}
Also used : IJobClusterDefinition(io.mantisrx.server.master.domain.IJobClusterDefinition) JobClusterConfig(io.mantisrx.server.master.domain.JobClusterConfig) 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)

Aggregations

JobDefinition (io.mantisrx.server.master.domain.JobDefinition)42 Test (org.junit.Test)31 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)25 JobClusterManagerProto (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)18 TestKit (akka.testkit.javadsl.TestKit)17 JobId (io.mantisrx.server.master.domain.JobId)17 Label (io.mantisrx.common.Label)15 ActorRef (akka.actor.ActorRef)14 IJobClusterDefinition (io.mantisrx.server.master.domain.IJobClusterDefinition)14 SchedulingInfo (io.mantisrx.runtime.descriptor.SchedulingInfo)13 ArrayList (java.util.ArrayList)13 MantisJobStore (io.mantisrx.server.master.persistence.MantisJobStore)12 JobProto (io.mantisrx.master.jobcluster.proto.JobProto)11 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)11 IOException (java.io.IOException)11 WorkerId (io.mantisrx.server.core.domain.WorkerId)10 GetJobDetailsResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobDetailsResponse)9 JobClusterDefinitionImpl (io.mantisrx.server.master.domain.JobClusterDefinitionImpl)9 StageSchedulingInfo (io.mantisrx.runtime.descriptor.StageSchedulingInfo)8 MachineDefinition (io.mantisrx.runtime.MachineDefinition)7