@Test public void oldMantisWorkerMetadataReadTest() throws IOException { ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module()); final String oldWorkerMetadataWriteableStr = "{\n" + " \"workerIndex\": 0,\n" + " \"workerNumber\": 1,\n" + " \"jobId\": \"cname-1\",\n" + " \"stageNum\": 1,\n" + " \"numberOfPorts\": 3,\n" + " \"metricsPort\": 1,\n" + " \"consolePort\": 3,\n" + " \"debugPort\": 2,\n" + " \"customPort\": 5,\n" + " \"ports\": [4],\n" + " \"state\": \"Completed\",\n" + " \"slave\": \"slave1\",\n" + " \"slaveID\": \"slaveId1\",\n" + " \"cluster\": \"prefCluster\",\n" + " \"acceptedAt\": 999,\n" + " \"launchedAt\": 1000,\n" + " \"startingAt\": 1234,\n" + " \"startedAt\": 1001,\n" + " \"completedAt\": 2000,\n" + " \"reason\": \"Normal\",\n" + " \"resubmitOf\": 42,\n" + " \"totalResubmitCount\": 1\n" + "}"; MantisWorkerMetadataWritable oldMetadataWritable = mapper.readValue(oldWorkerMetadataWriteableStr, MantisWorkerMetadataWritable.class); Optional<String> prefCluster = of("prefCluster"); int metricsPort = 1; int debugPort = 2; int consolePort = 3; int customPort = 5; int ssePort = 4; List<Integer> ports = Lists.newArrayList(); ports.add(metricsPort); ports.add(debugPort); ports.add(consolePort); ports.add(customPort); ports.add(ssePort); WorkerPorts workerPorts = new WorkerPorts(ports); int workerNum = 1; int workerIndex = 0; long startingAt = 1234l; int stageNum = 1; String slaveid = "slaveId1"; String slave = "slave1"; int resubmitCnt = 1; int portNums = ports.size(); long launchedAt = 1000l; JobId jobId = new JobId("cname", 1); long acceptedAt = 999l; long completedAt = 2000l; long startedAt = 1001l; int resubOf = 42; JobWorker worker = new JobWorker.Builder() .withPreferredCluster(prefCluster) .withJobCompletedReason(JobCompletedReason.Normal) .withWorkerPorts(workerPorts) .withWorkerNumber(workerNum) .withWorkerIndex(workerIndex) .withState(WorkerState.Completed) .withStartingAt(startingAt) .withStartedAt(startedAt) .withCompletedAt(completedAt) .withStageNum(stageNum) .withSlaveID(slaveid) .withSlave(slave) .withResubmitCount(resubmitCnt) .withResubmitOf(resubOf) .withNumberOfPorts(portNums) .withLaunchedAt(launchedAt) .withJobId(jobId) .withAcceptedAt(acceptedAt) .withLifecycleEventsPublisher(eventPublisher) .build(); IMantisWorkerMetadata expectedWorkerMeta = worker.getMetadata(); assertEquals(prefCluster,oldMetadataWritable.getCluster()); assertEquals(workerIndex, oldMetadataWritable.getWorkerIndex()); assertEquals(workerNum, oldMetadataWritable.getWorkerNumber()); assertEquals(jobId.getId(),oldMetadataWritable.getJobId()); assertEquals(acceptedAt,oldMetadataWritable.getAcceptedAt()); assertEquals(startingAt,oldMetadataWritable.getStartingAt()); assertEquals(startedAt, oldMetadataWritable.getStartedAt()); assertEquals(launchedAt, oldMetadataWritable.getLaunchedAt()); assertEquals(completedAt, oldMetadataWritable.getCompletedAt()); assertEquals(stageNum, oldMetadataWritable.getStageNum()); assertEquals(slave, oldMetadataWritable.getSlave()); assertEquals(slaveid, oldMetadataWritable.getSlaveID()); assertEquals(metricsPort, oldMetadataWritable.getMetricsPort()); assertEquals(consolePort, oldMetadataWritable.getConsolePort()); assertEquals(debugPort, oldMetadataWritable.getDebugPort()); assertEquals(5, oldMetadataWritable.getCustomPort()); assertEquals(MantisJobState.Completed, oldMetadataWritable.getState()); assertEquals(resubmitCnt, oldMetadataWritable.getTotalResubmitCount()); assertEquals(resubOf, oldMetadataWritable.getResubmitOf()); assertEquals(3, oldMetadataWritable.getNumberOfPorts()); assertEquals(1, oldMetadataWritable.getPorts().size()); assertEquals(ssePort, (long)oldMetadataWritable.getPorts().get(0)); assertEquals(JobCompletedReason.Normal, oldMetadataWritable.getReason()); JobWorker convertedMetadata = DataFormatAdapter.convertMantisWorkerMetadataWriteableToMantisWorkerMetadata(oldMetadataWritable, eventPublisher); assertEquals(expectedWorkerMeta, convertedMetadata.getMetadata()); }
public static JobWorker convertMantisWorkerMetadataWriteableToMantisWorkerMetadata(MantisWorkerMetadata writeable, LifecycleEventPublisher eventPublisher) { if(logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converting worker {}", writeable); } String jobId = writeable.getJobId(); List<Integer> ports = new ArrayList<>(writeable.getNumberOfPorts()); ports.add(writeable.getMetricsPort()); ports.add(writeable.getDebugPort()); ports.add(writeable.getConsolePort()); ports.add(writeable.getCustomPort()); if(writeable.getPorts().size() > 0) { ports.add(writeable.getPorts().get(0)); } WorkerPorts workerPorts = null; try { workerPorts = new WorkerPorts(ports); } catch (IllegalArgumentException | IllegalStateException e) { logger.warn("problem loading worker {} for Job ID {}", writeable.getWorkerId(), jobId, e); } JobWorker converted = new JobWorker.Builder() .withJobId(jobId) .withAcceptedAt(writeable.getAcceptedAt()) .withLaunchedAt(writeable.getLaunchedAt()) .withStartingAt(writeable.getStartingAt()) .withStartedAt(writeable.getStartedAt()) .withCompletedAt(writeable.getCompletedAt()) .withNumberOfPorts(ports.size()) .withWorkerPorts(workerPorts) .withResubmitCount(writeable.getTotalResubmitCount()) .withResubmitOf(writeable.getResubmitOf()) .withSlave(writeable.getSlave()) .withSlaveID(writeable.getSlaveID()) .withStageNum(writeable.getStageNum()) .withState(convertMantisJobStateToWorkerState(writeable.getState())) .withWorkerIndex(writeable.getWorkerIndex()) .withWorkerNumber(writeable.getWorkerNumber()) .withJobCompletedReason(writeable.getReason()) .withPreferredCluster(writeable.getCluster()) .withLifecycleEventsPublisher(eventPublisher) .build(); if( logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converted worker {}", converted); } return converted; }
DataFormatAdapter { public static JobWorker convertMantisWorkerMetadataWriteableToMantisWorkerMetadata(MantisWorkerMetadata writeable, LifecycleEventPublisher eventPublisher) { if(logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converting worker {}", writeable); } String jobId = writeable.getJobId(); List<Integer> ports = new ArrayList<>(writeable.getNumberOfPorts()); ports.add(writeable.getMetricsPort()); ports.add(writeable.getDebugPort()); ports.add(writeable.getConsolePort()); ports.add(writeable.getCustomPort()); if(writeable.getPorts().size() > 0) { ports.add(writeable.getPorts().get(0)); } WorkerPorts workerPorts = null; try { workerPorts = new WorkerPorts(ports); } catch (IllegalArgumentException | IllegalStateException e) { logger.warn("problem loading worker {} for Job ID {}", writeable.getWorkerId(), jobId, e); } JobWorker converted = new JobWorker.Builder() .withJobId(jobId) .withAcceptedAt(writeable.getAcceptedAt()) .withLaunchedAt(writeable.getLaunchedAt()) .withStartingAt(writeable.getStartingAt()) .withStartedAt(writeable.getStartedAt()) .withCompletedAt(writeable.getCompletedAt()) .withNumberOfPorts(ports.size()) .withWorkerPorts(workerPorts) .withResubmitCount(writeable.getTotalResubmitCount()) .withResubmitOf(writeable.getResubmitOf()) .withSlave(writeable.getSlave()) .withSlaveID(writeable.getSlaveID()) .withStageNum(writeable.getStageNum()) .withState(convertMantisJobStateToWorkerState(writeable.getState())) .withWorkerIndex(writeable.getWorkerIndex()) .withWorkerNumber(writeable.getWorkerNumber()) .withJobCompletedReason(writeable.getReason()) .withPreferredCluster(writeable.getCluster()) .withLifecycleEventsPublisher(eventPublisher) .build(); if( logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converted worker {}", converted); } return converted; } }
DataFormatAdapter { public static JobWorker convertMantisWorkerMetadataWriteableToMantisWorkerMetadata(MantisWorkerMetadata writeable, LifecycleEventPublisher eventPublisher) { if(logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converting worker {}", writeable); } String jobId = writeable.getJobId(); List<Integer> ports = new ArrayList<>(writeable.getNumberOfPorts()); ports.add(writeable.getMetricsPort()); ports.add(writeable.getDebugPort()); ports.add(writeable.getConsolePort()); ports.add(writeable.getCustomPort()); if(writeable.getPorts().size() > 0) { ports.add(writeable.getPorts().get(0)); } WorkerPorts workerPorts = null; try { workerPorts = new WorkerPorts(ports); } catch (IllegalArgumentException | IllegalStateException e) { logger.warn("problem loading worker {} for Job ID {}", writeable.getWorkerId(), jobId, e); } JobWorker converted = new JobWorker.Builder() .withJobId(jobId) .withAcceptedAt(writeable.getAcceptedAt()) .withLaunchedAt(writeable.getLaunchedAt()) .withStartingAt(writeable.getStartingAt()) .withStartedAt(writeable.getStartedAt()) .withCompletedAt(writeable.getCompletedAt()) .withNumberOfPorts(ports.size()) .withWorkerPorts(workerPorts) .withResubmitCount(writeable.getTotalResubmitCount()) .withResubmitOf(writeable.getResubmitOf()) .withSlave(writeable.getSlave()) .withSlaveID(writeable.getSlaveID()) .withStageNum(writeable.getStageNum()) .withState(convertMantisJobStateToWorkerState(writeable.getState())) .withWorkerIndex(writeable.getWorkerIndex()) .withWorkerNumber(writeable.getWorkerNumber()) .withJobCompletedReason(writeable.getReason()) .withPreferredCluster(writeable.getCluster()) .withLifecycleEventsPublisher(eventPublisher) .build(); if( logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converted worker {}", converted); } return converted; }  }
DataFormatAdapter { public static JobWorker convertMantisWorkerMetadataWriteableToMantisWorkerMetadata(MantisWorkerMetadata writeable, LifecycleEventPublisher eventPublisher) { if(logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converting worker {}", writeable); } String jobId = writeable.getJobId(); List<Integer> ports = new ArrayList<>(writeable.getNumberOfPorts()); ports.add(writeable.getMetricsPort()); ports.add(writeable.getDebugPort()); ports.add(writeable.getConsolePort()); ports.add(writeable.getCustomPort()); if(writeable.getPorts().size() > 0) { ports.add(writeable.getPorts().get(0)); } WorkerPorts workerPorts = null; try { workerPorts = new WorkerPorts(ports); } catch (IllegalArgumentException | IllegalStateException e) { logger.warn("problem loading worker {} for Job ID {}", writeable.getWorkerId(), jobId, e); } JobWorker converted = new JobWorker.Builder() .withJobId(jobId) .withAcceptedAt(writeable.getAcceptedAt()) .withLaunchedAt(writeable.getLaunchedAt()) .withStartingAt(writeable.getStartingAt()) .withStartedAt(writeable.getStartedAt()) .withCompletedAt(writeable.getCompletedAt()) .withNumberOfPorts(ports.size()) .withWorkerPorts(workerPorts) .withResubmitCount(writeable.getTotalResubmitCount()) .withResubmitOf(writeable.getResubmitOf()) .withSlave(writeable.getSlave()) .withSlaveID(writeable.getSlaveID()) .withStageNum(writeable.getStageNum()) .withState(convertMantisJobStateToWorkerState(writeable.getState())) .withWorkerIndex(writeable.getWorkerIndex()) .withWorkerNumber(writeable.getWorkerNumber()) .withJobCompletedReason(writeable.getReason()) .withPreferredCluster(writeable.getCluster()) .withLifecycleEventsPublisher(eventPublisher) .build(); if( logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converted worker {}", converted); } return converted; }  static NamedJob convertJobClusterMetadataToNamedJob(IJobClusterMetadata jobCluster); static NamedJob.CompletedJob convertCompletedJobToNamedJobCompletedJob(JobClusterDefinitionImpl.CompletedJob cJob); static JobClusterDefinitionImpl.CompletedJob convertNamedJobCompletedJobToCompletedJob(NamedJob.CompletedJob completedJob); static IJobClusterMetadata convertNamedJobToJobClusterMetadata(NamedJob nJob); static List<NamedJob.Jar> convertJobClusterConfigsToJars(List<JobClusterConfig> jobClusterConfigs); static List<JobClusterConfig> convertJarsToJobClusterConfigs(List<NamedJob.Jar> jars); static NamedJob.Jar convertJobClusterConfigToJar(JobClusterConfig jConfig); static JobClusterConfig convertJarToJobClusterConfig(NamedJob.Jar jar ); static URL generateURL(String artifactName); static Optional<String> extractArtifactName(String jarStr); static Optional<String> extractArtifactName(URL jar); static NamedJob.SLA convertSLAToNamedJobSLA(io.mantisrx.server.master.domain.SLA sla); static NamedJobDefinition.CronPolicy convertToNamedJobDefinitionCronPolicy(IJobClusterDefinition.CronPolicy cPolicy); static MantisWorkerMetadataWritable convertMantisWorkerMetadataToMantisWorkerMetadataWritable(IMantisWorkerMetadata workerMeta); static FilterableMantisWorkerMetadataWritable convertMantisWorkerMetadataToFilterableMantisWorkerMetadataWritable(IMantisWorkerMetadata workerMeta); static void setWorkerMetadataWritable(MantisWorkerMetadataWritable writable, IMantisWorkerMetadata workerMeta); static JobWorker convertMantisWorkerMetadataWriteableToMantisWorkerMetadata(MantisWorkerMetadata writeable, LifecycleEventPublisher eventPublisher); static MantisStageMetadataWritable convertMantisStageMetadataToMantisStageMetadataWriteable(IMantisStageMetadata stageMeta); static FilterableMantisStageMetadataWritable convertFilterableMantisStageMetadataToMantisStageMetadataWriteable(IMantisStageMetadata stageMeta); static io.mantisrx.server.master.domain.SLA convertToSLA(NamedJob.SLA sla); static IJobClusterDefinition.CronPolicy convertToCronPolicy(NamedJobDefinition.CronPolicy cronPolicy); static IMantisJobMetadata convertMantisJobWriteableToMantisJobMetadata(MantisJobMetadata archJob, LifecycleEventPublisher eventPublisher); static IMantisJobMetadata convertMantisJobWriteableToMantisJobMetadata(MantisJobMetadata archJob, LifecycleEventPublisher eventPublisher, boolean isArchived); static IMantisStageMetadata convertMantisStageMetadataWriteableToMantisStageMetadata(
            MantisStageMetadata stageMeta,
            LifecycleEventPublisher eventPublisher); static IMantisStageMetadata convertMantisStageMetadataWriteableToMantisStageMetadata(MantisStageMetadata stageMeta,
                                                                                                LifecycleEventPublisher eventPublisher,
                                                                                                boolean skipAddingWorkerMetaData); static MantisJobMetadataWritable convertMantisJobMetadataToMantisJobMetadataWriteable(IMantisJobMetadata jobMetadata); static FilterableMantisJobMetadataWritable convertMantisJobMetadataToFilterableMantisJobMetadataWriteable(IMantisJobMetadata jobMetadata); static JobState convertMantisJobStateToJobState(MantisJobState state); static MantisJobState convertToMantisJobState(JobState state); static MantisJobState convertWorkerStateToMantisJobState(WorkerState state); static WorkerState convertMantisJobStateToWorkerState(MantisJobState state); static List<JobClusterInfo.JarInfo> convertNamedJobJarListToJarInfoList(List<NamedJob.Jar> jars); }
