예제 #1
0
        /// <exception cref="System.Exception"/>
        public virtual NodeHeartbeatResponse NodeHeartbeat(IDictionary <ApplicationId, IList
                                                                        <Org.Apache.Hadoop.Yarn.Api.Records.ContainerStatus> > conts, bool isHealthy, int
                                                           resId)
        {
            NodeHeartbeatRequest req = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <NodeHeartbeatRequest
                                                                                      >();
            NodeStatus status = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <NodeStatus>();

            status.SetResponseId(resId);
            status.SetNodeId(nodeId);
            foreach (KeyValuePair <ApplicationId, IList <Org.Apache.Hadoop.Yarn.Api.Records.ContainerStatus
                                                         > > entry in conts)
            {
                Org.Mortbay.Log.Log.Info("entry.getValue() " + entry.Value);
                status.SetContainersStatuses(entry.Value);
            }
            NodeHealthStatus healthStatus = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <NodeHealthStatus
                                                                                           >();

            healthStatus.SetHealthReport(string.Empty);
            healthStatus.SetIsNodeHealthy(isHealthy);
            healthStatus.SetLastHealthReportTime(1);
            status.SetNodeHealthStatus(healthStatus);
            req.SetNodeStatus(status);
            req.SetLastKnownContainerTokenMasterKey(this.currentContainerTokenMasterKey);
            req.SetLastKnownNMTokenMasterKey(this.currentNMTokenMasterKey);
            NodeHeartbeatResponse heartbeatResponse = resourceTracker.NodeHeartbeat(req);
            MasterKey             masterKeyFromRM   = heartbeatResponse.GetContainerTokenMasterKey();

            if (masterKeyFromRM != null && masterKeyFromRM.GetKeyId() != this.currentContainerTokenMasterKey
                .GetKeyId())
            {
                this.currentContainerTokenMasterKey = masterKeyFromRM;
            }
            masterKeyFromRM = heartbeatResponse.GetNMTokenMasterKey();
            if (masterKeyFromRM != null && masterKeyFromRM.GetKeyId() != this.currentNMTokenMasterKey
                .GetKeyId())
            {
                this.currentNMTokenMasterKey = masterKeyFromRM;
            }
            return(heartbeatResponse);
        }
예제 #2
0
        private void PopulateKeys(NodeHeartbeatRequest request, NodeHeartbeatResponse nodeHeartBeatResponse
                                  )
        {
            // Check if node's masterKey needs to be updated and if the currentKey has
            // roller over, send it across
            // ContainerTokenMasterKey
            MasterKey nextMasterKeyForNode = this.containerTokenSecretManager.GetNextKey();

            if (nextMasterKeyForNode != null && (request.GetLastKnownContainerTokenMasterKey(
                                                     ).GetKeyId() != nextMasterKeyForNode.GetKeyId()))
            {
                nodeHeartBeatResponse.SetContainerTokenMasterKey(nextMasterKeyForNode);
            }
            // NMTokenMasterKey
            nextMasterKeyForNode = this.nmTokenSecretManager.GetNextKey();
            if (nextMasterKeyForNode != null && (request.GetLastKnownNMTokenMasterKey().GetKeyId
                                                     () != nextMasterKeyForNode.GetKeyId()))
            {
                nodeHeartBeatResponse.SetNMTokenMasterKey(nextMasterKeyForNode);
            }
        }
예제 #3
0
 public virtual void SetMasterKey(MasterKey masterKeyRecord)
 {
     lock (this)
     {
         // Update keys only if the key has changed.
         if (base.currentMasterKey == null || base.currentMasterKey.GetMasterKey().GetKeyId
                 () != masterKeyRecord.GetKeyId())
         {
             Log.Info("Rolling master-key for container-tokens, got key with id " + masterKeyRecord
                      .GetKeyId());
             if (base.currentMasterKey != null)
             {
                 UpdatePreviousMasterKey(base.currentMasterKey);
             }
             UpdateCurrentMasterKey(new MasterKeyData(masterKeyRecord, CreateSecretKey(((byte[]
                                                                                         )masterKeyRecord.GetBytes().Array()))));
         }
     }
 }
예제 #4
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (!(obj is MasterKey))
            {
                return(false);
            }
            MasterKey other = (MasterKey)obj;

            if (this.GetKeyId() != other.GetKeyId())
            {
                return(false);
            }
            if (!this.GetBytes().Equals(other.GetBytes()))
            {
                return(false);
            }
            return(true);
        }
