Exemplo n.º 1
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;
 }
Exemplo 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;
 }
Exemplo n.º 3
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;
  }