Package org.springframework.batch.core

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


   *
   * @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

   */
  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

    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

    }

    @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

  @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

    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

    JobLauncher launcher = context.getBean(JobLauncher.class);
    Job job = context.getBean(Job.class);

    JobParameters jobParameters = new JobParametersBuilder().toJobParameters();

    JobExecution execution = launcher.run(job, jobParameters);
    assertTrue("status was: " + execution.getStatus(), execution.getStatus() == BatchStatus.COMPLETED);
    context.close();
  }
View Full Code Here

    }

    @Test
    public void shouldReturnJobExecution() throws Exception {
        // Given
        JobExecution jobExecution = mock(JobExecution.class);
        when(jobLauncher.run(eq(job), any(JobParameters.class))).thenReturn(jobExecution);

        // When
        sendBody("direct:start", "Start the job, please.");
View Full Code Here

    }

    @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

TOP

Related Classes of org.springframework.batch.core.JobExecution

Copyright © 2018 www.massapicom. 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.