Java Code Examples for org.springframework.batch.core.StepExecution#getWriteCount()

The following examples show how to use org.springframework.batch.core.StepExecution#getWriteCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CampusInterceptor.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Generates an appropriate statistic of the processed, <br>
 * delegates the cleanup and the metric notification.
 * 
 * @param se
 *            the StepExecution
 */
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public ExitStatus afterStep(StepExecution se) {
    LOG.info(se);

    statisticDao.save(createImportStatistic(se));

    if (CampusProcessStep.IMPORT_CONTROLFILE.name().equalsIgnoreCase(se.getStepName())) {
        if (se.getWriteCount() != getFixedNumberOfFilesToBeExported()) {
            // if (se.getReadCount() != getFixedNumberOfFilesToBeExported() || se.getWriteCount() != getFixedNumberOfFilesToBeExported()) {
            notifyMetrics(se);
            return ExitStatus.FAILED;
        }
    }

    removeOldDataIfExist(se);
    notifyMetrics(se);

    return null;
}
 
Example 2
Source File: StepExecutionEvent.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the StepExecution to initialize the DTO.
 * @param stepExecution the StepExecution to build this DTO around.
 */
public StepExecutionEvent(StepExecution stepExecution) {
	super();
	Assert.notNull(stepExecution,
			"StepExecution must be provided to re-hydrate an existing StepExecutionEvent");
	Assert.notNull(stepExecution.getJobExecution(),
			"JobExecution must be provided to re-hydrate an existing StepExecutionEvent");
	setId(stepExecution.getId());
	this.jobExecutionId = stepExecution.getJobExecutionId();
	this.stepName = stepExecution.getStepName();

	this.status = stepExecution.getStatus();
	this.exitStatus = new ExitStatus(stepExecution.getExitStatus());
	this.executionContext = stepExecution.getExecutionContext();
	for (Throwable throwable : stepExecution.getFailureExceptions()) {
		this.failureExceptions.add(throwable);
	}
	this.terminateOnly = stepExecution.isTerminateOnly();

	this.endTime = stepExecution.getEndTime();
	this.lastUpdated = stepExecution.getLastUpdated();
	this.startTime = stepExecution.getStartTime();

	this.commitCount = stepExecution.getCommitCount();
	this.filterCount = stepExecution.getFilterCount();
	this.processSkipCount = stepExecution.getProcessSkipCount();
	this.readCount = stepExecution.getReadCount();
	this.readSkipCount = stepExecution.getReadSkipCount();
	this.rollbackCount = stepExecution.getRollbackCount();
	this.writeCount = stepExecution.getWriteCount();
	this.writeSkipCount = stepExecution.getWriteSkipCount();

}
 
Example 3
Source File: CampusInterceptor.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * Prepares the metric data and delegates the actual notification to the {@link CampusNotifier}.
 * 
 * @param se
 *            the StepExecution
 */
private void notifyMetrics(StepExecution se) {
    if (CampusProcessStep.IMPORT_CONTROLFILE.name().equalsIgnoreCase(se.getStepName())) {
        campusNotifier.notifyStartOfImportProcess();
        CampusStatistics.EXPORT_STATUS exportStatus = CampusStatistics.EXPORT_STATUS.OK;

        if (se.getReadCount() != getFixedNumberOfFilesToBeExported() && se.getReadCount() != 2 * getFixedNumberOfFilesToBeExported()) {
            // THE CASE THAT THE EXPORT FILE (CONTROL FILE) HASN'T BEEN CREATED YET
            if (se.getReadCount() == 0) {
                exportStatus = CampusStatistics.EXPORT_STATUS.NO_EXPORT;
            }
            // THE CASE OF EXPORTING LESS THAN THE EXPECTED FILES (LESS THAN 8(ONLY CURRENT) OR LESS THAN 16 (CURRENT AND NEXT)
            else {
                exportStatus = CampusStatistics.EXPORT_STATUS.INCOMPLETE_EXPORT;
            }
        }
        // THE CASE OF EXPORTING THE OLD FILES
        if (se.getWriteCount() != getFixedNumberOfFilesToBeExported()) {
            exportStatus = CampusStatistics.EXPORT_STATUS.NO_EXPORT;
        }

        campusNotifier.notifyExportStatus(exportStatus);
    }

    campusNotifier.notifyStepExecution(se);

}
 
Example 4
Source File: MetricsListener.java    From spring-boot-starter-batch-web with Apache License 2.0 5 votes vote down vote up
@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();
	meterRegistry.gauge(METRIC_NAME, Arrays.asList(//
			new ImmutableTag("context", getStepExecutionIdentifier(stepExecution)), //
			new ImmutableTag("name", "duration")//
	), stepDuration);
	long itemCount = stepExecution.getWriteCount() + stepExecution.getSkipCount();
	meterRegistry.gauge(METRIC_NAME, Arrays.asList(//
			new ImmutableTag("context", getStepExecutionIdentifier(stepExecution)), //
			new ImmutableTag("name", "item.count")//
	), itemCount);
	// Calculate execution time per item
	long durationPerItem = 0;
	if (itemCount > 0) {
		durationPerItem = stepDuration / itemCount;
	}
	meterRegistry.gauge(METRIC_NAME, Arrays.asList(//
			new ImmutableTag("context", getStepExecutionIdentifier(stepExecution)), //
			new ImmutableTag("name", "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 Number) {
			meterRegistry.gauge(METRIC_NAME, Arrays.asList(//
					new ImmutableTag("context", getStepExecutionIdentifier(stepExecution)), //
					new ImmutableTag("name", metric.getKey())//
			), (Number) metric.getValue());
		}
	}
	return null;
}
 
Example 5
Source File: FailedStepStepExecutionListener.java    From batchers with Apache License 2.0 4 votes vote down vote up
private boolean someItemsGotSkippedDueToTaxWebServiceExceptions(StepExecution stepExecution) {
    return stepExecution.getReadCount() != stepExecution.getWriteCount() || stepExecution.getRollbackCount() > 0;
}