public JobExecution launch(String jobName, JobParameters jobParameters)
      throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException,
          JobInstanceAlreadyCompleteException, JobParametersInvalidException {

    Job job = jobLocator.getJob(jobName);

    JobExecution lastJobExecution = jobRepository.getLastJobExecution(jobName, jobParameters);
    boolean restart = false;
    if (lastJobExecution != null) {
      BatchStatus status = lastJobExecution.getStatus();
      if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) {
        restart = true;
      }
    }

    if (job.getJobParametersIncrementer() != null && !restart) {
      jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
    }

    JobExecution jobExecution = jobLauncher.run(job, jobParameters);

    if (jobExecution.isRunning()) {
      activeExecutions.add(jobExecution);
    }
    return jobExecution;
  }
  @Test
  public void testGrabLineStop() throws Exception {
    BatchStatus batchStatus;
    JobParametersBuilder builder =
        new JobParametersBuilder(getJobLauncherTestUtils().getUniqueJobParameters());

    builder.addParameter("input.file.path", new JobParameter("train-list.properties"));
    builder.addParameter(
        "date", new JobParameter(new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2000")));
    builder.addParameter("language", new JobParameter(Language.EN.name()));
    builder.addParameter("station.departure", new JobParameter("Liège-Guillemins"));
    builder.addParameter("station.arrival", new JobParameter("Bruxelles-Central"));
    builder.addParameter("excel.output.path", new JobParameter("./target"));
    builder.addParameter("excel.file.name", new JobParameter("sncb_"));
    builder.addParameter("excel.file.extension", new JobParameter("xls"));
    builder.addParameter("excel.archive.path", new JobParameter("./target"));
    builder.addParameter("text.output.path", new JobParameter("./target/output.txt"));
    builder.addParameter(
        "excel.template.path",
        new JobParameter(new ClassPathResource("template.xls").getFile().getAbsolutePath()));

    batchStatus = getJobLauncherTestUtils().launchJob(builder.toJobParameters()).getStatus();

    Assert.assertFalse(batchStatus.isUnsuccessful());
  }
Esempio n. 3
0
  /**
   * Returns the status of a given job
   *
   * @param id
   * @return
   */
  public String getStatus(String id) {
    JobExecution ex = executions.get(id);
    if (ex != null) {
      BatchStatus st = ex.getStatus();
      String status = "";
      if (BatchStatus.FAILED == st) {
        status = "Clustering job aborted."; // Please make sure the given parameters comply with the
        // specification.";

        List<Throwable> lst = ex.getAllFailureExceptions();
        for (Throwable e : lst) {
          e.printStackTrace();
          status += "\n " + e.getMessage();
        }
      } else if (ex.getExecutionContext().containsKey("status")) {
        status = ex.getExecutionContext().getString("status");
      }
      return st.name() + " - " + status;
    }

    if (FileManager.INSTANCE.getTaskFile(id) != null)
      return "COMPLETED - clustered job '" + id + "'";

    return "Unknown job '" + id + "'";
  }
  public JobExecutionInfo(JobExecution jobExecution, TimeZone timeZone) {

    // this.jobExecution = jobExecution;
    this.exitStatus = jobExecution.getExitStatus();
    this.timeZone = timeZone;
    this.id = jobExecution.getId();
    this.jobId = jobExecution.getJobId();
    this.stepExecutionCount = jobExecution.getStepExecutions().size();
    this.jobParameters = converter.getProperties(jobExecution.getJobParameters());
    this.jobParametersString =
        new JobParametersExtractor().fromJobParameters(jobExecution.getJobParameters());

    JobInstance jobInstance = jobExecution.getJobInstance();
    if (jobInstance != null) {
      this.jobName = jobInstance.getJobName();
      BatchStatus status = jobExecution.getStatus();
      this.restartable =
          status.isGreaterThan(BatchStatus.STOPPING) && status.isLessThan(BatchStatus.ABANDONED);
      this.abandonable =
          status.isGreaterThan(BatchStatus.STARTED) && status != BatchStatus.ABANDONED;
      this.stoppable = status.isLessThan(BatchStatus.STOPPING);
    } else {
      this.jobName = "?";
    }

    // Duration is always in GMT
    durationFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    // The others can be localized
    timeFormat.setTimeZone(timeZone);
    dateFormat.setTimeZone(timeZone);
    if (jobExecution.getStartTime() != null) {
      this.startDate = dateFormat.format(jobExecution.getStartTime());
      this.startTime = timeFormat.format(jobExecution.getStartTime());
      Date endTime = jobExecution.getEndTime() != null ? jobExecution.getEndTime() : new Date();
      this.duration =
          durationFormat.format(
              new Date(endTime.getTime() - jobExecution.getStartTime().getTime()));
    }
  }
 @Override
 public StepExecution mapRow(ResultSet rs, int rowNum) throws SQLException {
   StepExecution stepExecution = new StepExecution(rs.getString(2), jobExecution, rs.getLong(1));
   stepExecution.setStartTime(rs.getTimestamp(3));
   stepExecution.setEndTime(rs.getTimestamp(4));
   stepExecution.setStatus(BatchStatus.valueOf(rs.getString(5)));
   stepExecution.setCommitCount(rs.getInt(6));
   stepExecution.setReadCount(rs.getInt(7));
   stepExecution.setFilterCount(rs.getInt(8));
   stepExecution.setWriteCount(rs.getInt(9));
   stepExecution.setExitStatus(new ExitStatus(rs.getString(10), rs.getString(11)));
   stepExecution.setReadSkipCount(rs.getInt(12));
   stepExecution.setWriteSkipCount(rs.getInt(13));
   stepExecution.setProcessSkipCount(rs.getInt(14));
   stepExecution.setRollbackCount(rs.getInt(15));
   stepExecution.setLastUpdated(rs.getTimestamp(16));
   stepExecution.setVersion(rs.getInt(17));
   return stepExecution;
 }
    @Override
    public JobExecution mapRow(ResultSet rs, int rowNum) throws SQLException {
      Long id = rs.getLong(1);
      JobExecution jobExecution;

      JobParameters jobParameters = getJobParameters(id);

      JobInstance jobInstance = new JobInstance(rs.getLong(10), rs.getString(11));
      jobExecution = new JobExecution(jobInstance, jobParameters);
      jobExecution.setId(id);

      jobExecution.setStartTime(rs.getTimestamp(2));
      jobExecution.setEndTime(rs.getTimestamp(3));
      jobExecution.setStatus(BatchStatus.valueOf(rs.getString(4)));
      jobExecution.setExitStatus(new ExitStatus(rs.getString(5), rs.getString(6)));
      jobExecution.setCreateTime(rs.getTimestamp(7));
      jobExecution.setLastUpdated(rs.getTimestamp(8));
      jobExecution.setVersion(rs.getInt(9));
      return jobExecution;
    }
Esempio n. 7
0
  /**
   * Run the specified job, handling all listener and repository calls, and delegating the actual
   * processing to {@link #doExecute(JobExecution)}.
   *
   * @see Job#execute(JobExecution)
   * @throws StartLimitExceededException if start limit of one of the steps was exceeded
   */
  @Override
  public final void execute(JobExecution execution) {

    logger.debug("Job execution starting: " + execution);

    try {

      jobParametersValidator.validate(execution.getJobInstance().getJobParameters());

      if (execution.getStatus() != BatchStatus.STOPPING) {

        execution.setStartTime(new Date());
        updateStatus(execution, BatchStatus.STARTED);

        listener.beforeJob(execution);

        try {
          doExecute(execution);
          logger.debug("Job execution complete: " + execution);
        } catch (RepeatException e) {
          throw e.getCause();
        }
      } else {

        // The job was already stopped before we even got this far. Deal
        // with it in the same way as any other interruption.
        execution.setStatus(BatchStatus.STOPPED);
        execution.setExitStatus(ExitStatus.COMPLETED);
        logger.debug("Job execution was stopped: " + execution);
      }

    } catch (JobInterruptedException e) {
      logger.info("Encountered interruption executing job: " + e.getMessage());
      if (logger.isDebugEnabled()) {
        logger.debug("Full exception", e);
      }
      execution.setExitStatus(getDefaultExitStatusForFailure(e));
      execution.setStatus(BatchStatus.max(BatchStatus.STOPPED, e.getStatus()));
      execution.addFailureException(e);
    } catch (Throwable t) {
      logger.error("Encountered fatal error executing job", t);
      execution.setExitStatus(getDefaultExitStatusForFailure(t));
      execution.setStatus(BatchStatus.FAILED);
      execution.addFailureException(t);
    } finally {

      if (execution.getStatus().isLessThanOrEqualTo(BatchStatus.STOPPED)
          && execution.getStepExecutions().isEmpty()) {
        ExitStatus exitStatus = execution.getExitStatus();
        execution.setExitStatus(
            exitStatus.and(
                ExitStatus.NOOP.addExitDescription(
                    "All steps already completed or no steps configured for this job.")));
      }

      execution.setEndTime(new Date());

      try {
        listener.afterJob(execution);
      } catch (Exception e) {
        logger.error("Exception encountered in afterStep callback", e);
      }

      jobRepository.update(execution);
    }
  }
 private boolean isComplete(BatchStatus status) {
   return status.equals(BatchStatus.COMPLETED) || status.isGreaterThan(BatchStatus.STARTED);
 }