/// <summary>This method creates the Curator client and connects to ZooKeeper.</summary> /// <param name="config">configuration properties</param> /// <returns>A Curator client</returns> /// <exception cref="System.Exception"/> protected internal virtual CuratorFramework CreateCuratorClient(Properties config ) { string connectionString = config.GetProperty(ZookeeperConnectionString, "localhost:2181" ); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); ACLProvider aclProvider; string authType = config.GetProperty(ZookeeperAuthType, "none"); if (authType.Equals("sasl")) { Log.Info("Connecting to ZooKeeper with SASL/Kerberos" + "and using 'sasl' ACLs"); string principal = SetJaasConfiguration(config); Runtime.SetProperty(ZooKeeperSaslClient.LoginContextNameKey, JaasLoginEntryName); Runtime.SetProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider" ); aclProvider = new ZKSignerSecretProvider.SASLOwnerACLProvider(principal); } else { // "none" Log.Info("Connecting to ZooKeeper without authentication"); aclProvider = new DefaultACLProvider(); } // open to everyone CuratorFramework cf = CuratorFrameworkFactory.Builder().ConnectString(connectionString ).RetryPolicy(retryPolicy).AclProvider(aclProvider).Build(); cf.Start(); return(cf); }
public virtual void TestACLs() { DelegationTokenManager tm1; string connectString = zkServer.GetConnectString(); Configuration conf = GetSecretConf(connectString); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); string userPass = "******"; ACL digestACL = new ACL(ZooDefs.Perms.All, new ID("digest", DigestAuthenticationProvider .GenerateDigest(userPass))); ACLProvider digestAclProvider = new _ACLProvider_319(digestACL); CuratorFramework curatorFramework = CuratorFrameworkFactory.Builder().ConnectString (connectString).RetryPolicy(retryPolicy).AclProvider(digestAclProvider).Authorization ("digest", Runtime.GetBytesForString(userPass, "UTF-8")).Build(); curatorFramework.Start(); ZKDelegationTokenSecretManager.SetCurator(curatorFramework); tm1 = new DelegationTokenManager(conf, new Text("bla")); tm1.Init(); // check ACL string workingPath = conf.Get(ZKDelegationTokenSecretManager.ZkDtsmZnodeWorkingPath ); VerifyACL(curatorFramework, "/" + workingPath, digestACL); tm1.Destroy(); ZKDelegationTokenSecretManager.SetCurator(null); curatorFramework.Close(); }
public void testExponentialBackoffRetryLimit() { IRetrySleeper sleeper = new RetrySleeper(); ExponentialBackoffRetry retry = new ExponentialBackoffRetry(1, Int32.MaxValue, 100); for (int i = 0; i >= 0; ++i) { retry.allowRetry(i, 0, sleeper); } }