コード例 #1
0
 public virtual void TestMultiNodeOperations()
 {
     for (int i = 0; i < TestRetries; i++)
     {
         DelegationTokenManager tm1;
         DelegationTokenManager tm2  = null;
         string        connectString = zkServer.GetConnectString();
         Configuration conf          = GetSecretConf(connectString);
         tm1 = new DelegationTokenManager(conf, new Text("bla"));
         tm1.Init();
         tm2 = new DelegationTokenManager(conf, new Text("bla"));
         tm2.Init();
         Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = (Org.Apache.Hadoop.Security.Token.Token
                                                                                     <DelegationTokenIdentifier>)tm1.CreateToken(UserGroupInformation.GetCurrentUser(
                                                                                                                                     ), "foo");
         NUnit.Framework.Assert.IsNotNull(token);
         tm2.VerifyToken(token);
         tm2.RenewToken(token, "foo");
         tm1.VerifyToken(token);
         tm1.CancelToken(token, "foo");
         try
         {
             VerifyTokenFail(tm2, token);
             NUnit.Framework.Assert.Fail("Expected InvalidToken");
         }
         catch (SecretManager.InvalidToken)
         {
         }
         // Ignore
         token = (Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier>)tm2.CreateToken
                     (UserGroupInformation.GetCurrentUser(), "bar");
         NUnit.Framework.Assert.IsNotNull(token);
         tm1.VerifyToken(token);
         tm1.RenewToken(token, "bar");
         tm2.VerifyToken(token);
         tm2.CancelToken(token, "bar");
         try
         {
             VerifyTokenFail(tm1, token);
             NUnit.Framework.Assert.Fail("Expected InvalidToken");
         }
         catch (SecretManager.InvalidToken)
         {
         }
         // Ignore
         VerifyDestroy(tm1, conf);
         VerifyDestroy(tm2, conf);
     }
 }
コード例 #2
0
        public virtual void TestStopThreads()
        {
            DelegationTokenManager tm1 = null;
            string connectString       = zkServer.GetConnectString();
            // let's make the update interval short and the shutdown interval
            // comparatively longer, so if the update thread runs after shutdown,
            // it will cause an error.
            long          updateIntervalSeconds = 1;
            long          shutdownTimeoutMillis = updateIntervalSeconds * 1000 * 5;
            Configuration conf = GetSecretConf(connectString);

            conf.SetLong(DelegationTokenManager.UpdateInterval, updateIntervalSeconds);
            conf.SetLong(DelegationTokenManager.RemovalScanInterval, updateIntervalSeconds);
            conf.SetLong(DelegationTokenManager.RenewInterval, updateIntervalSeconds);
            conf.SetLong(ZKDelegationTokenSecretManager.ZkDtsmZkShutdownTimeout, shutdownTimeoutMillis
                         );
            tm1 = new DelegationTokenManager(conf, new Text("foo"));
            tm1.Init();
            Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = (Org.Apache.Hadoop.Security.Token.Token
                                                                                        <DelegationTokenIdentifier>)tm1.CreateToken(UserGroupInformation.GetCurrentUser(
                                                                                                                                        ), "foo");
            NUnit.Framework.Assert.IsNotNull(token);
            AbstractDelegationTokenSecretManager sm   = tm1.GetDelegationTokenSecretManager();
            ZKDelegationTokenSecretManager       zksm = (ZKDelegationTokenSecretManager)sm;
            ExecutorService es = zksm.GetListenerThreadPool();

            es.Submit(new _Callable_300(shutdownTimeoutMillis));
            // force this to be shutdownNow
            tm1.Destroy();
        }
コード例 #3
0
 public virtual void TestRenewTokenSingleManager()
 {
     for (int i = 0; i < TestRetries; i++)
     {
         DelegationTokenManager tm1  = null;
         string        connectString = zkServer.GetConnectString();
         Configuration conf          = GetSecretConf(connectString);
         tm1 = new DelegationTokenManager(conf, new Text("foo"));
         tm1.Init();
         Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = (Org.Apache.Hadoop.Security.Token.Token
                                                                                     <DelegationTokenIdentifier>)tm1.CreateToken(UserGroupInformation.GetCurrentUser(
                                                                                                                                     ), "foo");
         NUnit.Framework.Assert.IsNotNull(token);
         tm1.RenewToken(token, "foo");
         tm1.VerifyToken(token);
         VerifyDestroy(tm1, conf);
     }
 }
