コード例 #1
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);
        }
コード例 #2
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;
     }
 }