Package org.springframework.batch.item

Examples of org.springframework.batch.item.ExecutionContext


      }
    }
    assertNotNull("MR step not found", mrStep);
    //Check JobRepository
    MapJobRepositoryFactoryBean repo = ctx.getBean(MapJobRepositoryFactoryBean.class);
    ExecutionContext ec =
        repo.getExecutionContextDao().getExecutionContext(mrStep);
    assertTrue("Looking for Job ID", ec.containsKey("Job Status::ID"));
    assertTrue("Looking for Job Name", ec.containsKey("Job Status::Name"));
    assertTrue("Looking for Job State", ec.containsKey("Job Status::State"));
    assertTrue("Looking for File System Counters",
        (ec.containsKey("File System Counters::FILE: Number of bytes read")) ||
            ec.containsKey("FileSystemCounters::FILE_BYTES_READ"));
  }
View Full Code Here


  MultiResourceItemReader<?> multiReader;

  @Test
  public void testSingleReader() throws Exception {
    try {
      reader.open(new ExecutionContext());
      assertNotNull(reader.read());
    } finally {
      reader.close();
    }
  }
View Full Code Here

  @Test
  public void testMultiReader() throws Exception {
    assertNotNull(multiReader);
    try {
      multiReader.open(new ExecutionContext());
      assertNotNull(multiReader.read());
    } finally {
      reader.close();
    }
  }
View Full Code Here

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

    int number = 0;
    int start = min;
    int end = start + targetSize - 1;

    while (start <= max) {
      ExecutionContext value = new ExecutionContext();
      result.put("partition" + number, value);

      if (end >= max) {
        end = max;
      }
      value.putInt("minValue", start);
      value.putInt("maxValue", end);
      start += targetSize;
      end += targetSize;
      number++;
    }
View Full Code Here

    this.inputKeyName = inputKeyName;
  }

  @BeforeStep
  public void createOutputNameFromInput(StepExecution stepExecution) {
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    String inputName = stepExecution.getStepName().replace(":", "-");
    if (executionContext.containsKey(inputKeyName)) {
      inputName = executionContext.getString(inputKeyName);
    }
    if (!executionContext.containsKey(outputKeyName)) {
      executionContext.putString(outputKeyName, path + FilenameUtils.getBaseName(inputName)
          + ".csv");
    }
  }
View Full Code Here

    assertNull(itemReader.read());
  }
 
  @Test
  public void testRestart() throws Exception{
    ExecutionContext executionContext = new ExecutionContext();
    ((ItemStream)itemReader).open(executionContext);
    assertEquals("1", itemReader.read());
    ((ItemStream)itemReader).update(executionContext);
    List<String> items = new ArrayList<String>();
    items.add("1");
View Full Code Here

   }

   @Override
   public ExitStatus afterStep(StepExecution se) {
      logger.info("step finished: " + se.getStepName());
      ExecutionContext jec = se.getJobExecution().getExecutionContext();
      Boolean locked =
            TrackableTasklet.getFromJobExecutionContext(jec,
                  JobConstants.CLUSTER_EXCLUSIVE_WRITE_LOCKED, Boolean.class);
      String clusterName =
            se.getJobParameters()
                  .getString(JobConstants.CLUSTER_NAME_JOB_PARAM);
      if (locked != null && locked && lockClusterEntityMgr != null) {
         try {
            lockClusterEntityMgr.getLock(clusterName).unlock();
         } catch (Exception e) {
            logger.error(
                  "Got exception while release exclusive write lock, ingore it.",
                  e);
         }
         TrackableTasklet.putIntoJobExecutionContext(jec,
               JobConstants.CLUSTER_EXCLUSIVE_WRITE_LOCKED, false);
      }

      if (se.getStatus().equals(BatchStatus.COMPLETED)) {
         jec.put(se.getStepName() + ".COMPLETED", true);
         jobExecutionStatusHolder.setCurrentStepProgress(se.getJobExecution()
               .getId(), 1);
      } else {
         for (Throwable t : se.getFailureExceptions()) {
            String msg = t.getMessage();
View Full Code Here

      Collection<String> stepNames = job.getStepNames();

      int steps = stepNames.size();
      double done = 0;
      for (String stepName : stepNames) {
         ExecutionContext jec = se.getJobExecution().getExecutionContext();
         Boolean completed = (Boolean) jec.get(stepName + ".COMPLETED");

         if (completed != null && completed) {
            ++done;
         }
      }
View Full Code Here

    * @see AbstractStep#doExecute(StepExecution)
    */
   @Override
   protected void doExecute(StepExecution stepExecution) throws Exception {

      ExecutionContext executionContext = stepExecution.getExecutionContext();

      JobParameters jobParameters;
      if (executionContext.containsKey(subJobParametersKey)) {
         jobParameters =
               (JobParameters) executionContext.get(subJobParametersKey);
      } else {
         jobParameters =
               jobParametersExtractor.getJobParameters(job, stepExecution);
         executionContext.put(subJobParametersKey, jobParameters);
      }

      JobExecution subJobExecution = jobLauncher.run(job, jobParameters);
      //Wait for job completion
      while (true) {
         if (subJobExecution.getStatus().isRunning()) {
            double subJobProgress =
                  jobExecutionStatusHolder.getCurrentProgress(subJobExecution
                        .getId());
            mainJobExecutionStatusHolder.setCurrentStepProgress(stepExecution
                  .getJobExecution().getId(), subJobProgress);
            Thread.sleep(3000);
         } else {
            break;
         }
      }

      String nodeName = null;
      if (subJobExecution.getJobInstance().getJobParameters().getParameters()
            .containsKey(JobConstants.SUB_JOB_NODE_NAME)) {
         nodeName =
               subJobExecution.getJobInstance().getJobParameters()
                     .getString(JobConstants.SUB_JOB_NODE_NAME);
      } else {
         String stepName = stepExecution.getStepName();
         nodeName = stepName.substring(stepName.lastIndexOf("-") + 1);
      }
      ExecutionContext mainJobExecutionContext =
            stepExecution.getJobExecution().getExecutionContext();
      updateExecutionStatus(subJobExecution, nodeName, mainJobExecutionContext);
   }
View Full Code Here

TOP

Related Classes of org.springframework.batch.item.ExecutionContext

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.