public virtual void TestSimple() { Timing timing = new Timing(); ChildReaper reaper = null; CuratorFramework client = CuratorFrameworkFactory.NewClient(server.GetConnectString (), timing.Session(), timing.Connection(), new RetryOneTime(1)); try { client.Start(); for (int i = 0; i < 10; ++i) { client.Create().CreatingParentsIfNeeded().ForPath("/test/" + Extensions.ToString (i)); } reaper = new ChildReaper(client, "/test", Reaper.Mode.ReapUntilDelete, 1); reaper.Start(); timing.ForWaiting().SleepABit(); Stat stat = client.CheckExists().ForPath("/test"); Assert.Equal(stat.GetNumChildren(), 0); } finally { CloseableUtils.CloseQuietly(reaper); CloseableUtils.CloseQuietly(client); } }
public virtual void TestNamespace() { Timing timing = new Timing(); ChildReaper reaper = null; CuratorFramework client = CuratorFrameworkFactory.Builder().ConnectString(server. GetConnectString()).SessionTimeoutMs(timing.Session()).ConnectionTimeoutMs(timing .Connection()).RetryPolicy(new RetryOneTime(1)).Namespace("foo").Build(); try { client.Start(); for (int i = 0; i < 10; ++i) { client.Create().CreatingParentsIfNeeded().ForPath("/test/" + Extensions.ToString (i)); } reaper = new ChildReaper(client, "/test", Reaper.Mode.ReapUntilDelete, 1); reaper.Start(); timing.ForWaiting().SleepABit(); Stat stat = client.CheckExists().ForPath("/test"); Assert.Equal(stat.GetNumChildren(), 0); stat = client.UsingNamespace(null).CheckExists().ForPath("/foo/test"); NUnit.Framework.Assert.IsNotNull(stat); Assert.Equal(stat.GetNumChildren(), 0); } finally { CloseableUtils.CloseQuietly(reaper); CloseableUtils.CloseQuietly(client); } }
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(); }
/// <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); }
/// <exception cref="System.IO.IOException"/> public override void StartThreads() { if (!isExternalClient) { try { zkClient.Start(); } catch (Exception e) { throw new IOException("Could not start Curator Framework", e); } } else { // If namespace parents are implicitly created, they won't have ACLs. // So, let's explicitly create them. CuratorFramework nullNsFw = zkClient.UsingNamespace(null); EnsurePath ensureNs = nullNsFw.NewNamespaceAwareEnsurePath("/" + zkClient.GetNamespace ()); try { ensureNs.Ensure(nullNsFw.GetZookeeperClient()); } catch (Exception e) { throw new IOException("Could not create namespace", e); } } listenerThreadPool = Executors.NewSingleThreadExecutor(); try { delTokSeqCounter = new SharedCount(zkClient, ZkDtsmSeqnumRoot, 0); if (delTokSeqCounter != null) { delTokSeqCounter.Start(); } } catch (Exception e) { throw new IOException("Could not start Sequence Counter", e); } try { keyIdSeqCounter = new SharedCount(zkClient, ZkDtsmKeyidRoot, 0); if (keyIdSeqCounter != null) { keyIdSeqCounter.Start(); } } catch (Exception e) { throw new IOException("Could not start KeyId Counter", e); } try { CreatePersistentNode(ZkDtsmMasterKeyRoot); CreatePersistentNode(ZkDtsmTokensRoot); } catch (Exception) { throw new RuntimeException("Could not create ZK paths"); } try { keyCache = new PathChildrenCache(zkClient, ZkDtsmMasterKeyRoot, true); if (keyCache != null) { keyCache.Start(PathChildrenCache.StartMode.BuildInitialCache); keyCache.GetListenable().AddListener(new _PathChildrenCacheListener_340(this), listenerThreadPool ); } } catch (Exception e) { throw new IOException("Could not start PathChildrenCache for keys", e); } try { tokenCache = new PathChildrenCache(zkClient, ZkDtsmTokensRoot, true); if (tokenCache != null) { tokenCache.Start(PathChildrenCache.StartMode.BuildInitialCache); tokenCache.GetListenable().AddListener(new _PathChildrenCacheListener_368(this), listenerThreadPool); } } catch (Exception e) { throw new IOException("Could not start PathChildrenCache for tokens", e); } base.StartThreads(); }