예제 #5
0
        /// <exception cref="System.Exception"/>
        private void ValidateRMNMKeyExchange(YarnConfiguration conf)
        {
            // Default rolling and activation intervals are large enough, no need to
            // intervene
            DrainDispatcher dispatcher = new DrainDispatcher();
            ResourceManager rm         = new _ResourceManager_56(dispatcher);

            // Do nothing.
            // Don't need it, skip.
            rm.Init(conf);
            rm.Start();
            // Testing ContainerToken and NMToken
            string containerToken = "Container Token : ";
            string nmToken        = "NM Token : ";
            MockNM nm             = new MockNM("host:1234", 3072, rm.GetResourceTrackerService());
            RegisterNodeManagerResponse registrationResponse = nm.RegisterNode();
            MasterKey containerTokenMasterKey = registrationResponse.GetContainerTokenMasterKey
                                                    ();

            NUnit.Framework.Assert.IsNotNull(containerToken + "Registration should cause a key-update!"
                                             , containerTokenMasterKey);
            MasterKey nmTokenMasterKey = registrationResponse.GetNMTokenMasterKey();

            NUnit.Framework.Assert.IsNotNull(nmToken + "Registration should cause a key-update!"
                                             , nmTokenMasterKey);
            dispatcher.Await();
            NodeHeartbeatResponse response = nm.NodeHeartbeat(true);

            NUnit.Framework.Assert.IsNull(containerToken + "First heartbeat after registration shouldn't get any key updates!"
                                          , response.GetContainerTokenMasterKey());
            NUnit.Framework.Assert.IsNull(nmToken + "First heartbeat after registration shouldn't get any key updates!"
                                          , response.GetNMTokenMasterKey());
            dispatcher.Await();
            response = nm.NodeHeartbeat(true);
            NUnit.Framework.Assert.IsNull(containerToken + "Even second heartbeat after registration shouldn't get any key updates!"
                                          , response.GetContainerTokenMasterKey());
            NUnit.Framework.Assert.IsNull(nmToken + "Even second heartbeat after registration shouldn't get any key updates!"
                                          , response.GetContainerTokenMasterKey());
            dispatcher.Await();
            // Let's force a roll-over
            rm.GetRMContext().GetContainerTokenSecretManager().RollMasterKey();
            rm.GetRMContext().GetNMTokenSecretManager().RollMasterKey();
            // Heartbeats after roll-over and before activation should be fine.
            response = nm.NodeHeartbeat(true);
            NUnit.Framework.Assert.IsNotNull(containerToken + "Heartbeats after roll-over and before activation should not err out."
                                             , response.GetContainerTokenMasterKey());
            NUnit.Framework.Assert.IsNotNull(nmToken + "Heartbeats after roll-over and before activation should not err out."
                                             , response.GetNMTokenMasterKey());
            NUnit.Framework.Assert.AreEqual(containerToken + "Roll-over should have incremented the key-id only by one!"
                                            , containerTokenMasterKey.GetKeyId() + 1, response.GetContainerTokenMasterKey().
                                            GetKeyId());
            NUnit.Framework.Assert.AreEqual(nmToken + "Roll-over should have incremented the key-id only by one!"
                                            , nmTokenMasterKey.GetKeyId() + 1, response.GetNMTokenMasterKey().GetKeyId());
            dispatcher.Await();
            response = nm.NodeHeartbeat(true);
            NUnit.Framework.Assert.IsNull(containerToken + "Second heartbeat after roll-over shouldn't get any key updates!"
                                          , response.GetContainerTokenMasterKey());
            NUnit.Framework.Assert.IsNull(nmToken + "Second heartbeat after roll-over shouldn't get any key updates!"
                                          , response.GetNMTokenMasterKey());
            dispatcher.Await();
            // Let's force activation
            rm.GetRMContext().GetContainerTokenSecretManager().ActivateNextMasterKey();
            rm.GetRMContext().GetNMTokenSecretManager().ActivateNextMasterKey();
            response = nm.NodeHeartbeat(true);
            NUnit.Framework.Assert.IsNull(containerToken + "Activation shouldn't cause any key updates!"
                                          , response.GetContainerTokenMasterKey());
            NUnit.Framework.Assert.IsNull(nmToken + "Activation shouldn't cause any key updates!"
                                          , response.GetNMTokenMasterKey());
            dispatcher.Await();
            response = nm.NodeHeartbeat(true);
            NUnit.Framework.Assert.IsNull(containerToken + "Even second heartbeat after activation shouldn't get any key updates!"
                                          , response.GetContainerTokenMasterKey());
            NUnit.Framework.Assert.IsNull(nmToken + "Even second heartbeat after activation shouldn't get any key updates!"
                                          , response.GetNMTokenMasterKey());
            dispatcher.Await();
            rm.Stop();
        }