Search in sources :

Example 1 with MantisJobMetadata

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());
}
Also used : MantisJobMetadata(io.mantisrx.server.master.store.MantisJobMetadata) MantisWorkerMetadata(io.mantisrx.server.master.store.MantisWorkerMetadata) HashMap(java.util.HashMap) CompactJobInfo(io.mantisrx.server.master.http.api.CompactJobInfo) MantisStageMetadata(io.mantisrx.server.master.store.MantisStageMetadata)

Example 2 with MantisJobMetadata

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());
}
Also used : MantisStageMetadataImpl(io.mantisrx.master.jobcluster.job.MantisStageMetadataImpl) Instant(java.time.Instant) Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) JobWorker(io.mantisrx.master.jobcluster.job.worker.JobWorker) MantisJobMetadata(io.mantisrx.server.master.store.MantisJobMetadata) IMantisJobMetadata(io.mantisrx.master.jobcluster.job.IMantisJobMetadata) WorkerPorts(io.mantisrx.common.WorkerPorts) Parameter(io.mantisrx.runtime.parameter.Parameter) IMantisWorkerMetadata(io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata) JobSla(io.mantisrx.runtime.JobSla) MantisJobMetadataImpl(io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl) NamedJobDefinition(io.mantisrx.runtime.NamedJobDefinition) MantisWorkerMetadataImpl(io.mantisrx.master.jobcluster.job.worker.MantisWorkerMetadataImpl) Test(org.junit.Test)

Aggregations

MantisJobMetadata (io.mantisrx.server.master.store.MantisJobMetadata)2 Label (io.mantisrx.common.Label)1 WorkerPorts (io.mantisrx.common.WorkerPorts)1 IMantisJobMetadata (io.mantisrx.master.jobcluster.job.IMantisJobMetadata)1 MantisJobMetadataImpl (io.mantisrx.master.jobcluster.job.MantisJobMetadataImpl)1 MantisStageMetadataImpl (io.mantisrx.master.jobcluster.job.MantisStageMetadataImpl)1 IMantisWorkerMetadata (io.mantisrx.master.jobcluster.job.worker.IMantisWorkerMetadata)1 JobWorker (io.mantisrx.master.jobcluster.job.worker.JobWorker)1 MantisWorkerMetadataImpl (io.mantisrx.master.jobcluster.job.worker.MantisWorkerMetadataImpl)1 JobSla (io.mantisrx.runtime.JobSla)1 NamedJobDefinition (io.mantisrx.runtime.NamedJobDefinition)1 Parameter (io.mantisrx.runtime.parameter.Parameter)1 CompactJobInfo (io.mantisrx.server.master.http.api.CompactJobInfo)1 MantisStageMetadata (io.mantisrx.server.master.store.MantisStageMetadata)1 MantisWorkerMetadata (io.mantisrx.server.master.store.MantisWorkerMetadata)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1