Search in sources :

Example 31 with LiteJobConfiguration

use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project LinkAgent by shulieTech.

the class JobExecutorFactoryGetJobExecutorInterceptor method processWithoutSpring.

private boolean processWithoutSpring(ShadowJob shadowJob) {
    boolean ok = false;
    Map<String, SimpleJob> map = PradarSpringUtil.getBeanFactory().getBeansOfType(SimpleJob.class);
    for (Map.Entry<String, SimpleJob> entry : map.entrySet()) {
        SimpleJob simpleJob = entry.getValue();
        if (!simpleJob.getClass().getName().equals(shadowJob.getClassName())) {
            continue;
        }
        ZookeeperRegistryCenter regCenter = getRegisterConter();
        Object originJob = simpleJob;
        ElasticSimpleJob elasticSimpleJobAnnotation = simpleJob.getClass().getAnnotation(ElasticSimpleJob.class);
        Class ptJobClass = PtElasticJobSimpleJob.class;
        String cron = StringUtils.defaultIfBlank(elasticSimpleJobAnnotation.cron(), elasticSimpleJobAnnotation.value());
        SimpleJobConfiguration simpleJobConfiguration = new SimpleJobConfiguration(JobCoreConfiguration.newBuilder(ptJobClass.getName(), cron, elasticSimpleJobAnnotation.shardingTotalCount()).shardingItemParameters(elasticSimpleJobAnnotation.shardingItemParameters()).build(), simpleJob.getClass().getCanonicalName());
        LiteJobConfiguration liteJobConfiguration = LiteJobConfiguration.newBuilder(simpleJobConfiguration).overwrite(true).build();
        DefaultListableBeanFactory defaultListableBeanFactory = PradarSpringUtil.getBeanFactory();
        BeanDefinitionBuilder beanSimple = BeanDefinitionBuilder.rootBeanDefinition(ptJobClass);
        defaultListableBeanFactory.registerBeanDefinition(ptJobClass.getSimpleName() + originJob.getClass().getName(), beanSimple.getBeanDefinition());
        ElasticJob ptJob = (ElasticJob) PradarSpringUtil.getBeanFactory().getBean(ptJobClass.getSimpleName() + originJob.getClass().getName());
        String dataSourceRef = elasticSimpleJobAnnotation.dataSource();
        if (StringUtils.isNotBlank(dataSourceRef)) {
            if (!PradarSpringUtil.getBeanFactory().containsBean(dataSourceRef)) {
                throw new RuntimeException("not exist datasource [" + dataSourceRef + "] !");
            }
            DataSource dataSource = (DataSource) PradarSpringUtil.getBeanFactory().getBean(dataSourceRef);
            JobEventRdbConfiguration jobEventRdbConfiguration = new JobEventRdbConfiguration(dataSource);
            SpringJobScheduler jobScheduler = new SpringJobScheduler(ptJob, regCenter, liteJobConfiguration, jobEventRdbConfiguration);
            jobScheduler.init();
            if (originJob instanceof SimpleJob) {
                ((PtElasticJobSimpleJob) Reflect.on(jobScheduler).get("elasticJob")).setSimpleJob((SimpleJob) originJob);
            }
            ok = true;
            break;
        } else {
            SpringJobScheduler jobScheduler = new SpringJobScheduler(ptJob, regCenter, liteJobConfiguration);
            jobScheduler.init();
            if (originJob instanceof SimpleJob) {
                ((PtElasticJobSimpleJob) Reflect.on(jobScheduler).get("elasticJob")).setSimpleJob((SimpleJob) originJob);
            }
            ok = true;
            break;
        }
    }
    return ok;
}
Also used : PtElasticJobSimpleJob(com.pamirs.attach.plugin.shadowjob.obj.PtElasticJobSimpleJob) JobEventRdbConfiguration(com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) DataSource(javax.sql.DataSource) ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) ElasticJob(com.dangdang.ddframe.job.api.ElasticJob) SpringJobScheduler(com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler) PtElasticJobSimpleJob(com.pamirs.attach.plugin.shadowjob.obj.PtElasticJobSimpleJob) SimpleJob(com.dangdang.ddframe.job.api.simple.SimpleJob) ElasticSimpleJob(com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob) ElasticSimpleJob(com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob) Map(java.util.Map)

Example 32 with LiteJobConfiguration

use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project project by Ahaochan.

the class ElasticJobRegister method init.

private void init(DefaultJobProperties defaultProperties, BaseJobProperties jobProperties) {
    String beanName = jobProperties.getBeanName();
    ElasticJob elasticJob = StringUtils.isEmpty(beanName) ? null : ctx.getBean(jobProperties.getBeanName(), ElasticJob.class);
    Class<?> clazz = elasticJob == null ? null : elasticJob.getClass();
    JobCoreConfiguration coreConfig = jobProperties.generateJobCoreConfig(defaultProperties);
    JobTypeConfiguration typeConfig = jobProperties.generateJobTypeConfig(coreConfig, clazz);
    LiteJobConfiguration liteConfig = jobProperties.generateLiteJobConfig(defaultProperties, typeConfig);
    registerSpringJobSchedulerV2(defaultProperties, jobProperties, liteConfig, elasticJob);
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) ElasticJob(com.dangdang.ddframe.job.api.ElasticJob) JobTypeConfiguration(com.dangdang.ddframe.job.config.JobTypeConfiguration)

Aggregations

LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)32 Test (org.junit.Test)14 JobCoreConfiguration (com.dangdang.ddframe.job.config.JobCoreConfiguration)7 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)6 SpringJobScheduler (com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler)5 ElasticJob (com.dangdang.ddframe.job.api.ElasticJob)4 JobTypeConfiguration (com.dangdang.ddframe.job.config.JobTypeConfiguration)4 SimpleJob (com.dangdang.ddframe.job.api.simple.SimpleJob)3 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)3 JobEventRdbConfiguration (com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration)3 ElasticJobListener (com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener)3 ScriptJobConfiguration (com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)2 JobNodePath (com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)2 ElasticSimpleJob (com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob)2 PtElasticJobSimpleJob (com.pamirs.attach.plugin.shadowjob.obj.PtElasticJobSimpleJob)2 Map (java.util.Map)2 DataSource (javax.sql.DataSource)2 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 DataflowJob (com.dangdang.ddframe.job.api.dataflow.DataflowJob)1