Exemplo n.º 1
0
 /// <exception cref="System.Exception"/>
 private void LoadRMDTSecretManagerState(RMStateStore.RMState rmState)
 {
     CheckAndResumeUpdateOperation(rmDTSecretManagerRoot);
     FileStatus[] childNodes = ListStatusWithRetries(rmDTSecretManagerRoot);
     foreach (FileStatus childNodeStatus in childNodes)
     {
         System.Diagnostics.Debug.Assert(childNodeStatus.IsFile());
         string childNodeName = childNodeStatus.GetPath().GetName();
         if (CheckAndRemovePartialRecordWithRetries(childNodeStatus.GetPath()))
         {
             continue;
         }
         if (childNodeName.StartsWith(DelegationTokenSequenceNumberPrefix))
         {
             rmState.rmSecretManagerState.dtSequenceNumber = System.Convert.ToInt32(childNodeName
                                                                                    .Split("_")[1]);
             continue;
         }
         Path   childNodePath     = GetNodePath(rmDTSecretManagerRoot, childNodeName);
         byte[] childData         = ReadFileWithRetries(childNodePath, childNodeStatus.GetLen());
         ByteArrayInputStream @is = new ByteArrayInputStream(childData);
         using (DataInputStream fsIn = new DataInputStream(@is))
         {
             if (childNodeName.StartsWith(DelegationKeyPrefix))
             {
                 DelegationKey key = new DelegationKey();
                 key.ReadFields(fsIn);
                 rmState.rmSecretManagerState.masterKeyState.AddItem(key);
                 if (Log.IsDebugEnabled())
                 {
                     Log.Debug("Loaded delegation key: keyId=" + key.GetKeyId() + ", expirationDate="
                               + key.GetExpiryDate());
                 }
             }
             else
             {
                 if (childNodeName.StartsWith(DelegationTokenPrefix))
                 {
                     RMDelegationTokenIdentifierData identifierData = new RMDelegationTokenIdentifierData
                                                                          ();
                     identifierData.ReadFields(fsIn);
                     RMDelegationTokenIdentifier identifier = identifierData.GetTokenIdentifier();
                     long renewDate = identifierData.GetRenewDate();
                     rmState.rmSecretManagerState.delegationTokenState[identifier] = renewDate;
                     if (Log.IsDebugEnabled())
                     {
                         Log.Debug("Loaded RMDelegationTokenIdentifier: " + identifier + " renewDate=" + renewDate
                                   );
                     }
                 }
                 else
                 {
                     Log.Warn("Unknown file for recovering RMDelegationTokenSecretManager");
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        private int LoadRMDTSecretManagerTokens(RMStateStore.RMState state)
        {
            int             numTokens = 0;
            LeveldbIterator iter      = null;

            try
            {
                iter = new LeveldbIterator(db);
                iter.Seek(JniDBFactory.Bytes(RmDtTokenKeyPrefix));
                while (iter.HasNext())
                {
                    KeyValuePair <byte[], byte[]> entry = iter.Next();
                    string key = JniDBFactory.AsString(entry.Key);
                    if (!key.StartsWith(RmDtTokenKeyPrefix))
                    {
                        break;
                    }
                    RMDelegationTokenIdentifierData tokenData = LoadDelegationToken(entry.Value);
                    RMDelegationTokenIdentifier     tokenId   = tokenData.GetTokenIdentifier();
                    long renewDate = tokenData.GetRenewDate();
                    state.rmSecretManagerState.delegationTokenState[tokenId] = renewDate;
                    ++numTokens;
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Loaded RM delegation token from " + key + ": tokenId=" + tokenId + ", renewDate="
                                  + renewDate);
                    }
                }
            }
            catch (DBException e)
            {
                throw new IOException(e);
            }
            finally
            {
                if (iter != null)
                {
                    iter.Close();
                }
            }
            return(numTokens);
        }