Search in sources :

Example 1 with ElasticJobListener

use of com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener in project elastic-job by dangdangdotcom.

the class LiteJobFacadeTest method setUp.

@Before
public void setUp() throws NoSuchFieldException {
    MockitoAnnotations.initMocks(this);
    liteJobFacade = new LiteJobFacade(null, "test_job", Collections.<ElasticJobListener>singletonList(new TestElasticJobListener(caller)), eventBus);
    ReflectionUtils.setFieldValue(liteJobFacade, "configService", configService);
    ReflectionUtils.setFieldValue(liteJobFacade, "serverService", serverService);
    ReflectionUtils.setFieldValue(liteJobFacade, "shardingService", shardingService);
    ReflectionUtils.setFieldValue(liteJobFacade, "executionContextService", executionContextService);
    ReflectionUtils.setFieldValue(liteJobFacade, "executionService", executionService);
    ReflectionUtils.setFieldValue(liteJobFacade, "failoverService", failoverService);
}
Also used : ElasticJobListener(com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener) TestElasticJobListener(com.dangdang.ddframe.job.lite.api.listener.fixture.TestElasticJobListener) TestElasticJobListener(com.dangdang.ddframe.job.lite.api.listener.fixture.TestElasticJobListener) Before(org.junit.Before)

Example 2 with ElasticJobListener

use of com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener in project elastic-job by dangdangdotcom.

the class SchedulerFacadeTest method setUp.

@Before
public void setUp() throws NoSuchFieldException {
    MockitoAnnotations.initMocks(this);
    schedulerFacade = new SchedulerFacade(null, "test_job", Collections.<ElasticJobListener>emptyList());
    when(configService.load(true)).thenReturn(LiteJobConfiguration.newBuilder(new DataflowJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestDataflowJob.class.getCanonicalName(), false)).build());
    ReflectionUtils.setFieldValue(schedulerFacade, "configService", configService);
    ReflectionUtils.setFieldValue(schedulerFacade, "leaderElectionService", leaderElectionService);
    ReflectionUtils.setFieldValue(schedulerFacade, "serverService", serverService);
    ReflectionUtils.setFieldValue(schedulerFacade, "shardingService", shardingService);
    ReflectionUtils.setFieldValue(schedulerFacade, "executionService", executionService);
    ReflectionUtils.setFieldValue(schedulerFacade, "monitorService", monitorService);
    ReflectionUtils.setFieldValue(schedulerFacade, "listenerManager", listenerManager);
}
Also used : ElasticJobListener(com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener) DataflowJobConfiguration(com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration) Before(org.junit.Before)

Example 3 with ElasticJobListener

use of com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener in project loc-framework by lord-of-code.

the class LocElasticJobAutoConfiguration method createBean.

private void createBean(ZookeeperRegistryCenter registryCenter, @Nullable JobEventConfiguration jobEventConfiguration, String[] jobs) {
    if (ArrayUtils.isNotEmpty(jobs)) {
        Arrays.stream(jobs).forEach(job -> {
            try {
                ElasticJob elasticJob = this.applicationContext.getBean(job, ElasticJob.class);
                LocElasticJob locElasticJob = elasticJob.getClass().getAnnotation(LocElasticJob.class);
                LiteJobConfiguration liteJobConfiguration;
                if (elasticJob instanceof SimpleJob) {
                    liteJobConfiguration = createSimpleJobLiteJobConfiguration(elasticJob, locElasticJob);
                } else if (elasticJob instanceof DataflowJob) {
                    liteJobConfiguration = createDataFlowJobConfiguration(elasticJob, locElasticJob);
                } else if (elasticJob instanceof ScriptJob) {
                    liteJobConfiguration = createScriptJobConfiguration(elasticJob, locElasticJob);
                } else {
                    throw new IllegalArgumentException("error elasticJob type");
                }
                Preconditions.checkNotNull(liteJobConfiguration, "liteJobConfiguration不能为空");
                ElasticJobListener[] elasticJobListeners = getElasticJobListeners(locElasticJob.elasticJobListeners());
                List<Object> argList = Lists.newArrayList();
                if (elasticJob instanceof ScriptJob) {
                    argList.add(null);
                } else {
                    argList.add(elasticJob);
                }
                argList.add(registryCenter);
                argList.add(liteJobConfiguration);
                Optional.ofNullable(jobEventConfiguration).ifPresent(argList::add);
                argList.add(elasticJobListeners);
                createSpringJobScheduler(elasticJob.getClass().getSimpleName() + "JobScheduler", argList);
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        });
    }
}
Also used : ElasticJobListener(com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener) ScriptJob(com.dangdang.ddframe.job.api.script.ScriptJob) DataflowJob(com.dangdang.ddframe.job.api.dataflow.DataflowJob) FatalBeanException(org.springframework.beans.FatalBeanException) BeansException(org.springframework.beans.BeansException) LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) ElasticJob(com.dangdang.ddframe.job.api.ElasticJob) SimpleJob(com.dangdang.ddframe.job.api.simple.SimpleJob)

Aggregations

ElasticJobListener (com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener)3 Before (org.junit.Before)2 ElasticJob (com.dangdang.ddframe.job.api.ElasticJob)1 DataflowJob (com.dangdang.ddframe.job.api.dataflow.DataflowJob)1 ScriptJob (com.dangdang.ddframe.job.api.script.ScriptJob)1 SimpleJob (com.dangdang.ddframe.job.api.simple.SimpleJob)1 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)1 TestElasticJobListener (com.dangdang.ddframe.job.lite.api.listener.fixture.TestElasticJobListener)1 LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)1 BeansException (org.springframework.beans.BeansException)1 FatalBeanException (org.springframework.beans.FatalBeanException)1