コード例 #4
0
 public virtual void TestCancelTokenSingleManager()
 {
     for (int i = 0; i < TestRetries; i++)
     {
         DelegationTokenManager tm1  = null;
         string        connectString = zkServer.GetConnectString();
         Configuration conf          = GetSecretConf(connectString);
         tm1 = new DelegationTokenManager(conf, new Text("foo"));
         tm1.Init();
         Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token = (Org.Apache.Hadoop.Security.Token.Token
                                                                                     <DelegationTokenIdentifier>)tm1.CreateToken(UserGroupInformation.GetCurrentUser(
                                                                                                                                     ), "foo");
         NUnit.Framework.Assert.IsNotNull(token);
         tm1.CancelToken(token, "foo");
         try
         {
             VerifyTokenFail(tm1, token);
             NUnit.Framework.Assert.Fail("Expected InvalidToken");
         }
         catch (SecretManager.InvalidToken it)
         {
             Runtime.PrintStackTrace(it);
         }
         VerifyDestroy(tm1, conf);
     }
 }
コード例 #5
0
 public virtual void TestNodeUpAferAWhile()
 {
     for (int i = 0; i < TestRetries; i++)
     {
         string                 connectString = zkServer.GetConnectString();
         Configuration          conf          = GetSecretConf(connectString);
         DelegationTokenManager tm1           = new DelegationTokenManager(conf, new Text("bla"));
         tm1.Init();
         Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token1 = (Org.Apache.Hadoop.Security.Token.Token
                                                                                      <DelegationTokenIdentifier>)tm1.CreateToken(UserGroupInformation.GetCurrentUser(
                                                                                                                                      ), "foo");
         NUnit.Framework.Assert.IsNotNull(token1);
         Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token2 = (Org.Apache.Hadoop.Security.Token.Token
                                                                                      <DelegationTokenIdentifier>)tm1.CreateToken(UserGroupInformation.GetCurrentUser(
                                                                                                                                      ), "bar");
         NUnit.Framework.Assert.IsNotNull(token2);
         Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token3 = (Org.Apache.Hadoop.Security.Token.Token
                                                                                      <DelegationTokenIdentifier>)tm1.CreateToken(UserGroupInformation.GetCurrentUser(
                                                                                                                                      ), "boo");
         NUnit.Framework.Assert.IsNotNull(token3);
         tm1.VerifyToken(token1);
         tm1.VerifyToken(token2);
         tm1.VerifyToken(token3);
         // Cancel one token
         tm1.CancelToken(token1, "foo");
         // Start second node after some time..
         Thread.Sleep(1000);
         DelegationTokenManager tm2 = new DelegationTokenManager(conf, new Text("bla"));
         tm2.Init();
         tm2.VerifyToken(token2);
         tm2.VerifyToken(token3);
         try
         {
             VerifyTokenFail(tm2, token1);
             NUnit.Framework.Assert.Fail("Expected InvalidToken");
         }
         catch (SecretManager.InvalidToken)
         {
         }
         // Ignore
         // Create a new token thru the new ZKDTSM
         Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token4 = (Org.Apache.Hadoop.Security.Token.Token
                                                                                      <DelegationTokenIdentifier>)tm2.CreateToken(UserGroupInformation.GetCurrentUser(
                                                                                                                                      ), "xyz");
         NUnit.Framework.Assert.IsNotNull(token4);
         tm2.VerifyToken(token4);
         tm1.VerifyToken(token4);
         // Bring down tm2
         VerifyDestroy(tm2, conf);
         // Start third node after some time..
         Thread.Sleep(1000);
         DelegationTokenManager tm3 = new DelegationTokenManager(conf, new Text("bla"));
         tm3.Init();
         tm3.VerifyToken(token2);
         tm3.VerifyToken(token3);
         tm3.VerifyToken(token4);
         try
         {
             VerifyTokenFail(tm3, token1);
             NUnit.Framework.Assert.Fail("Expected InvalidToken");
         }
         catch (SecretManager.InvalidToken)
         {
         }
         // Ignore
         VerifyDestroy(tm3, conf);
         VerifyDestroy(tm1, conf);
     }
 }