Examples of JobExecution


Examples of org.springframework.batch.core.JobExecution

    @Test
    public void testCreateAndFindWithNoStartDate() throws Exception {
        job.setRestartable(true);

        JobExecution firstExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
        firstExecution.setStartTime(new Date(0));
        firstExecution.setEndTime(new Date(1));
        jobRepository.update(firstExecution);
        JobExecution secondExecution = jobRepository.createJobExecution(job.getName(), jobParameters);

        assertEquals(firstExecution.getJobInstance(), secondExecution.getJobInstance());
        assertEquals(job.getName(), secondExecution.getJobInstance().getJobName());
    }
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

    public void testGetStepExecutionCountAndLastStepExecution() throws Exception {
        job.setRestartable(true);
        StepSupport step = new StepSupport("restartedStep");

        // first execution
        JobExecution firstJobExec = jobRepository.createJobExecution(job.getName(), jobParameters);
        StepExecution firstStepExec = new StepExecution(step.getName(), firstJobExec);
        jobRepository.add(firstStepExec);

        assertEquals(1, jobRepository.getStepExecutionCount(firstJobExec.getJobInstance(), step.getName()));
        assertEquals(firstStepExec, jobRepository.getLastStepExecution(firstJobExec.getJobInstance(), step.getName()));

        // first execution failed
        firstJobExec.setStartTime(new Date(4));
        firstStepExec.setStartTime(new Date(5));
        firstStepExec.setStatus(BatchStatus.FAILED);
        firstStepExec.setEndTime(new Date(6));
        jobRepository.update(firstStepExec);
        firstJobExec.setStatus(BatchStatus.FAILED);
        firstJobExec.setEndTime(new Date(7));
        jobRepository.update(firstJobExec);

        // second execution
        JobExecution secondJobExec = jobRepository.createJobExecution(job.getName(), jobParameters);
        StepExecution secondStepExec = new StepExecution(step.getName(), secondJobExec);
        jobRepository.add(secondStepExec);

        assertEquals(2, jobRepository.getStepExecutionCount(secondJobExec.getJobInstance(), step.getName()));
        assertEquals(secondStepExec, jobRepository.getLastStepExecution(secondJobExec.getJobInstance(), step.getName()));
    }
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

    @Test
    public void testSaveExecutionContext() throws Exception {
        ExecutionContext ctx = new ExecutionContext();
        ctx.putLong("crashedPosition", 7);
        JobExecution jobExec = jobRepository.createJobExecution(job.getName(), jobParameters);
        jobExec.setStartTime(new Date(0));
        jobExec.setExecutionContext(ctx);
        Step step = new StepSupport("step1");
        StepExecution stepExec = new StepExecution(step.getName(), jobExec);
        stepExec.setExecutionContext(ctx);

        jobRepository.add(stepExec);

        StepExecution retrievedStepExec = jobRepository.getLastStepExecution(jobExec.getJobInstance(), step.getName());
        assertEquals(stepExec, retrievedStepExec);
        assertEquals(ctx, retrievedStepExec.getExecutionContext());

    }
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

        }
    }

    @Test
    public void testGetLastJobExecution() throws Exception {
        JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
        jobExecution.setStatus(BatchStatus.FAILED);
        jobExecution.setEndTime(new Date());
        jobRepository.update(jobExecution);
        Thread.sleep(10);
        jobExecution = jobRepository.createJobExecution(job.getName(), jobParameters);
        assertEquals(jobExecution, jobRepository.getLastJobExecution(job.getName(), jobParameters));
    }
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

   *
   * @param type the step execution type
   * @return converted step execution
   */
  public static StepExecution convertStepExecutionType(StepExecutionType type) {
    JobExecution jobExecution = convertJobExecutionType(type.jobExecution);
    StepExecution stepExecution = type.id != null ? new StepExecution(type.stepName, jobExecution, type.id)
        : new StepExecution(type.stepName, jobExecution);
    stepExecution.setVersion(type.version);
    stepExecution.setStatus(type.status);
    stepExecution.setExitStatus(new ExitStatus(type.exitStatus));
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

   */
  public static JobExecution convertJobExecutionType(JobExecutionType type) {
    JobInstance jobInstance = convertJobInstanceType(type.jobInstance);
    JobParameters jobParameters = convertJobParametersType(type.jobParameters);

    JobExecution jobExecution = new JobExecution(jobInstance, type.id, jobParameters, type.jobConfigurationLocation);

    jobExecution.setVersion(type.version);
    jobExecution.setStatus(type.status);
    jobExecution.setStartTime(nullsafeToDate(type.startTime));
    jobExecution.setEndTime(nullsafeToDate(type.endTime));
    jobExecution.setCreateTime(nullsafeToDate(type.createTime));
    jobExecution.setLastUpdated(nullsafeToDate(type.lastUpdated));
    jobExecution.setExitStatus(new ExitStatus(type.exitStatus));

    List<StepExecution> stepExecutions = new ArrayList<StepExecution>();
    for(StepExecutionType stepExecutionType : type.stepExecutions) {
      StepExecution convertStepExecutionType = convertStepExecutionType(stepExecutionType);
      stepExecutions.add(convertStepExecutionType);
    }
    jobExecution.addStepExecutions(stepExecutions);

    ExecutionContext executionContext = convertExecutionContextType(type.executionContext);

    jobExecution.setExecutionContext(executionContext);

    return jobExecution;
  }
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

    if (jobProperties != null && jobProperties.isRestart()) {
      if (jobExplorer == null) {
        throw new JobExecutionException("A JobExplorer must be provided for a restart or start next operation.");
      }
      JobExecution jobExecution = getLastFailedJobExecution(jobIdentifier);
      if (log.isDebugEnabled()) {
        log.info("Last failed JobExecution: " + jobExecution);
      }
      if (jobExecution == null && jobProperties.isFailRestart()) {
        throw new JobExecutionNotFailedException("No failed or stopped execution found for job="
            + jobIdentifier);
      } else {
        log.info("No failed or stopped execution found for job=" + jobIdentifier
            + ", batch properties flag for failRestart=" + jobProperties.isFailRestart()
            + " so we don't fail restart.");
      }
      if (jobExecution != null) {
        restart = true;
        jobParameters = jobExecution.getJobParameters();
      }
    }

    if (jobProperties != null && jobProperties.isNext() && !restart) {
      if (jobExplorer == null) {
        throw new JobExecutionException("A JobExplorer must be provided for a restart or start next operation.");
      }
      JobParameters nextParameters = getNextJobParameters(job, false);
      Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters());
      map.putAll(jobParameters.getParameters());
      jobParameters = new JobParameters(map);
      if (log.isDebugEnabled()) {
        log.info("JobParameter for job=[" + job + "] next=" + nextParameters + " used=" + jobParameters);
      }
    }

    JobExecution execution = this.jobLauncher.run(job, jobParameters);
    if (this.publisher != null) {
      this.publisher.publishEvent(new JobExecutionEvent(this, execution));
    }
  }
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

    }

    @Override
    public void process(Exchange exchange) throws Exception {
        JobParameters jobParameters = prepareJobParameters(exchange.getIn().getHeaders());
        JobExecution jobExecution = jobLauncher.run(job, jobParameters);
        exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
        exchange.getOut().setBody(jobExecution);
    }
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

  @Test
  public void testJobTaskletKill() throws Exception {
    Job victimJob = ctx.getBean("tasklet-victim-job", Job.class);

    // start async job execution
    JobExecution batchJob = JobsTrigger.startJob(ctx, "mainJob");

    // wait a bit for the job to be started
    while (!(JobUtils.getStatus(victimJob).isRunning() || JobUtils.getStatus(victimJob).isFinished())) {
      Thread.sleep(WAIT_FOR_JOB_TO_START);
    }

    batchJob.stop();

    checkHadoopJobWasKilled(victimJob);
  }
View Full Code Here

Examples of org.springframework.batch.core.JobExecution

    List<JobExecution> executions = new ArrayList<JobExecution>(jobs.size());
    for (Map.Entry<String, Job> entry : jobs.entrySet()) {
      RuntimeException e = null;
      try {
        JobExecution jobExec = launcher.run(entry.getValue(), params);
        executions.add(jobExec);
        if (jobExec.getStatus().equals(BatchStatus.FAILED)) {
          e = new BeanInitializationException("Failed executing job " + entry.getKey());
        }
      } catch (Exception ex) {
        throw new BeanInitializationException("Cannot execute job " + entry.getKey(), ex);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.