List of usage examples for org.springframework.batch.core JobParametersBuilder JobParametersBuilder
public JobParametersBuilder()
From source file:bamons.process.batch.task.BatchScheduledTasks.java
public void sampleJob() throws Exception { try {//from w w w . j av a 2s .c o m DateTime dt = new DateTime(); dt = dt.minusDays(1); String targetDate = dt.toString(DateTimeFormat.forPattern("yyyy-MM-dd")); JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()) .addString("targetDate", targetDate).toJobParameters(); JobExecution execution = jobLauncher.run(sampleJob, jobParameters); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.vmware.example.lucene.loader.CacheBatchLoader.java
public void start() { logger.info("Launching batch loading....."); long time = System.currentTimeMillis(); try {//from w w w.ja va 2 s . co m JobParametersBuilder paramsBuilder = new JobParametersBuilder(); for (Entry<Object, Object> e : batchResources.entrySet()) { paramsBuilder.addString((String) e.getKey(), (String) e.getValue()); } jobLauncher.run(job, paramsBuilder.toJobParameters()); System.out.println("All data loaded."); } catch (JobExecutionAlreadyRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JobRestartException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JobInstanceAlreadyCompleteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JobParametersInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } time = System.currentTimeMillis() - time; System.out.println(String.format("Completed batch loading (%d)", time)); }
From source file:org.cloudfoundry.identity.uaa.scim.job.UserMigrationJobIntegrationTests.java
@Test public void testJobRuns() throws Exception { TestUtils.deleteFrom(cloudControllerDataSource, "users"); TestUtils.deleteFrom(uaaDataSource, "users"); new JdbcTemplate(cloudControllerDataSource).update( "insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)", 4, true, "invalid", "ENCRYPT_ME", new Date(), new Date()); new JdbcTemplate(cloudControllerDataSource).update( "insert into users (id, active, email, crypted_password, created_at, updated_at) values (?, ?, ?, ?, ?, ?)", 4, true, "vcap_tester@vmware.com", "ENCRYPT_ME", new Date(), new Date()); JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addString("users", "marissa@test.org,vcap_tester@vmware.com") .addLong("run.id", 0L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); Iterator<StepExecution> iterator = execution.getStepExecutions().iterator(); assertEquals(1, iterator.next().getWriteCount()); assertEquals(1, iterator.next().getWriteCount()); JdbcTemplate jdbcTemplate = new JdbcTemplate(uaaDataSource); assertEquals(1, jdbcTemplate.queryForInt("select count(*) from users")); assertEquals(1,//from w w w . ja v a 2 s .co m jdbcTemplate.queryForInt("select count(*) from users where authorities=?", "uaa.admin,uaa.user")); }
From source file:com.create.batch.integration.FileMessageToJobRequest.java
@Transformer(inputChannel = "inboundFileChannel", outputChannel = "outboundJobRequestChannel") public JobLaunchRequest toRequest(final Message<File> message) { log.debug("toRequest : {}", message); final Instant timestamp = clock.instant(); final JobParameters jobParameters = new JobParametersBuilder() .addString(jobParameter, message.getPayload().getAbsolutePath()) .addLong(TIMESTAMP_PARAMETER, timestamp.getEpochSecond()).toJobParameters(); return new JobLaunchRequest(job, jobParameters); }
From source file:org.trpr.platform.batch.impl.spring.job.BatchJob.java
/** * Interface method implementation. Launches the job specified by the "jobName" job data parameter * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) *//*from w w w .ja va2 s . c om*/ public void execute(JobExecutionContext context) throws JobExecutionException { try { /** Running the batch. */ JobParametersBuilder builder = new JobParametersBuilder(); builder.addLong(TIMESTAMP, System.currentTimeMillis()); ((JobLauncher) context.getJobDetail().getJobDataMap().get(JOB_LAUNCHER)).run( (org.springframework.batch.core.Job) context.getJobDetail().getJobDataMap().get(JOB_NAME), builder.toJobParameters()); } catch (JobExecutionAlreadyRunningException e) { LOGGER.error("Specified job is already running : " + e); } catch (JobRestartException e) { LOGGER.error("Unable to restart specified batch job : " + e); } catch (JobInstanceAlreadyCompleteException e) { LOGGER.error("Specified job is already complete : " + e); } catch (Exception e) { LOGGER.error("Job execution failed : " + e); } }
From source file:uk.ac.ebi.eva.test.utils.JobTestUtils.java
public static JobParameters getJobParameters() { return new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters(); }
From source file:org.cbioportal.annotation.TestAnnotationPipeline.java
@Test public void pipelineTest() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParametersBuilder() .addString("filename", classLoader.getResource("data/testmaf.txt").getPath()) .addString("outputFilename", "target/test-outputs/output.txt").addString("replace", "false") .addString("isoformOverride", "uniprot").toJobParameters()); AssertFile.assertFileEquals(//from w w w . j a v a 2s .c o m new FileSystemResource(classLoader.getResource("data/expectedmaf.txt").getPath()), new FileSystemResource("target/test-outputs/output.txt")); }
From source file:bamons.process.batch.task.BatchScheduledTasks.java
public void fileJob() throws Exception { try {/*from w ww. j a va 2s . c o m*/ // json ? (? : test/resources/sample.json) String filePath = "/usr/local/*.json"; JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()) .addString("filePath", filePath).toJobParameters(); JobExecution execution = jobLauncher.run(restoreFileJob, jobParameters); } catch (Exception e) { e.printStackTrace(); } }
From source file:nu.yona.server.batch.service.BatchTaskService.java
public BatchJobResultDto aggregateActivities() { logger.info("Triggering activity aggregation"); JobParameters jobParameters = new JobParametersBuilder().addDate("uniqueInstanceId", new Date()) .toJobParameters();//from w w w. j a va2 s .c om // NOTICE: executes the job synchronously, on purpose, because the tests rely on this (they assert on job execution // results) and this is normally not scheduled manually JobExecution jobExecution = launchImmediatelySynchronously(activityAggregationJob, jobParameters); jobExecution.getStepExecutions().forEach(e -> logger.info("Step {} read {} entities and wrote {}", e.getStepName(), e.getReadCount(), e.getWriteCount())); return BatchJobResultDto.createInstance(jobExecution); }
From source file:org.cloudfoundry.identity.uaa.scim.job.ClearNamesJobIntegrationTests.java
@Test public void testJobRuns() throws Exception { TestUtils.deleteFrom(cloudControllerDataSource, "users"); TestUtils.deleteFrom(uaaDataSource, "users"); JdbcTemplate uaaTemplate = new JdbcTemplate(uaaDataSource); uaaTemplate.update(//from www . jav a2 s . c o m "insert into users " + "(id, active, userName, email, password, familyName, givenName, created, lastModified) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)", "FOO", true, "uniqua", "uniqua@test.org", "ENCRYPT_ME", "Una", "Uniqua", new Date(), new Date()); uaaTemplate.update( "insert into users " + "(id, active, userName, email, password, familyName, givenName, created, lastModified) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)", "BAR", true, "username", "uniqua@test.org", "ENCRYPT_ME", "uniqua", "test.org", new Date(), new Date()); uaaTemplate.update( "insert into users " + "(id, active, userName, email, password, familyName, givenName, created, lastModified) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)", "SPAM", true, "another", "uniqua@test.org", "ENCRYPT_ME", "another", "another", new Date(), new Date()); JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addDate("start.date", new Date(0L)).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); Iterator<StepExecution> iterator = execution.getStepExecutions().iterator(); StepExecution step = iterator.next(); assertEquals(3, step.getReadCount()); assertEquals(2, step.getWriteCount()); assertEquals(2, uaaTemplate.queryForInt("select count(*) from users where givenName is null")); }