Beispiel #1
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public override Org.Apache.Hadoop.Yarn.Api.Records.Token GetRMDelegationToken(Text
                                                                                      renewer)
        {
            /* get the token from RM */
            GetDelegationTokenRequest rmDTRequest = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord
                                                    <GetDelegationTokenRequest>();

            rmDTRequest.SetRenewer(renewer.ToString());
            GetDelegationTokenResponse response = rmClient.GetDelegationToken(rmDTRequest);

            return(response.GetRMDelegationToken());
        }
        /// <exception cref="Com.Google.Protobuf.ServiceException"/>
        public virtual SecurityProtos.GetDelegationTokenResponseProto GetDelegationToken(
            RpcController controller, SecurityProtos.GetDelegationTokenRequestProto proto)
        {
            GetDelegationTokenRequestPBImpl request = new GetDelegationTokenRequestPBImpl(proto
                                                                                          );

            try
            {
                GetDelegationTokenResponse response = real.GetDelegationToken(request);
                return(((GetDelegationTokenResponsePBImpl)response).GetProto());
            }
            catch (YarnException e)
            {
                throw new ServiceException(e);
            }
            catch (IOException e)
            {
                throw new ServiceException(e);
            }
        }
        public virtual void TestClusterGetDelegationToken()
        {
            Configuration conf    = new Configuration(false);
            Cluster       cluster = null;

            try
            {
                conf = new Configuration();
                conf.Set(MRConfig.FrameworkName, MRConfig.YarnFrameworkName);
                cluster = new Cluster(conf);
                YARNRunner yrunner = (YARNRunner)cluster.GetClient();
                GetDelegationTokenResponse getDTResponse = recordFactory.NewRecordInstance <GetDelegationTokenResponse
                                                                                            >();
                Token rmDTToken = recordFactory.NewRecordInstance <Token>();
                rmDTToken.SetIdentifier(ByteBuffer.Wrap(new byte[2]));
                rmDTToken.SetKind("Testclusterkind");
                rmDTToken.SetPassword(ByteBuffer.Wrap(Sharpen.Runtime.GetBytesForString("testcluster"
                                                                                        )));
                rmDTToken.SetService("0.0.0.0:8032");
                getDTResponse.SetRMDelegationToken(rmDTToken);
                ApplicationClientProtocol cRMProtocol = Org.Mockito.Mockito.Mock <ApplicationClientProtocol
                                                                                  >();
                Org.Mockito.Mockito.When(cRMProtocol.GetDelegationToken(Matchers.Any <GetDelegationTokenRequest
                                                                                      >())).ThenReturn(getDTResponse);
                ResourceMgrDelegate rmgrDelegate = new _ResourceMgrDelegate_112(cRMProtocol, new
                                                                                YarnConfiguration(conf));
                yrunner.SetResourceMgrDelegate(rmgrDelegate);
                Org.Apache.Hadoop.Security.Token.Token t = cluster.GetDelegationToken(new Text(" "
                                                                                               ));
                NUnit.Framework.Assert.IsTrue("Token kind is instead " + t.GetKind().ToString(),
                                              "Testclusterkind".Equals(t.GetKind().ToString()));
            }
            finally
            {
                if (cluster != null)
                {
                    cluster.Close();
                }
            }
        }