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

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

Introduction

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

Prototype

public Date getStartTime() 

Source Link

Document

Gets the time this execution started

Usage

From source file:admin.jmx.SimpleStepExecutionMetrics.java

private StepExecution getLatestStepExecution(String stepName) {
    // On the cautious side: grab the last 4 executions by ID and look for
    // the one that was last started...
    Collection<StepExecution> stepExecutions = jobService.listStepExecutionsForStep(jobName, stepName, 0, 4);
    if (stepExecutions.isEmpty()) {
        return null;
    }//from  w  w w . ja va2  s  .  c o m
    long lastUpdated = 0L;
    StepExecution result = null;
    for (StepExecution stepExecution : stepExecutions) {
        long updated = stepExecution.getStartTime().getTime();
        if (updated > lastUpdated) {
            result = stepExecution;
            lastUpdated = updated;
        }
    }
    return result;
}

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)
 * //from  w ww.ja  va 2 s. co  m
 * @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 w w .j  a va  2s.  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:de.codecentric.batch.metrics.MetricsListener.java

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    // Calculate step execution time
    // Why is stepExecution.getEndTime().getTime() not available here? (see AbstractStep)
    long stepDuration = System.currentTimeMillis() - stepExecution.getStartTime().getTime();
    gaugeService.submit(TIMER_PREFIX + getStepExecutionIdentifier(stepExecution) + ".duration", stepDuration);
    long itemCount = stepExecution.getWriteCount() + stepExecution.getSkipCount();
    gaugeService.submit(GAUGE_PREFIX + getStepExecutionIdentifier(stepExecution) + ".item.count", itemCount);
    // Calculate execution time per item
    long durationPerItem = 0;
    if (itemCount > 0) {
        durationPerItem = stepDuration / itemCount;
    }/*  w  w  w  . j  av a2  s  .c o  m*/
    gaugeService.submit(TIMER_PREFIX + getStepExecutionIdentifier(stepExecution) + ".item.duration",
            durationPerItem);
    // Export metrics from StepExecution to MetricRepositories
    Set<Entry<String, Object>> metrics = stepExecution.getExecutionContext().entrySet();
    for (Entry<String, Object> metric : metrics) {
        if (metric.getValue() instanceof Long) {
            gaugeService.submit(
                    GAUGE_PREFIX + getStepExecutionIdentifier(stepExecution) + "." + metric.getKey(),
                    (Long) metric.getValue());
        } else if (metric.getValue() instanceof Double) {
            gaugeService.submit(
                    GAUGE_PREFIX + getStepExecutionIdentifier(stepExecution) + "." + metric.getKey(),
                    (Double) metric.getValue());
        }
    }
    return null;
}

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  2s  .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);/*from  ww  w .  j  a v a2s .  com*/

    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: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
 *///w  ww  . ja v a  2s. com
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:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java

@Test
public void optionalStepsShouldBeSkipped() throws Exception {
    initVariantConfigurationJob();// w ww  .  j ava 2s  .c om

    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.StepExecutionRepresentation.java

/**
 * Instantiates a new step execution representation.
 *
 * @param stepExecution the step execution
 * @param timeZone      the time zone/* ww  w .  ja v  a2  s. co  m*/
 */
public StepExecutionRepresentation(StepExecution stepExecution, TimeZone timeZone) {

    this.setStepExecutionDetailsRepresentation(new StepExecutionDetailsRepresentation(stepExecution));
    this.id = stepExecution.getId();
    this.name = stepExecution.getStepName();
    this.jobName = stepExecution.getJobExecution() == null
            || stepExecution.getJobExecution().getJobInstance() == null ? "?"
                    : stepExecution.getJobExecution().getJobInstance().getJobName();
    this.jobExecutionId = stepExecution.getJobExecutionId();
    // Duration is always in GMT
    durationFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    timeFormat.setTimeZone(timeZone);
    dateFormat.setTimeZone(timeZone);
    if (stepExecution.getStartTime() != null) {
        this.startDate = dateFormat.format(stepExecution.getStartTime());
        this.startTime = timeFormat.format(stepExecution.getStartTime());
        Date endTime = stepExecution.getEndTime() != null ? stepExecution.getEndTime() : new Date();

        this.durationMillis = endTime.getTime() - stepExecution.getStartTime().getTime();
        this.duration = durationFormat.format(new Date(durationMillis));
    }
    if (stepExecution.getEndTime() != null) {
        this.endTime = timeFormat.format(stepExecution.getEndTime());
    }

}

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

@Test
public void annotationStepsShouldBeSkipped() throws Exception {
    initVariantConfigurationJob();//from   w w  w.  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()));
}