List of usage examples for org.springframework.batch.core JobExecution getStepExecutions
public Collection<StepExecution> getStepExecutions()
From source file:de.codecentric.batch.test.metrics.BatchMetricsFlatFileToDbIntegrationTest.java
@Test public void testRunFlatFileToDbSkipJob_SkipInWrite_ProcessorNonTransactional() throws InterruptedException { JobExecution jobExecution = runJob("flatFileToDbSkipProcessorNonTransactionalJob", "metrics/flatFileToDbSkipJob_SkipInWrite.csv"); assertThat(jobExecution.getStatus(), is(BatchStatus.COMPLETED)); ExecutionContext executionContext = jobExecution.getStepExecutions().iterator().next() .getExecutionContext();//from w w w. j av a 2s. c o m long writeCount = 7L; MetricValidator validator = MetricValidatorBuilder.metricValidator().withExecutionContext(executionContext) .withBeforeChunkCount(4L).withStreamOpenCount(1L).withStreamUpdateCount(4L).withStreamCloseCount(0L) .withBeforeReadCount(9L).withReadCount(9L).withAfterReadCount(8L).withReadErrorCount(0L) .withBeforeProcessCount(8L).withProcessCount(8L).withAfterProcessCount(8L).withProcessErrorCount(0L) .withBeforeWriteCount(5L).withWriteCount(writeCount).withAfterWriteCount(7L).withWriteErrorCount(4L) .withAfterChunkCount(4L).withChunkErrorCount(2L).withSkipInReadCount(0L).withSkipInProcessCount(0L) .withSkipInWriteCount(1L).build(); // TODO Bug in beforeWrite listener in Spring Batch? validator.validate(); // if one is correct, all will be in the metricReader, so I check just one assertThat((Double) metricReader.findOne("gauge.batch.flatFileToDbSkipProcessorNonTransactionalJob.step." + MetricNames.PROCESS_COUNT.getName()).getValue(), is(notNullValue())); assertThat(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM ITEM", Long.class), is(writeCount)); }
From source file:de.codecentric.batch.test.metrics.BatchMetricsFlatFileToDbIntegrationTest.java
@Test public void testRunFlatFileToDbSkipJob_SkipInProcess_ProcessorNonTransactional() throws InterruptedException { JobExecution jobExecution = runJob("flatFileToDbSkipProcessorNonTransactionalJob", "metrics/flatFileToDbSkipJob_SkipInProcess.csv"); assertThat(jobExecution.getStatus(), is(BatchStatus.COMPLETED)); ExecutionContext executionContext = jobExecution.getStepExecutions().iterator().next() .getExecutionContext();/*from w w w.j a v a 2s . co m*/ long writeCount = 7L; MetricValidator validator = MetricValidatorBuilder.metricValidator().withExecutionContext(executionContext) .withBeforeChunkCount(3L).withStreamOpenCount(1L).withStreamUpdateCount(4L).withStreamCloseCount(0L) .withBeforeReadCount(9L).withReadCount(9L).withAfterReadCount(8L).withReadErrorCount(0L) .withBeforeProcessCount(8L).withProcessCount(8L).withAfterProcessCount(7L).withProcessErrorCount(1L) .withBeforeWriteCount(7L).withWriteCount(writeCount).withAfterWriteCount(7L).withAfterChunkCount(3L) .withChunkErrorCount(1L).withSkipInReadCount(0L).withSkipInProcessCount(1L).withSkipInWriteCount(0L) .build(); validator.validate(); // if one is correct, all will be in the metricReader, so I check just one assertThat((Double) metricReader.findOne("gauge.batch.flatFileToDbSkipProcessorNonTransactionalJob.step." + MetricNames.PROCESS_COUNT.getName()).getValue(), is(notNullValue())); assertThat(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM ITEM", Long.class), is(writeCount)); }
From source file:org.trpr.platform.batch.impl.spring.jmx.JobAdministrator.java
/** * Returns the JobStatistics array for all jobs deployed locally * @return JobStatistics array containing one instance per job deployed locally *//* w ww . j a va 2 s . co m*/ private JobStatistics[] getStats() { JobStatistics[] jobStatistics = new JobStatistics[this.getJobOperator().getJobNames().size()]; int count = 0; for (String jobName : this.getJobOperator().getJobNames()) { jobStatistics[count] = new JobStatistics(); jobStatistics[count].setHostIP(this.getHostIP()); jobStatistics[count].setHostStartTimeStamp(this.getHostStartTimeStamp()); jobStatistics[count].setJobName(jobName); // get the last run JobInstance if any List<JobInstance> jobInstancesList = this.getJobExplorer().getJobInstances(jobName, 0, 1); // end is set as 1 to get a single element List if (jobInstancesList.size() > 0) { // there is at least one job instance // get the first i.e. the most recent job instance JobInstance jobInstance = jobInstancesList.get(0); // now get all successful JobExecution(s) for this JobInstance List<JobExecution> jobExecutionList = this.getJobExplorer().getJobExecutions(jobInstance); if (jobExecutionList.size() > 0) { // there is at least one job execution for the job instance // get the first i.e. the most recent job execution JobExecution jobExecution = jobExecutionList.get(0); jobStatistics[count].setJobStatus(jobExecution.getStatus().name()); if (jobExecution.getStatus() == BatchStatus.FAILED) { // try to get the exit description from the contained steps that errored out Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions(); for (StepExecution step : stepExecutions) { jobStatistics[count].getJobSteps().add(step.getStepName()); if (step.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())) { jobStatistics[count].setJobStepInError(step.getStepName()); jobStatistics[count].setJobMessage(step.getExitStatus().getExitDescription()); } } } else { jobStatistics[count].setJobMessage(jobExecution.getExitStatus().getExitDescription()); } Calendar jobStartTimeStamp = Calendar.getInstance(); jobStartTimeStamp.setTime(jobExecution.getStartTime()); jobStatistics[count].setJobStartTimeStamp(jobStartTimeStamp); Calendar jobEndTimeStamp = Calendar.getInstance(); jobEndTimeStamp.setTime(jobExecution.getEndTime()); jobStatistics[count].setJobEndTimestamp(jobEndTimeStamp); } } count += 1; } return jobStatistics; }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java
/** * Interface method implementation//from w w w . ja v a2 s.c o m * @see org.springframework.batch.admin.service.JobService#getStepNamesForJob(java.lang.String) */ public Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobException { Collection<String> stepNames = new LinkedHashSet<String>(); for (JobExecution jobExecution : listJobExecutionsForJob(jobName, 0, 100)) { for (StepExecution stepExecution : jobExecution.getStepExecutions()) { stepNames.add(stepExecution.getStepName()); } } return Collections.unmodifiableList(new ArrayList<String>(stepNames)); }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java
/** * Interface method implementation/*from w ww . j av a 2 s . c o m*/ * @see org.springframework.batch.admin.service.JobService#countStepExecutionsForStep(java.lang.String, java.lang.String) */ public int countStepExecutionsForStep(String jobName, String stepName) throws NoSuchStepException { int count = 0; for (String name : this.jobRegistry.getJobNames()) { if (name.contains(jobName)) { for (JobInstance jobInstance : this.jobExplorer.getJobInstances(jobName, 0, Integer.MAX_VALUE)) { for (JobExecution jobExecution : this.jobExplorer.getJobExecutions(jobInstance)) { Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions(); for (StepExecution step : stepExecutions) { if (step.getStepName().contains(stepName)) { count += 1; } } } } } } return count; }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java
/** * Interface method implementation// w w w . j av a2 s. co m * @see org.springframework.batch.admin.service.JobService#listStepExecutionsForStep(java.lang.String, java.lang.String, int, int) */ public Collection<StepExecution> listStepExecutionsForStep(String jobName, String stepName, int start, int count) throws NoSuchStepException { if (this.countStepExecutionsForStep(jobName, stepName) == 0) { throw new NoSuchStepException("No step executions exist with this step name: " + stepName); } List<StepExecution> steps = new LinkedList<StepExecution>(); for (String name : this.jobRegistry.getJobNames()) { if (name.contains(jobName)) { for (JobInstance jobInstance : this.jobExplorer.getJobInstances(jobName, 0, Integer.MAX_VALUE)) { for (JobExecution jobExecution : this.jobExplorer.getJobExecutions(jobInstance)) { Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions(); for (StepExecution step : stepExecutions) { if (step.getStepName().contains(stepName)) { steps.add(step); } } } } } } if (start >= steps.size()) { return new LinkedList<StepExecution>(); // return empty list instead of a sub-list } if (start + count >= steps.size()) { count = steps.size() - start; } return steps.subList(start, count); }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java
/** * Interface method implementation//from w w w .ja v a 2 s .co m * @see org.springframework.batch.admin.service.JobService#getStepExecutions(java.lang.Long) */ public Collection<StepExecution> getStepExecutions(Long jobExecutionId) throws NoSuchJobExecutionException { for (String jobName : this.jobRegistry.getJobNames()) { for (JobInstance jobInstance : this.jobExplorer.getJobInstances(jobName, 0, Integer.MAX_VALUE)) { for (JobExecution jobExecution : this.jobExplorer.getJobExecutions(jobInstance)) { if (jobExecution.getId() == jobExecutionId) { return jobExecution.getStepExecutions(); } } } } return null; }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java
/** * Interface method implementation/* ww w .j ava2 s .c o m*/ * @see org.springframework.batch.admin.service.JobService#getStepExecution(java.lang.Long, java.lang.Long) */ public StepExecution getStepExecution(Long jobExecutionId, Long stepExecutionId) throws NoSuchStepExecutionException, NoSuchJobExecutionException { for (String jobName : this.jobRegistry.getJobNames()) { for (JobInstance jobInstance : this.jobExplorer.getJobInstances(jobName, 0, Integer.MAX_VALUE)) { for (JobExecution jobExecution : this.jobExplorer.getJobExecutions(jobInstance)) { if (jobExecution.getId() == jobExecutionId) { for (StepExecution step : jobExecution.getStepExecutions()) { if (step.getId() == stepExecutionId) { return step; } } } } } } return null; }
From source file:com.philips.cn.hr.pps.App.java
private void startCaclBtnActionPerformed(java.awt.event.ActionEvent evt) { String f1 = this.filePath1.getText(); String f2 = this.filePath2.getText(); String saveTo = this.saveToPath.getText(); StringBuffer message = new StringBuffer(); if (!isInputValidate(f1, f2, saveTo)) { message.append("file path null is not allowed"); JOptionPane.showMessageDialog(null, message); // System.exit(0); return;//ww w.j av a 2 s. c o m } System.out.println("going to execute application with parameters " + Arrays.asList(f1, f2, saveTo)); JobExecution jobExecution = null; try { jobExecution = Application.execute(f1, f2, saveTo, false); } catch (Exception e) { e.printStackTrace(); message.append(e.getMessage()); JOptionPane.showMessageDialog(null, message); return; } if (jobExecution.getExitStatus().equals(ExitStatus.COMPLETED)) { //job completed; message.append("Job execution completed ,Please verify generated files in "); message.append(saveTo); JOptionPane.showMessageDialog(null, message); } else { // for (Throwable exception : jobExecution.getAllFailureExceptions()) { // message.append("cause:" + exception.getCause()).append("message " + exception.getMessage()); // } // JOptionPane.showMessageDialog(null, message); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { if (!stepExecution.getExitStatus().equals(ExitStatus.COMPLETED)) { message.append(stepExecution.getFailureExceptions()); message.append(" occurred when executing "); message.append(stepExecution.getStepName()); break; } } JOptionPane.showMessageDialog(null, message); } // System.exit(0);don't exit; return; }