/// <summary>Verify that that a service is in a given state.</summary> /// <param name="expectedState">the desired state</param> /// <exception cref="ServiceStateException"> /// if the service state is different from /// the desired state /// </exception> public virtual void EnsureCurrentState(Service.STATE expectedState) { if (state != expectedState) { throw new ServiceStateException(name + ": for this operation, the " + "current service state must be " + expectedState + " instead of " + state); } }
/// <summary> /// Check that a state tansition is valid and /// throw an exception if not /// </summary> /// <param name="name">name of the service (can be null)</param> /// <param name="state">current state</param> /// <param name="proposed">proposed new state</param> public static void CheckStateTransition(string name, Service.STATE state, Service.STATE proposed) { if (!IsValidStateTransition(state, proposed)) { throw new ServiceStateException(name + " cannot enter state " + proposed + " from state " + state); } }
/// <summary>Create a service state model instance in the chosen state</summary> /// <param name="state">the starting state</param> public ServiceStateModel(string name, Service.STATE state) { // uninited inited started stopped /* uninited */ /* inited */ /* started */ /* stopped */ this.state = state; this.name = name; }
/// <summary>Enter a state -thread safe.</summary> /// <param name="proposed">proposed new state</param> /// <returns>the original state</returns> /// <exception cref="ServiceStateException">if the transition is not permitted</exception> public virtual Service.STATE EnterState(Service.STATE proposed) { lock (this) { CheckStateTransition(name, state, proposed); Service.STATE oldState = state; //atomic write of the new state state = proposed; return(oldState); } }
public ClusterInfo(ResourceManager rm) { // JAXB needs this long ts = ResourceManager.GetClusterTimeStamp(); this.id = ts; this.state = rm.GetServiceState(); this.haState = rm.GetRMContext().GetHAServiceState(); this.rmStateStoreName = rm.GetRMContext().GetStateStore().GetType().FullName; this.startedOn = ts; this.resourceManagerVersion = YarnVersionInfo.GetVersion(); this.resourceManagerBuildVersion = YarnVersionInfo.GetBuildVersion(); this.resourceManagerVersionBuiltOn = YarnVersionInfo.GetDate(); this.hadoopVersion = VersionInfo.GetVersion(); this.hadoopBuildVersion = VersionInfo.GetBuildVersion(); this.hadoopVersionBuiltOn = VersionInfo.GetDate(); this.haZooKeeperConnectionState = rm.GetRMContext().GetRMAdminService().GetHAZookeeperConnectionState (); }
/// <exception cref="System.Exception"/> public virtual void WaitForState(Service.STATE finalState) { if (finalState == Service.STATE.Stopped) { NUnit.Framework.Assert.IsTrue("Timeout while waiting for MRApp to stop", WaitForServiceToStop (20 * 1000)); } else { int timeoutSecs = 0; while (!finalState.Equals(GetServiceState()) && timeoutSecs++ < 20) { System.Console.Out.WriteLine("MRApp State is : " + GetServiceState() + " Waiting for state : " + finalState); Sharpen.Thread.Sleep(500); } System.Console.Out.WriteLine("MRApp State is : " + GetServiceState()); NUnit.Framework.Assert.AreEqual("MRApp state is not correct (timedout)", finalState , GetServiceState()); } }
/// <summary>Query that the state is in a specific state</summary> /// <param name="proposed">proposed new state</param> /// <returns>the state</returns> public virtual bool IsInState(Service.STATE proposed) { return(state.Equals(proposed)); }
/// <summary> /// Is a state transition valid? /// There are no checks for current==proposed /// as that is considered a non-transition. /// </summary> /// <remarks> /// Is a state transition valid? /// There are no checks for current==proposed /// as that is considered a non-transition. /// using an array kills off all branch misprediction costs, at the expense /// of cache line misses. /// </remarks> /// <param name="current">current state</param> /// <param name="proposed">proposed new state</param> /// <returns>true if the transition to a new state is valid</returns> public static bool IsValidStateTransition(Service.STATE current, Service.STATE proposed ) { bool[] row = statemap[current.GetValue()]; return(row[proposed.GetValue()]); }