use of io.mantisrx.server.master.store.MantisJobMetadata in project mantis by Netflix.
the class JobClusterProtoAdapter method toCompactJobInfo.
public static final CompactJobInfo toCompactJobInfo(final MantisJobMetadataView view) {
MantisJobMetadata jm = view.getJobMetadata();
int workers = 0;
double totCPUs = 0.0;
double totMem = 0.0;
Map<String, Integer> stSmry = new HashMap<>();
for (MantisStageMetadata s : view.getStageMetadataList()) {
workers += s.getNumWorkers();
totCPUs += s.getNumWorkers() * s.getMachineDefinition().getCpuCores();
totMem += s.getNumWorkers() * s.getMachineDefinition().getMemoryMB();
}
for (MantisWorkerMetadata w : view.getWorkerMetadataList()) {
final Integer prevVal = stSmry.get(w.getState() + "");
if (prevVal == null) {
stSmry.put(w.getState() + "", 1);
} else {
stSmry.put(w.getState() + "", prevVal + 1);
}
}
return new CompactJobInfo(jm.getJobId(), (jm.getJarUrl() != null) ? jm.getJarUrl().toString() : "", jm.getSubmittedAt(), jm.getUser(), jm.getState(), jm.getSla() != null ? jm.getSla().getDurationType() : MantisJobDurationType.Transient, jm.getNumStages(), workers, totCPUs, totMem, stSmry, jm.getLabels());
}
use of io.mantisrx.server.master.store.MantisJobMetadata in project mantis by Netflix.
the class DataFormatAdapterTest method convertMantisJobWriteableTest.
@Test
public void convertMantisJobWriteableTest() throws Exception {
String artifactName = "artifact";
String version = "1.0.0";
String clusterName = "myCluster";
List<Label> labels = new ArrayList<>();
Label label = new Label("myLable", "myVal");
labels.add(label);
List<Parameter> params = new ArrayList<>();
Parameter param = new Parameter("myparam", "myval");
params.add(param);
long subTimeout = 1000;
JobSla jobSla = new JobSla(100, 10, JobSla.StreamSLAType.Lossy, MantisJobDurationType.Perpetual, "userType");
JobDefinition jobDefn = new JobDefinition.Builder().withArtifactName(artifactName).withName(clusterName).withLabels(labels).withParameters(params).withSchedulingInfo(DEFAULT_SCHED_INFO).withUser("user").withJobSla(jobSla).withSubscriptionTimeoutSecs(subTimeout).withNumberOfStages(DEFAULT_SCHED_INFO.getStages().size()).build();
JobId jobId = new JobId(clusterName, 1);
long currTime = System.currentTimeMillis();
Instant startedAt = Instant.ofEpochMilli(currTime);
Instant endedAt = startedAt.plusSeconds(5);
Instant submittedAt = startedAt.minusSeconds(5);
IMantisJobMetadata jobmeta = new MantisJobMetadataImpl.Builder().withJobDefinition(jobDefn).withJobId(jobId).withNextWorkerNumToUse(2).withSubmittedAt(submittedAt).withJobState(JobState.Launched).build();
IMantisWorkerMetadata workerMetadata = new MantisWorkerMetadataImpl(0, 1, jobId.getId(), 1, 3, new WorkerPorts(Lists.newArrayList(8000, 9000, 9010, 9020, 9030)), WorkerState.Started, "slave", "slaveId", startedAt.toEpochMilli(), startedAt.toEpochMilli(), startedAt.toEpochMilli(), startedAt.toEpochMilli(), -1, JobCompletedReason.Normal, 0, 0, of("cluster"));
((MantisJobMetadataImpl) jobmeta).addJobStageIfAbsent(new MantisStageMetadataImpl.Builder().withNumStages(1).withStageNum(1).withNumWorkers(1).withJobId(jobId).withHardConstraints(Lists.newArrayList()).withSoftConstraints(Lists.newArrayList()).withMachineDefinition(DEFAULT_MACHINE_DEFINITION).build());
((MantisJobMetadataImpl) jobmeta).addWorkerMetadata(1, new JobWorker(workerMetadata, eventPublisher));
MantisJobMetadata oldFormat = DataFormatAdapter.convertMantisJobMetadataToMantisJobMetadataWriteable(jobmeta);
System.out.println("oldForamt -> " + oldFormat);
assertEquals(jobId.getId(), oldFormat.getJobId());
assertEquals(label, oldFormat.getLabels().get(0));
assertEquals(param, oldFormat.getParameters().get(0));
assertEquals(clusterName, oldFormat.getName());
assertEquals(jobSla, oldFormat.getSla());
assertEquals(1, oldFormat.getNumStages());
assertEquals(subTimeout, oldFormat.getSubscriptionTimeoutSecs());
assertEquals(2, oldFormat.getNextWorkerNumberToUse());
assertEquals("http://" + artifactName, oldFormat.getJarUrl().toString());
assertEquals(MantisJobState.Launched, oldFormat.getState());
assertEquals(submittedAt.toEpochMilli(), oldFormat.getSubmittedAt());
assertEquals("user", oldFormat.getUser());
IMantisJobMetadata reconverted = DataFormatAdapter.convertMantisJobWriteableToMantisJobMetadata(oldFormat, eventPublisher);
System.out.println("newForamt -> " + reconverted);
// assertEquals(jobmeta, reconverted);
// assertTrue(jobmeta.equals(reconverted));
assertEquals(jobmeta.getArtifactName(), reconverted.getArtifactName());
assertEquals(jobmeta.getClusterName(), reconverted.getClusterName());
System.out.println("expected Jobdef " + jobmeta.getJobDefinition());
System.out.println("actual Jobdef " + reconverted.getJobDefinition());
assertEquals(jobmeta.getJobDefinition(), reconverted.getJobDefinition());
assertEquals(jobmeta.getJobId(), reconverted.getJobId());
assertEquals(jobmeta.getJobJarUrl(), reconverted.getJobJarUrl());
assertEquals(jobmeta.getLabels().get(0), reconverted.getLabels().get(0));
assertEquals(jobmeta.getParameters().get(0), reconverted.getParameters().get(0));
assertEquals(jobmeta.getMinRuntimeSecs(), reconverted.getMinRuntimeSecs());
assertEquals(jobmeta.getNextWorkerNumberToUse(), reconverted.getNextWorkerNumberToUse());
assertEquals(jobmeta.getSla().get(), reconverted.getSla().get());
assertEquals(jobmeta.getSubmittedAtInstant(), reconverted.getSubmittedAtInstant());
assertEquals(jobmeta.getState(), reconverted.getState());
assertEquals(jobmeta.getSubscriptionTimeoutSecs(), reconverted.getSubscriptionTimeoutSecs());
assertEquals(jobmeta.getTotalStages(), reconverted.getTotalStages());
assertEquals(jobmeta.getUser(), reconverted.getUser());
// assertEquals(jobmeta.getSchedulingInfo(), reconverted.getSchedulingInfo());
}
Aggregations