Search in sources :

Example 31 with RetryPolicy

use of org.apache.curator.RetryPolicy in project BRFS by zhangnianli.

the class InitTaskManager method createMetaTaskManager.

/**
 * 概述:创建集群任务管理服务
 * @param manager
 * @param zkPaths
 * @param config
 * @throws Exception
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static void createMetaTaskManager(SchedulerManagerInterface manager, ZookeeperPaths zkPaths, ResourceTaskConfig config, String serverId) throws Exception {
    MetaTaskLeaderManager leader = new MetaTaskLeaderManager(manager, config);
    RetryPolicy retryPolicy = new RetryNTimes(3, 1000);
    String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
    CuratorFramework client = CuratorFrameworkFactory.newClient(zkAddresses, retryPolicy);
    client.start();
    leaderLatch = new LeaderLatch(client, zkPaths.getBaseLocksPath() + "/TaskManager/MetaTaskLeaderLock", serverId);
    leaderLatch.addListener(leader);
    leaderLatch.start();
}
Also used : RetryNTimes(org.apache.curator.retry.RetryNTimes) CuratorFramework(org.apache.curator.framework.CuratorFramework) LeaderLatch(org.apache.curator.framework.recipes.leader.LeaderLatch) RetryPolicy(org.apache.curator.RetryPolicy)

Example 32 with RetryPolicy

use of org.apache.curator.RetryPolicy in project BRFS by zhangnianli.

the class TestServiceManager method main.

public static void main(String[] args) throws Exception {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.newClient(zk_address, 5 * 1000, 30 * 1000, retryPolicy);
    client.start();
    client.blockUntilConnected();
    ServiceManager sm = new DefaultServiceManager(client.usingNamespace("test_c"));
    sm.start();
    sm.addServiceStateListener("ss_g", new ServiceStateListener() {

        @Override
        public void serviceRemoved(Service service) {
        // TODO Auto-generated method stub
        }

        @Override
        public void serviceAdded(Service service) {
            System.out.println("##########################################before add " + service);
        }
    });
    sm.registerService(new Service("ss_1", "ss_g", "localhost", 999));
    Thread.sleep(1000);
    sm.addServiceStateListener("ss_g", new ServiceStateListener() {

        @Override
        public void serviceRemoved(Service service) {
        // TODO Auto-generated method stub
        }

        @Override
        public void serviceAdded(Service service) {
            System.out.println("##########################################after add " + service);
        }
    });
    sm.addServiceStateListener("ss_g", new ServiceStateListener() {

        @Override
        public void serviceRemoved(Service service) {
        // TODO Auto-generated method stub
        }

        @Override
        public void serviceAdded(Service service) {
            System.out.println("##########################################after_2 add " + service);
        }
    });
    sm.registerService(new Service("ss_2", "ss_g", "localhost", 1222));
    synchronized (sm) {
        sm.wait();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) RetryPolicy(org.apache.curator.RetryPolicy)

Example 33 with RetryPolicy

use of org.apache.curator.RetryPolicy in project turbo-rpc by hank-whu.

the class ZooKeeperRegister method init.

@Override
public void init(List<HostPort> hostPorts) {
    watcherMap = new ConcurrentHashMap<>();
    String connectString = hostPorts.stream().map(i -> i.toString()).collect(Collectors.joining(","));
    RetryPolicy retryPolicy = new ForeverRetryPolicy(1000, 60 * 1000);
    client = CuratorFrameworkFactory.newClient(connectString, 1000 * 10, 1000 * 3, retryPolicy);
    client.start();
}
Also used : CreateMode(org.apache.zookeeper.CreateMode) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) Register(rpc.turbo.registry.Register) IOException(java.io.IOException) Protocol(rpc.turbo.config.server.Protocol) Collectors(java.util.stream.Collectors) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) AddressWithWeight(rpc.turbo.config.AddressWithWeight) StandardCharsets(java.nio.charset.StandardCharsets) StartMode(org.apache.curator.framework.recipes.cache.PathChildrenCache.StartMode) ForeverRetryPolicy(rpc.turbo.zk.common.ForeverRetryPolicy) ConcurrentMap(java.util.concurrent.ConcurrentMap) Objects(java.util.Objects) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) HostPort(rpc.turbo.config.HostPort) RetryPolicy(org.apache.curator.RetryPolicy) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) ConcurrentHashMap(org.jboss.netty.util.internal.ConcurrentHashMap) HexUtils(rpc.turbo.util.HexUtils) ForeverRetryPolicy(rpc.turbo.zk.common.ForeverRetryPolicy) ForeverRetryPolicy(rpc.turbo.zk.common.ForeverRetryPolicy) RetryPolicy(org.apache.curator.RetryPolicy)

Example 34 with RetryPolicy

use of org.apache.curator.RetryPolicy in project flink by apache.

the class KafkaTestEnvironmentImpl method createCuratorClient.

/**
	 * Only for the 0.8 server we need access to the zk client.
	 */
