コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        public CuratorFrameworkImpl(CuratorFrameworkFactory.Builder builder)
        {
            IZookeeperFactory localZookeeperFactory = makeZookeeperFactory(builder.GetZookeeperFactory());
            this.client = new CuratorZookeeperClient(localZookeeperFactory,
                                                        builder.GetEnsembleProvider(),
                                                        builder.GetSessionTimeoutMs(),
                                                        builder.GetConnectionTimeoutMs(),
                                                        new WatchedWatcher(this),
                                                        builder.GetRetryPolicy(),
                                                        builder.CanBeReadOnly());

            listeners = new ListenerContainer<ICuratorListener>();
            unhandledErrorListeners = new ListenerContainer<IUnhandledErrorListener>();
            backgroundOperations = new DelayQueue<OperationAndData<object>>();
            @namespace = new NamespaceImpl(this, builder.GetNamespace());
            maxCloseWaitMs = builder.GetMaxCloseWaitMs();
            connectionStateManager = new ConnectionStateManager(this, builder.GetEventQueueSize());
            compressionProvider = builder.GetCompressionProvider();
            aclProvider = builder.GetAclProvider();
            state = new AtomicReference<CuratorFrameworkState>(CuratorFrameworkState.LATENT);
            useContainerParentsIfAvailable = builder.UseContainerParentsIfAvailable();

            byte[] builderDefaultData = builder.GetDefaultData();
            byte[] destDefaults = new byte[builderDefaultData.Length];
            Array.Copy(builderDefaultData, destDefaults, builderDefaultData.Length);
            defaultData = (builderDefaultData != null)
                            ?  destDefaults
                            : new byte[0];
            authInfos = buildAuths(builder);

            failedDeleteManager = new FailedDeleteManager(this);
            namespaceWatcherMap = new NamespaceWatcherMap(this);
            namespaceFacadeCache = new NamespaceFacadeCache(this);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        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();
        }
コード例 #6
0
 internal ZooKeeperClient(EnsembleProvider ensembleProvider, TimeSpan sessionTimeout, RetryStrategy retryStrategy, string nameSpace, bool canBeReadonly, ILog log)
     : this(
         CuratorFrameworkFactory
         .builder()
         .ensembleProvider(ensembleProvider)
         .sessionTimeoutMs((int)sessionTimeout.TotalMilliseconds)
         .connectionTimeoutMs(retryStrategy.ToCuratorConnectionTimeout())
         .retryPolicy(retryStrategy.ToCuratorRetryPolicy())
         .@namespace(string.IsNullOrWhiteSpace(nameSpace) ? null : nameSpace.TrimStart('/'))
         .canBeReadOnly(canBeReadonly)
         .build(),
         log,
         new ConnectionStringRandomizer(ensembleProvider))
 {
 }
コード例 #7
0
ファイル: CuratorService.cs プロジェクト: orf53975/hadoop.net
        /// <summary>
        /// Create a new curator instance off the root path; using configuration
        /// options provided in the service configuration to set timeouts and
        /// retry policy.
        /// </summary>
        /// <returns>the newly created creator</returns>
        /// <exception cref="System.IO.IOException"/>
        private CuratorFramework CreateCurator()
        {
            Configuration conf = GetConfig();

            CreateEnsembleProvider();
            int sessionTimeout = conf.GetInt(KeyRegistryZkSessionTimeout, DefaultZkSessionTimeout
                                             );
            int connectionTimeout = conf.GetInt(KeyRegistryZkConnectionTimeout, DefaultZkConnectionTimeout
                                                );
            int retryTimes    = conf.GetInt(KeyRegistryZkRetryTimes, DefaultZkRetryTimes);
            int retryInterval = conf.GetInt(KeyRegistryZkRetryInterval, DefaultZkRetryInterval
                                            );
            int retryCeiling = conf.GetInt(KeyRegistryZkRetryCeiling, DefaultZkRetryCeiling);

            if (Log.IsDebugEnabled())
            {
                Log.Debug("Creating CuratorService with connection {}", connectionDescription);
            }
            CuratorFramework framework;

            lock (typeof(Org.Apache.Hadoop.Registry.Client.Impl.ZK.CuratorService))
            {
                // set the security options
                // build up the curator itself
                CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.Builder();
                builder.EnsembleProvider(ensembleProvider).ConnectionTimeoutMs(connectionTimeout)
                .SessionTimeoutMs(sessionTimeout).RetryPolicy(new BoundedExponentialBackoffRetry
                                                                  (retryInterval, retryCeiling, retryTimes));
                // set up the builder AND any JVM context
                registrySecurity.ApplySecurityEnvironment(builder);
                //log them
                securityConnectionDiagnostics = BuildSecurityDiagnostics();
                framework = builder.Build();
                framework.Start();
            }
            return(framework);
        }
