Ejemplo n.º 1
0
        /// <summary>This tests whether a containerId is serialized/deserialized with epoch.</summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private void TestContainerTokenWithEpoch(Configuration conf)
        {
            Log.Info("Running test for serializing/deserializing containerIds");
            NMTokenSecretManagerInRM nmTokenSecretManagerInRM = yarnCluster.GetResourceManager
                                                                    ().GetRMContext().GetNMTokenSecretManager();
            ApplicationId            appId                    = ApplicationId.NewInstance(1, 1);
            ApplicationAttemptId     appAttemptId             = ApplicationAttemptId.NewInstance(appId, 0);
            ContainerId              cId                      = ContainerId.NewContainerId(appAttemptId, (5L << 40) | 3L);
            NodeManager              nm                       = yarnCluster.GetNodeManager(0);
            NMTokenSecretManagerInNM nmTokenSecretManagerInNM = nm.GetNMContext().GetNMTokenSecretManager
                                                                    ();
            string user = "******";

            WaitForNMToReceiveNMTokenKey(nmTokenSecretManagerInNM, nm);
            NodeId nodeId = nm.GetNMContext().GetNodeId();

            // Both id should be equal.
            NUnit.Framework.Assert.AreEqual(nmTokenSecretManagerInNM.GetCurrentKey().GetKeyId
                                                (), nmTokenSecretManagerInRM.GetCurrentKey().GetKeyId());
            // Creating a normal Container Token
            RMContainerTokenSecretManager containerTokenSecretManager = yarnCluster.GetResourceManager
                                                                            ().GetRMContext().GetContainerTokenSecretManager();
            Resource r = Resource.NewInstance(1230, 2);

            Org.Apache.Hadoop.Yarn.Api.Records.Token containerToken = containerTokenSecretManager
                                                                      .CreateContainerToken(cId, nodeId, user, r, Priority.NewInstance(0), 0);
            ContainerTokenIdentifier containerTokenIdentifier = new ContainerTokenIdentifier(
                );

            byte[]          tokenIdentifierContent = ((byte[])containerToken.GetIdentifier().Array());
            DataInputBuffer dib = new DataInputBuffer();

            dib.Reset(tokenIdentifierContent, tokenIdentifierContent.Length);
            containerTokenIdentifier.ReadFields(dib);
            NUnit.Framework.Assert.AreEqual(cId, containerTokenIdentifier.GetContainerID());
            NUnit.Framework.Assert.AreEqual(cId.ToString(), containerTokenIdentifier.GetContainerID
                                                ().ToString());
            Org.Apache.Hadoop.Yarn.Api.Records.Token nmToken = nmTokenSecretManagerInRM.CreateNMToken
                                                                   (appAttemptId, nodeId, user);
            YarnRPC rpc = YarnRPC.Create(conf);

            TestStartContainer(rpc, appAttemptId, nodeId, containerToken, nmToken, false);
            IList <ContainerId> containerIds = new List <ContainerId>();

            containerIds.AddItem(cId);
            ContainerManagementProtocol proxy = GetContainerManagementProtocolProxy(rpc, nmToken
                                                                                    , nodeId, user);
            GetContainerStatusesResponse res = proxy.GetContainerStatuses(GetContainerStatusesRequest
                                                                          .NewInstance(containerIds));

            NUnit.Framework.Assert.IsNotNull(res.GetContainerStatuses()[0]);
            NUnit.Framework.Assert.AreEqual(cId, res.GetContainerStatuses()[0].GetContainerId
                                                ());
            NUnit.Framework.Assert.AreEqual(cId.ToString(), res.GetContainerStatuses()[0].GetContainerId
                                                ().ToString());
        }
Ejemplo n.º 2
0
 /// <summary>Convert a protobuf token into a rpc token and set its service.</summary>
 /// <param name="protoToken">the yarn token</param>
 /// <param name="service">the service for the token</param>
 public static Org.Apache.Hadoop.Security.Token.Token <T> ConvertFromYarn <T>(Org.Apache.Hadoop.Yarn.Api.Records.Token
                                                                              protoToken, Text service)
     where T : TokenIdentifier
 {
     Org.Apache.Hadoop.Security.Token.Token <T> token = new Org.Apache.Hadoop.Security.Token.Token
                                                        <T>(((byte[])protoToken.GetIdentifier().Array()), ((byte[])protoToken.GetPassword
                                                                                                               ().Array()), new Text(protoToken.GetKind()), new Text(protoToken.GetService()));
     if (service != null)
     {
         token.SetService(service);
     }
     return(token);
 }
Ejemplo n.º 3
0
        /// <exception cref="System.IO.IOException"/>
        private ContainerTokenIdentifier GetContainerTokenIdentifierFromToken(Org.Apache.Hadoop.Yarn.Api.Records.Token
                                                                              containerToken)
        {
            ContainerTokenIdentifier containerTokenIdentifier;

            containerTokenIdentifier = new ContainerTokenIdentifier();
            byte[]          tokenIdentifierContent = ((byte[])containerToken.GetIdentifier().Array());
            DataInputBuffer dib = new DataInputBuffer();

            dib.Reset(tokenIdentifierContent, tokenIdentifierContent.Length);
            containerTokenIdentifier.ReadFields(dib);
            return(containerTokenIdentifier);
        }
Ejemplo n.º 4
0
 /// <exception cref="System.IO.IOException"/>
 public static ContainerTokenIdentifier NewContainerTokenIdentifier(Org.Apache.Hadoop.Yarn.Api.Records.Token
                                                                    containerToken)
 {
     Org.Apache.Hadoop.Security.Token.Token <ContainerTokenIdentifier> token = new Org.Apache.Hadoop.Security.Token.Token
                                                                               <ContainerTokenIdentifier>(((byte[])containerToken.GetIdentifier().Array()), ((byte
                                                                                                                                                              [])containerToken.GetPassword().Array()), new Text(containerToken.GetKind()), new
                                                                                                          Text(containerToken.GetService()));
     return(token.DecodeIdentifier());
 }