public CuratorFramework createCuratorClient() {
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(100, 10);
    CuratorFramework curatorClient = CuratorFrameworkFactory.newClient(standardProps.getProperty("zookeeper.connect"), retryPolicy);
    curatorClient.start();
    return curatorClient;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy)

Example 35 with RetryPolicy

use of org.apache.curator.RetryPolicy in project hadoop by apache.

the class TestZKDelegationTokenSecretManager method testACLs.

@Test
public void testACLs() throws Exception {
    DelegationTokenManager tm1;
    String connectString = zkServer.getConnectString();
    Configuration conf = getSecretConf(connectString);
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    String userPass = "myuser:mypass";
    final ACL digestACL = new ACL(ZooDefs.Perms.ALL, new Id("digest", DigestAuthenticationProvider.generateDigest(userPass)));
    ACLProvider digestAclProvider = new ACLProvider() {

        @Override
        public List<ACL> getAclForPath(String path) {
            return getDefaultAcl();
        }

        @Override
        public List<ACL> getDefaultAcl() {
            List<ACL> ret = new ArrayList<ACL>();
            ret.add(digestACL);
            return ret;
        }
    };
    CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().connectString(connectString).retryPolicy(retryPolicy).aclProvider(digestAclProvider).authorization("digest", userPass.getBytes("UTF-8")).build();
    curatorFramework.start();
    ZKDelegationTokenSecretManager.setCurator(curatorFramework);
    tm1 = new DelegationTokenManager(conf, new Text("bla"));
    tm1.init();
    // check ACL
    String workingPath = conf.get(ZKDelegationTokenSecretManager.ZK_DTSM_ZNODE_WORKING_PATH);
    verifyACL(curatorFramework, "/" + workingPath, digestACL);
    tm1.destroy();
    ZKDelegationTokenSecretManager.setCurator(null);
    curatorFramework.close();
}
Also used : ACLProvider(org.apache.curator.framework.api.ACLProvider) CuratorFramework(org.apache.curator.framework.CuratorFramework) Configuration(org.apache.hadoop.conf.Configuration) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Text(org.apache.hadoop.io.Text) Id(org.apache.zookeeper.data.Id) RetryPolicy(org.apache.curator.RetryPolicy) DelegationTokenManager(org.apache.hadoop.security.token.delegation.web.DelegationTokenManager) Test(org.junit.Test)

Aggregations

RetryPolicy (org.apache.curator.RetryPolicy)69 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)47 CuratorFramework (org.apache.curator.framework.CuratorFramework)42 RetryNTimes (org.apache.curator.retry.RetryNTimes)12 IOException (java.io.IOException)10 ACLProvider (org.apache.curator.framework.api.ACLProvider)7 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)6 TestingServer (org.apache.curator.test.TestingServer)5 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)4 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)4 SimpleEventListener (org.apache.metron.zookeeper.SimpleEventListener)4 ZKCache (org.apache.metron.zookeeper.ZKCache)4 ACL (org.apache.zookeeper.data.ACL)4 Before (org.junit.Before)4 DefaultServiceManager (com.bonree.brfs.common.service.impl.DefaultServiceManager)3 AuthInfo (org.apache.curator.framework.AuthInfo)3 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)3 Test (org.junit.Test)3 Service (com.bonree.brfs.common.service.Service)2 ServiceManager (com.bonree.brfs.common.service.ServiceManager)2