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

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

Introduction

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

Prototype

public int getCommitCount() 

Source Link

Document

Returns the current number of commits for this execution

Usage

From source file:org.seedstack.spring.batch.fixtures.FlatFileBatchDemo.java

protected static void printStatistics(JobExecution jobExecution) {
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        System.out.println("-----------------------------------");
        System.out.println("STEP name: " + stepExecution.getStepName());
        System.out.println("-----------------------------------");
        System.out.println("CommitCount: " + stepExecution.getCommitCount());
        System.out.println("FilterCount: " + stepExecution.getFilterCount());
        System.out.println("ProcessSkipCount: " + stepExecution.getProcessSkipCount());
        System.out.println("ReadCount: " + stepExecution.getReadCount());
        System.out.println("ReadSkipCount: " + stepExecution.getReadSkipCount());
        System.out.println("RollbackCount: " + stepExecution.getRollbackCount());
        System.out.println("SkipCount: " + stepExecution.getSkipCount());
        System.out.println("WriteCount: " + stepExecution.getWriteCount());
        System.out.println("WriteSkipCount: " + stepExecution.getWriteSkipCount());
        if (stepExecution.getFailureExceptions().size() > 0) {
            System.out.println("exceptions:");
            System.out.println("-----------------------------------");
            for (Throwable t : stepExecution.getFailureExceptions()) {
                System.out.println(t.getMessage());
            }/*from   w w w.j  a  v a  2  s  .  c o  m*/
        }
        System.out.println("-----------------------------------");
    }
}

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)
 * // w  w  w . j av  a2 s.  c o  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.jmx.SimpleStepExecutionMetrics.java

public int getLatestCommitCount() {
    StepExecution stepExecution = getLatestStepExecution(stepName);
    return stepExecution == null ? 0 : stepExecution.getCommitCount();
}

From source file:com.javaetmoi.elasticsearch.musicbrainz.batch.TestMusicAlbumJob.java

@Test
public void indexMusicAlbum() throws Exception {
    JobExecution execution = testUtils.launchJob();

    // Batch Status
    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
    StepExecution indexMusicAlbum = getStepExecution(execution, "indexMusicAlbum");
    assertEquals(13, indexMusicAlbum.getWriteCount());
    assertEquals(2 * 2, indexMusicAlbum.getCommitCount());

    // Elasticsearch status
    ElasticSearchHelper.refreshIndex(client);
    DocsStatus docs = getDocStatus();/*from  w w  w .j  a v a2s.co m*/
    assertEquals(13, docs.getNumDocs());
}

From source file:com.javaetmoi.core.batch.listener.LogStepListener.java

@Override
public ExitStatus afterStep(StepExecution pStepExecution) {
    if (LOG.isInfoEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Step ").append(pStepExecution.getStepName());
        msg.append(" - Read count: ").append(pStepExecution.getReadCount());
        msg.append(" - Write count: ").append(pStepExecution.getWriteCount());
        msg.append(" - Commit count: ").append(pStepExecution.getCommitCount());
        LOG.info(msg.toString());/* w ww  . j  a  v a 2s. c o  m*/
    }
    return super.afterStep(pStepExecution);
}

From source file:de.codecentric.batch.listener.ProtocolListener.java

