/// <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"); } } } } }
/// <exception cref="System.IO.IOException"/> private void LoadTokenMasterKey(HistoryServerStateStoreService.HistoryServerState state, byte[] data) { DelegationKey key = new DelegationKey(); DataInputStream @in = new DataInputStream(new ByteArrayInputStream(data)); try { key.ReadFields(@in); } finally { IOUtils.Cleanup(Log, @in); } state.tokenMasterKeyState.AddItem(key); }
/// <exception cref="System.IO.IOException"/> private DelegationKey LoadDelegationKey(byte[] data) { DelegationKey key = new DelegationKey(); DataInputStream @in = new DataInputStream(new ByteArrayInputStream(data)); try { key.ReadFields(@in); } finally { IOUtils.Cleanup(Log, @in); } return(key); }
/// <summary>Process the Delegation Token related section in fsimage.</summary> /// <param name="in">DataInputStream to process</param> /// <param name="v">Visitor to walk over records</param> /// <exception cref="System.IO.IOException"/> private void ProcessDelegationTokens(DataInputStream @in, ImageVisitor v) { v.Visit(ImageVisitor.ImageElement.CurrentDelegationKeyId, @in.ReadInt()); int numDKeys = @in.ReadInt(); v.VisitEnclosingElement(ImageVisitor.ImageElement.DelegationKeys, ImageVisitor.ImageElement .NumDelegationKeys, numDKeys); for (int i = 0; i < numDKeys; i++) { DelegationKey key = new DelegationKey(); key.ReadFields(@in); v.Visit(ImageVisitor.ImageElement.DelegationKey, key.ToString()); } v.LeaveEnclosingElement(); v.Visit(ImageVisitor.ImageElement.DelegationTokenSequenceNumber, @in.ReadInt()); int numDTokens = @in.ReadInt(); v.VisitEnclosingElement(ImageVisitor.ImageElement.DelegationTokens, ImageVisitor.ImageElement .NumDelegationTokens, numDTokens); for (int i_1 = 0; i_1 < numDTokens; i_1++) { DelegationTokenIdentifier id = new DelegationTokenIdentifier(); id.ReadFields(@in); long expiryTime = @in.ReadLong(); v.VisitEnclosingElement(ImageVisitor.ImageElement.DelegationTokenIdentifier); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierKind, id.GetKind().ToString ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierSeqno, id.GetSequenceNumber ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierOwner, id.GetOwner().ToString ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierRenewer, id.GetRenewer ().ToString()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierRealuser, id.GetRealUser ().ToString()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierIssueDate, id.GetIssueDate ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierMaxDate, id.GetMaxDate ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierExpiryTime, expiryTime ); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierMasterKeyId, id.GetMasterKeyId ()); v.LeaveEnclosingElement(); } // DELEGATION_TOKEN_IDENTIFIER v.LeaveEnclosingElement(); }
/// <summary>Private helper method to load delegation keys from fsimage.</summary> /// <exception cref="System.IO.IOException">on error</exception> private void LoadAllKeys(DataInput @in) { lock (this) { StartupProgress prog = NameNode.GetStartupProgress(); Step step = new Step(StepType.DelegationKeys); prog.BeginStep(Phase.LoadingFsimage, step); int numberOfKeys = @in.ReadInt(); prog.SetTotal(Phase.LoadingFsimage, step, numberOfKeys); StartupProgress.Counter counter = prog.GetCounter(Phase.LoadingFsimage, step); for (int i = 0; i < numberOfKeys; i++) { DelegationKey value = new DelegationKey(); value.ReadFields(@in); this._enclosing.AddKey(value); counter.Increment(); } prog.EndStep(Phase.LoadingFsimage, step); } }