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;
 }
 @Override
 public ExitStatus afterStep(StepExecution stepExecution) {
   if (!ExitStatus.FAILED.equals(stepExecution.getExitStatus())
       && stepExecution.getSkipCount() > 0) {
     return new ExitStatus("COMPLETED WITH SKIPS");
   } else {
     return stepExecution.getExitStatus();
   }
 }
 @Test
 public void testInterrupted() throws Exception {
   taskletStep.setStepExecutionListeners(new StepExecutionListener[] {new InterruptionListener()});
   taskletStep.execute(stepExecution);
   assertEquals(STOPPED, stepExecution.getStatus());
   assertEquals(STOPPED.toString(), stepExecution.getExitStatus().getExitCode());
 }
  @Test
  public void testApplicationException() throws Exception {

    taskletStep.execute(stepExecution);
    assertEquals(FAILED, stepExecution.getStatus());
    assertEquals(FAILED.toString(), stepExecution.getExitStatus().getExitCode());
  }
示例#5
0
 public String getJobFailDescription(String jobName) {
   String failDescription = null;
   JobExplorer explorer = getBatchJobExplorer();
   List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 1);
   if (jobInstances.size() > 0) {
     List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstances.get(0));
     if (jobExecutions.size() > 0) {
       Collection<StepExecution> steps = jobExecutions.get(0).getStepExecutions();
       if (steps.size() > 0) {
         StepExecution step = steps.iterator().next();
         if (!step.getExitStatus().getExitDescription().isEmpty()) {
           failDescription = step.getExitStatus().getExitDescription();
         }
       }
     }
   }
   return failDescription;
 }
 @Override
 public ExitStatus afterStep(StepExecution stepExecution) {
   logger.log("all writes to s3 are done");
   logger.log(logger.getWrittenFiles() + " files were written");
   logger.log(
       logger.getFailedWrites() > 0
           ? logger.getFailedWrites() + " files failed to write"
           : "there were no write failures");
   return stepExecution.getExitStatus();
 }
  @Test
  public void testDefaultFailure() throws Exception {

    JobExecution jobExecution = createJobExecution();
    job.execute(jobExecution);
    assertEquals(2, stepNamesList.size());
    assertTrue(stepNamesList.contains("s1"));
    assertTrue(stepNamesList.contains("fail"));

    assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
    assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus().getExitCode());

    StepExecution stepExecution1 = getStepExecution(jobExecution, "s1");
    assertEquals(BatchStatus.COMPLETED, stepExecution1.getStatus());
    assertEquals(ExitStatus.COMPLETED, stepExecution1.getExitStatus());

    StepExecution stepExecution2 = getStepExecution(jobExecution, "fail");
    assertEquals(BatchStatus.FAILED, stepExecution2.getStatus());
    assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution2.getExitStatus().getExitCode());
  }
 @Test
 public void testInterruptedWithCustomStatus() throws Exception {
   taskletStep.setTasklet(
       new Tasklet() {
         public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
             throws Exception {
           contribution.setExitStatus(new ExitStatus("FUNNY"));
           throw new JobInterruptedException("Planned");
         }
       });
   taskletStep.execute(stepExecution);
   assertEquals(STOPPED, stepExecution.getStatus());
   assertEquals("FUNNY", stepExecution.getExitStatus().getExitCode());
 }
  public ExitStatus afterStep(StepExecution stepExecution) {

    destroy();

    return stepExecution.getExitStatus();
  }
  @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);
      }

      stepExecution.incrementVersion();
    }
  }