@Bean Job personEtl(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory, FlatFileItemReader<Person> reader, JdbcBatchItemWriter<Person> writer ) { Step step = stepBuilderFactory.get("file-to-database") .<Person, Person>chunk(5) .reader(reader) .writer(writer) .build(); return jobBuilderFactory.get("etl") .start(step) .build(); }
@Test public void testCreateGenericArchive() throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException, IOException { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); JobParameters jobParameters = new JobParameters(parameters); Job palmwebArchive = jobLocator.getJob("PalmWeb"); assertNotNull("Palmweb must not be null", palmwebArchive); JobExecution jobExecution = jobLauncher.run(palmwebArchive, jobParameters); assertEquals("The job should complete successfully",jobExecution.getExitStatus().getExitCode(),"COMPLETED"); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { logger.info(stepExecution.getStepName() + " " + stepExecution.getReadCount() + " " + stepExecution.getFilterCount() + " " + stepExecution.getWriteCount() + " " + stepExecution.getCommitCount()); } }
@Override public Job getObject() throws Exception { ComposedRunnerVisitor composedRunnerVisitor = new ComposedRunnerVisitor(); TaskParser taskParser = new TaskParser("composed-task-runner", this.dsl,false,true); taskParser.parse().accept(composedRunnerVisitor); this.visitorDeque = composedRunnerVisitor.getFlow(); FlowJobBuilder builder = this.jobBuilderFactory .get(this.taskNameResolver.getTaskName()) .start(this.flowBuilder .start(createFlow()) .end()) .end(); if(this.incrementInstanceEnabled) { builder.incrementer(new RunIdIncrementer()); } return builder.build(); }
public void start() throws IOException, InterruptedException { List<JobExecution> jobExecutions = new ArrayList<>(); // launch jobs jobExecutions.addAll(IntStream.range(0, this.cardinality).mapToObj(i -> { Job analysisJob = this.jobFactory.get(); JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(); jobParametersBuilder.addString("id", analysisJob.getName() + "-" + i, true); try { return this.jobLauncher.run(analysisJob, jobParametersBuilder.toJobParameters()); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException exception) { throw new RuntimeException(exception); } }).collect(Collectors.toList())); // wait for termination while (jobExecutions.stream().anyMatch(jobExecution -> jobExecution.getStatus().isRunning())) { Thread.sleep(1000); } }
private Map<String, Object> registerJob(String jobName) throws DuplicateJobException { String taskId = jobKeyMap.get(JoinCode.getTaskCode(jobName)).getTaskId(); TaskDefineEntity tm = taskDefineMap.get(taskId); Job job = taskletConfig.job(conf, jobName, tm.getTaskType(), tm.getScriptFile()); ReferenceJobFactory regJob = new ReferenceJobFactory(job); try { jobRegistry.register(regJob); } catch (DuplicateJobException e) { jobRegistry.unregister(jobName); jobRegistry.register(regJob); } logger.debug("register job,job name is :{}", jobName); Map<String, Object> map = new HashMap<>(); map.put("jobName", jobName); map.put("jobLauncher", jobLauncher); map.put("jobRegistry", jobRegistry); map.put("jobKeyStatusService", jobKeyStatusService); map.put("argumentService", argumentService); return map; }
private void executeRegisteredJobs(JobParameters jobParameters) 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); } catch (NoSuchJobException ex) { logger.debug("No job found in registry for job name: " + jobName); continue; } } } }
@Bean public Job discreteJob() { AbstractJob job = new AbstractJob("discreteRegisteredJob") { @Override public Collection<String> getStepNames() { return Collections.emptySet(); } @Override public Step getStep(String stepName) { return null; } @Override protected void doExecute(JobExecution execution) throws JobExecutionException { execution.setStatus(BatchStatus.COMPLETED); } }; job.setJobRepository(this.jobRepository); return job; }
@Bean public Job discreteJob() { AbstractJob job = new AbstractJob("discreteLocalJob") { @Override public Collection<String> getStepNames() { return Collections.emptySet(); } @Override public Step getStep(String stepName) { return null; } @Override protected void doExecute(JobExecution execution) throws JobExecutionException { execution.setStatus(BatchStatus.COMPLETED); } }; job.setJobRepository(this.jobRepository); return job; }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("multiResourceItemReaderJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("customReaderWriterProcesorJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("taskletJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("customListeners"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("flatFileItemWriterJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("parallelStepsJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("chunkJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("secuentialControlFlow"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
public static void main(String[] args) { String[] springConfig = { "spring/batch/jobs/job-config.xml" }; @SuppressWarnings("resource") ApplicationContext context = new ClassPathXmlApplicationContext(springConfig); JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher"); Job job = (Job) context.getBean("xmlReadersWritersJob"); try { JobParameters jobParameters = new JobParametersBuilder().addLong("time",System.currentTimeMillis()).toJobParameters(); JobExecution execution = jobLauncher.run(job, jobParameters); System.out.println("Exit Status : " + execution.getStatus()); System.out.println("Exit Status : " + execution.getAllFailureExceptions()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); }
@Override public void process(Exchange exchange) throws Exception { JobParameters jobParameters = prepareJobParameters(exchange.getIn().getHeaders()); String messageJobName = jobParameters.getString(SpringBatchConstants.JOB_NAME); Job job2run = this.job; if (messageJobName != null) { job2run = CamelContextHelper.mandatoryLookup(getEndpoint().getCamelContext(), messageJobName, Job.class); } if (job2run == null) { exchange.setException(new CamelExchangeException("jobName was not specified in the endpoint construction " + " and header " + SpringBatchConstants.JOB_NAME + " could not be found", exchange)); return; } JobExecution jobExecution = jobLauncher.run(job2run, jobParameters); exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders()); exchange.getOut().setBody(jobExecution); }
/** * @return main job */ @Bean public Job job() { return jobs.get("mainJob") .incrementer(new RunIdIncrementer()) .flow(loadProcessedListIds()) .next(new FlowBuilder<SimpleFlow>("splitFlow") .start(loadScans()) .split(taskExecutor()) .add(new FlowBuilder<SimpleFlow>("loadTranscriptsFlow") .start(loadTranscripts()) .build()) .build()) .next(addSign()) .end() .build(); }
CommandLineRunner runner(JobLauncher launcher, Job job, @Value("${file}") File in, JdbcTemplate jdbcTemplate) { return args -> { JobExecution execution = launcher.run(job, new JobParametersBuilder() .addString("file", in.getAbsolutePath()) .toJobParameters()); System.out.println("execution status: " + execution.getExitStatus().toString()); List<Person> personList = jdbcTemplate.query("select * from PEOPLE", (resultSet, i) -> new Person(resultSet.getString("first"), resultSet.getString("last"), resultSet.getString("email"))); personList.forEach(System.out::println); }; }
private void executeRegisteredJobs(JobParameters jobParameters) 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); } catch (NoSuchJobException nsje) { logger.debug("No job found in registry for job name: " + jobName); continue; } } } }
@Override public void launch(JobLaunchRequest request) { Job job; try { job = jobLocator.getJob(request.getJob()); Map<String, JobParameter> jobParameterMap = new HashMap<String, JobParameter>(); for(String parameterName : request.getParameters().keySet()) { jobParameterMap.put(parameterName, new JobParameter(request.getParameters().get(parameterName))); } JobParameters jobParameters = new JobParameters(jobParameterMap); try { jobLauncher.run(job, jobParameters); } catch (JobExecutionAlreadyRunningException jeare) { jobStatusNotifier.notify(new JobExecutionException(jeare.getLocalizedMessage()), request.getParameters().get("resource.identifier")); } catch (JobRestartException jre) { jobStatusNotifier.notify(new JobExecutionException(jre.getLocalizedMessage()), request.getParameters().get("resource.identifier")); } catch (JobInstanceAlreadyCompleteException jiace) { jobStatusNotifier.notify(new JobExecutionException(jiace.getLocalizedMessage()), request.getParameters().get("resource.identifier")); } catch (JobParametersInvalidException jpie) { jobStatusNotifier.notify(new JobExecutionException(jpie.getLocalizedMessage()), request.getParameters().get("resource.identifier")); } } catch (NoSuchJobException nsje) { jobStatusNotifier.notify(new JobExecutionException(nsje.getLocalizedMessage()), request.getParameters().get("resource.identifier")); } }
/** * @throws Exception */ @Test public void testWriteTaxonFile() throws Exception { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); parameters.put("query", new JobParameter("")); parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae")); parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon)))); parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".txt")); parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString())); parameters.put("download.fieldsTerminatedBy", new JobParameter("\t")); parameters.put("download.fieldsEnclosedBy", new JobParameter("\"")); parameters.put("download.format", new JobParameter("taxon")); JobParameters jobParameters = new JobParameters(parameters); Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation"); assertNotNull("flatFileCreatorJob must exist", archiveCreatorJob); JobExecution jobExecution = jobLauncher.run(archiveCreatorJob, jobParameters); assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus()); }
@Test public void testWriteChecklistPdf() throws Exception { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); parameters.put("query", new JobParameter("")); parameters.put("selected.facets", new JobParameter("taxon.family_ss=Araceae")); parameters.put("download.taxon", new JobParameter(toParameter(DarwinCorePropertyMap.getConceptTerms(DwcTerm.Taxon)))); parameters.put("download.file", new JobParameter(UUID.randomUUID().toString() + ".pdf")); parameters.put("download.limit", new JobParameter(new Integer(Integer.MAX_VALUE).toString())); parameters.put("download.fieldsTerminatedBy", new JobParameter("\t")); parameters.put("download.fieldsEnclosedBy", new JobParameter("\"")); parameters.put("download.sort", new JobParameter("searchable.label_sort_asc")); parameters.put("download.format", new JobParameter("hierarchicalChecklist")); parameters.put("download.template.filepath", new JobParameter("org/emonocot/job/download/reports/name_report1.jrxml")); JobParameters jobParameters = new JobParameters(parameters); Job archiveCreatorJob = jobLocator.getJob("FlatFileCreation"); assertNotNull("flatFileCreator Job must exist", archiveCreatorJob); JobExecution jobExecution = jobLauncher.run(archiveCreatorJob, jobParameters); assertEquals("The Job should be sucessful", ExitStatus.COMPLETED, jobExecution.getExitStatus()); }
/** * * @throws IOException * if a temporary file cannot be created. * @throws NoSuchJobException * if SpeciesPageHarvestingJob cannot be located * @throws JobParametersInvalidException * if the job parameters are invalid * @throws JobInstanceAlreadyCompleteException * if the job has already completed * @throws JobRestartException * if the job cannot be restarted * @throws JobExecutionAlreadyRunningException * if the job is already running */ @Test public final void testNotModifiedResponse() throws IOException, NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); parameters.put("query.string", new JobParameter("select i from Image i")); JobParameters jobParameters = new JobParameters(parameters); Job job = jobLocator.getJob("ImageProcessing"); assertNotNull("ImageProcessing must not be null", job); JobExecution jobExecution = jobLauncher.run(job, jobParameters); assertEquals("The job should complete successfully",jobExecution.getExitStatus().getExitCode(),"COMPLETED"); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { logger.info(stepExecution.getStepName() + " " + stepExecution.getReadCount() + " " + stepExecution.getFilterCount() + " " + stepExecution.getWriteCount()); } }
@Override public void launch(JobLaunchRequest request) { Job job; try { job = jobLocator.getJob(request.getJob()); Map<String, JobParameter> jobParameterMap = new HashMap<String, JobParameter>(); for(String parameterName : request.getParameters().keySet()) { jobParameterMap.put(parameterName, new JobParameter(request.getParameters().get(parameterName))); } JobParameters jobParameters = new JobParameters(jobParameterMap); jobLauncher.run(job, jobParameters); } catch (NoSuchJobException | JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException exception) { jobStatusNotifier.notify(new JobExecutionException(exception.getLocalizedMessage()), request.getParameters().get("job.configuration.id")); } }
private JobExecution launchImmediately(TaskExecutor taskExecutor, Job job, JobParameters jobParameters) { try { SimpleJobLauncher launcher = new SimpleJobLauncher(); launcher.setJobRepository(jobRepository); launcher.setTaskExecutor(taskExecutor); return launcher.run(job, jobParameters); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException e) { logger.error("Unexpected exception", e); throw YonaException.unexpected(e); } }
@Bean public Job deptBatchJob() { return jobCreators.get("deptBatchJob") .start(taskletStep()) .next(chunkStep()) .build(); }
@Bean public Job xmlToJsonToMongo() { return jobBuilderFactory.get("XML_Processor") .start(step1()) .next(step2()) .build(); }
@Bean(name = "githubJob") public Job githubJob() throws Exception { return jobBuilderFactory.get("githubJob") .incrementer(new RunIdIncrementer()) .listener(githubJobListener) .flow(githubStep1()) .end() .build(); }