Search in sources :

Example 1 with JobConstraints

use of io.mantisrx.runtime.JobConstraints in project mantis by Netflix.

the class JobDefinitionResolverTest method versionSchedPresentTest.

@Test
public void versionSchedPresentTest() {
    String clusterName = "versionSchedPresentTest";
    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.1";
    JobConstraints softConstraints = JobConstraints.ExclusiveHost;
    List<JobConstraints> constraintsList = new ArrayList<>();
    constraintsList.add(softConstraints);
    SchedulingInfo schedulingInfo = new SchedulingInfo.Builder().numberOfStages(1).singleWorkerStageWithConstraints(DEFAULT_MACHINE_DEFINITION, Lists.newArrayList(), constraintsList).build();
    try {
        JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).withSchedulingInfo(schedulingInfo).withVersion(version).build();
        JobDefinitionResolver resolver = new JobDefinitionResolver();
        JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
        // artifact will get populated using the given version.
        assertEquals(DEFAULT_ARTIFACT_NAME, resolvedJobDefinition.getArtifactName());
        // scheduling info will be the one specified by us
        assertEquals(schedulingInfo, resolvedJobDefinition.getSchedulingInfo());
        // version should match what we set.
        assertEquals(version, resolvedJobDefinition.getVersion());
        // assert the parameters and labels are inherited since they were not specified
        assertEquals(1, resolvedJobDefinition.getLabels().size());
        assertEquals(label, resolvedJobDefinition.getLabels().get(0));
        assertEquals(1, resolvedJobDefinition.getParameters().size());
        assertEquals(parameter, resolvedJobDefinition.getParameters().get(0));
    } catch (InvalidJobException e) {
        e.printStackTrace();
        fail();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // Only version is specified
    try {
        JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).withVersion(version).build();
        JobDefinitionResolver resolver = new JobDefinitionResolver();
        JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
        // assert the artifact is inherited
        assertEquals(DEFAULT_ARTIFACT_NAME, resolvedJobDefinition.getArtifactName());
        // assert the scheduling info is inherited
        assertEquals(SINGLE_WORKER_SCHED_INFO, resolvedJobDefinition.getSchedulingInfo());
        // assert a version is the one we gave
        assertEquals(version, resolvedJobDefinition.getVersion());
        // assert the parameters and labels are inherited since they were not specified
        assertEquals(1, resolvedJobDefinition.getLabels().size());
        assertEquals(label, resolvedJobDefinition.getLabels().get(0));
        assertEquals(1, resolvedJobDefinition.getParameters().size());
        assertEquals(parameter, resolvedJobDefinition.getParameters().get(0));
    } catch (InvalidJobException e) {
        e.printStackTrace();
        fail();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) JobConstraints(io.mantisrx.runtime.JobConstraints) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) Parameter(io.mantisrx.runtime.parameter.Parameter) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) Test(org.junit.Test)

Example 2 with JobConstraints

use of io.mantisrx.runtime.JobConstraints in project mantis by Netflix.

the class JobDefinitionResolverTest method SchedPresentTest.

