Example usage for org.springframework.batch.core StepExecution getEndTime

List of usage examples for org.springframework.batch.core StepExecution getEndTime

Introduction

In this page you can find the example usage for org.springframework.batch.core StepExecution getEndTime.

Prototype

public Date getEndTime() 

Source Link

Document

Returns the time that this execution ended

Usage

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java

/**
 * Returns a copy of {@link StepExecution}, by adding new Objects for every field(no references are passed)
 * //www .j  a  va  2  s  .  c om
 * @param original StepExecution to be copied
 * @return StepExecution copy
 */
private static StepExecution copy(StepExecution original) {
    StepExecution copy = new StepExecution(original.getStepName(), original.getJobExecution());
    copy.setCommitCount(original.getCommitCount());
    if (original.getEndTime() != null) {
        copy.setEndTime((Date) original.getEndTime().clone());
    }
    //Warning: no deep copy
    if (original.getExitStatus() != null) {
        copy.setExitStatus(new ExitStatus(original.getExitStatus().getExitCode(),
                original.getExitStatus().getExitDescription()));
    }
    copy.setFilterCount(original.getFilterCount());
    copy.setId(original.getId());
    if (original.getLastUpdated() != null) {
        copy.setLastUpdated((Date) original.getLastUpdated().clone());
    }
    copy.setProcessSkipCount(original.getProcessSkipCount());
    copy.setReadCount(original.getReadCount());
    copy.setReadSkipCount(original.getReadSkipCount());
    copy.setRollbackCount(original.getRollbackCount());
    if (original.getStartTime() != null) {
        copy.setStartTime((Date) original.getStartTime().clone());
    }
    if (original.getStatus() != null) {
        copy.setStatus(BatchStatus.valueOf(original.getStatus().name()));
    }
    if (original.isTerminateOnly()) {
        copy.setTerminateOnly();
    }
    copy.setVersion(original.getVersion());
    copy.setWriteCount(original.getWriteCount());
    copy.setWriteSkipCount(original.getWriteSkipCount());
    return copy;
}

From source file:admin.history.StepExecutionHistory.java

public void append(StepExecution stepExecution) {
    if (stepExecution.getEndTime() == null) {
        // ignore unfinished executions
        return;//from w ww .ja va2  s . c  o m
    }
    Date startTime = stepExecution.getStartTime();
    Date endTime = stepExecution.getEndTime();
    long time = endTime.getTime() - startTime.getTime();
    duration.append(time);
    if (stepExecution.getReadCount() > 0) {
        durationPerRead.append(time / stepExecution.getReadCount());
    }
    count++;
    commitCount.append(stepExecution.getCommitCount());
    rollbackCount.append(stepExecution.getRollbackCount());
    readCount.append(stepExecution.getReadCount());
    writeCount.append(stepExecution.getWriteCount());
    filterCount.append(stepExecution.getFilterCount());
    readSkipCount.append(stepExecution.getReadSkipCount());
    writeSkipCount.append(stepExecution.getWriteSkipCount());
    processSkipCount.append(stepExecution.getProcessSkipCount());
}

From source file:admin.jmx.SimpleJobExecutionMetrics.java

private StepExecution getLatestStepExecution(JobExecution jobExecution) {
    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
    StepExecution stepExecution = null;/*from   w w w .  j  a  va  2 s  .c  o  m*/
    if (!stepExecutions.isEmpty()) {
        Date latest = new Date(0L);
        for (StepExecution candidate : stepExecutions) {
            Date stepDate = candidate.getEndTime();
            stepDate = stepDate == null ? new Date() : stepDate;
            if (stepDate.after(latest)) {
                latest = stepDate;
                stepExecution = candidate;
            } else if (stepExecution != null && stepDate.equals(latest)
                    && candidate.getId() > stepExecution.getId()) {
                // Tie breaker using ID
                stepExecution = candidate;
            }
        }
    }
    return stepExecution;
}

From source file:admin.jmx.SimpleStepExecutionMetrics.java

public double getLatestDuration() {
    StepExecution stepExecution = getLatestStepExecution(stepName);
    if (stepExecution == null) {
        return 0;
    }/*from  ww  w  .  j a  v a  2 s . com*/
    Date endTime = stepExecution.getEndTime();
    return (endTime != null ? endTime.getTime() : System.currentTimeMillis())
            - stepExecution.getStartTime().getTime();
}

From source file:uk.ac.ebi.eva.pipeline.jobs.AggregatedVcfJobTest.java

