Package org.springframework.batch.core

Examples of org.springframework.batch.core.Job


  }

  @Test
  public void testInvalidCommitIntervalJobParameter() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml");
    Job job = context.getBean(Job.class);
    JobLauncher launcher = context.getBean(JobLauncher.class);

    JobExecution execution = launcher.run(job, new JobParametersBuilder().addLong("commit.intervall", 1l).toJobParameters());

    assertEquals(BatchStatus.FAILED, execution.getStatus());
View Full Code Here


  @SuppressWarnings("resource"
  @Test
  public void testMultithreadedSplit() throws Throwable {

    JobLauncher jobLauncher = null;
    Job job = null;
   
    ClassPathXmlApplicationContext context = null;

    for (int i = 0; i < MAX_COUNT; i++) {
View Full Code Here

    final JobInstance lastInstance = jobExecution.getJobInstance();
    final ExpandedJobParametersConverter expandedJobParametersConverter = new ExpandedJobParametersConverter();
    final JobParameters jobParameters = jobExecution.getJobParameters();

    final Job job;
    try {
      job = jobLocator.getJob(lastInstance.getJobName());
    }
    catch (NoSuchJobException e1) {
      throw new org.springframework.xd.dirt.job.NoSuchBatchJobException("The job '" + lastInstance.getJobName()
          + "' does not exist.");
    }
    try {
      job.getJobParametersValidator().validate(jobParameters);
    }
    catch (JobParametersInvalidException e) {
      throw new org.springframework.xd.dirt.job.JobParametersInvalidException(
          "The Job Parameters for Job Execution " + jobExecution.getId()
          + " are invalid.");
    }

    final BatchStatus status = jobExecution.getStatus();

    if (status == BatchStatus.COMPLETED || status == BatchStatus.ABANDONED) {
      throw new org.springframework.xd.dirt.job.JobInstanceAlreadyCompleteException(
          "Job Execution " + jobExecution.getId() + " is already complete.");
    }

    if (!job.isRestartable()) {
      throw new org.springframework.xd.dirt.job.JobRestartException(
          "The job '" + lastInstance.getJobName() + "' is not restartable.");
    }

    final String jobParametersAsString = expandedJobParametersConverter
View Full Code Here

    this.jobParametersConverter.setMakeParametersUnique(makeParametersUnique);
  }

  @Transformer
  public JobLaunchRequest toJobLaunchRequest(Message<?> message) {
    Job job;
    try {
      job = jobRegistry.getJob(jobName);
    }
    catch (NoSuchJobException e) {
      throw new IllegalArgumentException("The job " + jobName + " doesn't exist. Is it deployed?");
    }
    final Object payload = message.getPayload();
    JobParameters jobParameters;

    if (logger.isDebugEnabled()) {
      logger.debug(String.format("JobParameters are provided as '%s'. "
          + "Convertering to Spring Batch JobParameters...", payload.getClass().getSimpleName()));
    }

    if (payload instanceof File) {
      jobParameters = jobParametersConverter.getJobParametersForFile((File) message.getPayload());
    }
    else if (payload instanceof String) {
      jobParameters = jobParametersConverter.getJobParametersForJsonString((String) payload);
    }
    else if (payload instanceof Properties) {
      jobParameters = jobParametersConverter.getJobParameters((Properties) payload);
    }
    else if (payload instanceof Map<?, ?>) {
      jobParameters = jobParametersConverter.getJobParametersForMap((Map) payload);
    }
    else if (payload instanceof Tuple) {

      final Tuple tuple = (Tuple) payload;
      final List<Object> tupleValues = tuple.getValues();

      final Map<String, Object> map = new LinkedHashMap<String, Object>(tupleValues.size());
      for (int i = 0; i < tupleValues.size(); i++) {
        map.put(tuple.getFieldNames().get(i), tupleValues.get(i));
      }

      jobParameters = jobParametersConverter.getJobParametersForMap(map);

    }
    else {
      throw new IllegalArgumentException("This transformer does not support payloads of type "
          + payload.getClass().getSimpleName());
    }

    final boolean isRestart = Boolean.valueOf(jobParameters.getString(ExpandedJobParametersConverter.IS_RESTART_JOB_PARAMETER_KEY));

    if (job.getJobParametersIncrementer() != null && !isRestart) {
      jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
    }

    jobParameters = jobParametersConverter.removeRestartParameterIfExists(jobParameters);

    return new JobLaunchRequest(job, jobParameters);
View Full Code Here

    assertEquals("The number of step names returned from hsqldb did not match.", 2, count);
  }

  @Test
  public void checkThatContainerHasRepo() throws Exception {
    Job job = new SimpleJob(SIMPLE_JOB_NAME);
    try {
      launcher.run(job, new JobParameters());
    }
    catch (Exception ex) {
      // we can ignore this. Just want to create a fake job instance.
View Full Code Here

      throws JobExecutionException {
    if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) {
      String[] jobsToRun = this.jobNames.split(",");
      for (String jobName : jobsToRun) {
        try {
          Job job = this.jobRegistry.getJob(jobName);
          if (this.jobs.contains(job)) {
            continue;
          }
          execute(job, jobParameters);
        }
View Full Code Here

    private Map<String, JobLauncher> allResolvedJobLaunchers;

    @Override
    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
        Job resolvedJob = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Job.class);
        return new SpringBatchEndpoint(uri, this, jobLauncher, defaultResolvedJobLauncher, allResolvedJobLaunchers, resolvedJob);
    }
View Full Code Here

TOP

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

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.