Package org.springframework.batch.core.job

Examples of org.springframework.batch.core.job.SimpleJob


  public JobExecution launch(JobLaunchRequest request)
          throws JobExecutionAlreadyRunningException, JobRestartException,
                 JobInstanceAlreadyCompleteException, JobParametersInvalidException,
                 NoSuchJobException {
    Job job = new SimpleJob(request.getJobName());
    JobParametersBuilder builder = new JobParametersBuilder();
    for (Map.Entry<String, String> entry : request.getJobParameters().entrySet()) {
      builder.addString(entry.getKey(), entry.getValue());
    }
    return jobLauncher.run(job, builder.toJobParameters());
View Full Code Here


   */
  public JobExecution launchStep(Step step, JobParameters jobParameters, final ExecutionContext jobExecutionContext) {
    //
    // Create a fake job
    //
    SimpleJob job = new SimpleJob();
    job.setName("TestJob");
    job.setJobRepository(this.jobRepository);

    List<Step> stepsToExecute = new ArrayList<Step>();
    stepsToExecute.add(step);
    job.setSteps(stepsToExecute);

    //
    // Dump the given Job ExecutionContext using a listener
    //
    if (jobExecutionContext != null && !jobExecutionContext.isEmpty()) {
      job.setJobExecutionListeners(new JobExecutionListener[] { new JobExecutionListenerSupport() {
        @Override
        public void beforeJob(JobExecution jobExecution) {
          ExecutionContext jobContext = jobExecution.getExecutionContext();
          for (Map.Entry<String, Object> entry : jobExecutionContext.entrySet()) {
            jobContext.put(entry.getKey(), entry.getValue());
View Full Code Here

    */
   private synchronized long createAndLaunchJobWithSubJob(String clusterName,
         String subJobName, List<JobParameters> subJobParameters,
         ClusterStatus successStatus,
         ClusterStatus failStatus) throws Exception {
      SimpleJob mainJob =
            new SimpleJob("composed-job-" + clusterName + "-" + subJobName
                  + "-" + System.nanoTime());
      //SimpleJob mainJob = new SimpleJob("composed-job-" + clusterName + "-" + subJobName);
      StepExecutionListener[] jobStepListeners = createJobStepListener();
      Map<String, JobParameter> mainJobParams =
            new TreeMap<String, JobParameter>();
      mainJobParams.put(JobConstants.TIMESTAMP_JOB_PARAM, new JobParameter(
            new Date()));
      mainJobParams.put(JobConstants.CLUSTER_NAME_JOB_PARAM, new JobParameter(
            clusterName));
      mainJobParams.put(JobConstants.CLUSTER_SUCCESS_STATUS_JOB_PARAM,
            new JobParameter(successStatus.name()));
      mainJobParams.put(JobConstants.CLUSTER_FAILURE_STATUS_JOB_PARAM,
            new JobParameter(failStatus.name()));
      //enable sub job indicator to for job progress query
      mainJobParams.put(JobConstants.SUB_JOB_ENABLED, new JobParameter(1l));
      Job subJob = jobRegistry.getJob(subJobName);
      for (int stepNumber = 0, j = subJobParameters.size(); stepNumber < j; stepNumber++) {
         SubJobStep subJobStep = new SubJobStep();
         subJobStep.setName(subJobName + "-subJobStep-" + stepNumber);
         subJobStep.setJob(subJob);
         subJobStep.setJobParametersExtractor(jobParametersExtractor);
         subJobStep.setJobExecutionStatusHolder(jobExecutionStatusHolder);
         subJobStep
               .setMainJobExecutionStatusHolder(mainJobExecutionStatusHolder);
         subJobStep.setJobLauncher(jobLauncher);
         subJobStep.setJobRepository(jobRepository);
         subJobStep.setStepExecutionListeners(jobStepListeners);
         subJobStep.afterPropertiesSet();
         mainJob.addStep(subJobStep);
         logger.debug("added sub job step: " + subJobStep.getName());
         int subJobParametersNumber =
               subJobParameters.get(stepNumber).getParameters().keySet().size();
         mainJobParams.put(JobConstants.SUB_JOB_PARAMETERS_NUMBER + stepNumber,
               new JobParameter((long) subJobParametersNumber));
         int count = 0;
         for (String key : subJobParameters.get(stepNumber).getParameters()
               .keySet()) {
            int index = count++;
            mainJobParams.put(
                  JobUtils.getSubJobParameterPrefixKey(stepNumber, index),
                  new JobParameter(key));
            mainJobParams.put(
                  JobUtils.getSubJobParameterPrefixValue(stepNumber, index),
                  subJobParameters.get(stepNumber).getParameters().get(key));
         }
      }
      mainJob
            .setJobExecutionListeners(new JobExecutionListener[] { mainJobExecutionListener });
      mainJob.setJobRepository(jobRepository);
      mainJob.afterPropertiesSet();
      JobFactory jobFactory = new ReferenceJobFactory(mainJob);
      jobRegistry.register(jobFactory);
      logger.info("registered job: " + mainJob.getName());
      JobParameters mainJobParameters = new JobParameters(mainJobParams);
      JobExecution mainJobExecution =
            jobLauncher.run(mainJob, mainJobParameters);
      logger.info("launched main job: " + mainJob.getName());
      return mainJobExecution.getId();
   }
View Full Code Here

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  @Before
  public void init() throws Exception {
    jobRegistry.register(new ReferenceJobFactory(new SimpleJob("foo")));
    adapter.setJobLocator(jobRegistry);
    adapter.setJobExplorer(jobExplorer);
  }
View Full Code Here

  private StringToJobLaunchRequestAdapter adapter = new StringToJobLaunchRequestAdapter();
  private MapJobRegistry jobRegistry = new MapJobRegistry();

  @Before
  public void init() throws Exception {
    jobRegistry.register(new ReferenceJobFactory(new SimpleJob("foo")));
    jobRegistry.register(new ReferenceJobFactory(new SimpleJob("foo-bar")));
    adapter.setJobLocator(jobRegistry);
  }
View Full Code Here

    EasyMock.verify(jobLocator, stepExecutionDao, jobExecutionDao, jobInstanceDao, executionContextDao);
  }

  @Test
  public void testGetStepNamesFromStepLocator() throws Exception {
    SimpleJob job = new SimpleJob("job");
    job.addStep(new TaskletStep("foo"));
    EasyMock.expect(jobLocator.getJob("job")).andReturn(job);
    EasyMock.replay(jobLocator);
    Collection<String> result = service.getStepNamesForJob("job");
    assertNotNull(result);
    assertEquals("[foo]", result.toString());
View Full Code Here

  private FileToJobLaunchRequestAdapter adapter = new FileToJobLaunchRequestAdapter();

  @Before
  public void init() throws Exception {
    adapter.setJob(new SimpleJob("foo"));
  }
View Full Code Here

    }
  }

  private StepExecution getStepExecution(Step step) throws JobExecutionAlreadyRunningException, JobRestartException,
  JobInstanceAlreadyCompleteException {
    SimpleJob job = new SimpleJob();
    job.setName("job");
    JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParametersBuilder().addLong(
        "job.counter", jobCounter++).toJobParameters());
    StepExecution stepExecution = jobExecution.createStepExecution(step.getName());
    jobRepository.add(stepExecution);
    return stepExecution;
  }
View Full Code Here

    }
  }

  private StepExecution getStepExecution(Step step) throws JobExecutionAlreadyRunningException, JobRestartException,
  JobInstanceAlreadyCompleteException {
    SimpleJob job = new SimpleJob();
    job.setName("job");
    JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParametersBuilder().addLong(
        "job.counter", jobCounter++).toJobParameters());
    StepExecution stepExecution = jobExecution.createStepExecution(step.getName());
    jobRepository.add(stepExecution);
    return stepExecution;
  }
View Full Code Here

    JobRepository jobRepository = repositoryFactory.getObject();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    jobLauncher.afterPropertiesSet();

    SimpleJob job = new SimpleJob("job");
    TaskletStep step = new TaskletStep("step");
    step.setTasklet(new Tasklet() {
      @Override
      public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        while (block) {
          Thread.sleep(100L);
        }
        return RepeatStatus.FINISHED;
      }
    });
    step.setTransactionManager(repositoryFactory.getTransactionManager());
    step.setJobRepository(jobRepository);
    step.afterPropertiesSet();
    job.addStep(step);
    job.setJobRepository(jobRepository);
    job.afterPropertiesSet();

    jobLauncher.run(job, new JobParametersBuilder().addString("test", getClass().getName()).toJobParameters());

    Thread.sleep(500L);
    JobExplorer explorer = new MapJobExplorerFactoryBean(repositoryFactory).getObject();
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.job.SimpleJob

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.