コード例 #8
0
 public CuratorTempFrameworkImpl(CuratorFrameworkFactory.Builder factory, long inactiveThresholdMs)
 {
     this.factory = factory;
     this.inactiveThresholdMs = inactiveThresholdMs;
 }
コード例 #9
0
 public ZKDelegationTokenSecretManager(Configuration conf)
     : base(conf.GetLong(DelegationTokenManager.UpdateInterval, DelegationTokenManager
                         .UpdateIntervalDefault) * 1000, conf.GetLong(DelegationTokenManager.MaxLifetime,
                                                                      DelegationTokenManager.MaxLifetimeDefault) * 1000, conf.GetLong(DelegationTokenManager
                                                                                                                                      .RenewInterval, DelegationTokenManager.RenewIntervalDefault * 1000), conf.GetLong
                (DelegationTokenManager.RemovalScanInterval, DelegationTokenManager.RemovalScanIntervalDefault
                ) * 1000)
 {
     shutdownTimeout = conf.GetLong(ZkDtsmZkShutdownTimeout, ZkDtsmZkShutdownTimeoutDefault
                                    );
     if (CuratorTl.Get() != null)
     {
         zkClient = CuratorTl.Get().UsingNamespace(conf.Get(ZkDtsmZnodeWorkingPath, ZkDtsmZnodeWorkingPathDeafult
                                                            ) + "/" + ZkDtsmNamespace);
         isExternalClient = true;
     }
     else
     {
         string connString = conf.Get(ZkDtsmZkConnectionString);
         Preconditions.CheckNotNull(connString, "Zookeeper connection string cannot be null"
                                    );
         string authType = conf.Get(ZkDtsmZkAuthType);
         // AuthType has to be explicitly set to 'none' or 'sasl'
         Preconditions.CheckNotNull(authType, "Zookeeper authType cannot be null !!");
         Preconditions.CheckArgument(authType.Equals("sasl") || authType.Equals("none"), "Zookeeper authType must be one of [none, sasl]"
                                     );
         CuratorFrameworkFactory.Builder builder = null;
         try
         {
             ACLProvider aclProvider = null;
             if (authType.Equals("sasl"))
             {
                 Log.Info("Connecting to ZooKeeper with SASL/Kerberos" + "and using 'sasl' ACLs");
                 string principal = SetJaasConfiguration(conf);
                 Runtime.SetProperty(ZooKeeperSaslClient.LoginContextNameKey, JaasLoginEntryName);
                 Runtime.SetProperty("zookeeper.authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"
                                     );
                 aclProvider = new ZKDelegationTokenSecretManager.SASLOwnerACLProvider(principal);
             }
             else
             {
                 // "none"
                 Log.Info("Connecting to ZooKeeper without authentication");
                 aclProvider = new DefaultACLProvider();
             }
             // open to everyone
             int sessionT   = conf.GetInt(ZkDtsmZkSessionTimeout, ZkDtsmZkSessionTimeoutDefault);
             int numRetries = conf.GetInt(ZkDtsmZkNumRetries, ZkDtsmZkNumRetriesDefault);
             builder = CuratorFrameworkFactory.Builder().AclProvider(aclProvider).Namespace(conf
                                                                                            .Get(ZkDtsmZnodeWorkingPath, ZkDtsmZnodeWorkingPathDeafult) + "/" + ZkDtsmNamespace
                                                                                            ).SessionTimeoutMs(sessionT).ConnectionTimeoutMs(conf.GetInt(ZkDtsmZkConnectionTimeout
                                                                                                                                                         , ZkDtsmZkConnectionTimeoutDefault)).RetryPolicy(new RetryNTimes(numRetries, sessionT
                                                                                                                                                                                                                          / numRetries));
         }
         catch (Exception)
         {
             throw new RuntimeException("Could not Load ZK acls or auth");
         }
         zkClient = builder.EnsembleProvider(new FixedEnsembleProvider(connString)).Build(
             );
         isExternalClient = false;
     }
 }