public static JobSchedulerConfiguration createJobSchedulerConfiguration(final String cronExpression, final Long fixedDelay, final Long initialDelay, final JobSchedulerType jobSchedulerType) { final JobSchedulerConfiguration jobSchedulerConfiguration = new JobSchedulerConfiguration(); jobSchedulerConfiguration.setCronExpression(cronExpression); jobSchedulerConfiguration.setFixedDelay(fixedDelay); jobSchedulerConfiguration.setInitialDelay(initialDelay); jobSchedulerConfiguration.setJobSchedulerType(jobSchedulerType); jobSchedulerConfiguration.setTaskExecutorType(TaskExecutorType.SYNCHRONOUS); jobSchedulerConfiguration.setSchedulerStatus(SchedulerStatus.INITIALIZED); return jobSchedulerConfiguration; }
public static List<ValueRecord> map(final JobSchedulerConfiguration jobSchedulerConfiguration, final Long jobConfigurationId) { final List<ValueRecord> valueRecords = new ArrayList<>(); final ValueRecord beanName = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.BEAN_NAME, jobSchedulerConfiguration.getBeanName()); final ValueRecord cronExpression = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.CRON_EXPRESSION, jobSchedulerConfiguration.getCronExpression()); final ValueRecord fixedDelay = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.FIXED_DELAY, jobSchedulerConfiguration.getFixedDelay()); final ValueRecord initialDelay = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.INITIAL_DELAY, jobSchedulerConfiguration.getInitialDelay()); final ValueRecord schedulerStatus = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.STATUS, jobSchedulerConfiguration.getSchedulerStatus().getValue()); final ValueRecord schedulerType = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.SCHEDULER_TYPE, jobSchedulerConfiguration.getJobSchedulerType().getId()); final ValueRecord executorType = new ValueRecord(jobConfigurationId, JobSchedulerConfigurationKey.TASK_EXECUTOR_TYPE, jobSchedulerConfiguration.getTaskExecutorType().getId()); valueRecords.add(beanName); valueRecords.add(cronExpression); valueRecords.add(fixedDelay); valueRecords.add(initialDelay); valueRecords.add(schedulerStatus); valueRecords.add(schedulerType); valueRecords.add(executorType); return valueRecords; } }
@Override public void schedule() { final Date initialDelay = new Date(System.currentTimeMillis() + this.jobSchedulerConfiguration.getInitialDelay()); log.debug("Scheduling: " + this.jobRunner.getJob().getName() + " with Parameters: " + this.jobRunner.getJobParameters().toProperties()); this.threadPoolTaskScheduler.scheduleWithFixedDelay(this.jobRunner, initialDelay, this.jobSchedulerConfiguration.getFixedDelay()); this.setStatus(SchedulerStatus.RUNNING); }
@Test public void getJobConfigurationsIT() throws NoSuchJobException, NoSuchJobConfigurationException { final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration(null, 10L, 10L, JobSchedulerType.PERIOD); jobSchedulerConfiguration.setBeanName("testBean"); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); final JobConfiguration addedJobConfiguration = this.getJobConfigurationRepository().add(jobConfiguration, APPLICATION_NAME); assertThat(addedJobConfiguration).isNotNull(); assertThat(addedJobConfiguration.getJobConfigurationId()).isNotNull(); assertThat(addedJobConfiguration.getJobSchedulerConfiguration()).isNotNull(); final JobConfiguration secondAddedJobConfiguration = this.getJobConfigurationRepository().add(jobConfiguration, APPLICATION_NAME); assertThat(secondAddedJobConfiguration).isNotNull(); assertThat(secondAddedJobConfiguration.getJobConfigurationId()).isNotNull(); assertThat(secondAddedJobConfiguration.getJobSchedulerConfiguration()).isNotNull(); final Collection<JobConfiguration> jobConfigurations = this.getJobConfigurationRepository().getJobConfigurations("sampleJob", APPLICATION_NAME); assertThat(jobConfigurations.size()).isEqualTo(2); }
@Override public void updateJobConfiguration(final JobConfiguration jobConfiguration) { jobConfiguration.validateForUpdate(); try { final JobConfiguration existingJobConfiguration = this.jobConfigurationRepository.getJobConfiguration(jobConfiguration.getJobConfigurationId(), this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (existingJobConfiguration.getJobSchedulerConfiguration() != null) { final String existingBeanName = existingJobConfiguration.getJobSchedulerConfiguration().getBeanName(); jobConfiguration.getJobSchedulerConfiguration().setBeanName(existingBeanName); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); this.schedulerService.refreshSchedulerForJob(jobConfiguration); if (SchedulerStatus.RUNNING.equals(jobConfiguration.getJobSchedulerConfiguration().getSchedulerStatus())) { this.schedulerService.schedule(jobConfiguration.getJobSchedulerConfiguration().getBeanName(), Boolean.TRUE); } else { log.info("Scheduler not started, no scheduling triggered!"); } } else if (existingJobConfiguration.getJobListenerConfiguration() != null) { final String existingBeanName = existingJobConfiguration.getJobListenerConfiguration().getBeanName(); jobConfiguration.getJobListenerConfiguration().setBeanName(existingBeanName); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); this.listenerService.refreshListenerForJob(jobConfiguration); } } catch (final NoSuchJobConfigurationException e) { log.error(e.getMessage()); throw new SpringBatchLightminApplicationException(e, e.getMessage()); } }
public CronScheduler(final SchedulerConstructorWrapper schedulerConstructorWrapper) { this.jobConfiguration = schedulerConstructorWrapper.getJobConfiguration(); this.threadPoolTaskScheduler = schedulerConstructorWrapper.getThreadPoolTaskScheduler(); this.jobSchedulerConfiguration = this.jobConfiguration.getJobSchedulerConfiguration(); this.timeZone = TimeZone.getDefault(); this.trigger = new CronTrigger(this.jobSchedulerConfiguration.getCronExpression(), this.timeZone); this.job = schedulerConstructorWrapper.getJob(); this.jobRunner = new JobRunner(this.job, schedulerConstructorWrapper.getJobLauncher(), schedulerConstructorWrapper.getJobParameters(), schedulerConstructorWrapper.getJobIncrementer()); final SchedulerStatus schedulerStatus; if (this.jobSchedulerConfiguration.getSchedulerStatus() != null) { schedulerStatus = this.jobSchedulerConfiguration.getSchedulerStatus(); } else { schedulerStatus = SchedulerStatus.INITIALIZED; } this.setStatus(schedulerStatus); }
jobConfiguration.validateForSave(); if (jobConfiguration.getJobSchedulerConfiguration() != null) { jobConfiguration.getJobSchedulerConfiguration().setBeanName(TEMP_BEAN_NAME + "_SCHEDULER_" + jobConfiguration.getJobConfigurationId()); } else if (jobConfiguration.getJobListenerConfiguration() != null) { jobConfiguration.getJobListenerConfiguration().setBeanName(TEMP_BEAN_NAME + "_LISTENER_" + jobConfiguration this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (addedJobConfiguration.getJobSchedulerConfiguration() != null) { addedJobConfiguration.getJobSchedulerConfiguration().setBeanName(null); final String beanName = this.schedulerService.registerSchedulerForJob(addedJobConfiguration); addedJobConfiguration.getJobSchedulerConfiguration().setBeanName(beanName); try { this.jobConfigurationRepository.update(addedJobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (SchedulerStatus.RUNNING.equals(addedJobConfiguration.getJobSchedulerConfiguration().getSchedulerStatus())) { this.schedulerService.schedule(beanName, Boolean.TRUE); } else {
public PeriodScheduler(final SchedulerConstructorWrapper schedulerConstructorWrapper) { this.jobConfiguration = schedulerConstructorWrapper.getJobConfiguration(); this.threadPoolTaskScheduler = schedulerConstructorWrapper.getThreadPoolTaskScheduler(); this.jobSchedulerConfiguration = this.jobConfiguration.getJobSchedulerConfiguration(); this.job = schedulerConstructorWrapper.getJob(); this.jobRunner = new JobRunner(this.job, schedulerConstructorWrapper.getJobLauncher(), schedulerConstructorWrapper.getJobParameters(), schedulerConstructorWrapper.getJobIncrementer()); final SchedulerStatus schedulerStatus; if (this.jobSchedulerConfiguration.getSchedulerStatus() != null) { schedulerStatus = this.jobSchedulerConfiguration.getSchedulerStatus(); } else { schedulerStatus = SchedulerStatus.INITIALIZED; } this.setStatus(schedulerStatus); }
@Test public void getJobConfigurationsByNameIT() throws NoSuchJobException { final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration(null, 10L, 10L, JobSchedulerType.PERIOD); jobSchedulerConfiguration.setBeanName("testBean"); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); final Map<String, Object> jobParameters = new HashMap<>(); jobParameters.put("LONG", 10L); jobParameters.put("DOUBLE", 20.2); jobParameters.put("STRING", "test"); jobParameters.put("DATE", "2015/03/27 23:19:24:120"); jobParameters.put("DATE", "2015/03/27"); jobConfiguration.setJobParameters(jobParameters); final JobConfiguration addedJobConfiguration = this.getJobConfigurationRepository().add(jobConfiguration, APPLICATION_NAME); assertThat(addedJobConfiguration).isNotNull(); assertThat(addedJobConfiguration.getJobConfigurationId()).isNotNull(); assertThat(addedJobConfiguration.getJobSchedulerConfiguration()).isNotNull(); final JobConfiguration secondAddedJobConfiguration = this.getJobConfigurationRepository().add(jobConfiguration, APPLICATION_NAME); assertThat(secondAddedJobConfiguration).isNotNull(); assertThat(secondAddedJobConfiguration.getJobConfigurationId()).isNotNull(); assertThat(secondAddedJobConfiguration.getJobSchedulerConfiguration()).isNotNull(); final Collection<String> jobNames = new LinkedList<>(); jobNames.add("sampleJob"); jobNames.add("sampleJobSecond"); final Collection<JobConfiguration> jobConfigurations = this.getJobConfigurationRepository() .getAllJobConfigurationsByJobNames(jobNames, APPLICATION_NAME); assertThat(jobConfigurations.size()).isEqualTo(2); }
@Override public void updateJobConfiguration(final JobConfiguration jobConfiguration) { jobConfiguration.validateForUpdate(); try { final JobConfiguration existingJobConfiguration = this.jobConfigurationRepository.getJobConfiguration(jobConfiguration.getJobConfigurationId(), this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (existingJobConfiguration.getJobSchedulerConfiguration() != null) { final String existingBeanName = existingJobConfiguration.getJobSchedulerConfiguration().getBeanName(); jobConfiguration.getJobSchedulerConfiguration().setBeanName(existingBeanName); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); this.schedulerService.refreshSchedulerForJob(jobConfiguration); if (SchedulerStatus.RUNNING.equals(jobConfiguration.getJobSchedulerConfiguration().getSchedulerStatus())) { this.schedulerService.schedule(jobConfiguration.getJobSchedulerConfiguration().getBeanName(), Boolean.TRUE); } else { log.info("Scheduler not started, no scheduling triggered!"); } } else if (existingJobConfiguration.getJobListenerConfiguration() != null) { final String existingBeanName = existingJobConfiguration.getJobListenerConfiguration().getBeanName(); jobConfiguration.getJobListenerConfiguration().setBeanName(existingBeanName); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); this.listenerService.refreshListenerForJob(jobConfiguration); } } catch (final NoSuchJobConfigurationException e) { log.error(e.getMessage()); throw new SpringBatchLightminApplicationException(e, e.getMessage()); } }
@Override public void schedule() { final Date initialDelay = new Date(System.currentTimeMillis() + this.jobSchedulerConfiguration.getInitialDelay()); log.debug("Scheduling: " + this.jobRunner.getJob().getName() + " with Parameters: " + this.jobRunner.getJobParameters().toProperties()); this.threadPoolTaskScheduler.scheduleWithFixedDelay(this.jobRunner, initialDelay, this.jobSchedulerConfiguration.getFixedDelay()); this.setStatus(SchedulerStatus.RUNNING); }
public CronScheduler(final SchedulerConstructorWrapper schedulerConstructorWrapper) { this.jobConfiguration = schedulerConstructorWrapper.getJobConfiguration(); this.threadPoolTaskScheduler = schedulerConstructorWrapper.getThreadPoolTaskScheduler(); this.jobSchedulerConfiguration = this.jobConfiguration.getJobSchedulerConfiguration(); this.timeZone = TimeZone.getDefault(); this.trigger = new CronTrigger(this.jobSchedulerConfiguration.getCronExpression(), this.timeZone); this.job = schedulerConstructorWrapper.getJob(); this.jobRunner = new JobRunner(this.job, schedulerConstructorWrapper.getJobLauncher(), schedulerConstructorWrapper.getJobParameters(), schedulerConstructorWrapper.getJobIncrementer()); final SchedulerStatus schedulerStatus; if (this.jobSchedulerConfiguration.getSchedulerStatus() != null) { schedulerStatus = this.jobSchedulerConfiguration.getSchedulerStatus(); } else { schedulerStatus = SchedulerStatus.INITIALIZED; } this.setStatus(schedulerStatus); }
jobConfiguration.validateForSave(); if (jobConfiguration.getJobSchedulerConfiguration() != null) { jobConfiguration.getJobSchedulerConfiguration().setBeanName(TEMP_BEAN_NAME + "_SCHEDULER_" + jobConfiguration.getJobConfigurationId()); } else if (jobConfiguration.getJobListenerConfiguration() != null) { jobConfiguration.getJobListenerConfiguration().setBeanName(TEMP_BEAN_NAME + "_LISTENER_" + jobConfiguration this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (addedJobConfiguration.getJobSchedulerConfiguration() != null) { addedJobConfiguration.getJobSchedulerConfiguration().setBeanName(null); final String beanName = this.schedulerService.registerSchedulerForJob(addedJobConfiguration); addedJobConfiguration.getJobSchedulerConfiguration().setBeanName(beanName); try { this.jobConfigurationRepository.update(addedJobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); if (SchedulerStatus.RUNNING.equals(addedJobConfiguration.getJobSchedulerConfiguration().getSchedulerStatus())) { this.schedulerService.schedule(beanName, Boolean.TRUE); } else {
public PeriodScheduler(final SchedulerConstructorWrapper schedulerConstructorWrapper) { this.jobConfiguration = schedulerConstructorWrapper.getJobConfiguration(); this.threadPoolTaskScheduler = schedulerConstructorWrapper.getThreadPoolTaskScheduler(); this.jobSchedulerConfiguration = this.jobConfiguration.getJobSchedulerConfiguration(); this.job = schedulerConstructorWrapper.getJob(); this.jobRunner = new JobRunner(this.job, schedulerConstructorWrapper.getJobLauncher(), schedulerConstructorWrapper.getJobParameters(), schedulerConstructorWrapper.getJobIncrementer()); final SchedulerStatus schedulerStatus; if (this.jobSchedulerConfiguration.getSchedulerStatus() != null) { schedulerStatus = this.jobSchedulerConfiguration.getSchedulerStatus(); } else { schedulerStatus = SchedulerStatus.INITIALIZED; } this.setStatus(schedulerStatus); }
public static JobSchedulerConfiguration map(final Map<String, Object> values) { final JobSchedulerConfiguration jobSchedulerConfiguration = new JobSchedulerConfiguration(); jobSchedulerConfiguration.setBeanName(getValueOrNull(values, JobSchedulerConfigurationKey.BEAN_NAME, String.class)); final JobSchedulerType jobSchedulerType = JobSchedulerType.getById(getValueOrNull(values, JobSchedulerConfigurationKey.SCHEDULER_TYPE, Long.class)); if (JobSchedulerType.CRON == jobSchedulerType) { jobSchedulerConfiguration.setCronExpression(getValueOrNull(values, JobSchedulerConfigurationKey.CRON_EXPRESSION, String.class)); } else if (JobSchedulerType.PERIOD == jobSchedulerType) { jobSchedulerConfiguration.setFixedDelay(getValueOrNull(values, JobSchedulerConfigurationKey.FIXED_DELAY, Long.class)); jobSchedulerConfiguration.setInitialDelay(getValueOrNull(values, JobSchedulerConfigurationKey.INITIAL_DELAY, Long.class)); } jobSchedulerConfiguration.setJobSchedulerType(jobSchedulerType); final SchedulerStatus schedulerStatus = SchedulerStatus.getByValue(getValueOrNull(values, JobSchedulerConfigurationKey.STATUS, String.class)); jobSchedulerConfiguration.setSchedulerStatus(schedulerStatus); final TaskExecutorType taskExecutorType = TaskExecutorType.getById(getValueOrNull(values, JobSchedulerConfigurationKey.TASK_EXECUTOR_TYPE, Long.class)); jobSchedulerConfiguration.setTaskExecutorType(taskExecutorType); return jobSchedulerConfiguration; }
private static JobSchedulerConfiguration map(final org.tuxdevelop.spring.batch.lightmin.domain.JobSchedulerConfiguration jobSchedulerConfiguration) { final JobSchedulerConfiguration response; if (jobSchedulerConfiguration != null) { response = new JobSchedulerConfiguration(); response.setCronExpression(jobSchedulerConfiguration.getCronExpression()); response.setFixedDelay(jobSchedulerConfiguration.getFixedDelay()); response.setInitialDelay(jobSchedulerConfiguration.getInitialDelay()); response.setJobSchedulerType(map(jobSchedulerConfiguration.getJobSchedulerType())); response.setSchedulerStatus(map(jobSchedulerConfiguration.getSchedulerStatus())); response.setTaskExecutorType(map(jobSchedulerConfiguration.getTaskExecutorType())); } else { response = null; } return response; }
@Test public void getJobConfigurationsIT() throws NoSuchJobException, NoSuchJobConfigurationException { final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration(null, 10L, 10L, JobSchedulerType.PERIOD); jobSchedulerConfiguration.setBeanName("testBean"); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); final JobConfiguration addedJobConfiguration = this.getJobConfigurationRepository().add(jobConfiguration, APPLICATION_NAME); assertThat(addedJobConfiguration).isNotNull(); assertThat(addedJobConfiguration.getJobConfigurationId()).isNotNull(); assertThat(addedJobConfiguration.getJobSchedulerConfiguration()).isNotNull(); final JobConfiguration secondAddedJobConfiguration = this.getJobConfigurationRepository().add(jobConfiguration, APPLICATION_NAME); assertThat(secondAddedJobConfiguration).isNotNull(); assertThat(secondAddedJobConfiguration.getJobConfigurationId()).isNotNull(); assertThat(secondAddedJobConfiguration.getJobSchedulerConfiguration()).isNotNull(); final Collection<JobConfiguration> jobConfigurations = this.getJobConfigurationRepository().getJobConfigurations("sampleJob", APPLICATION_NAME); assertThat(jobConfigurations.size()).isEqualTo(2); }
private static JobSchedulerConfiguration map(final org.tuxdevelop.spring.batch.lightmin.api.resource.admin.JobSchedulerConfiguration jobSchedulerConfiguration) { final JobSchedulerConfiguration response; if (jobSchedulerConfiguration != null) { response = new JobSchedulerConfiguration(); response.setJobSchedulerType(map(jobSchedulerConfiguration.getJobSchedulerType())); response.setCronExpression(jobSchedulerConfiguration.getCronExpression()); response.setFixedDelay(jobSchedulerConfiguration.getFixedDelay()); response.setInitialDelay(jobSchedulerConfiguration.getInitialDelay()); response.setSchedulerStatus(map(jobSchedulerConfiguration.getSchedulerStatus())); response.setTaskExecutorType(map(jobSchedulerConfiguration.getTaskExecutorType())); } else { response = null; } return response; }
private static JobSchedulerConfiguration map(final org.tuxdevelop.spring.batch.lightmin.domain.JobSchedulerConfiguration jobSchedulerConfiguration) { final JobSchedulerConfiguration response; if (jobSchedulerConfiguration != null) { response = new JobSchedulerConfiguration(); response.setCronExpression(jobSchedulerConfiguration.getCronExpression()); response.setFixedDelay(jobSchedulerConfiguration.getFixedDelay()); response.setInitialDelay(jobSchedulerConfiguration.getInitialDelay()); response.setJobSchedulerType(map(jobSchedulerConfiguration.getJobSchedulerType())); response.setSchedulerStatus(map(jobSchedulerConfiguration.getSchedulerStatus())); response.setTaskExecutorType(map(jobSchedulerConfiguration.getTaskExecutorType())); } else { response = null; } return response; }
@Test public void getJobConfigurationsByNameIT() throws NoSuchJobException { final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration(null, 10L, 10L, JobSchedulerType.PERIOD); jobSchedulerConfiguration.setBeanName("testBean"); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); final Map<String, Object> jobParameters = new HashMap<>(); jobParameters.put("LONG", 10L); jobParameters.put("DOUBLE", 20.2); jobParameters.put("STRING", "test"); jobParameters.put("DATE", "2015/03/27 23:19:24:120"); jobParameters.put("DATE", "2015/03/27"); jobConfiguration.setJobParameters(jobParameters); final JobConfiguration addedJobConfiguration = this.getJobConfigurationRepository().add(jobConfiguration, APPLICATION_NAME); assertThat(addedJobConfiguration).isNotNull(); assertThat(addedJobConfiguration.getJobConfigurationId()).isNotNull(); assertThat(addedJobConfiguration.getJobSchedulerConfiguration()).isNotNull(); final JobConfiguration secondAddedJobConfiguration = this.getJobConfigurationRepository().add(jobConfiguration, APPLICATION_NAME); assertThat(secondAddedJobConfiguration).isNotNull(); assertThat(secondAddedJobConfiguration.getJobConfigurationId()).isNotNull(); assertThat(secondAddedJobConfiguration.getJobSchedulerConfiguration()).isNotNull(); final Collection<String> jobNames = new LinkedList<>(); jobNames.add("sampleJob"); jobNames.add("sampleJobSecond"); final Collection<JobConfiguration> jobConfigurations = this.getJobConfigurationRepository() .getAllJobConfigurationsByJobNames(jobNames, APPLICATION_NAME); assertThat(jobConfigurations.size()).isEqualTo(2); }