public void afterJob(JobExecution jobExecution) {
    StringBuilder protocol = new StringBuilder();
    protocol.append("\n");
    protocol.append(createFilledLine('*'));
    protocol.append(createFilledLine('-'));
    protocol.append("Protocol for " + jobExecution.getJobInstance().getJobName() + " \n");
    protocol.append("  Started:      " + jobExecution.getStartTime() + "\n");
    protocol.append("  Finished:     " + jobExecution.getEndTime() + "\n");
    protocol.append("  Exit-Code:    " + jobExecution.getExitStatus().getExitCode() + "\n");
    protocol.append("  Exit-Descr:   " + jobExecution.getExitStatus().getExitDescription() + "\n");
    protocol.append("  Status:       " + jobExecution.getStatus() + "\n");
    protocol.append("  Content of Job-ExecutionContext:\n");
    for (Entry<String, Object> entry : jobExecution.getExecutionContext().entrySet()) {
        protocol.append("  " + entry.getKey() + "=" + entry.getValue() + "\n");
    }/*from  w  w w . java 2s  .c o m*/
    protocol.append("  Job-Parameter: \n");
    JobParameters jp = jobExecution.getJobParameters();
    for (Iterator<Entry<String, JobParameter>> iter = jp.getParameters().entrySet().iterator(); iter
            .hasNext();) {
        Entry<String, JobParameter> entry = iter.next();
        protocol.append("  " + entry.getKey() + "=" + entry.getValue() + "\n");
    }
    protocol.append(createFilledLine('-'));
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        protocol.append("Step " + stepExecution.getStepName() + " \n");
        protocol.append("  ReadCount:    " + stepExecution.getReadCount() + "\n");
        protocol.append("  WriteCount:   " + stepExecution.getWriteCount() + "\n");
        protocol.append("  Commits:      " + stepExecution.getCommitCount() + "\n");
        protocol.append("  SkipCount:    " + stepExecution.getSkipCount() + "\n");
        protocol.append("  Rollbacks:    " + stepExecution.getRollbackCount() + "\n");
        protocol.append("  Filter:       " + stepExecution.getFilterCount() + "\n");
        protocol.append("  Content of Step-ExecutionContext:\n");
        for (Entry<String, Object> entry : stepExecution.getExecutionContext().entrySet()) {
            protocol.append("  " + entry.getKey() + "=" + entry.getValue() + "\n");
        }
        protocol.append(createFilledLine('-'));
    }
    protocol.append(createFilledLine('*'));
    LOGGER.info(protocol.toString());
}

From source file:com.example.listener.CustomJobExecutionListener.java

public void afterJob(org.springframework.batch.core.JobExecution jobExecution) {
    StringBuilder protocol = new StringBuilder();
    protocol.append("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
    protocol.append("Protocol for " + jobExecution.getJobInstance().getJobName() + " \n");
    protocol.append("  Started     : " + jobExecution.getStartTime() + "\n");
    protocol.append("  Finished    : " + jobExecution.getEndTime() + "\n");
    protocol.append("  Exit-Code   : " + jobExecution.getExitStatus().getExitCode() + "\n");
    protocol.append("  Exit-Descr. : " + jobExecution.getExitStatus().getExitDescription() + "\n");
    protocol.append("  Status      : " + jobExecution.getStatus() + "\n");
    protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");

    protocol.append("Job-Parameter: \n");
    JobParameters jp = jobExecution.getJobParameters();
    for (Iterator<Map.Entry<String, JobParameter>> iter = jp.getParameters().entrySet().iterator(); iter
            .hasNext();) {/*w ww  .jav  a  2 s .c  o m*/
        Map.Entry<String, JobParameter> entry = iter.next();
        protocol.append("  " + entry.getKey() + "=" + entry.getValue() + "\n");
    }
    protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");

    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        protocol.append("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
        protocol.append("Step " + stepExecution.getStepName() + " \n");
        protocol.append("ReadCount " + stepExecution.getReadCount() + " \n");
        protocol.append("WriteCount: " + stepExecution.getWriteCount() + "\n");
        protocol.append("Commits: " + stepExecution.getCommitCount() + "\n");
        protocol.append("SkipCount: " + stepExecution.getSkipCount() + "\n");
        protocol.append("Rollbacks: " + stepExecution.getRollbackCount() + "\n");
        protocol.append("Filter: " + stepExecution.getFilterCount() + "\n");
        protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
    }
    log.info("{}", protocol.toString());
}

From source file:admin.history.StepExecutionHistory.java

public void append(StepExecution stepExecution) {
    if (stepExecution.getEndTime() == null) {
        // ignore unfinished executions
        return;/*from  w w w .ja va 2 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:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionDetailsRepresentation.java

/**
 * Constructor that substitutes in null for the execution id.
 *
 * @param stepExecution the step execution
 *///  ww  w  . 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:org.springframework.batch.core.jsr.configuration.xml.RetryListenerTests.java

@Test
@SuppressWarnings("resource")
public void testReadRetryOnce() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "org/springframework/batch/core/jsr/configuration/xml/RetryReadListenerRetryOnce.xml");

    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    JobExecution jobExecution = jobLauncher.run(context.getBean(Job.class), new JobParameters());

    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
    assertEquals(1, stepExecutions.size());

    StepExecution stepExecution = stepExecutions.iterator().next();
    assertEquals(1, stepExecution.getCommitCount());
    assertEquals(2, stepExecution.getReadCount());

    assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
}