@Test
public void aggregatedTransformAndLoadShouldBeExecuted() throws Exception {
    Config.setOpenCGAHome(opencgaHome);//  w  ww . j a  va  2s  . c o m

    JobExecution jobExecution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    // check execution flow
    Assert.assertEquals(2, jobExecution.getStepExecutions().size());
    List<StepExecution> steps = new ArrayList<>(jobExecution.getStepExecutions());
    StepExecution transformStep = steps.get(0);
    StepExecution loadStep = steps.get(1);

    Assert.assertEquals(AggregatedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName());
    Assert.assertEquals(AggregatedVcfJob.LOAD_VARIANTS, loadStep.getStepName());

    assertTrue(transformStep.getEndTime().before(loadStep.getStartTime()));

    // check transformed file
    String outputFilename = getTransformedOutputPath(Paths.get(input).getFileName(), compressExtension,
            outputDir);

    long lines = JobTestUtils.getLines(new GZIPInputStream(new FileInputStream(outputFilename)));
    assertEquals(156, lines);

    // check ((documents in DB) == (lines in transformed file))
    VariantStorageManager variantStorageManager = StorageManagerFactory.getVariantStorageManager();
    VariantDBAdaptor variantDBAdaptor = variantStorageManager.getDBAdaptor(dbName, null);
    VariantDBIterator iterator = variantDBAdaptor.iterator(new QueryOptions());

    Assert.assertEquals(JobTestUtils.count(iterator), lines);

    // check that stats are loaded properly
    assertFalse(variantDBAdaptor.iterator(new QueryOptions()).next().getSourceEntries().values().iterator()
            .next().getCohortStats().isEmpty());
}

From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java

@Test
public void optionalStepsShouldBeSkipped() throws Exception {
    initVariantConfigurationJob();//from w  w  w  . j av a  2s. co  m

    jobOptions.getPipelineOptions().put(AnnotationJob.SKIP_ANNOT, true);
    jobOptions.getPipelineOptions().put(PopulationStatisticsJob.SKIP_STATS, true);

    JobExecution execution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
    assertEquals(2, execution.getStepExecutions().size());

    List<StepExecution> steps = new ArrayList<>(execution.getStepExecutions());
    StepExecution transformStep = steps.get(0);
    StepExecution loadStep = steps.get(1);

    assertEquals(GenotypedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName());
    assertEquals(GenotypedVcfJob.LOAD_VARIANTS, loadStep.getStepName());

    assertTrue(transformStep.getEndTime().before(loadStep.getStartTime()));
}

From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionProgressPresentation.java

/**
 * Instantiates a new step execution progress presentation.
 *
 * @param stepExecution        the step execution
 * @param stepExecutionHistory the step execution history
 *///from   w  ww .  j  a  v  a 2 s .c  om
public StepExecutionProgressPresentation(StepExecution stepExecution,
        StepExecutionHistory stepExecutionHistory) {
    this.stepExecution = stepExecution;
    this.stepExecutionHistory = stepExecutionHistory;
    Date startTime = stepExecution.getStartTime();
    Date endTime = stepExecution.getEndTime();
    if (endTime == null) {
        endTime = new Date();
    } else {
        isFinished = true;
    }
    if (startTime == null) {
        startTime = new Date();
    }
    duration = endTime.getTime() - startTime.getTime();
    percentageComplete = calculatePercentageComplete();
}

From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionDetailsRepresentation.java

/**
 * Constructor that substitutes in null for the execution id.
 *
 * @param stepExecution the step execution
 *///from  www. jav a 2s  . c o  m
public StepExecutionDetailsRepresentation(StepExecution stepExecution) {
    Assert.notNull(stepExecution.getId(),
            "The entity Id must be provided to re-hydrate an existing StepExecution");
    this.stepName = stepExecution.getStepName();
    this.commitCount = stepExecution.getCommitCount();
    this.endTime = stepExecution.getEndTime() == null ? "" : timeFormat.format(stepExecution.getEndTime());
    this.executionContext = stepExecution.getExecutionContext();

    this.statusExitCode = stepExecution.getExitStatus() != null ? stepExecution.getExitStatus().getExitCode()
            : "";
    this.statusExitDescription = stepExecution.getExitStatus() != null
            ? stepExecution.getExitStatus().getExitDescription()
            : "";
    this.failureExceptions = stepExecution.getFailureExceptions();
    this.filterCount = stepExecution.getFilterCount();
    this.lastUpdated = stepExecution.getLastUpdated() == null ? ""
            : dateFormat.format(stepExecution.getLastUpdated());
    this.processSkipCount = stepExecution.getProcessSkipCount();
    this.readCount = stepExecution.getReadCount();
    this.readSkipCount = stepExecution.getReadSkipCount();
    this.rollbackCount = stepExecution.getRollbackCount();
    this.startTime = timeFormat.format(stepExecution.getStartTime());
    this.status = stepExecution.getStatus();
    this.stepName = stepExecution.getStepName();
    this.terminateOnly = stepExecution.isTerminateOnly();
    this.writeCount = stepExecution.getWriteCount();
    this.writeSkipCount = stepExecution.getWriteSkipCount();
}

