public BrokenLifecycleEvent(Org.Apache.Hadoop.Service.Service service, string action ) : base("Lifecycle Failure during " + action + " state is " + service.GetServiceState ()) { state = service.GetServiceState(); }
public virtual void SetFailingState(Service.STATE failingState) { lock (this) { this.failingState = failingState; } }
/// <summary>Stop the services in reverse order</summary> /// <param name="numOfServicesStarted">index from where the stop should work</param> /// <param name="stopOnlyStartedServices"> /// flag to say "only start services that are /// started, not those that are NOTINITED or INITED. /// </param> /// <exception cref="RuntimeException"> /// the first exception raised during the /// stop process -<i>after all services are stopped</i> /// </exception> private void Stop(int numOfServicesStarted, bool stopOnlyStartedServices) { // stop in reverse order of start Exception firstException = null; IList <Org.Apache.Hadoop.Service.Service> services = GetServices(); for (int i = numOfServicesStarted - 1; i >= 0; i--) { Org.Apache.Hadoop.Service.Service service = services[i]; if (Log.IsDebugEnabled()) { Log.Debug("Stopping service #" + i + ": " + service); } Service.STATE state = service.GetServiceState(); //depending on the stop police if (state == Service.STATE.Started || (!stopOnlyStartedServices && state == Service.STATE .Inited)) { Exception ex = ServiceOperations.StopQuietly(Log, service); if (ex != null && firstException == null) { firstException = ex; } } } //after stopping all services, rethrow the first exception raised if (firstException != null) { throw ServiceStateException.Convert(firstException); } }
public static void AssertServiceInState(Org.Apache.Hadoop.Service.Service service , Service.STATE state) { NUnit.Framework.Assert.IsNotNull("Null service", service); Assert.Equal("Service in wrong state: " + service, state, service .GetServiceState()); }
public AddSiblingService(CompositeService parent, Org.Apache.Hadoop.Service.Service serviceToAdd, Service.STATE triggerState) : base("ParentStateManipulatorService") { this.parent = parent; this.serviceToAdd = serviceToAdd; this.triggerState = triggerState; }
public virtual void StateChanged(Org.Apache.Hadoop.Service.Service service) { lock (this) { notifyingState = service.GetServiceState(); Runtime.NotifyAll(this); } }
/// <summary>Assert that all services are in the same expected state</summary> /// <param name="expected">expected state value</param> /// <param name="services">services to examine</param> /// <param name="start">start offset</param> /// <param name="finish">finish offset: the count stops before this number</param> private void AssertInState(Service.STATE expected, TestCompositeService.CompositeServiceImpl [] services, int start, int finish) { for (int i = start; i < finish; i++) { Org.Apache.Hadoop.Service.Service service = services[i]; AssertInState(expected, service); } }
/// <summary> /// Assert that the breakable service has entered a state exactly the number /// of time asserted. /// </summary> /// <param name="service">service -if null an assertion is raised.</param> /// <param name="state">state to check.</param> /// <param name="expected">expected count.</param> public static void AssertStateCount(BreakableService service, Service.STATE state , int expected) { NUnit.Framework.Assert.IsNotNull("Null service", service); int actual = service.GetCount(state); if (expected != actual) { NUnit.Framework.Assert.Fail("Expected entry count for state [" + state + "] of " + service + " to be " + expected + " but was " + actual); } }
/// <summary> /// Enter a state; record this via /// <see cref="RecordLifecycleEvent()"/> /// and log at the info level. /// </summary> /// <param name="newState">the proposed new state</param> /// <returns> /// the original state /// it wasn't already in that state, and the state model permits state re-entrancy. /// </returns> private Service.STATE EnterState(Service.STATE newState) { System.Diagnostics.Debug.Assert(stateModel != null, "null state in " + name + " " + this.GetType()); Service.STATE oldState = stateModel.EnterState(newState); if (oldState != newState) { if (Log.IsDebugEnabled()) { Log.Debug("Service: " + GetName() + " entered state " + GetServiceState()); } RecordLifecycleEvent(); } return(oldState); }
public virtual void StateChanged(Org.Apache.Hadoop.Service.Service service) { lock (this) { eventCount++; lastService = service; lastState = service.GetServiceState(); stateEventList.AddItem(lastState); if (lastState == failingState) { failureCount++; throw new BreakableService.BrokenLifecycleEvent(service, "Failure entering " + lastState + " for " + service.GetName()); } } }
/// <summary> /// Failure handling: record the exception /// that triggered it -if there was not one already. /// </summary> /// <remarks> /// Failure handling: record the exception /// that triggered it -if there was not one already. /// Services are free to call this themselves. /// </remarks> /// <param name="exception">the exception</param> protected internal void NoteFailure(Exception exception) { if (Log.IsDebugEnabled()) { Log.Debug("noteFailure " + exception, null); } if (exception == null) { //make sure failure logic doesn't itself cause problems return; } //record the failure details, and log it lock (this) { if (failureCause == null) { failureCause = exception; failureState = GetServiceState(); Log.Info("Service " + GetName() + " failed in state " + failureState + "; cause: " + exception, exception); } } }
private int Convert(Service.STATE state) { return(state.GetValue()); }
public sealed override bool IsInState(Service.STATE expected) { return(stateModel.IsInState(expected)); }
private void AssertInState(Service.STATE expected, Org.Apache.Hadoop.Service.Service service) { Assert.Equal("Service state should have been " + expected + " in " + service, expected, service.GetServiceState()); }
/// <summary>Query to see if the service is in a specific state.</summary> /// <remarks> /// Query to see if the service is in a specific state. /// In a multi-threaded system, the state may not hold for very long. /// </remarks> /// <param name="state">the expected state</param> /// <returns>true if, at the time of invocation, the service was in that state.</returns> public abstract bool IsInState(Service.STATE state);
/// <summary>Assert that all services are in the same expected state</summary> /// <param name="expected">expected state value</param> /// <param name="services">services to examine</param> private void AssertInState(Service.STATE expected, TestCompositeService.CompositeServiceImpl [] services) { AssertInState(expected, services, 0, services.Length); }
public virtual int GetCount(Service.STATE state) { return(counts[Convert(state)]); }
/// <summary>Assert that the last state of the listener is that the test expected.</summary> /// <param name="breakable">a breakable listener</param> /// <param name="state">the expected state</param> public virtual void AssertListenerState(BreakableStateChangeListener breakable, Service.STATE state) { Assert.Equal("Wrong state in " + breakable, state, breakable.GetLastState ()); }
private void Inc(Service.STATE state) { int index = Convert(state); counts[index]++; }