public JobExecution restart(Long jobExecutionId)
      throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException,
          JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException {

    JobExecution target = getJobExecution(jobExecutionId);
    JobInstance lastInstance = target.getJobInstance();

    Job job = jobLocator.getJob(lastInstance.getJobName());

    JobExecution jobExecution = jobLauncher.run(job, lastInstance.getJobParameters());

    if (jobExecution.isRunning()) {
      activeExecutions.add(jobExecution);
    }
    return jobExecution;
  }
  @Override
  public List<JobInstance> findJobInstancesByName(String jobName, int start, int count) {
    List<JobInstance> result = new ArrayList<JobInstance>();
    List<JobInstance> jobInstances =
        mapJobInstances(
            getCollection()
                .find(new BasicDBObject(JOB_NAME_KEY, jobName))
                .sort(jobInstanceIdObj(-1L)));
    for (JobInstance instanceEntry : jobInstances) {
      String key = instanceEntry.getJobName();
      String curJobName = key.substring(0, key.lastIndexOf("|"));

      if (curJobName.equals(jobName)) {
        result.add(instanceEntry);
      }
    }
    return result;
  }
  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 int getJobInstanceCount(String jobName) throws NoSuchJobException {

    int count = 0;
    List<JobInstance> jobInstances =
        mapJobInstances(
            getCollection()
                .find(new BasicDBObject(JOB_NAME_KEY, jobName))
                .sort(jobInstanceIdObj(-1L)));
    for (JobInstance instanceEntry : jobInstances) {
      String key = instanceEntry.getJobName();
      String curJobName = key.substring(0, key.lastIndexOf("|"));

      if (curJobName.equals(jobName)) {
        count++;
      }
    }

    if (count == 0) {
      throw new NoSuchJobException("No job instances for job name " + jobName + " were found");
    } else {
      return count;
    }
  }
示例#5
0
  @Test
  public void testGetJobName() {
    when(instance.getJobName()).thenReturn("jobName");

    assertEquals("jobName", context.getJobName());
  }