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();
}
}
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();
}
}
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);
}
;
}
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);
}
Aggregations