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();
}
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();
}
}
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();
}
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;
}
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();
}
Aggregations