Esempio n. 1
0
 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());
 }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
0
 /// <summary>Stop a service.</summary>
 /// <remarks>
 /// Stop a service.
 /// <p/>Do nothing if the service is null or not
 /// in a state in which it can be/needs to be stopped.
 /// <p/>
 /// The service state is checked <i>before</i> the operation begins.
 /// This process is <i>not</i> thread safe.
 /// </remarks>
 /// <param name="service">a service or null</param>
 public static void Stop(Org.Apache.Hadoop.Service.Service service)
 {
     if (service != null)
     {
         service.Stop();
     }
 }
Esempio n. 4
0
 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 StateChanged(Org.Apache.Hadoop.Service.Service service)
 {
     lock (this)
     {
         notifyingState = service.GetServiceState();
         Runtime.NotifyAll(this);
     }
 }
 public override void StateChanged(Org.Apache.Hadoop.Service.Service service)
 {
     lock (this)
     {
         base.StateChanged(service);
         service.UnregisterServiceListener(this);
     }
 }
 public AddSiblingService(CompositeService parent, Org.Apache.Hadoop.Service.Service
                          serviceToAdd, Service.STATE triggerState)
     : base("ParentStateManipulatorService")
 {
     this.parent       = parent;
     this.serviceToAdd = serviceToAdd;
     this.triggerState = triggerState;
 }
 /// <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);
     }
 }
            protected internal override void ServiceInit(Configuration conf)
            {
                int notAService = 0;

                NUnit.Framework.Assert.IsFalse("Added an integer as a service", this.AddIfService
                                                   (notAService));
                this.service = new _AbstractService_325("Service");
                Assert.True("Unable to add a service", this.AddIfService(this.service
                                                                         ));
            }
Esempio n. 10
0
 protected internal virtual bool RemoveService(Org.Apache.Hadoop.Service.Service service
                                               )
 {
     lock (this)
     {
         lock (serviceList)
         {
             return(serviceList.Remove(service));
         }
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Add the passed
 /// <see cref="Service"/>
 /// to the list of services managed by this
 /// <see cref="CompositeService"/>
 /// </summary>
 /// <param name="service">
 /// the
 /// <see cref="Service"/>
 /// to be added
 /// </param>
 protected internal virtual void AddService(Org.Apache.Hadoop.Service.Service service
                                            )
 {
     if (Log.IsDebugEnabled())
     {
         Log.Debug("Adding service " + service.GetName());
     }
     lock (serviceList)
     {
         serviceList.AddItem(service);
     }
 }
Esempio n. 12
0
 /// <summary>Stop a service; if it is null do nothing.</summary>
 /// <remarks>
 /// Stop a service; if it is null do nothing. Exceptions are caught and
 /// logged at warn level. (but not Throwables). This operation is intended to
 /// be used in cleanup operations
 /// </remarks>
 /// <param name="log">the log to warn at</param>
 /// <param name="service">a service; may be null</param>
 /// <returns>any exception that was caught; null if none was.</returns>
 /// <seealso cref="StopQuietly(Service)"/>
 public static Exception StopQuietly(Log log, Org.Apache.Hadoop.Service.Service service
                                     )
 {
     try
     {
         Stop(service);
     }
     catch (Exception e)
     {
         log.Warn("When stopping the service " + service.GetName() + " : " + e, e);
         return(e);
     }
     return(null);
 }
 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());
         }
     }
 }
Esempio n. 14
0
 /// <summary>Change to a new state and notify all listeners.</summary>
 /// <remarks>
 /// Change to a new state and notify all listeners.
 /// This method will block until all notifications have been issued.
 /// It caches the list of listeners before the notification begins,
 /// so additions or removal of listeners will not be visible.
 /// </remarks>
 /// <param name="service">the service that has changed state</param>
 public virtual void NotifyListeners(Org.Apache.Hadoop.Service.Service service)
 {
     //take a very fast snapshot of the callback list
     //very much like CopyOnWriteArrayList, only more minimal
     ServiceStateChangeListener[] callbacks;
     lock (this)
     {
         callbacks = Collections.ToArray(listeners, new ServiceStateChangeListener
                                         [listeners.Count]);
     }
     //iterate through the listeners outside the synchronized method,
     //ensuring that listener registration/unregistration doesn't break anything
     foreach (ServiceStateChangeListener l in callbacks)
     {
         l.StateChanged(service);
     }
 }
 protected internal static void AddToTeardown(Org.Apache.Hadoop.Service.Service svc
                                              )
 {
     servicesToTeardown.AddService(svc);
 }
Esempio n. 16
0
 /// <summary>Stop a service; if it is null do nothing.</summary>
 /// <remarks>
 /// Stop a service; if it is null do nothing. Exceptions are caught and
 /// logged at warn level. (but not Throwables). This operation is intended to
 /// be used in cleanup operations
 /// </remarks>
 /// <param name="service">a service; may be null</param>
 /// <returns>any exception that was caught; null if none was.</returns>
 public static Exception StopQuietly(Org.Apache.Hadoop.Service.Service service)
 {
     return(StopQuietly(Log, service));
 }
Esempio n. 17
0
 public static void AssertServiceStateStopped(Org.Apache.Hadoop.Service.Service service
                                              )
 {
     AssertServiceInState(service, Service.STATE.Stopped);
 }
Esempio n. 18
0
 /// <summary>Expose addService method</summary>
 /// <param name="parent">parent service</param>
 /// <param name="child">child to add</param>
 public static void AddChildToService(CompositeService parent, Org.Apache.Hadoop.Service.Service
                                      child)
 {
     parent.AddService(child);
 }
Esempio n. 19
0
 /// <summary>
 /// Assert that a service configuration contains a specific key; the value
 /// is ignored.
 /// </summary>
 /// <param name="service">service to check</param>
 /// <param name="key">key to look for</param>
 public static void AssertServiceConfigurationContains(Org.Apache.Hadoop.Service.Service
                                                       service, string key)
 {
     NUnit.Framework.Assert.IsNotNull("No option " + key + " in service configuration"
                                      , service.GetConfig().Get(key));
 }
Esempio n. 20
0
 public CompositeServiceAddingAChild(Org.Apache.Hadoop.Service.Service child)
     : base("CompositeServiceAddingAChild")
 {
     this.child = child;
 }
Esempio n. 21
0
 public static void AssertServiceStateCreated(Org.Apache.Hadoop.Service.Service service
                                              )
 {
     AssertServiceInState(service, Service.STATE.Notinited);
 }
Esempio n. 22
0
 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());
 }
Esempio n. 23
0
 /// <summary>Callback for a state change event: log it</summary>
 /// <param name="service">the service that has changed.</param>
 public virtual void StateChanged(Org.Apache.Hadoop.Service.Service service)
 {
     log.Info("Entry to state " + service.GetServiceState() + " for " + service.GetName
                  ());
 }