From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java

@Test
public void annotationStepsShouldBeSkipped() throws Exception {
    initVariantConfigurationJob();// w  ww  .j a v  a2 s .  co m
    jobOptions.getPipelineOptions().put(AnnotationJob.SKIP_ANNOT, true);

    JobExecution execution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
    assertEquals(4, execution.getStepExecutions().size());

    List<StepExecution> steps = new ArrayList<>(execution.getStepExecutions());
    StepExecution transformStep = steps.get(0);
    StepExecution loadStep = steps.get(1);

    Map<String, StepExecution> parallelStepsNameToStepExecution = new HashMap<>();
    for (int i = 2; i <= steps.size() - 1; i++) {
        parallelStepsNameToStepExecution.put(steps.get(i).getStepName(), steps.get(i));
    }

    assertEquals(GenotypedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName());
    assertEquals(GenotypedVcfJob.LOAD_VARIANTS, loadStep.getStepName());

    Set<String> parallelStepNamesExecuted = parallelStepsNameToStepExecution.keySet();
    Set<String> parallelStepNamesToCheck = new HashSet<>(Arrays
            .asList(PopulationStatisticsJob.CALCULATE_STATISTICS, PopulationStatisticsJob.LOAD_STATISTICS));

    assertEquals(parallelStepNamesToCheck, parallelStepNamesExecuted);

    assertTrue(transformStep.getEndTime().before(loadStep.getStartTime()));
    assertTrue(loadStep.getEndTime().before(
            parallelStepsNameToStepExecution.get(PopulationStatisticsJob.CALCULATE_STATISTICS).getStartTime()));

    assertTrue(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.CALCULATE_STATISTICS).getEndTime()
            .before(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.LOAD_STATISTICS)
                    .getStartTime()));
}

From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java

@Test
public void statsStepsShouldBeSkipped() throws Exception {
    initVariantConfigurationJob();//from w  w  w  .j ava  2 s .c  o  m
    jobOptions.getPipelineOptions().put(PopulationStatisticsJob.SKIP_STATS, true);

    jobOptions.getPipelineOptions().put("db.name", "diegoTest");

    JobExecution execution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
    assertEquals(5, execution.getStepExecutions().size());

    List<StepExecution> steps = new ArrayList<>(execution.getStepExecutions());
    StepExecution transformStep = steps.get(0);
    StepExecution loadStep = steps.get(1);

    Map<String, StepExecution> parallelStepsNameToStepExecution = new HashMap<>();
    for (int i = 2; i <= steps.size() - 1; i++) {
        parallelStepsNameToStepExecution.put(steps.get(i).getStepName(), steps.get(i));
    }

    assertEquals(GenotypedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName());
    assertEquals(GenotypedVcfJob.LOAD_VARIANTS, loadStep.getStepName());

    Set<String> parallelStepNamesExecuted = parallelStepsNameToStepExecution.keySet();
    Set<String> parallelStepNamesToCheck = new HashSet<>(Arrays.asList(
            VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE, VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION,
            AnnotationLoaderStep.LOAD_VEP_ANNOTATION));

    assertEquals(parallelStepNamesToCheck, parallelStepNamesExecuted);

    assertTrue(transformStep.getEndTime().before(loadStep.getStartTime()));
    assertTrue(loadStep.getEndTime().before(parallelStepsNameToStepExecution
            .get(VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE).getStartTime()));

    assertTrue(parallelStepsNameToStepExecution.get(VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE)
            .getEndTime().before(parallelStepsNameToStepExecution
                    .get(VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION).getStartTime()));
    assertTrue(parallelStepsNameToStepExecution.get(VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION)
            .getEndTime().before(parallelStepsNameToStepExecution.get(AnnotationLoaderStep.LOAD_VEP_ANNOTATION)
                    .getStartTime()));
}