/** * Build a step from the job provided. * * @return a new job step */ public Step build() { JobStep step = new JobStep(); step.setName(getName()); super.enhance(step); if (job != null) { step.setJob(job); } if (jobParametersExtractor != null) { step.setJobParametersExtractor(jobParametersExtractor); } if (jobLauncher == null) { SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(getJobRepository()); try { jobLauncher.afterPropertiesSet(); } catch (Exception e) { throw new StepBuilderException(e); } this.jobLauncher = jobLauncher; } step.setJobLauncher(jobLauncher); try { step.afterPropertiesSet(); } catch (Exception e) { throw new StepBuilderException(e); } return step; }
@Bean public SimpleJobLauncher jobLauncher() { SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(jobRepository); jobLauncher.setTaskExecutor(taskExecutor()); return jobLauncher; }
@Before public void setUp() throws Exception { jobLauncher = new SimpleJobLauncher(); jobRepository = createMock(JobRepository.class); jobLauncher.setJobRepository(jobRepository); }
@Test public void testPropertyFileLoaderJob() { try { logger.debug("Begin Testing File Loader"); SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setTaskExecutor(new SyncTaskExecutor()); jobLauncher.setJobRepository(jobRepository); jobLauncherTestUtils.setJobLauncher(jobLauncher); SimpleJob job = importProductsJob(); logJobDetails(job); jobLauncherTestUtils.setJob(job); JobExecution exec = jobLauncherTestUtils.launchJob(new JobParameters()); Collection<String> stepNames = job.getStepNames(); for (String stepName : stepNames) { TaskletStep step = (TaskletStep) job.getStep(stepName); step.setTransactionManager(transactionManager); } assertTrue("Steps MUST exist", stepNames != null); assertTrue("At least ONE step MUST exist", stepNames.size() > 0); Assert.assertTrue( "Product Repository MUST have records", jobRepository.isJobInstanceExists(job.getName(), new JobParameters())); logger.debug("Job Execution Status {}", exec.getExitStatus()); logJobRepository(exec); Assert.assertEquals(BatchStatus.COMPLETED, exec.getStatus()); } catch (Exception e) { logger.error(e.getMessage(), e); Assert.fail(e.getMessage()); } }
@Before public void setUp() throws Exception { step.setName("step"); MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); jobRepository = factory.getObject(); step.setJobRepository(jobRepository); JobExecution jobExecution = jobRepository.createJobExecution("job", new JobParameters()); stepExecution = jobExecution.createStepExecution("step"); jobRepository.add(stepExecution); SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(jobRepository); jobLauncher.afterPropertiesSet(); step.setJobLauncher(jobLauncher); }
/** * This method reads all the task from an xml file and registers them with the MifosScheduler * * @param document Task configuration document * @throws TaskSystemException when something goes wrong */ @Deprecated private void registerTasksOldConfigurationFile(Document document) throws TaskSystemException { try { logger.warn( "Old format task.xml configuration file is deprecated. Please configure scheduler using spring managed beans."); NodeList rootSchedulerTasks = document.getElementsByTagName(SchedulerConstants.SCHEDULER_TASKS); Element rootNodeName = (Element) rootSchedulerTasks.item(0); NodeList collectionOfScheduledTasks = rootNodeName.getElementsByTagName(SchedulerConstants.SCHEDULER); DataSource dataSource = SessionFactoryUtils.getDataSource(StaticHibernateUtil.getSessionFactory()); SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); JobRegistry jobRegistry = new MapJobRegistry(); this.jobLocator = jobRegistry; JdbcJobInstanceDao jobInstanceDao = new JdbcJobInstanceDao(); jobInstanceDao.setJdbcTemplate(jdbcTemplate); jobInstanceDao.setJobIncrementer( new MySQLMaxValueIncrementer(dataSource, "BATCH_JOB_SEQ", "id")); jobInstanceDao.afterPropertiesSet(); JdbcJobExecutionDao jobExecutionDao = new JdbcJobExecutionDao(); jobExecutionDao.setJdbcTemplate(jdbcTemplate); jobExecutionDao.setJobExecutionIncrementer( new MySQLMaxValueIncrementer(dataSource, "BATCH_JOB_EXECUTION_SEQ", "id")); jobExecutionDao.afterPropertiesSet(); JdbcStepExecutionDao stepExecutionDao = new JdbcStepExecutionDao(); stepExecutionDao.setJdbcTemplate(jdbcTemplate); stepExecutionDao.setStepExecutionIncrementer( new MySQLMaxValueIncrementer(dataSource, "BATCH_STEP_EXECUTION_SEQ", "id")); stepExecutionDao.afterPropertiesSet(); JdbcExecutionContextDao executionContextDao = new JdbcExecutionContextDao(); executionContextDao.setJdbcTemplate(jdbcTemplate); executionContextDao.afterPropertiesSet(); JobRepository jobRepository = new SimpleJobRepository( jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao); this.jobRepository = jobRepository; SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(jobRepository); jobLauncher.setTaskExecutor(new SyncTaskExecutor()); jobLauncher.afterPropertiesSet(); this.jobLauncher = jobLauncher; JobExplorer jobExplorer = new SimpleJobExplorer( jobInstanceDao, jobExecutionDao, stepExecutionDao, executionContextDao); this.jobExplorer = jobExplorer; Map<String, Object> jobData = new HashMap<String, Object>(); jobData.put("jobLocator", jobRegistry); jobData.put("jobLauncher", jobLauncher); jobData.put("jobExplorer", jobExplorer); jobData.put("jobRepository", jobRepository); JobRegistryBeanPostProcessor jobRegistryProcessor = new JobRegistryBeanPostProcessor(); jobRegistryProcessor.setJobRegistry(jobRegistry); ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager(); Date loanArrearsTaskInitialTime = null; Long loanArrearsTaskDelayTime = null; boolean portfolioAtRiskTaskExists = false; for (int i = 0; i < collectionOfScheduledTasks.getLength(); i++) { Element scheduledTask = (Element) collectionOfScheduledTasks.item(i); Element subNodeName1 = (Element) scheduledTask.getElementsByTagName(SchedulerConstants.TASK_CLASS_NAME).item(0); String taskName = ((Text) subNodeName1.getFirstChild()).getData().trim(); Element subNodeName2 = (Element) scheduledTask.getElementsByTagName(SchedulerConstants.INITIAL_TIME).item(0); String initialTime = ((Text) subNodeName2.getFirstChild()).getData().trim(); Element subNodeName3; String delayTime = null; if ((scheduledTask.getElementsByTagName(SchedulerConstants.DELAY_TIME)) != null) { subNodeName3 = (Element) scheduledTask.getElementsByTagName(SchedulerConstants.DELAY_TIME).item(0); if (subNodeName3.getFirstChild() != null) { delayTime = ((Text) subNodeName3.getFirstChild()).getData().trim(); } } if (Long.parseLong(delayTime) < 86400) { throw new IllegalArgumentException("Please specify the delay time >= 86400(1 day)"); } if (scheduler.getJobDetail(taskName, Scheduler.DEFAULT_GROUP) != null) { scheduler.unscheduleJob(taskName, Scheduler.DEFAULT_GROUP); } if ("LoanArrearsTask".equals(taskName)) { loanArrearsTaskInitialTime = parseInitialTime(initialTime); loanArrearsTaskDelayTime = Long.parseLong(delayTime) * 1000; continue; } if ("PortfolioAtRiskTask".equals(taskName)) { portfolioAtRiskTaskExists = true; continue; } schedule( taskName, parseInitialTime(initialTime), Long.parseLong(delayTime) * 1000, jobRegistry, jobRepository, jobData, transactionManager); } if (loanArrearsTaskInitialTime != null) { if (portfolioAtRiskTaskExists) { scheduleLoanArrearsAndPortfolioAtRisk( loanArrearsTaskInitialTime, loanArrearsTaskDelayTime, jobRegistry, jobRepository, jobData, transactionManager); } else { schedule( "LoanArrearsTask", loanArrearsTaskInitialTime, loanArrearsTaskDelayTime, jobRegistry, jobRepository, jobData, transactionManager); } } } catch (Exception e) { throw new TaskSystemException(e); } }
protected JobLauncher createJobLauncher() throws Exception { SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(getJobRepository()); jobLauncher.afterPropertiesSet(); return jobLauncher; }
@Test public void testInitialiseWithRepository() throws Exception { jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(jobRepository); jobLauncher.afterPropertiesSet(); // no error }