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.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionRepresentation.java

/**
 * Instantiates a new step execution representation.
 *
 * @param stepExecution the step execution
 * @param timeZone      the time zone/*  www .j  a  v a2s .  c om*/
 */
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 allStepsShouldBeExecuted() throws Exception {
    initVariantConfigurationJob();/*w ww. ja va 2 s  .c  o m*/

    JobExecution execution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
    assertEquals(7, 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,
            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(PopulationStatisticsJob.CALCULATE_STATISTICS).getStartTime()));
    assertTrue(loadStep.getEndTime().before(parallelStepsNameToStepExecution
            .get(VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE).getStartTime()));

    assertTrue(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.CALCULATE_STATISTICS).getEndTime()
            .before(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.LOAD_STATISTICS)
                    .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()));
}

From source file:org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.java

private List<Object[]> buildStepExecutionParameters(StepExecution stepExecution) {
    Assert.isNull(stepExecution.getId(),
            "to-be-saved (not updated) StepExecution can't already have an id assigned");
    Assert.isNull(stepExecution.getVersion(),
            "to-be-saved (not updated) StepExecution can't already have a version assigned");
    validateStepExecution(stepExecution);
    stepExecution.setId(stepExecutionIncrementer.nextLongValue());
    stepExecution.incrementVersion(); //Should be 0
    List<Object[]> parameters = new ArrayList<Object[]>();
    String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription());
    Object[] parameterValues = new Object[] { stepExecution.getId(), stepExecution.getVersion(),
            stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(),
            stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(),
            stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(),
            stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(),
            stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(),
            stepExecution.getRollbackCount(), stepExecution.getLastUpdated() };
    Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT,
            Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
            Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
            Types.INTEGER, Types.TIMESTAMP };
    parameters.add(0, Arrays.copyOf(parameterValues, parameterValues.length));
    parameters.add(1, Arrays.copyOf(parameterTypes, parameterTypes.length));
    return parameters;
}

From source file:org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.java

@Override
public void updateStepExecution(StepExecution stepExecution) {

    validateStepExecution(stepExecution);
    Assert.notNull(stepExecution.getId(),
            "StepExecution Id cannot be null. StepExecution must saved" + " before it can be updated.");

    // Do not check for existence of step execution considering
    // it is saved at every commit point.

    String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription());

    // Attempt to prevent concurrent modification errors by blocking here if
    // someone is already trying to do it.
    synchronized (stepExecution) {

        Integer version = stepExecution.getVersion() + 1;
        Object[] parameters = new Object[] { stepExecution.getStartTime(), stepExecution.getEndTime(),
                stepExecution.getStatus().toString(), stepExecution.getCommitCount(),
                stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(),
                stepExecution.getExitStatus().getExitCode(), exitDescription, version,
                stepExecution.getReadSkipCount(), stepExecution.getProcessSkipCount(),
                stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(),
                stepExecution.getLastUpdated(), stepExecution.getId(), stepExecution.getVersion() };
        int count = getJdbcTemplate().update(getQuery(UPDATE_STEP_EXECUTION), parameters,
                new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
                        Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER,
                        Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP,
                        Types.BIGINT, Types.INTEGER });

        // Avoid concurrent modifications...
        if (count == 0) {
            int curentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_STEP_EXECUTION),
                    new Object[] { stepExecution.getId() }, Integer.class);
            throw new OptimisticLockingFailureException(
                    "Attempt to update step execution id=" + stepExecution.getId() + " with wrong version ("
                            + stepExecution.getVersion() + "), where current version is " + curentVersion);
        }/*from www .ja  v  a 2s  .c  om*/

        stepExecution.incrementVersion();

    }
}

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanTests.java

private void assertStepExecutionsAreEqual(StepExecution expected, StepExecution actual) {
    assertEquals(expected.getId(), actual.getId());
    assertEquals(expected.getStartTime(), actual.getStartTime());
    assertEquals(expected.getEndTime(), actual.getEndTime());
    assertEquals(expected.getSkipCount(), actual.getSkipCount());
    assertEquals(expected.getCommitCount(), actual.getCommitCount());
    assertEquals(expected.getReadCount(), actual.getReadCount());
    assertEquals(expected.getWriteCount(), actual.getWriteCount());
    assertEquals(expected.getFilterCount(), actual.getFilterCount());
    assertEquals(expected.getWriteSkipCount(), actual.getWriteSkipCount());
    assertEquals(expected.getReadSkipCount(), actual.getReadSkipCount());
    assertEquals(expected.getProcessSkipCount(), actual.getProcessSkipCount());
    assertEquals(expected.getRollbackCount(), actual.getRollbackCount());
    assertEquals(expected.getExitStatus(), actual.getExitStatus());
    assertEquals(expected.getLastUpdated(), actual.getLastUpdated());
    assertEquals(expected.getExitStatus(), actual.getExitStatus());
    assertEquals(expected.getJobExecutionId(), actual.getJobExecutionId());
}