Search in sources :

Example 1 with ZookeeperRegistryCenter

use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter in project elastic-job by dangdangdotcom.

the class Bootstrap method main.

/**
     * 启动入口.
     * 
     * @param args 命令行参数无需传入
     * @throws InterruptedException 线程中断异常
     */
// CHECKSTYLE:OFF
public static void main(final String[] args) throws InterruptedException {
    // CHECKSTYLE:ON
    CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(BootstrapEnvironment.getInstance().getZookeeperConfiguration());
    regCenter.init();
    final ZookeeperElectionService electionService = new ZookeeperElectionService(BootstrapEnvironment.getInstance().getFrameworkHostPort(), (CuratorFramework) regCenter.getRawClient(), HANode.ELECTION_NODE, new SchedulerElectionCandidate(regCenter));
    electionService.start();
    final CountDownLatch latch = new CountDownLatch(1);
    latch.await();
    Runtime.getRuntime().addShutdownHook(new Thread("shutdown-hook") {

        @Override
        public void run() {
            electionService.stop();
            latch.countDown();
        }
    });
}
Also used : ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) ZookeeperElectionService(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperElectionService) CountDownLatch(java.util.concurrent.CountDownLatch) SchedulerElectionCandidate(com.dangdang.ddframe.job.cloud.scheduler.ha.SchedulerElectionCandidate) CoordinatorRegistryCenter(com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)

Example 2 with ZookeeperRegistryCenter

use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter in project elastic-job by dangdangdotcom.

the class JavaMain method setUpRegistryCenter.

private static CoordinatorRegistryCenter setUpRegistryCenter() {
    ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(ZOOKEEPER_CONNECTION_STRING, JOB_NAMESPACE);
    CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(zkConfig);
    result.init();
    return result;
}
Also used : ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) ZookeeperConfiguration(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration) CoordinatorRegistryCenter(com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)

Example 3 with ZookeeperRegistryCenter

use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter in project elastic-job by dangdangdotcom.

the class RegistryCenterFactory method createCoordinatorRegistryCenter.

/**
     * 创建注册中心.
     *
     * @param connectString 注册中心连接字符串
     * @param namespace 注册中心命名空间
     * @param digest 注册中心凭证
     * @return 注册中心对象
     */
public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) {
    Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8);
    if (digest.isPresent()) {
        hasher.putString(digest.get(), Charsets.UTF_8);
    }
    HashCode hashCode = hasher.hash();
    CoordinatorRegistryCenter result = REG_CENTER_REGISTRY.get(hashCode);
    if (null != result) {
        return result;
    }
    ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace);
    if (digest.isPresent()) {
        zkConfig.setDigest(digest.get());
    }
    result = new ZookeeperRegistryCenter(zkConfig);
    result.init();
    REG_CENTER_REGISTRY.put(hashCode, result);
    return result;
}
Also used : ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) Hasher(com.google.common.hash.Hasher) HashCode(com.google.common.hash.HashCode) ZookeeperConfiguration(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration) CoordinatorRegistryCenter(com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)

Example 4 with ZookeeperRegistryCenter

use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter in project loc-framework by lord-of-code.

the class LocElasticJobAutoConfiguration method registerCenter.

private ZookeeperRegistryCenter registerCenter(LocElasticJobProperties elasticJobProperties) {
    ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(elasticJobProperties.getServerList(), elasticJobProperties.getNamespace());
    BeanUtils.copyProperties(elasticJobProperties, zookeeperConfiguration, "serverLists", "namespace");
    ZookeeperRegistryCenter registryCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
    registryCenter.init();
    return registryCenter;
}
Also used : ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) ZookeeperConfiguration(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration)

Example 5 with ZookeeperRegistryCenter

use of com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter in project loc-framework by lord-of-code.

the class LocElasticJobAutoConfiguration method init.

private void init() {
    LocElasticJobProperties elasticJobProperties = resolverJobProperties();
    String[] jobs = this.applicationContext.getBeanNamesForAnnotation(LocElasticJob.class);
    ZookeeperRegistryCenter registryCenter = registerCenter(elasticJobProperties);
    JobEventConfiguration jobEventConfiguration = Optional.ofNullable(Strings.emptyToNull(elasticJobProperties.getDataSource())).map(s -> new JobEventRdbConfiguration(applicationContext.getBean(s + "Ds", DataSource.class))).orElse(null);
    createBean(registryCenter, jobEventConfiguration, jobs);
}
Also used : JobEventConfiguration(com.dangdang.ddframe.job.event.JobEventConfiguration) Arrays(java.util.Arrays) JobEventRdbConfiguration(com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) LocDataSourceAutoConfiguration(com.loc.framework.autoconfigure.jdbc.LocDataSourceAutoConfiguration) ArrayUtils(org.apache.commons.lang3.ArrayUtils) StringUtils(org.apache.commons.lang3.StringUtils) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) AutoConfigureAfter(org.springframework.boot.autoconfigure.AutoConfigureAfter) ScriptJobConfiguration(com.dangdang.ddframe.job.config.script.ScriptJobConfiguration) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) DataSource(javax.sql.DataSource) ElasticJobListener(com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener) Nullable(org.springframework.lang.Nullable) SpringJobScheduler(com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler) ScriptJob(com.dangdang.ddframe.job.api.script.ScriptJob) Bindable(org.springframework.boot.context.properties.bind.Bindable) SimpleJob(com.dangdang.ddframe.job.api.simple.SimpleJob) ZookeeperConfiguration(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration) FatalBeanException(org.springframework.beans.FatalBeanException) BeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor) Throwables(com.google.common.base.Throwables) BeansException(org.springframework.beans.BeansException) ConditionalOnPrefixProperty(com.loc.framework.autoconfigure.ConditionalOnPrefixProperty) DataflowJobConfiguration(com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration) ApplicationContext(org.springframework.context.ApplicationContext) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) Configuration(org.springframework.context.annotation.Configuration) ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) EnvironmentAware(org.springframework.context.EnvironmentAware) Environment(org.springframework.core.env.Environment) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Binder(org.springframework.boot.context.properties.bind.Binder) DataflowJob(com.dangdang.ddframe.job.api.dataflow.DataflowJob) LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) ElasticJob(com.dangdang.ddframe.job.api.ElasticJob) ApplicationContextAware(org.springframework.context.ApplicationContextAware) BeanUtils(org.springframework.beans.BeanUtils) ZookeeperRegistryCenter(com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter) JobEventRdbConfiguration(com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration) JobEventConfiguration(com.dangdang.ddframe.job.event.JobEventConfiguration) DataSource(javax.sql.DataSource)

Aggregations

ZookeeperRegistryCenter (com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter)5 ZookeeperConfiguration (com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration)4 CoordinatorRegistryCenter (com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter)3 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 SchedulerElectionCandidate (com.dangdang.ddframe.job.cloud.scheduler.ha.SchedulerElectionCandidate)1 JobCoreConfiguration (com.dangdang.ddframe.job.config.JobCoreConfiguration)1 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)1 ScriptJobConfiguration (com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)1 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)1 JobEventConfiguration (com.dangdang.ddframe.job.event.JobEventConfiguration)1 JobEventRdbConfiguration (com.dangdang.ddframe.job.event.rdb.JobEventRdbConfiguration)1 ElasticJobListener (com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener)1 LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)1 SpringJobScheduler (com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler)1 ZookeeperElectionService (com.dangdang.ddframe.job.reg.zookeeper.ZookeeperElectionService)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1