@Test
public void SchedPresentTest() {
    String clusterName = "SchedPresentTest";
    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);
    JobConstraints softConstraints = JobConstraints.ExclusiveHost;
    List<JobConstraints> constraintsList = new ArrayList<>();
    constraintsList.add(softConstraints);
    SchedulingInfo schedulingInfo = new SchedulingInfo.Builder().numberOfStages(1).singleWorkerStageWithConstraints(DEFAULT_MACHINE_DEFINITION, Lists.newArrayList(), constraintsList).build();
    try {
        // only sched info set.
        JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).withSchedulingInfo(schedulingInfo).build();
        JobDefinitionResolver resolver = new JobDefinitionResolver();
        JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
        // artifact will get populated using the given version.
        assertEquals(DEFAULT_ARTIFACT_NAME, resolvedJobDefinition.getArtifactName());
        // scheduling info will be the one specified by us
        assertEquals(schedulingInfo, resolvedJobDefinition.getSchedulingInfo());
        // version should match the latest on the cluster
        assertEquals(DEFAULT_VERSION, resolvedJobDefinition.getVersion());
        // assert the parameters and labels are inherited since they were not specified
        assertEquals(1, resolvedJobDefinition.getLabels().size());
        assertEquals(label, resolvedJobDefinition.getLabels().get(0));
        assertEquals(1, resolvedJobDefinition.getParameters().size());
        assertEquals(parameter, resolvedJobDefinition.getParameters().get(0));
    } catch (InvalidJobException e) {
        e.printStackTrace();
        fail();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // NOTHING is specified
    try {
        JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).build();
        JobDefinitionResolver resolver = new JobDefinitionResolver();
        JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
        // assert the artifact is inherited
        assertEquals(DEFAULT_ARTIFACT_NAME, resolvedJobDefinition.getArtifactName());
        // assert the scheduling info is inherited
        assertEquals(SINGLE_WORKER_SCHED_INFO, resolvedJobDefinition.getSchedulingInfo());
        // assert a version is the dfeault one.
        assertEquals(DEFAULT_VERSION, resolvedJobDefinition.getVersion());
        // assert the parameters and labels are inherited since they were not specified
        assertEquals(1, resolvedJobDefinition.getLabels().size());
        assertEquals(label, resolvedJobDefinition.getLabels().get(0));
        assertEquals(1, resolvedJobDefinition.getParameters().size());
        assertEquals(parameter, resolvedJobDefinition.getParameters().get(0));
    } catch (InvalidJobException e) {
        e.printStackTrace();
        fail();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
    // NOTHING is specified2
    try {
        JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).withVersion("null").build();
        JobDefinitionResolver resolver = new JobDefinitionResolver();
        JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
        // assert the artifact is inherited
        assertEquals(DEFAULT_ARTIFACT_NAME, resolvedJobDefinition.getArtifactName());
        // assert the scheduling info is inherited
        assertEquals(SINGLE_WORKER_SCHED_INFO, resolvedJobDefinition.getSchedulingInfo());
        // assert a version is the dfeault one.
        assertEquals(DEFAULT_VERSION, resolvedJobDefinition.getVersion());
        // assert the parameters and labels are inherited since they were not specified
        assertEquals(1, resolvedJobDefinition.getLabels().size());
        assertEquals(label, resolvedJobDefinition.getLabels().get(0));
        assertEquals(1, resolvedJobDefinition.getParameters().size());
        assertEquals(parameter, resolvedJobDefinition.getParameters().get(0));
    } catch (InvalidJobException e) {
        e.printStackTrace();
        fail();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : SchedulingInfo(io.mantisrx.runtime.descriptor.SchedulingInfo) Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) JobConstraints(io.mantisrx.runtime.JobConstraints) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) Parameter(io.mantisrx.runtime.parameter.Parameter) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) Test(org.junit.Test)

Example 3 with JobConstraints

use of io.mantisrx.runtime.JobConstraints in project mantis by Netflix.

the class JobClusterActor method validateJobDefinition.

/**
 * @param definition Job Definition to be validated
 * @throws InvalidJobRequest If the job definition is invalid
 */
private void validateJobDefinition(JobDefinition definition) throws InvalidJobRequest {
    if (definition == null) {
        throw new InvalidJobRequest(null, "MantisJobDefinition cannot be null");
    }
    if (definition.getArtifactName() == null) {
        throw new InvalidJobRequest(null, "MantisJobDefinition job artifactName attribute cannot be null");
    }
    if (definition.getName() == null) {
        throw new InvalidJobRequest(null, "MantisJobDefinition name attribute cannot be null");
    }
    if (definition.getSchedulingInfo() == null) {
        throw new InvalidJobRequest(null, "MantisJobDefinition schedulingInfo cannot be null");
    }
    for (StageSchedulingInfo ssi : definition.getSchedulingInfo().getStages().values()) {
        List<JobConstraints> hardConstraints = ssi.getHardConstraints();
        List<JobConstraints> softConstraints = ssi.getSoftConstraints();
        validateConstraints(softConstraints, hardConstraints);
    }
    ;
}
Also used : StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) JobConstraints(io.mantisrx.runtime.JobConstraints) InvalidJobRequest(io.mantisrx.server.master.InvalidJobRequest)

Example 4 with JobConstraints

use of io.mantisrx.runtime.JobConstraints in project mantis by Netflix.

the class DataFormatAdapterTest method convertMantisStageMetaTest.

