Ejemplo n.º 1
0
 public Date getJobsPreviousRunTime(String jobName) {
   JobExplorer explorer = getBatchJobExplorer();
   List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 1);
   if (jobInstances.size() == 0) {
     return new Date(0);
   }
   JobInstance jobInstance = jobInstances.get(0);
   long executionTimeInMillis =
       jobInstance.getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY);
   return new Date(executionTimeInMillis);
 }
  @Test
  public void testSimpleJob() throws Exception {

    JobInstance jobInstance = MetaDataInstanceFactory.createJobInstance("foo", 11L);
    JobExecution jobExecution = MetaDataInstanceFactory.createJobExecution("foo", 11L, 123L);
    jobExecution.setEndTime(new Date());
    jobExecution.setStatus(BatchStatus.FAILED);

    when(jobExplorer.getJobInstances("foo", 0, 100)).thenReturn(Arrays.asList(jobInstance));
    when(jobExplorer.getJobExecutions(jobInstance)).thenReturn(Arrays.asList(jobExecution));

    JobLaunchRequest request = adapter.adapt("foo");
    assertEquals("foo", request.getJob().getName());
    assertEquals(0, request.getJobParameters().getParameters().size());
  }
Ejemplo n.º 3
0
  public String getJobsPreviousRunStatus(String jobName) {
    JobExplorer explorer = getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 1);
    if (jobInstances.size() == 0) {
      return "Never executed yet";
    }
    List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstances.get(0));
    if (jobExecutions.size() == 0) {
      return "Never executed yet";
    }
    String runStatus = jobExecutions.get(0).getStatus().toString();
    runStatus = runStatus.substring(0, 1) + runStatus.substring(1).toLowerCase();

    return runStatus;
  }
Ejemplo n.º 4
0
  public Date getJobsLastSuccessfulRunTime(String jobName) {
    JobExplorer explorer = getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 100);

    for (JobInstance job : jobInstances) {
      for (JobExecution execution : explorer.getJobExecutions(job)) {
        if (BatchStatus.COMPLETED.equals(execution.getStatus())) {
          long executionTimeInMillis =
              job.getJobParameters().getLong(MifosBatchJob.JOB_EXECUTION_TIME_KEY);
          return new Date(executionTimeInMillis);
        }
      }
    }

    return new Date(0);
  }
  @Test
  public void testSimpleJobNotFailed() throws Exception {

    thrown.expect(JobParametersNotFoundException.class);
    thrown.expectMessage("No failed or stopped execution");

    JobInstance jobInstance = MetaDataInstanceFactory.createJobInstance("foo", 11L);
    JobExecution jobExecution = MetaDataInstanceFactory.createJobExecution("foo", 11L, 123L);
    jobExecution.setEndTime(new Date());
    jobExecution.setStatus(BatchStatus.COMPLETED);

    when(jobExplorer.getJobInstances("foo", 0, 100)).thenReturn(Arrays.asList(jobInstance));
    when(jobExplorer.getJobExecutions(jobInstance)).thenReturn(Arrays.asList(jobExecution));
    when(jobExplorer.getJobInstances("foo", 100, 100)).thenReturn(new ArrayList<JobInstance>());

    adapter.adapt("foo");
  }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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;
  }
 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;
 }
 /**
  * returns end date of the execution provided execution id
  *
  * @param jobExecutionId : id of the job execution
  * @return Date : end date of execution
  */
 public Date getEndDate(Integer jobExecutionId) {
   JobExecution execution = jobExplorer.getJobExecution(jobExecutionId.longValue());
   return execution == null ? null : execution.getEndTime();
 }
 /**
  * returns start date of the execution provided execution id
  *
  * @param jobExecutionId : id of the job execution
  * @return Date : start date of execution
  */
 public Date getStartDate(Integer jobExecutionId) {
   logger.debug("Entering getStartDate()");
   JobExecution execution = jobExplorer.getJobExecution(jobExecutionId.longValue());
   logger.debug("Found execution: " + execution);
   return execution == null ? null : execution.getStartTime();
 }
 /**
  * gets date value from job parameters
  *
  * @param executionId
  * @return
  */
 private Date getDateFromJbParametersByExecutionId(Integer executionId) {
   return jobExplorer
       .getJobExecution(executionId.longValue())
       .getJobParameters()
       .getDate(ServerConstants.BATCH_JOB_PARAM_BILLING_DATE);
 }