Ejemplo n.º 1
0
 private JobExecution getLastFailedJobExecution(String jobIdentifier) {
   List<JobExecution> jobExecutions =
       getJobExecutionsWithStatusGreaterThan(jobIdentifier, BatchStatus.STOPPING);
   if (jobExecutions.isEmpty()) {
     return null;
   }
   return jobExecutions.get(0);
 }
Ejemplo n.º 2
0
 private List<JobExecution> getRunningJobExecutions(String jobIdentifier) {
   List<JobExecution> jobExecutions =
       getJobExecutionsWithStatusGreaterThan(jobIdentifier, BatchStatus.COMPLETED);
   if (jobExecutions.isEmpty()) {
     return null;
   }
   List<JobExecution> result = new ArrayList<JobExecution>();
   for (JobExecution jobExecution : jobExecutions) {
     if (jobExecution.isRunning()) {
       result.add(jobExecution);
     }
   }
   return result.isEmpty() ? null : result;
 }
Ejemplo n.º 3
0
 private List<JobExecution> getStoppedJobExecutions(String jobIdentifier) {
   List<JobExecution> jobExecutions =
       getJobExecutionsWithStatusGreaterThan(jobIdentifier, BatchStatus.STARTED);
   if (jobExecutions.isEmpty()) {
     return null;
   }
   List<JobExecution> result = new ArrayList<JobExecution>();
   for (JobExecution jobExecution : jobExecutions) {
     if (jobExecution.getStatus() != BatchStatus.ABANDONED) {
       result.add(jobExecution);
     }
   }
   return result.isEmpty() ? null : result;
 }
Ejemplo n.º 4
0
  /**
   * @param job the job that we need to find the next parameters for
   * @return the next job parameters if they can be located
   * @throws JobParametersNotFoundException if there is a problem
   */
  private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException {
    String jobIdentifier = job.getName();
    JobParameters jobParameters;
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1);

    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    if (incrementer == null) {
      throw new JobParametersNotFoundException(
          "No job parameters incrementer found for job=" + jobIdentifier);
    }

    if (lastInstances.isEmpty()) {
      jobParameters = incrementer.getNext(new JobParameters());
      if (jobParameters == null) {
        throw new JobParametersNotFoundException(
            "No bootstrap parameters found from incrementer for job=" + jobIdentifier);
      }
    } else {
      jobParameters = incrementer.getNext(lastInstances.get(0).getJobParameters());
    }
    return jobParameters;
  }
Ejemplo n.º 5
0
  /**
   * @param jobIdentifier a job execution id or job name
   * @param minStatus the highest status to exclude from the result
   * @return
   */
  private List<JobExecution> getJobExecutionsWithStatusGreaterThan(
      String jobIdentifier, BatchStatus minStatus) {

    Long executionId = getLongIdentifier(jobIdentifier);
    if (executionId != null) {
      JobExecution jobExecution = jobExplorer.getJobExecution(executionId);
      if (jobExecution.getStatus().isGreaterThan(minStatus)) {
        return Arrays.asList(jobExecution);
      }
      return Collections.emptyList();
    }

    int start = 0;
    int count = 100;
    List<JobExecution> executions = new ArrayList<JobExecution>();
    List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, start, count);

    while (!lastInstances.isEmpty()) {

      for (JobInstance jobInstance : lastInstances) {
        List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
        if (jobExecutions == null || jobExecutions.isEmpty()) {
          continue;
        }
        for (JobExecution jobExecution : jobExecutions) {
          if (jobExecution.getStatus().isGreaterThan(minStatus)) {
            executions.add(jobExecution);
          }
        }
      }

      start += count;
      lastInstances = jobExplorer.getJobInstances(jobIdentifier, start, count);
    }

    return executions;
  }