DataFormatAdapter { public static JobWorker convertMantisWorkerMetadataWriteableToMantisWorkerMetadata(MantisWorkerMetadata writeable, LifecycleEventPublisher eventPublisher) { if(logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converting worker {}", writeable); } String jobId = writeable.getJobId(); List<Integer> ports = new ArrayList<>(writeable.getNumberOfPorts()); ports.add(writeable.getMetricsPort()); ports.add(writeable.getDebugPort()); ports.add(writeable.getConsolePort()); ports.add(writeable.getCustomPort()); if(writeable.getPorts().size() > 0) { ports.add(writeable.getPorts().get(0)); } WorkerPorts workerPorts = null; try { workerPorts = new WorkerPorts(ports); } catch (IllegalArgumentException | IllegalStateException e) { logger.warn("problem loading worker {} for Job ID {}", writeable.getWorkerId(), jobId, e); } JobWorker converted = new JobWorker.Builder() .withJobId(jobId) .withAcceptedAt(writeable.getAcceptedAt()) .withLaunchedAt(writeable.getLaunchedAt()) .withStartingAt(writeable.getStartingAt()) .withStartedAt(writeable.getStartedAt()) .withCompletedAt(writeable.getCompletedAt()) .withNumberOfPorts(ports.size()) .withWorkerPorts(workerPorts) .withResubmitCount(writeable.getTotalResubmitCount()) .withResubmitOf(writeable.getResubmitOf()) .withSlave(writeable.getSlave()) .withSlaveID(writeable.getSlaveID()) .withStageNum(writeable.getStageNum()) .withState(convertMantisJobStateToWorkerState(writeable.getState())) .withWorkerIndex(writeable.getWorkerIndex()) .withWorkerNumber(writeable.getWorkerNumber()) .withJobCompletedReason(writeable.getReason()) .withPreferredCluster(writeable.getCluster()) .withLifecycleEventsPublisher(eventPublisher) .build(); if( logger.isDebugEnabled()) { logger.debug("DataFormatAdatper:converted worker {}", converted); } return converted; }  static NamedJob convertJobClusterMetadataToNamedJob(IJobClusterMetadata jobCluster); static NamedJob.CompletedJob convertCompletedJobToNamedJobCompletedJob(JobClusterDefinitionImpl.CompletedJob cJob); static JobClusterDefinitionImpl.CompletedJob convertNamedJobCompletedJobToCompletedJob(NamedJob.CompletedJob completedJob); static IJobClusterMetadata convertNamedJobToJobClusterMetadata(NamedJob nJob); static List<NamedJob.Jar> convertJobClusterConfigsToJars(List<JobClusterConfig> jobClusterConfigs); static List<JobClusterConfig> convertJarsToJobClusterConfigs(List<NamedJob.Jar> jars); static NamedJob.Jar convertJobClusterConfigToJar(JobClusterConfig jConfig); static JobClusterConfig convertJarToJobClusterConfig(NamedJob.Jar jar ); static URL generateURL(String artifactName); static Optional<String> extractArtifactName(String jarStr); static Optional<String> extractArtifactName(URL jar); static NamedJob.SLA convertSLAToNamedJobSLA(io.mantisrx.server.master.domain.SLA sla); static NamedJobDefinition.CronPolicy convertToNamedJobDefinitionCronPolicy(IJobClusterDefinition.CronPolicy cPolicy); static MantisWorkerMetadataWritable convertMantisWorkerMetadataToMantisWorkerMetadataWritable(IMantisWorkerMetadata workerMeta); static FilterableMantisWorkerMetadataWritable convertMantisWorkerMetadataToFilterableMantisWorkerMetadataWritable(IMantisWorkerMetadata workerMeta); static void setWorkerMetadataWritable(MantisWorkerMetadataWritable writable, IMantisWorkerMetadata workerMeta); static JobWorker convertMantisWorkerMetadataWriteableToMantisWorkerMetadata(MantisWorkerMetadata writeable, LifecycleEventPublisher eventPublisher); static MantisStageMetadataWritable convertMantisStageMetadataToMantisStageMetadataWriteable(IMantisStageMetadata stageMeta); static FilterableMantisStageMetadataWritable convertFilterableMantisStageMetadataToMantisStageMetadataWriteable(IMantisStageMetadata stageMeta); static io.mantisrx.server.master.domain.SLA convertToSLA(NamedJob.SLA sla); static IJobClusterDefinition.CronPolicy convertToCronPolicy(NamedJobDefinition.CronPolicy cronPolicy); static IMantisJobMetadata convertMantisJobWriteableToMantisJobMetadata(MantisJobMetadata archJob, LifecycleEventPublisher eventPublisher); static IMantisJobMetadata convertMantisJobWriteableToMantisJobMetadata(MantisJobMetadata archJob, LifecycleEventPublisher eventPublisher, boolean isArchived); static IMantisStageMetadata convertMantisStageMetadataWriteableToMantisStageMetadata(
            MantisStageMetadata stageMeta,
            LifecycleEventPublisher eventPublisher); static IMantisStageMetadata convertMantisStageMetadataWriteableToMantisStageMetadata(MantisStageMetadata stageMeta,
                                                                                                LifecycleEventPublisher eventPublisher,
                                                                                                boolean skipAddingWorkerMetaData); static MantisJobMetadataWritable convertMantisJobMetadataToMantisJobMetadataWriteable(IMantisJobMetadata jobMetadata); static FilterableMantisJobMetadataWritable convertMantisJobMetadataToFilterableMantisJobMetadataWriteable(IMantisJobMetadata jobMetadata); static JobState convertMantisJobStateToJobState(MantisJobState state); static MantisJobState convertToMantisJobState(JobState state); static MantisJobState convertWorkerStateToMantisJobState(WorkerState state); static WorkerState convertMantisJobStateToWorkerState(MantisJobState state); static List<JobClusterInfo.JarInfo> convertNamedJobJarListToJarInfoList(List<NamedJob.Jar> jars);  }