/// <exception cref="System.IO.IOException"/> private ApplicationStateData CreateApplicationState(string appIdStr, byte[] data) { ApplicationId appId = ConverterUtils.ToApplicationId(appIdStr); ApplicationStateDataPBImpl appState = new ApplicationStateDataPBImpl(YarnServerResourceManagerRecoveryProtos.ApplicationStateDataProto .ParseFrom(data)); if (!appId.Equals(appState.GetApplicationSubmissionContext().GetApplicationId())) { throw new YarnRuntimeException("The database entry for " + appId + " contains data for " + appState.GetApplicationSubmissionContext().GetApplicationId()); } return(appState); }
/// <exception cref="System.Exception"/> private void LoadRMAppState(RMStateStore.RMState rmState) { try { IList <ApplicationAttemptStateData> attempts = new AList <ApplicationAttemptStateData >(); foreach (FileStatus appDir in ListStatusWithRetries(rmAppRoot)) { CheckAndResumeUpdateOperation(appDir.GetPath()); foreach (FileStatus childNodeStatus in ListStatusWithRetries(appDir.GetPath())) { System.Diagnostics.Debug.Assert(childNodeStatus.IsFile()); string childNodeName = childNodeStatus.GetPath().GetName(); if (CheckAndRemovePartialRecordWithRetries(childNodeStatus.GetPath())) { continue; } byte[] childData = ReadFileWithRetries(childNodeStatus.GetPath(), childNodeStatus .GetLen()); // Set attribute if not already set SetUnreadableBySuperuserXattrib(childNodeStatus.GetPath()); if (childNodeName.StartsWith(ApplicationId.appIdStrPrefix)) { // application if (Log.IsDebugEnabled()) { Log.Debug("Loading application from node: " + childNodeName); } ApplicationStateDataPBImpl appState = new ApplicationStateDataPBImpl(YarnServerResourceManagerRecoveryProtos.ApplicationStateDataProto .ParseFrom(childData)); ApplicationId appId = appState.GetApplicationSubmissionContext().GetApplicationId (); rmState.appState[appId] = appState; } else { if (childNodeName.StartsWith(ApplicationAttemptId.appAttemptIdStrPrefix)) { // attempt if (Log.IsDebugEnabled()) { Log.Debug("Loading application attempt from node: " + childNodeName); } ApplicationAttemptStateDataPBImpl attemptState = new ApplicationAttemptStateDataPBImpl (YarnServerResourceManagerRecoveryProtos.ApplicationAttemptStateDataProto.ParseFrom (childData)); attempts.AddItem(attemptState); } else { Log.Info("Unknown child node with name: " + childNodeName); } } } } // go through all attempts and add them to their apps, Ideally, each // attempt node must have a corresponding app node, because remove // directory operation remove both at the same time foreach (ApplicationAttemptStateData attemptState_1 in attempts) { ApplicationId appId = attemptState_1.GetAttemptId().GetApplicationId(); ApplicationStateData appState = rmState.appState[appId]; System.Diagnostics.Debug.Assert(appState != null); appState.attempts[attemptState_1.GetAttemptId()] = attemptState_1; } Log.Info("Done loading applications from FS state store"); } catch (Exception e) { Log.Error("Failed to load state.", e); throw; } }