@Test
public void convertMantisStageMetaTest() {
    Map<StageScalingPolicy.ScalingReason, StageScalingPolicy.Strategy> smap = new HashMap<>();
    smap.put(StageScalingPolicy.ScalingReason.CPU, new StageScalingPolicy.Strategy(StageScalingPolicy.ScalingReason.CPU, 0.5, 0.75, null));
    smap.put(StageScalingPolicy.ScalingReason.DataDrop, new StageScalingPolicy.Strategy(StageScalingPolicy.ScalingReason.DataDrop, 0.0, 2.0, null));
    int stageNo = 1;
    int min = 3;
    int max = 10;
    int increment = 1;
    int decrement = 1;
    int coolDownSecs = 300;
    StageScalingPolicy stageScalingPolicy = new StageScalingPolicy(stageNo, min, max, increment, decrement, coolDownSecs, smap);
    List<JobConstraints> softConstraintsList = new ArrayList<>();
    softConstraintsList.add(JobConstraints.ExclusiveHost);
    List<JobConstraints> hardConstraintsList = new ArrayList<>();
    hardConstraintsList.add(JobConstraints.M3Cluster);
    JobId jobId = new JobId("cName", 1);
    int numWorkers = 1;
    int numStages = 2;
    boolean isScalable = true;
    IMantisStageMetadata stageMeta = new MantisStageMetadataImpl.Builder().withStageNum(stageNo).withScalingPolicy(stageScalingPolicy).withNumWorkers(numWorkers).withMachineDefinition(DEFAULT_MACHINE_DEFINITION).withNumStages(numStages).withSoftConstraints(softConstraintsList).withHardConstraints(hardConstraintsList).withJobId(jobId).isScalable(isScalable).build();
    MantisStageMetadataWritable stageMetadataWritable = DataFormatAdapter.convertMantisStageMetadataToMantisStageMetadataWriteable(stageMeta);
    assertEquals(jobId.getId(), stageMetadataWritable.getJobId());
    assertEquals(JobConstraints.M3Cluster, stageMetadataWritable.getHardConstraints().get(0));
    assertEquals(JobConstraints.ExclusiveHost, stageMetadataWritable.getSoftConstraints().get(0));
    assertEquals(stageScalingPolicy, stageMetadataWritable.getScalingPolicy());
    assertTrue(stageMetadataWritable.getScalable());
    assertEquals(DEFAULT_MACHINE_DEFINITION, stageMetadataWritable.getMachineDefinition());
    assertEquals(numWorkers, stageMetadataWritable.getNumWorkers());
    assertEquals(numStages, stageMetadataWritable.getNumStages());
    assertEquals(stageNo, stageMetadataWritable.getStageNum());
    IMantisStageMetadata reconverted = DataFormatAdapter.convertMantisStageMetadataWriteableToMantisStageMetadata(stageMetadataWritable, eventPublisher);
    assertEquals(stageMeta, reconverted);
}
Also used : HashMap(java.util.HashMap) MantisStageMetadataWritable(io.mantisrx.server.master.store.MantisStageMetadataWritable) ArrayList(java.util.ArrayList) JobConstraints(io.mantisrx.runtime.JobConstraints) StageScalingPolicy(io.mantisrx.runtime.descriptor.StageScalingPolicy) IMantisStageMetadata(io.mantisrx.master.jobcluster.job.IMantisStageMetadata) Test(org.junit.Test)

Aggregations

JobConstraints (io.mantisrx.runtime.JobConstraints)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Label (io.mantisrx.common.Label)2 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)2 SchedulingInfo (io.mantisrx.runtime.descriptor.SchedulingInfo)2 Parameter (io.mantisrx.runtime.parameter.Parameter)2 JobClusterDefinitionImpl (io.mantisrx.server.master.domain.JobClusterDefinitionImpl)2 JobDefinition (io.mantisrx.server.master.domain.JobDefinition)2 IMantisStageMetadata (io.mantisrx.master.jobcluster.job.IMantisStageMetadata)1 StageScalingPolicy (io.mantisrx.runtime.descriptor.StageScalingPolicy)1 StageSchedulingInfo (io.mantisrx.runtime.descriptor.StageSchedulingInfo)1 InvalidJobRequest (io.mantisrx.server.master.InvalidJobRequest)1 MantisStageMetadataWritable (io.mantisrx.server.master.store.MantisStageMetadataWritable)1 HashMap (java.util.HashMap)1