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

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

Introduction

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

Prototype

public int getSkipCount() 

Source Link

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());
            }//w  w  w  .java  2 s.  c o m
        }
        System.out.println("-----------------------------------");
    }
}

From source file:lcn.module.batch.web.guide.support.SkipCheckingDecider.java

/**
 * skip? step ?? ? FlowExecution? Status .
 *//*from   w  ww.  j a  v a2  s  .co m*/
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {
    if (!stepExecution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())
            && stepExecution.getSkipCount() > 0) {
        return new FlowExecutionStatus("COMPLETED WITH SKIPS");
    } else {
        return new FlowExecutionStatus(ExitStatus.COMPLETED.getExitCode());
    }
}

From source file:org.jasig.ssp.util.importer.job.twodottwo.StageSuccessWithSkipTest.java

@Test
public void testStageSuccessWithSkip() throws Exception {

    //Test file should have 1 step which should write successfully but skip 1 line
    JobExecution jobExecution = jobLauncherTestUtils.launchJob();
    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
    for (StepExecution stepExecution : stepExecutions) {
        Assert.assertEquals(1, stepExecution.getWriteCount());
        Assert.assertEquals(1, stepExecution.getSkipCount());
    }/*from   w  w  w.  j  a va 2  s  .  com*/
    BatchStatus exitStatus = jobExecution.getStatus();

    Assert.assertEquals(BatchStatus.COMPLETED, exitStatus);

}

From source file:lcn.module.batch.web.guide.listener.SkipCheckingListener.java

/**
 * ? Fail?, Skip? ?? , ExitStatus ? COMPLETED WITH SKIPS  
 *///ww  w  . j a v  a  2s  .co m
@AfterStep
public ExitStatus checkForSkips(StepExecution stepExecution) {
    if (!stepExecution.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())
            && stepExecution.getSkipCount() > 0) {
        return new ExitStatus("COMPLETED WITH SKIPS");
    } else {
        return null;
    }
}

From source file:admin.jmx.SimpleStepExecutionMetrics.java

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

From source file:lcn.module.batch.web.guide.support.ErrorLogTasklet.java

/**
 * skipCount  Execution ? //from ww w . j  av  a  2  s.  c  o  m
 */
private int getSkipCount() {
    if (stepExecution == null || stepName == null) {
        return 0;
    }
    for (StepExecution execution : stepExecution.getJobExecution().getStepExecutions()) {
        if (execution.getStepName().equals(stepName)) {
            return execution.getSkipCount();
        }
    }
    return 0;
}

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. j  a  v a2s  . c  om
    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();) {/*from   w w  w . j  a  v  a2  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: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;
    }//from ww w.ja va 2 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:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanNonBufferingTests.java

/**
 * Check items causing errors are skipped as expected.
 *//*from  ww  w . j av a 2 s  .  c om*/
@Test
public void testSkip() throws Exception {
    @SuppressWarnings("unchecked")
    SkipListener<Integer, String> skipListener = mock(SkipListener.class);
    skipListener.onSkipInWrite("3", exception);
    skipListener.onSkipInWrite("4", exception);

    factory.setListeners(new SkipListener[] { skipListener });
    Step step = factory.getObject();

    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
    step.execute(stepExecution);

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());

    assertEquals(2, stepExecution.getSkipCount());
    assertEquals(0, stepExecution.getReadSkipCount());
    assertEquals(2, stepExecution.getWriteSkipCount());

    // only one exception caused rollback, and only once in this case
    // because all items in that chunk were skipped immediately
    assertEquals(1, stepExecution.getRollbackCount());

    assertFalse(writer.written.contains("4"));

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,5"));
    assertEquals(expectedOutput, writer.written);

    // 5 items + 1 rollbacks reading 2 items each time
    assertEquals(7, stepExecution.getReadCount());

}