Beispiel #1
0
        /// <summary>
        /// Creates a new instance of this LabStateManager, as well as a new IYodiiEngine.
        /// </summary>
        internal LabStateManager()
        {
            YodiiEngine engine = new YodiiEngine(this);

            _engine = engine;

            Debug.Assert(_engine.LiveInfo != null);
            _engine.PropertyChanged += _engine_PropertyChanged;
            _engine.LiveInfo.Plugins.CollectionChanged  += Plugins_CollectionChanged;
            _engine.LiveInfo.Services.CollectionChanged += Services_CollectionChanged;

            Debug.Assert(_engine.IsRunning == false);

            _serviceInfos = new CKObservableSortedArrayKeyList <ServiceInfo, string>(s => s.ServiceFullName, false);
            _pluginInfos  = new CKObservableSortedArrayKeyList <PluginInfo, string>(p => p.PluginFullName, false);

            _labServiceInfos = new CKObservableSortedArrayKeyList <LabServiceInfo, ServiceInfo>(s => s.ServiceInfo, (x, y) => String.CompareOrdinal(x.ServiceFullName, y.ServiceFullName), false);
            _labPluginInfos  = new CKObservableSortedArrayKeyList <LabPluginInfo, PluginInfo>(p => p.PluginInfo, (x, y) => String.CompareOrdinal(x.PluginFullName, y.PluginFullName), false);

            _runningPlugins = new ObservableCollection <IPluginInfo>();

            _serviceInfos.CollectionChanged += _serviceInfos_CollectionChanged;
            _pluginInfos.CollectionChanged  += _pluginInfos_CollectionChanged;

            UpdateEngineInfos();
        }
Beispiel #2
0
        public void ManagerCreationTests()
        {
            YodiiEngine engine = new YodiiEngine(new YodiiEngineHostMock());
            int         managerChangingCount = 0;
            int         managerChangedCount  = 0;

            engine.Configuration.ConfigurationChanging += delegate(object sender, ConfigurationChangingEventArgs e)
            {
                Assert.That(e.IsCanceled == false, "Configuration manager does not cancel by default.");
                Assert.That(e.FinalConfiguration != null, "Proposed FinalConfiguration exists.");

                managerChangingCount++;
            };

            engine.Configuration.ConfigurationChanged += delegate(object sender, ConfigurationChangedEventArgs e)
            {
                Assert.That(e.FinalConfiguration != null, "FinalConfiguration exists.");

                managerChangedCount++;
            };

            IYodiiEngineResult  result;
            IConfigurationLayer layer = engine.Configuration.Layers.Create("BaseConfig");

            result = layer.Items.Add("Yodii.ManagerService", ConfigurationStatus.Runnable);
            Assert.That(result.Success, Is.True);
            result = layer.Items.Add(Guid.NewGuid().ToString(), ConfigurationStatus.Disabled);
            Assert.That(result.Success, Is.True);

            Assert.That(managerChangingCount == 2);
            Assert.That(managerChangedCount == 2);

            Assert.That(engine.Configuration.FinalConfiguration != null, "Non-cancelled FinalConfiguration exists.");
        }
Beispiel #3
0
 internal LiveInfo(YodiiEngine engine)
 {
     Debug.Assert( engine != null );
     _engine = engine;
     _plugins = new CKObservableSortedArrayKeyList<LivePluginInfo, string>( l => l.PluginInfo.PluginFullName );
     _services = new CKObservableSortedArrayKeyList<LiveServiceInfo, string>( l => l.ServiceInfo.ServiceFullName );
 }
Beispiel #4
0
        static void CheckServicesStatus(this YodiiEngine @this, RunningStatus status, string pluginOrServiceNames, bool expectedIsPartial)
        {
            string[] expected      = pluginOrServiceNames.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var      withTheStatus = @this.LiveInfo.Services.Where(s => s.RunningStatus == status).Select(s => s.ServiceInfo.ServiceFullName);

            TestExtensions.CheckContainsWithAlternative(expected, withTheStatus, expectedIsPartial);
        }
Beispiel #5
0
        public void RemovingLayerTests()
        {
            var e     = new YodiiEngine(new YodiiEngineHostMock());
            var layer = e.Configuration.Layers.Create();

            layer.Items.AddSuccess("p1", ConfigurationStatus.Disabled, ConfigurationStatus.Disabled);
            layer.Items.AddSuccess("p2", ConfigurationStatus.Optional, ConfigurationStatus.Optional);
            layer.Items.AddSuccess("p3", ConfigurationStatus.Runnable, ConfigurationStatus.Runnable);
            layer.Items.AddSuccess("p4", ConfigurationStatus.Running, ConfigurationStatus.Running);

            e.Configuration.CheckFinalConfigurationItems("p1=Disabled", "p2=Optional", "p3=Runnable", "p4=Running");

            var layer2 = e.Configuration.Layers.Create();

            layer2.Items.AddSuccess("p1", ConfigurationStatus.Optional, ConfigurationStatus.Disabled);
            layer2.Items.AddSuccess("p2", ConfigurationStatus.Runnable, ConfigurationStatus.Runnable);
            layer2.Items.AddSuccess("p2", ConfigurationStatus.Running, ConfigurationStatus.Running);
            layer2.Items.AddSuccess("p2", ConfigurationStatus.Runnable, ConfigurationStatus.Runnable);
            layer2.Items.AddSuccess("p3", ConfigurationStatus.Running, ConfigurationStatus.Running);
            layer2.Items.AddSuccess("p4", ConfigurationStatus.Runnable, ConfigurationStatus.Running);

            e.Configuration.CheckFinalConfigurationItems("p1=Disabled", "p2=Runnable", "p3=Running", "p4=Running");

            e.Configuration.Layers.Remove(layer);

            e.Configuration.CheckFinalConfigurationItems("p1=Optional", "p2=Runnable", "p3=Running", "p4=Runnable");
        }
 ConfigurationSolver( YodiiEngine engine, bool revertServices = false, bool revertPlugins = false )
 {
     _engine = engine;
     _services = new Dictionary<string, ServiceData>();
     _serviceFamilies = new List<ServiceData.ServiceFamily>();
     _plugins = new Dictionary<string, PluginData>();
     _deferedPropagation = new HashSet<ServiceData>();
     _revertServicesOrder = revertServices;
     _revertPluginsOrder = revertPlugins;
 }
        public void EngineCreationTest()
        {
            YodiiEngineHostMock fakeMock = null;
            var ex = Assert.Throws<ArgumentNullException>(() => new YodiiEngine(fakeMock));
            Assert.That(ex.ParamName, Is.EqualTo( "host" ));

            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            Assert.That( engine.Host, Is.Not.Null );
            Assert.That( engine.IsRunning, Is.False );
            Assert.That( engine.Configuration, Is.Not.Null );
        }
        /// <summary>
        /// Static only success resolution constructor.
        /// </summary>
        public YodiiEngineResult( IConfigurationSolver solver, YodiiEngine engine )
        {
            Debug.Assert( solver != null );
            Debug.Assert( engine != null );

            var allP = solver.AllPlugins.Select( p => new SolvedPluginSnapshot( p ) ).ToDictionary( p => p.PluginInfo );
            var allS = solver.AllServices.Select( s => new SolvedServiceSnapshot( s ) ).ToDictionary( s => s.ServiceInfo.ServiceFullName );
            _staticOnlyResultConfiguration = new StaticSolvedConfiguration( allP.Values.ToReadOnlyList(), allS.Values.ToReadOnlyList() );
            _pluginCulprits = CKReadOnlyListEmpty<IPluginInfo>.Empty;
            _serviceCulprits = CKReadOnlyListEmpty<IServiceInfo>.Empty;
            _engine = engine;
        }
Beispiel #9
0
        public void TestXmlDeserialization()
        {
            YodiiEngine engineA = MockXmlUtils.CreateEngineFromXmlResource("Valid001a");
            YodiiEngine engineB = StaticConfigurationTests.CreateValid001a();

            EquivalenceExtensions.AssertEngineInfoEquivalence(engineA, engineB);

            engineA = MockXmlUtils.CreateEngineFromXmlResource("Graph005");
            var info = MockInfoFactory.CreateGraph005();

            EquivalenceExtensions.AssertDiscoveredInfoEquivalence(engineA.DiscoveredInfo, info);
        }
Beispiel #10
0
        public void EngineUseTest()
        {
            IYodiiEngine engine = new YodiiEngine(new YodiiEngineHostMock());

            Assert.Throws <ArgumentNullException>(() => engine.SetDiscoveredInfo(null));

            DiscoveredInfo discoveredInfo = MockInfoFactory.CreateGraph003();

            IYodiiEngineResult result = engine.SetDiscoveredInfo(discoveredInfo);

            Assert.That(result.Success, Is.True);
            Assert.That(engine.DiscoveredInfo == discoveredInfo);

            PluginInfo  pluginA1 = discoveredInfo.FindPlugin("PluginA-1");
            PluginInfo  pluginA2 = discoveredInfo.FindPlugin("PluginA-2");
            ServiceInfo serviceA = discoveredInfo.FindService("ServiceA");



            result = engine.Start();
            Assert.That(result.Success, Is.True);
            Assert.That(engine.LiveInfo, Is.Not.Null);
            Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).PluginInfo, Is.EqualTo(pluginA1));
            Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).PluginInfo, Is.EqualTo(pluginA2));
            Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).ServiceInfo, Is.EqualTo(serviceA));

            Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).IsRunning, Is.False);
            Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).IsRunning, Is.False);
            Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).IsRunning, Is.False);

            Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).RunningStatus, Is.EqualTo(RunningStatus.Stopped));
            Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).RunningStatus, Is.EqualTo(RunningStatus.Stopped));
            Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).RunningStatus, Is.EqualTo(RunningStatus.Stopped));

            Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).Service, Is.EqualTo(engine.LiveInfo.FindService(serviceA.ServiceFullName)));
            Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).Service, Is.EqualTo(engine.LiveInfo.FindService(serviceA.ServiceFullName)));
            Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).Generalization, Is.Null);

            Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).ConfigOriginalStatus, Is.EqualTo(ConfigurationStatus.Optional));
            Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).ConfigOriginalStatus, Is.EqualTo(ConfigurationStatus.Optional));
            Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).ConfigOriginalStatus, Is.EqualTo(ConfigurationStatus.Optional));

            Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).WantedConfigSolvedStatus, Is.EqualTo(SolvedConfigurationStatus.Runnable));
            Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).WantedConfigSolvedStatus, Is.EqualTo(SolvedConfigurationStatus.Runnable));
            Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).WantedConfigSolvedStatus, Is.EqualTo(SolvedConfigurationStatus.Runnable));

            Assert.That(engine.LiveInfo.FindPlugin(pluginA1.PluginFullName).CurrentError, Is.Null);
            Assert.That(engine.LiveInfo.FindPlugin(pluginA2.PluginFullName).CurrentError, Is.Null);
            Assert.That(engine.LiveInfo.FindService(serviceA.ServiceFullName).DisabledReason, Is.Null);

            engine.Stop();
        }
Beispiel #11
0
        public void EngineCreationTest()
        {
            YodiiEngineHostMock fakeMock = null;
            var ex = Assert.Throws <ArgumentNullException>(() => new YodiiEngine(fakeMock));

            Assert.That(ex.ParamName, Is.EqualTo("host"));

            YodiiEngine engine = new YodiiEngine(new YodiiEngineHostMock());

            Assert.That(engine.Host, Is.Not.Null);
            Assert.That(engine.IsRunning, Is.False);
            Assert.That(engine.Configuration, Is.Not.Null);
        }
Beispiel #12
0
        public void EngineUseTest()
        {
            IYodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );

            Assert.Throws<ArgumentNullException>( () => engine.SetDiscoveredInfo( null ) );

            DiscoveredInfo discoveredInfo = MockInfoFactory.CreateGraph003();

            IYodiiEngineResult result = engine.SetDiscoveredInfo( discoveredInfo );
            Assert.That( result.Success, Is.True );
            Assert.That( engine.DiscoveredInfo == discoveredInfo );

            PluginInfo pluginA1 = discoveredInfo.FindPlugin( "PluginA-1" );
            PluginInfo pluginA2 = discoveredInfo.FindPlugin( "PluginA-2" );
            ServiceInfo serviceA = discoveredInfo.FindService( "ServiceA" );

            result = engine.Start();
            Assert.That( result.Success, Is.True );
            Assert.That( engine.LiveInfo, Is.Not.Null );
            Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).PluginInfo, Is.EqualTo( pluginA1 ) );
            Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).PluginInfo, Is.EqualTo( pluginA2 ) );
            Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).ServiceInfo, Is.EqualTo( serviceA ) );

            Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).IsRunning, Is.False );
            Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).IsRunning, Is.False );
            Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).IsRunning, Is.False );

            Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).RunningStatus, Is.EqualTo( RunningStatus.Stopped ) );
            Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).RunningStatus, Is.EqualTo( RunningStatus.Stopped ) );
            Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).RunningStatus, Is.EqualTo( RunningStatus.Stopped ) );

            Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).Service, Is.EqualTo( engine.LiveInfo.FindService( serviceA.ServiceFullName ) ) );
            Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).Service, Is.EqualTo( engine.LiveInfo.FindService( serviceA.ServiceFullName ) ) );
            Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).Generalization, Is.Null );

            Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).ConfigOriginalStatus, Is.EqualTo( ConfigurationStatus.Optional ) );
            Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).ConfigOriginalStatus, Is.EqualTo( ConfigurationStatus.Optional ) );
            Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).ConfigOriginalStatus, Is.EqualTo( ConfigurationStatus.Optional ) );

            Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).WantedConfigSolvedStatus, Is.EqualTo( SolvedConfigurationStatus.Runnable ) );
            Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).WantedConfigSolvedStatus, Is.EqualTo( SolvedConfigurationStatus.Runnable ) );
            Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).WantedConfigSolvedStatus, Is.EqualTo( SolvedConfigurationStatus.Runnable ) );

            Assert.That( engine.LiveInfo.FindPlugin( pluginA1.PluginFullName ).CurrentError, Is.Null );
            Assert.That( engine.LiveInfo.FindPlugin( pluginA2.PluginFullName ).CurrentError, Is.Null );
            Assert.That( engine.LiveInfo.FindService( serviceA.ServiceFullName ).DisabledReason, Is.Null );

            engine.Stop();
        }
        protected LiveYodiiItemInfo( YodiiEngine engine, IYodiiItemData d, string fullName )
        {
            Debug.Assert( d != null && engine != null && !String.IsNullOrEmpty( fullName ) );

            _engine = engine;
            _capability = new LiveRunCapability( d.FinalConfigSolvedStatus, d.FinalStartableStatus );
            _fullName = fullName;
            Debug.Assert( d.DynamicStatus != null );
            _disabledReason = d.DisabledReason;
            _runningStatus = d.DynamicStatus.Value;
            _configOriginalStatus = d.ConfigOriginalStatus;
            _configSolvedStatus = d.ConfigSolvedStatus;
            _configOriginalImpact = d.ConfigOriginalImpact;
            _configSolvedImpact = d.RawConfigSolvedImpact;
        }
        /// <summary>
        /// Dynamic failure constructor.
        /// </summary>
        internal YodiiEngineResult( IConfigurationSolver solver, IEnumerable<Tuple<IPluginInfo, Exception>> errorInfo, YodiiEngine engine )
        {
            Debug.Assert( solver != null );
            Debug.Assert( errorInfo != null && errorInfo.Any() );
            Debug.Assert( engine != null );

            var allP = solver.AllPlugins.Select( p => new SolvedPluginSnapshot( p ) ).ToDictionary( ps => ps.PluginInfo );
            var allS = solver.AllServices.Select( s => new SolvedServiceSnapshot( s ) ).ToReadOnlyList();

            var errors = errorInfo.Select( e => new PluginRuntimeError( allP[e.Item1], e.Item2 ) ).ToReadOnlyList();
            _pluginCulprits = errors.Select( e => e.Plugin.PluginInfo ).ToReadOnlyList();
            _serviceCulprits = _pluginCulprits.Select( p => p.Service ).Where( s => s != null ).ToReadOnlyList();
            _engine = engine;

            _hostFailureResult = new DynamicFailureResult( new DynamicSolvedConfiguration( allP.Values.ToReadOnlyList(), allS ), errors );
        }
Beispiel #15
0
        public static YodiiEngine CreateEngineFromXml(XmlReader r)
        {
            YodiiEngine    e = new YodiiEngine(new YodiiEngineHostMock());
            DiscoveredInfo d = new DiscoveredInfo();

            // Used to index reference links between plugins and services.
            List <PendingGeneralization>   pendingGeneralizations   = new List <PendingGeneralization>();
            List <PendingPluginService>    pendingPluginServices    = new List <PendingPluginService>();
            List <PendingServiceReference> pendingServiceReferences = new List <PendingServiceReference>();

            CKSortedArrayKeyList <PluginInfo, string>  loadedPlugins;
            CKSortedArrayKeyList <ServiceInfo, string> loadedServices;

            loadedServices = new CKSortedArrayKeyList <ServiceInfo, string>(s => s.ServiceFullName, false);
            loadedPlugins  = new CKSortedArrayKeyList <PluginInfo, string>(p => p.PluginFullName, false);

            while (r.Read())
            {
                // Load services
                if (r.IsStartElement() && r.Name == "Services")
                {
                    ReadServices(r.ReadSubtree(), d, loadedServices, loadedPlugins, pendingGeneralizations, pendingPluginServices, pendingServiceReferences);
                }

                // Load plugins
                if (r.IsStartElement() && r.Name == "Plugins")
                {
                    ReadPlugins(r.ReadSubtree(), d, loadedServices, loadedPlugins, pendingPluginServices, pendingServiceReferences);
                }

                // Read configuration manager
                if (r.IsStartElement() && r.Name == "Configuration")
                {
                    ReadConfigurationManager(e.Configuration, r.ReadSubtree());
                }
            }

            e.SetDiscoveredInfo(d);

            return(e);
        }
Beispiel #16
0
        public static YodiiEngine CreateEngineFromXml( XmlReader r )
        {
            YodiiEngine e = new YodiiEngine( new YodiiEngineHostMock() );
            DiscoveredInfo d = new DiscoveredInfo();

            // Used to index reference links between plugins and services.
            List<PendingGeneralization> pendingGeneralizations = new List<PendingGeneralization>();
            List<PendingPluginService> pendingPluginServices = new List<PendingPluginService>();
            List<PendingServiceReference> pendingServiceReferences = new List<PendingServiceReference>();

            CKSortedArrayKeyList<PluginInfo, string> loadedPlugins;
            CKSortedArrayKeyList<ServiceInfo, string> loadedServices;
            loadedServices = new CKSortedArrayKeyList<ServiceInfo, string>( s => s.ServiceFullName, false );
            loadedPlugins = new CKSortedArrayKeyList<PluginInfo, string>( p => p.PluginFullName, false );

            while( r.Read() )
            {
                // Load services
                if( r.IsStartElement() && r.Name == "Services" )
                {
                    ReadServices( r.ReadSubtree(), d, loadedServices, loadedPlugins, pendingGeneralizations, pendingPluginServices, pendingServiceReferences );
                }

                // Load plugins
                if( r.IsStartElement() && r.Name == "Plugins" )
                {
                    ReadPlugins( r.ReadSubtree(), d, loadedServices, loadedPlugins, pendingPluginServices, pendingServiceReferences );
                }

                // Read configuration manager
                if( r.IsStartElement() && r.Name == "Configuration" )
                {
                    ReadConfigurationManager( e.Configuration, r.ReadSubtree() );
                }
            }

            e.SetDiscoveredInfo( d );

            return e;
        }
        public void Invalid001c()
        {
            #region graph
            /**
             *                  +--------+                              +--------+
             *      +---------->|ServiceA+-------+   *----------------->|ServiceB|
             *      |           |Optional|       |   | Need Running     |Disable |
             *      |           +---+----+       |   |                  +---+----+
             *      |               |            |   |                      |
             *      |               |            |   |                      |
             *      |               |            |   |                      |
             *  +---+-----+         |        +---+---*-+                    |
             *  |ServiceAx|     +---+-----+  |PluginA-2|                +---+-----+
             *  |Optional |     |PluginA-1|  |Running  |                |PluginB-1|
             *  +----+----+     |Optional |  +---------+                |Optional |
             *       |          +---------+                             +---------+
             *       |
             *  +----+-----+
             *  |PluginAx-1|
             *  |Optional  |
             *  +----------+
             */
            #endregion

            DiscoveredInfo info = MockInfoFactory.CreateGraph001();
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( info );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "ServiceB", ConfigurationStatus.Disabled );
            cl.Items.Add( "PluginA-2", ConfigurationStatus.Running );

            engine.FullStaticResolutionOnly( res =>
            {
                res.CheckAllBlockingPluginsAre( "PluginA-2" );
                res.CheckNoBlockingServices();
            } );
        }
Beispiel #18
0
        public void LayerCreationTest()
        {
            YodiiEngine e = new YodiiEngine(new YodiiEngineHostMock());

            IConfigurationLayer layer = e.Configuration.Layers.Create("TestConfig");

            Assert.That(layer.Items.Count == 0);
            Assert.That(layer.LayerName == "TestConfig");

            string             pluginIdentifier;
            IYodiiEngineResult result;

            // Add a random plugin GUID
            pluginIdentifier = Guid.NewGuid().ToString();
            result           = layer.Items.Add(pluginIdentifier, ConfigurationStatus.Disabled);
            Assert.That(result.Success, Is.True);
            Assert.That(layer.Items.Count == 1);
            Assert.That(layer.Items[pluginIdentifier], Is.InstanceOf <ConfigurationItem>());

            // Add another random plugin GUID
            pluginIdentifier = Guid.NewGuid().ToString();
            result           = layer.Items.Add(pluginIdentifier, ConfigurationStatus.Runnable);
            Assert.That(result.Success, Is.True);
            Assert.That(layer.Items.Count == 2);
            Assert.That(layer.Items[pluginIdentifier], Is.InstanceOf <ConfigurationItem>());

            // Remove last plugin GUID
            result = layer.Items.Remove(pluginIdentifier);
            Assert.That(result.Success, Is.True);
            Assert.That(layer.Items.Count == 1);

            // Add some service
            pluginIdentifier = "Yodii.ManagerService";
            result           = layer.Items.Add(pluginIdentifier, ConfigurationStatus.Runnable);
            Assert.That(result.Success, Is.True);
            Assert.That(layer.Items.Count == 2);
            Assert.That(layer.Items[pluginIdentifier], Is.InstanceOf <ConfigurationItem>());
        }
        /// <summary>
        /// Static failure resolution constructor.
        /// </summary>
        public YodiiEngineResult( IConfigurationSolver solver, List<PluginData> blockingPlugins, List<ServiceData> blockingServices, YodiiEngine engine )
        {
            Debug.Assert( blockingPlugins != null || blockingServices != null, "At least one must not be null." );
            Debug.Assert( solver != null );
            Debug.Assert( engine != null );

            var allP = solver.AllPlugins.Select( p => new SolvedPluginSnapshot( p ) ).ToDictionary( p => p.PluginInfo );
            var allS = solver.AllServices.Select( s => new SolvedServiceSnapshot( s ) ).ToDictionary( s => s.ServiceInfo.ServiceFullName );
            _staticOnlyResultConfiguration = new StaticSolvedConfiguration( allP.Values.ToReadOnlyList(), allS.Values.ToReadOnlyList() );

            var blkP = blockingPlugins == null
                            ? CKReadOnlyListEmpty<IStaticSolvedPlugin>.Empty
                            : blockingPlugins.Select( p => allP[p.PluginInfo] ).ToReadOnlyList();
            _pluginCulprits = blkP.Select( ps => ps.PluginInfo ).ToReadOnlyList();

            var blkS = blockingServices == null
                            ? CKReadOnlyListEmpty<IStaticSolvedService>.Empty
                            : blockingServices.Select( s => allS[s.ServiceInfo.ServiceFullName] ).ToReadOnlyList();
            _serviceCulprits = blkS.Select( ss => ss.ServiceInfo ).ToReadOnlyList();

            _engine = engine;
            _staticFailureResult = new StaticFailureResult( _staticOnlyResultConfiguration, blkP, blkS );
        }
Beispiel #20
0
        public static void FullStart(this YodiiEngine @this, Action <YodiiEngine, IYodiiEngineResult> tests, [CallerMemberName] string callerName = null)
        {
            IActivityMonitor   m = TestHelper.ConsoleMonitor;
            IYodiiEngineResult result;

            using (m.OpenInfo().Send("FullStart for {0}.", callerName))
            {
                using (m.OpenInfo().Send("FullStart()."))
                {
                    result = @this.Start(false, false);
                    result.Trace(m);
                    tests(@this, result);
                    @this.Stop();
                }
                using (m.OpenInfo().Send("FullStart( revertServices )."))
                {
                    result = @this.Start(true, false);
                    result.Trace(m);
                    tests(@this, result);
                    @this.Stop();
                }
                using (m.OpenInfo().Send("FullStart( revertPlugins )."))
                {
                    result = @this.Start(false, true);
                    result.Trace(m);
                    tests(@this, result);
                    @this.Stop();
                }
                using (m.OpenInfo().Send("FullStart( revertServices, revertPlugins )."))
                {
                    result = @this.Start(true, true);
                    result.Trace(m);
                    tests(@this, result);
                    @this.Stop();
                }
            }
        }
Beispiel #21
0
 public static void CheckServicesDisabled(this YodiiEngine @this, string pluginOrServiceNames)
 {
     CheckServicesStatus(@this, RunningStatus.Disabled, pluginOrServiceNames, true);
 }
Beispiel #22
0
 public static void CheckAllRunning(this YodiiEngine @this, string pluginOrServiceNames)
 {
     CheckStatus(@this, RunningStatus.Running, pluginOrServiceNames, false);
 }
        internal static YodiiEngine CreateValid003f()
        {
            DiscoveredInfo info = MockInfoFactory.CreateGraph003();
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( info );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "ServiceA", ConfigurationStatus.Runnable );
            cl.Items.Add( "PluginA-1", ConfigurationStatus.Runnable );
            cl.Items.Add( "PluginA-2", ConfigurationStatus.Runnable );
            return engine;
        }
 public SuccessYodiiEngineResult( YodiiEngine engine )
 {
     _engine = engine;
 }
Beispiel #25
0
 public static void CheckAllPluginsStopped(this YodiiEngine @this, string pluginOrServiceNames)
 {
     CheckPluginsStatus(@this, RunningStatus.Stopped, pluginOrServiceNames, false);
 }
        internal static YodiiEngine CreateValidRunnableReferences()
        {
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( MockInfoFactory.CreateGraph006() );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();

            return engine;
        }
        public void InvalidCommonReferences2()
        {
            #region graph
            /*
            *                  +--------+                            +--------+
            *      +-----------|Service1+                            |Service2|---------------+                  +---------------+
            *      |           |Running |                            |Running |               |                  |AnotherBlocking+
            *      |           +---+----+                            +---+----+               |                  |    Runnable   |
            *      |               |                                      |                   |                  +-------+-------+
            *      |               |                                      |                   |                          |
            *      |               |                                      |                   |                          |
            *  +---+-----+         |                                      |                   |                          |
            *  |Plugin1  |     +---+-----+                            +---+-----+         +---+-----+                    |
            *  |Optional |     |Plugin2  |                            |Plugin3  |         |Plugin4  |            +-------+-------------+
            *  +----+----+     |Optional |                            |Optional |         |Optional |            |DisabledForBlocking  |
            *       |          +---------+                            +---------+         +-----+---+            |     Disabled        |
            *       |                   |                                 |                     |                +---------------------+
            *       |                   |                                 |                     |
            *       |                   |                                 |                     |
            *       |                   |                                 |                     |
            *       |                   |                                 |                     |
             *      |                   |                                 |                     |
            *       |                   |                                 |                     |
            *       |                   |           +--------+            |                     |
            *       |                   |           |Service3+            |                     |
            *       |       +-----------|-----------|Optional|------------|------+--------------+-----------+
            *       |       |           |           +---+----+            |      |              |           |
            *       |       |           |               |                 |      |              |           |
            *       |       |           |               |                 |      |              |           |
            *       |   +---+-------+   +-------->+-----+-----+           |  +---+-------+      |       +---+-------+
            *       |   |Service3.1 |             |Service3.2 |           |  |Service3.3 |      |       |Service3.4 |
            *       +-->|Optional   |             |Optional   |           +->|Optional   |      +------>|Optional   |
            *           +-----------+             +-----------+              +-----------+              +-----------+
            *           |           |             |           |              |           |              |           |
            *           |           |             |           |              |           |              |           |
            *           |           |             |           |              |           |              |           |
            *       +---+-----+ +---+-----+   +---+-----+ +---+-----+    +---+-----+ +---+-----+    +---+-----+ +---+-----+
            *       |Plugin5  | |Plugin6  |   |Plugin7  | |Plugin8  |    |Plugin9  | |Plugin10 |    |Plugin11 | |Plugin12 |
            *       |Optional | |Optional |   |Optional | |Optional |    |Optional | |Optional |    |Optional | |Optional |
            *       +---------+ +---------+   +---------+ +---------+    +---------+ +---------+    +---------+ +---------+
            *
            */
            #endregion
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            var disco = MockInfoFactory.CreateGraph005b();
            var anotherBlocking = new ServiceInfo( "AnotherBlocking", disco.DefaultAssembly );
            var disabledForBlocking = new PluginInfo( "DisabledForBlocking", disco.DefaultAssembly );
            disabledForBlocking.Service = anotherBlocking;
            disco.ServiceInfos.Add( anotherBlocking );
            disco.PluginInfos.Add( disabledForBlocking );
            engine.SetDiscoveredInfo( disco );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "Service1", ConfigurationStatus.Running );
            cl.Items.Add( "Service2", ConfigurationStatus.Running );
            cl.Items.Add( "AnotherBlocking", ConfigurationStatus.Runnable );
            cl.Items.Add( "DisabledForBlocking", ConfigurationStatus.Disabled );

            engine.FullStaticResolutionOnly( res =>
               {
                   res.CheckAllBlockingServicesAre( "Service1 | Service2, AnotherBlocking" );
                   res.CheckNoBlockingPlugins();
               } );
        }
        public void SetDiscoverdInfo()
        {
            #region graph
            /**
             *                  +--------+                              +--------+
             *      +---------->|ServiceA+-------+   *----------------->|ServiceB|
             *      |           |Running |       |   | Need ?           |Running |
             *      |           +---+----+       |   |                  +---+----+
             *      |               |            |   |                      |
             *      |               |            |   |                      |
             *      |               |            |   |                      |
             *  +---+-----+         |        +---+---*-+                    |
             *  |ServiceAx|     +---+-----+  |PluginA-2|                +---+-----+
             *  |Optional |     |PluginA-1|  |Optional |                |PluginB-1|
             *  +----+----+     |Optional |  +---------+                |Optional |
             *       |          +---------+                             +---------+
             *       |
             *  +----+-----+
             *  |PluginAx-1|
             *  |Running   |
             *  +----------+
             */
            #endregion

            DiscoveredInfo info = MockInfoFactory.CreateGraph001();
            info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.Optional );

            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( info );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "ServiceB", ConfigurationStatus.Running );
            cl.Items.Add( "ServiceA", ConfigurationStatus.Running );
            cl.Items.Add( "PluginAx-1", ConfigurationStatus.Running );

            IYodiiEngineResult res = engine.Start();

            res.CheckSuccess();

            info = MockInfoFactory.CreateGraph001();
            info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.OptionalRecommended );

            res = engine.SetDiscoveredInfo( info );

            res.CheckSuccess();

            info = MockInfoFactory.CreateGraph001();
            info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.Runnable );

            res = engine.SetDiscoveredInfo( info );

            res.CheckSuccess();

            info = MockInfoFactory.CreateGraph001();
            info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.RunnableRecommended );

            res = engine.SetDiscoveredInfo( info );

            res.CheckSuccess();

            info = MockInfoFactory.CreateGraph001();
            info.FindPlugin( "PluginAx-1" ).AddServiceReference( info.FindService( "ServiceB" ), DependencyRequirement.Running );

            res = engine.SetDiscoveredInfo( info );

            res.CheckSuccess();
        }
        public void Invalid001MinusPluginAx()
        {
            #region graph
            /**
             *                  +--------+                              +--------+
             *      +---------->|ServiceA+-------+   *----------------->|ServiceB|
             *      |           |Runnable|       |   | Need Running     |Runnable|
             *      |           +---+----+       |   |                  +---+----+
             *      |               |            |   |                      |
             *      |               |            |   |                      |
             *      |               |            |   |                      |
             *  +---+-----+         |        +---+---*-+                    |
             *  |ServiceAx|     +---+-----+  |PluginA-2|                +---+-----+
             *  |Runnable |     |PluginA-1|  |Runnable |                |PluginB-1|
             *  +----+----+     |Runnable |  +---------+                |Runnable |
             *                  +---------+                             +---------+
             */
            #endregion

            DiscoveredInfo info = MockInfoFactory.CreateGraph001();
            info.PluginInfos.Remove( info.FindPlugin( "PluginAx-1" ) );

            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( info );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "ServiceA", ConfigurationStatus.Runnable );
            cl.Items.Add( "ServiceB", ConfigurationStatus.Runnable );
            cl.Items.Add( "ServiceAx", ConfigurationStatus.Runnable );
            cl.Items.Add( "PluginA-1", ConfigurationStatus.Runnable );
            cl.Items.Add( "PluginA-2", ConfigurationStatus.Runnable );
            cl.Items.Add( "PluginB-1", ConfigurationStatus.Runnable );

            engine.FullStaticResolutionOnly( res =>
                {

                    res.CheckAllBlockingServicesAre( "ServiceAx" );
                    res.CheckNoBlockingPlugins();
                    res.CheckWantedConfigSolvedStatusIs( "PluginA-2", SolvedConfigurationStatus.Runnable );
                } );
        }
        public void InvalidCommonReferences1()
        {
            #region graph
                /*
                *                  +--------+                            +--------+
                *      +-----------|Service1+                            |Service2|---------------+
                *      |           |Running |                            |Running |               |
                *      |           +---+----+                            +---+----+               |
                *      |               |                                      |                   |
                *      |               |                                      |                   |
                *      |               |                                      |                   |
                *  +---+-----+         |                                      |                   |
                *  |Plugin1  |     +---+-----+                            +---+-----+         +---+-----+
                *  |Optional |     |Plugin2  |                            |Plugin3  |         |Plugin4  |
                *  +----+----+     |Optional |                            |Optional |         |Optional |
                *       |          +---------+                            +---------+         +-----+---+
                *       |                   |                                 |                     |
                *       |                   |                                 |                     |
                *       |                   |                                 |                     |
                *       |                   |                                 |                     |
                *       |                   |                                 |                     |
                 *      |                   |                                 |                     |
                *       |                   |                                 |                     |
                *       |                   |           +--------+            |                     |
                *       |                   |           |Service3+            |                     |
                *       |       +-----------|-----------|Optional|------------|------+--------------+-----------+
                *       |       |           |           +---+----+            |      |              |           |
                *       |       |           |               |                 |      |              |           |
                *       |       |           |               |                 |      |              |           |
                *       |   +---+-------+   +-------->+-----+-----+           |  +---+-------+      |       +---+-------+
                *       |   |Service3.1 |             |Service3.2 |           |  |Service3.3 |      |       |Service3.4 |
                *       +-->|Optional   |             |Optional   |           +->|Optional   |<-----+       |Optional   |
                 *          +-----------+             +-----------+              +-----------+              +-----------+
                 *          |           |             |           |              |           |              |           |
                 *          |           |             |           |              |           |              |           |
                 *          |           |             |           |              |           |              |           |
                 *      +---+-----+ +---+-----+   +---+-----+ +---+-----+    +---+-----+ +---+-----+    +---+-----+ +---+-----+
                 *      |Plugin5  | |Plugin6  |   |Plugin7  | |Plugin8  |    |Plugin9  | |Plugin10 |    |Plugin11 | |Plugin12 |
                 *      |Optional | |Optional |   |Optional | |Optional |    |Optional | |Optional |    |Optional | |Optional |
                 *      +---------+ +---------+   +---------+ +---------+    +---------+ +---------+    +---------+ +---------+
                 *
                */
            #endregion
            DiscoveredInfo info = MockInfoFactory.CreateGraph005();
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( info );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "Service1", ConfigurationStatus.Running );
            cl.Items.Add( "Service2", ConfigurationStatus.Running );

            engine.FullStaticResolutionOnly( res =>
               {
                   res.CheckAllBlockingServicesAre( "Service1 | Service2" );
                   res.CheckNoBlockingPlugins();
               } );
        }
Beispiel #31
0
        public void ConfigChanged()
        {
            /**
             *  +--------+
             *  |ServiceA+ ------+
             *  |        |       |
             *  +---+----+       |
             *      |            |
             *      |            |
             *      |            |
             *      |        +---+---*-+
             *  +---+-----+  |PluginA-2|
             *  |PluginA-1|  |         |
             *  |         |  +---------+
             *  +---------+
             */
            DiscoveredInfo info   = MockInfoFactory.CreateGraph003();
            YodiiEngine    engine = new YodiiEngine(new YodiiEngineHostMock());

            engine.SetDiscoveredInfo(info);
            engine.Start();
            ILiveServiceInfo sA = engine.LiveInfo.FindService("ServiceA");
            ILivePluginInfo  p1 = engine.LiveInfo.FindPlugin("PluginA-1");
            ILivePluginInfo  p2 = engine.LiveInfo.FindPlugin("PluginA-2");

            Assert.That(sA != null && p1 != null && p2 != null);

            Assert.That(p1.Capability.CanStart && p2.Capability.CanStart && sA.Capability.CanStart, Is.True);
            Assert.That(p1.Capability.CanStartWithFullStart && p2.Capability.CanStartWithFullStart && sA.Capability.CanStartWithFullStart, Is.True);
            Assert.That(p1.Capability.CanStartWithStartRecommended && p2.Capability.CanStartWithStartRecommended && sA.Capability.CanStartWithStartRecommended, Is.True);
            Assert.That(p1.Capability.CanStartWithStopOptionalAndRunnable && p2.Capability.CanStartWithStopOptionalAndRunnable && sA.Capability.CanStartWithStopOptionalAndRunnable, Is.True);
            Assert.That(p1.Capability.CanStartWithFullStop && p2.Capability.CanStartWithFullStop && sA.Capability.CanStartWithFullStop, Is.True);

            HashSet <string> propertyChanged = new HashSet <string>();

            p1.PropertyChanged += (s, e) =>
            {
                Assert.That(s, Is.SameAs(p1));
                Assert.That(propertyChanged.Add("p1." + e.PropertyName));
            };
            p1.Capability.PropertyChanged += (s, e) =>
            {
                Assert.That(s, Is.SameAs(p1.Capability));
                Assert.That(propertyChanged.Add("p1.Capablity." + e.PropertyName));
            };
            p2.PropertyChanged += (s, e) =>
            {
                Assert.That(s, Is.SameAs(p2));
                Assert.That(propertyChanged.Add("p2." + e.PropertyName));
            };
            p2.Capability.PropertyChanged += (s, e) =>
            {
                Assert.That(s, Is.SameAs(p2.Capability));
                Assert.That(propertyChanged.Add("p2.Capablity." + e.PropertyName));
            };
            sA.PropertyChanged += (s, e) =>
            {
                Assert.That(s, Is.SameAs(sA));
                Assert.That(propertyChanged.Add("sA." + e.PropertyName));
            };
            sA.Capability.PropertyChanged += (s, e) =>
            {
                Assert.That(s, Is.SameAs(sA.Capability));
                Assert.That(propertyChanged.Add("sA.Capablity." + e.PropertyName));
            };

            IConfigurationLayer config = engine.Configuration.Layers.Create("Default");

            config.Items.Add(p1.FullName, ConfigurationStatus.Disabled);

            Assert.That(p1.Capability.CanStart && p1.Capability.CanStartWithFullStart &&
                        p1.Capability.CanStartWithStartRecommended && p1.Capability.CanStartWithStopOptionalAndRunnable &&
                        p1.Capability.CanStartWithFullStop, Is.False);

            Assert.That(p2.Capability.CanStart && sA.Capability.CanStart, Is.True);
            Assert.That(p2.Capability.CanStartWithFullStart && sA.Capability.CanStartWithFullStart, Is.True);
            Assert.That(p2.Capability.CanStartWithStartRecommended && sA.Capability.CanStartWithStartRecommended, Is.True);
            Assert.That(p2.Capability.CanStartWithStopOptionalAndRunnable && sA.Capability.CanStartWithStopOptionalAndRunnable, Is.True);
            Assert.That(p2.Capability.CanStartWithFullStop && sA.Capability.CanStartWithFullStop, Is.True);


            CollectionAssert.AreEquivalent(new string[] {
                "p1.Capablity.CanStart",
                "p1.Capablity.CanStartWithFullStart",
                "p1.Capablity.CanStartWithStartRecommended",
                "p1.Capablity.CanStartWithStopOptionalAndRunnable",
                "p1.Capablity.CanStartWithFullStop",
                "p1.DisabledReason",
                "p1.RunningStatus",
                "p1.ConfigOriginalStatus",
                "p1.WantedConfigSolvedStatus",
                "p1.FinalConfigSolvedStatus"
            }, propertyChanged);
            propertyChanged.Clear();

            config.Items.Add(p1.FullName, ConfigurationStatus.Optional);

            CollectionAssert.AreEquivalent(new string[] {
                "p1.Capablity.CanStart",
                "p1.Capablity.CanStartWithFullStart",
                "p1.Capablity.CanStartWithStartRecommended",
                "p1.Capablity.CanStartWithStopOptionalAndRunnable",
                "p1.Capablity.CanStartWithFullStop",
                "p1.DisabledReason",
                "p1.RunningStatus",
                "p1.ConfigOriginalStatus",
                "p1.WantedConfigSolvedStatus",
                "p1.FinalConfigSolvedStatus"
            }, propertyChanged);
        }
        public void Invalid003MinusPluginA2()
        {
            #region graph
            /**
             *  +--------+
             *  |ServiceA|
             *  |Disabled|
             *  +---+----+
             *      |
             *      |
             *      |
             *      |
             *  +---+-----+
             *  |PluginA-1|
             *  |Running  |
             *  +---------+
             */
            #endregion

            DiscoveredInfo info = MockInfoFactory.CreateGraph003();

            info.PluginInfos.Remove( info.FindPlugin( "PluginA-2" ) );
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( info );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "ServiceA", ConfigurationStatus.Disabled );
            cl.Items.Add( "PluginA-1", ConfigurationStatus.Running );

            engine.FullStaticResolutionOnly( res =>
               {
                   res.CheckAllBlockingPluginsAre( "PluginA-1" );
               } );
        }
        public void Invalid003e()
        {
            #region graph
            /**
             *  +--------+
             *  |ServiceA+ ------+
             *  |Disable |       |
             *  +---+----+       |
             *      |            |
             *      |            |
             *      |            |
             *      |        +---+---*-+
             *  +---+-----+  |PluginA-2|
             *  |PluginA-1|  |Optional |
             *  |Running  |  +---------+
             *  +---------+
             */
            #endregion

            DiscoveredInfo info = MockInfoFactory.CreateGraph003();
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( info );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "ServiceA", ConfigurationStatus.Disabled );
            cl.Items.Add( "PluginA-1", ConfigurationStatus.Running );

            engine.FullStaticResolutionOnly( res =>
                {
                    res.CheckAllBlockingPluginsAre( "PluginA-1" );
                    res.CheckWantedConfigSolvedStatusIs( "PluginA-1", SolvedConfigurationStatus.Running );
                } );
        }
        public void ConfigChanged()
        {
            /**
             *  +--------+
             *  |ServiceA+ ------+
             *  |        |       |
             *  +---+----+       |
             *      |            |
             *      |            |
             *      |            |
             *      |        +---+---*-+
             *  +---+-----+  |PluginA-2|
             *  |PluginA-1|  |         |
             *  |         |  +---------+
             *  +---------+
             */
            DiscoveredInfo info = MockInfoFactory.CreateGraph003();
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( info );
            engine.Start();
            ILiveServiceInfo sA = engine.LiveInfo.FindService( "ServiceA" );
            ILivePluginInfo p1 = engine.LiveInfo.FindPlugin( "PluginA-1" );
            ILivePluginInfo p2 = engine.LiveInfo.FindPlugin( "PluginA-2" );

            Assert.That( sA != null && p1 != null && p2 != null );

            Assert.That( p1.Capability.CanStart && p2.Capability.CanStart && sA.Capability.CanStart, Is.True );
            Assert.That( p1.Capability.CanStartWithFullStart && p2.Capability.CanStartWithFullStart && sA.Capability.CanStartWithFullStart, Is.True );
            Assert.That( p1.Capability.CanStartWithStartRecommended && p2.Capability.CanStartWithStartRecommended && sA.Capability.CanStartWithStartRecommended, Is.True );
            Assert.That( p1.Capability.CanStartWithStopOptionalAndRunnable && p2.Capability.CanStartWithStopOptionalAndRunnable && sA.Capability.CanStartWithStopOptionalAndRunnable, Is.True );
            Assert.That( p1.Capability.CanStartWithFullStop && p2.Capability.CanStartWithFullStop && sA.Capability.CanStartWithFullStop, Is.True );

            HashSet<string> propertyChanged = new HashSet<string>();
            p1.PropertyChanged += ( s, e ) =>
                                    {
                                        Assert.That( s, Is.SameAs( p1 ) );
                                        Assert.That( propertyChanged.Add( "p1."+e.PropertyName ) );
                                    };
            p1.Capability.PropertyChanged += ( s, e ) =>
                                                {
                                                    Assert.That( s, Is.SameAs( p1.Capability ) );
                                                    Assert.That( propertyChanged.Add( "p1.Capablity."+e.PropertyName ) );
                                                };
            p2.PropertyChanged += ( s, e ) =>
                                    {
                                        Assert.That( s, Is.SameAs( p2 ) );
                                        Assert.That( propertyChanged.Add( "p2."+e.PropertyName ) );
                                    };
            p2.Capability.PropertyChanged += ( s, e ) =>
                                                {
                                                    Assert.That( s, Is.SameAs( p2.Capability ) );
                                                    Assert.That( propertyChanged.Add( "p2.Capablity."+e.PropertyName ) );
                                                };
            sA.PropertyChanged += ( s, e ) =>
                                    {
                                        Assert.That( s, Is.SameAs( sA ) );
                                        Assert.That( propertyChanged.Add( "sA."+e.PropertyName ) );
                                    };
            sA.Capability.PropertyChanged += ( s, e ) =>
                                                {
                                                    Assert.That( s, Is.SameAs( sA.Capability ) );
                                                    Assert.That( propertyChanged.Add( "sA.Capablity."+e.PropertyName ) );
                                                };

            IConfigurationLayer config = engine.Configuration.Layers.Create( "Default" );
            config.Items.Add( p1.FullName, ConfigurationStatus.Disabled );

            Assert.That( p1.Capability.CanStart && p1.Capability.CanStartWithFullStart
                        && p1.Capability.CanStartWithStartRecommended && p1.Capability.CanStartWithStopOptionalAndRunnable
                        && p1.Capability.CanStartWithFullStop, Is.False );

            Assert.That( p2.Capability.CanStart && sA.Capability.CanStart, Is.True );
            Assert.That( p2.Capability.CanStartWithFullStart && sA.Capability.CanStartWithFullStart, Is.True );
            Assert.That( p2.Capability.CanStartWithStartRecommended && sA.Capability.CanStartWithStartRecommended, Is.True );
            Assert.That( p2.Capability.CanStartWithStopOptionalAndRunnable && sA.Capability.CanStartWithStopOptionalAndRunnable, Is.True );
            Assert.That( p2.Capability.CanStartWithFullStop && sA.Capability.CanStartWithFullStop, Is.True );

            CollectionAssert.AreEquivalent( new string[]{
                "p1.Capablity.CanStart",
                "p1.Capablity.CanStartWithFullStart",
                "p1.Capablity.CanStartWithStartRecommended",
                "p1.Capablity.CanStartWithStopOptionalAndRunnable",
                "p1.Capablity.CanStartWithFullStop",
                "p1.DisabledReason",
                "p1.RunningStatus",
                "p1.ConfigOriginalStatus",
                "p1.WantedConfigSolvedStatus",
                "p1.FinalConfigSolvedStatus" }, propertyChanged );
            propertyChanged.Clear();

            config.Items.Add( p1.FullName, ConfigurationStatus.Optional );

            CollectionAssert.AreEquivalent( new string[]{
                "p1.Capablity.CanStart",
                "p1.Capablity.CanStartWithFullStart",
                "p1.Capablity.CanStartWithStartRecommended",
                "p1.Capablity.CanStartWithStopOptionalAndRunnable",
                "p1.Capablity.CanStartWithFullStop",
                "p1.DisabledReason",
                "p1.RunningStatus",
                "p1.ConfigOriginalStatus",
                "p1.WantedConfigSolvedStatus",
                "p1.FinalConfigSolvedStatus" }, propertyChanged );
        }
Beispiel #35
0
 public static void CheckPluginsRunning(this YodiiEngine @this, string pluginOrServiceNames)
 {
     CheckPluginsStatus(@this, RunningStatus.Running, pluginOrServiceNames, true);
 }
Beispiel #36
0
 public static void CheckAllServicesRunningLocked(this YodiiEngine @this, string pluginOrServiceNames)
 {
     CheckServicesStatus(@this, RunningStatus.RunningLocked, pluginOrServiceNames, false);
 }
Beispiel #37
0
        public static void FullStaticResolutionOnly(this YodiiEngine @this, Action <IYodiiEngineStaticOnlyResult> tests, [CallerMemberName] string callerName = null)
        {
            IActivityMonitor m = TestHelper.ConsoleMonitor;

            IYodiiEngineStaticOnlyResult[] result = new IYodiiEngineStaticOnlyResult[4];

            using (m.OpenInfo().Send("FullStaticResolutionOnly for {0}.", callerName))
            {
                using (m.OpenInfo().Send("StaticResolutionOnly()."))
                {
                    result[0] = @this.StaticResolutionOnly(false, false);
                    result[0].Trace(m);
                }
                using (m.OpenInfo().Send("StaticResolutionOnly( revertServices )."))
                {
                    result[1] = @this.StaticResolutionOnly(true, false);
                    result[1].Trace(m);
                }
                using (m.OpenInfo().Send("StaticResolutionOnly( revertPlugins )."))
                {
                    result[2] = @this.StaticResolutionOnly(false, true);
                    result[2].Trace(m);
                }
                using (m.OpenInfo().Send("StaticResolutionOnly( revertServices, revertPlugins )."))
                {
                    result[3] = @this.StaticResolutionOnly(true, true);
                    result[3].Trace(m);
                }
                int comparingErrorCount   = 0;
                int comparingWarningCount = 0;
                using (m.CatchCounter((f, e, w) => { comparingErrorCount = f + e; comparingWarningCount = w; }))
                    using (m.OpenInfo().Send("Comparing results."))
                    {
                        if (result[0].Success)
                        {
                            if (!result[1].Success)
                            {
                                m.Error().Send("revertServices has failed.");
                            }
                            if (!result[2].Success)
                            {
                                m.Error().Send("revertPlugins has failed.");
                            }
                            if (!result[3].Success)
                            {
                                m.Error().Send("revertPlugins & revertServices has failed.");
                            }
                        }
                        else
                        {
                            var refItems = String.Join(", ", result[0].StaticFailureResult.BlockingItems.Select(i => i.FullName).OrderBy(Util.FuncIdentity));
                            if (result[1].Success)
                            {
                                m.Error().Send("revertServices succeeded.");
                            }
                            else
                            {
                                var items = String.Join(", ", result[1].StaticFailureResult.BlockingItems.Select(i => i.FullName).OrderBy(Util.FuncIdentity));
                                if (items != refItems)
                                {
                                    m.Warn().Send("revertServices found blocking items: '{1}' where default found: {0}.", refItems, items);
                                }
                            }
                            if (result[2].Success)
                            {
                                m.Error().Send("revertPlugins succeeded.");
                            }
                            else
                            {
                                var items = String.Join(", ", result[2].StaticFailureResult.BlockingItems.Select(i => i.FullName).OrderBy(Util.FuncIdentity));
                                if (items != refItems)
                                {
                                    m.Warn().Send("revertServices found blocking items: '{1}' where default found: {0}.", refItems, items);
                                }
                            }
                            if (result[3].Success)
                            {
                                m.Error().Send("revertPlugins & revertServices succeeded.");
                            }
                            else
                            {
                                var items = String.Join(", ", result[3].StaticFailureResult.BlockingItems.Select(i => i.FullName).OrderBy(Util.FuncIdentity));
                                if (items != refItems)
                                {
                                    m.Warn().Send("revertPlugins & revertServices found blocking items: '{1}' where default found: {0}.", refItems, items);
                                }
                            }
                        }
                    }
                using (m.OpenInfo().Send("Executing tests predicates."))
                {
                    tests(result[0]);
                    tests(result[1]);
                    tests(result[2]);
                    tests(result[3]);
                }
                if (comparingErrorCount == 0)
                {
                    if (comparingWarningCount == 0)
                    {
                        m.CloseGroup("No difference between plugin/service ordering.");
                    }
                    else
                    {
                        m.CloseGroup("Plugin/service ordering leads to different blocking detection. See logs for details.");
                    }
                }
                else
                {
                    Assert.Fail("Plugin/service ordering leads to different result! (See logs for details.)");
                }
            }
        }
Beispiel #38
0
 internal LivePluginInfo( PluginData p, YodiiEngine engine )
     : base(engine, p, p.PluginInfo.PluginFullName)
 {
     _pluginInfo = p.PluginInfo;
 }
        internal static YodiiEngine CreateValidOptionalReferences()
        {
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( MockInfoFactory.CreateGraph005e() );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "Service1", ConfigurationStatus.Running );

            return engine;
        }
Beispiel #40
0
        public void LayerAddPrecedenceTest()
        {
            var engine = new YodiiEngine(new YodiiEngineHostMock());
            IConfigurationLayer layer = engine.Configuration.Layers.Create("TestConfig");

            IYodiiEngineResult result;

            // Precedence test for Disabled
            string pluginId = Guid.NewGuid().ToString();

            result = layer.Items.Add(pluginId, ConfigurationStatus.Disabled);
            Assert.That(result.Success, Is.True);
            Assert.That(layer.Items[pluginId].Status == ConfigurationStatus.Disabled);

            result = layer.Items.Add(pluginId, ConfigurationStatus.Disabled);
            Assert.That(result.Success, Is.True, "Adding the same plugin twice, in the same state, is a valid operation.");
            Assert.That(layer.Items.Count == 1, "Adding the same plugin twice, in the same state, does not actually add it and increment the count.");

            result = layer.Items.Add(pluginId, ConfigurationStatus.Optional);
            Assert.That(result.Success, Is.True);
            result = layer.Items.Add(pluginId, ConfigurationStatus.Runnable);
            Assert.That(result.Success, Is.True);
            result = layer.Items.Add(pluginId, ConfigurationStatus.Running);
            Assert.That(result.Success, Is.True);

            result = layer.Items.Add(pluginId, ConfigurationStatus.Disabled);
            Assert.That(result.Success, Is.True);

            result = layer.Items.Remove(pluginId);
            Assert.That(result.Success, Is.True, "Plugin can always be removed if it exists and layer isn't bound to a parent.");

            // Precedence test for Running
            pluginId = Guid.NewGuid().ToString();

            result = layer.Items.Add(pluginId, ConfigurationStatus.Running);
            Assert.That(result.Success, Is.True);
            Assert.That(layer.Items[pluginId].Status == ConfigurationStatus.Running);

            result = layer.Items.Add(pluginId, ConfigurationStatus.Running);
            Assert.That(result.Success, Is.True, "Adding the same plugin twice, in the same state, is a valid operation.");
            Assert.That(layer.Items.Count == 1, "Adding the same plugin twice, in the same state, does not actually add it and increment the count.");

            result = layer.Items.Add(pluginId, ConfigurationStatus.Optional);
            Assert.That(result.Success, Is.True);
            result = layer.Items.Add(pluginId, ConfigurationStatus.Runnable);
            Assert.That(result.Success, Is.True);
            result = layer.Items.Add(pluginId, ConfigurationStatus.Disabled);
            Assert.That(result.Success, Is.True);

            result = layer.Items.Remove(pluginId);
            Assert.That(result.Success, Is.True, "Plugin can always be removed if it exists and layer isn't bound to a parent.");

            // Precedence test for Optional -> Runnable -> Running
            pluginId = Guid.NewGuid().ToString();

            result = layer.Items.Add(pluginId, ConfigurationStatus.Optional);
            Assert.That(result.Success, Is.True);
            Assert.That(layer.Items[pluginId].Status == ConfigurationStatus.Optional);

            result = layer.Items.Add(pluginId, ConfigurationStatus.Optional);
            Assert.That(result.Success, Is.True, "Adding the same plugin twice, in the same state, is a valid operation.");
            Assert.That(layer.Items.Count == 1, "Adding the same plugin twice, in the same state, does not actually add it and increment the count.");

            result = layer.Items.Add(pluginId, ConfigurationStatus.Runnable);
            Assert.That(result.Success, Is.True, "Layer override precedence: Optional -> Runnable is a valid operation.");
            Assert.That(layer.Items[pluginId].Status == ConfigurationStatus.Runnable);

            result = layer.Items.Add(pluginId, ConfigurationStatus.Running);
            Assert.That(result.Success, Is.True, "Layer override precedence: Runnable -> Running is a valid operation.");
            Assert.That(layer.Items[pluginId].Status == ConfigurationStatus.Running);

            Assert.That(layer.Items.Count == 1, "Adding the same plugin over and over does not actually increment the count.");

            result = layer.Items.Remove(pluginId);
            Assert.That(result.Success, Is.True, "Plugin can always be removed if it exists and layer isn't bound to a parent.");
        }
Beispiel #41
0
        /// <summary>
        /// Creates a new instance of this LabStateManager, as well as a new IYodiiEngine.
        /// </summary>
        internal LabStateManager()
        {
            YodiiEngine engine = new YodiiEngine( this );
            _engine = engine;

            Debug.Assert( _engine.LiveInfo != null );
            _engine.PropertyChanged += _engine_PropertyChanged;
            _engine.LiveInfo.Plugins.CollectionChanged += Plugins_CollectionChanged;
            _engine.LiveInfo.Services.CollectionChanged += Services_CollectionChanged;

            Debug.Assert( _engine.IsRunning == false );

            _serviceInfos = new CKObservableSortedArrayKeyList<ServiceInfo, string>( s => s.ServiceFullName, false );
            _pluginInfos = new CKObservableSortedArrayKeyList<PluginInfo, string>( p => p.PluginFullName, false );

            _labServiceInfos = new CKObservableSortedArrayKeyList<LabServiceInfo, ServiceInfo>( s => s.ServiceInfo, ( x, y ) => String.CompareOrdinal( x.ServiceFullName, y.ServiceFullName ), false );
            _labPluginInfos = new CKObservableSortedArrayKeyList<LabPluginInfo, PluginInfo>( p => p.PluginInfo, ( x, y ) => String.CompareOrdinal( x.PluginFullName, y.PluginFullName ), false );

            _runningPlugins = new ObservableCollection<IPluginInfo>();

            _serviceInfos.CollectionChanged += _serviceInfos_CollectionChanged;
            _pluginInfos.CollectionChanged += _pluginInfos_CollectionChanged;

            UpdateEngineInfos();
        }
 internal ConfigurationManager( YodiiEngine engine )
 {
     Engine = engine;
     _configurationLayerCollection = new ConfigurationLayerCollection( this );
     _finalConfiguration = new FinalConfiguration();
 }
 internal static Tuple<IYodiiEngineStaticOnlyResult, ConfigurationSolver> CreateAndApplyStaticResolution( YodiiEngine engine, FinalConfiguration finalConfiguration, IDiscoveredInfo discoveredInfo, bool revertServices, bool revertPlugins, bool createStaticSolvedConfigOnSuccess )
 {
     ConfigurationSolver temporarySolver = new ConfigurationSolver(  engine,revertServices, revertPlugins );
     IYodiiEngineStaticOnlyResult result =  temporarySolver.StaticResolution( finalConfiguration, discoveredInfo, createStaticSolvedConfigOnSuccess );
     // StaticResolution returns null on success.
     // If there is a result, it is either an error or createStaticSolvedConfigOnSuccess is true and this is a StaticResolutionOnly: in both
     // case we do not need to keep the temporary solver.
     if( result != null ) temporarySolver = null;
     return Tuple.Create( result, temporarySolver );
 }
Beispiel #44
0
 internal LiveServiceInfo( ServiceData s, YodiiEngine engine )
     : base(engine, s, s.ServiceInfo.ServiceFullName)
 {
     _serviceInfo = s.ServiceInfo;
 }
Beispiel #45
0
 public static void CheckRunningLocked(this YodiiEngine @this, string pluginOrServiceNames)
 {
     CheckStatus(@this, RunningStatus.RunningLocked, pluginOrServiceNames, true);
 }
        /// <summary>
        /// Configuration failure constructor.
        /// </summary>
        internal YodiiEngineResult( IConfigurationFailureResult configurationFailureResult, YodiiEngine engine )
        {
            Debug.Assert( configurationFailureResult.FailureReasons != null && configurationFailureResult.FailureReasons.Count > 0 );

            _engine = engine;
            _configurationFailureResult = configurationFailureResult;
        }
        internal static YodiiEngine CreateInvalidRunnableRecommendedReference()
        {
            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( MockInfoFactory.CreateGraph008() );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "Plugin1", ConfigurationStatus.Runnable );
            cl.Items.Add( "Plugin3", ConfigurationStatus.Disabled );
            cl.Items.Add( "Plugin4", ConfigurationStatus.Running );
            cl.Items.Add( "Plugin6", ConfigurationStatus.Disabled );
            cl.Items.Add( "Plugin8", ConfigurationStatus.Runnable );
            cl.Items.Add( "Plugin9", ConfigurationStatus.Disabled );
            cl.Items.Add( "Plugin10", ConfigurationStatus.Runnable );
            cl.Items.Add( "Plugin14", ConfigurationStatus.Disabled );
            cl.Items.Add( "Plugin17", ConfigurationStatus.Running );
            cl.Items.Add( "Plugin19", ConfigurationStatus.Runnable );
            cl.Items.Add( "Plugin20", ConfigurationStatus.Runnable );
            cl.Items.Add( "Plugin24", ConfigurationStatus.Disabled );

            cl.Items.Add( "Service2", ConfigurationStatus.Disabled );
            cl.Items.Add( "Service2.1", ConfigurationStatus.Running );
            cl.Items.Add( "Service1.1", ConfigurationStatus.Running );
            cl.Items.Add( "Service1.2", ConfigurationStatus.Runnable );
            cl.Items.Add( "Service1.1.2", ConfigurationStatus.Runnable );
            cl.Items.Add( "Service1.1.3", ConfigurationStatus.Runnable );

            return engine;
        }
        public void Invalid004b()
        {
            #region graph
            /**
             *  +--------+
             *  |ServiceA+ ------+
             *  |Running |       |
             *  +---+----+       |
             *      |            |
             *      |            |
             *      |            |
             *      |         +---+------+
             *  +---+------+  |ServiceAx2|
             *  |ServiceAx1|  |Running   |
             *  |Running   |  +----------+
             *  +----------+      |
             *      |             |
             *      |             |
             *      |             |
             *      |          +---+-------+
             *  +---+-------+  |PluginAx2-1|
             *  |PluginAx1-1|  |Optional   |
             *  |Optional   |  +-----------+
             *  +-----------+
             */
            #endregion

            YodiiEngine engine = new YodiiEngine( new YodiiEngineHostMock() );
            engine.SetDiscoveredInfo( MockInfoFactory.CreateGraph004() );

            IConfigurationLayer cl = engine.Configuration.Layers.Create();
            cl.Items.Add( "ServiceA", ConfigurationStatus.Running );
            cl.Items.Add( "ServiceAx1", ConfigurationStatus.Running );
            cl.Items.Add( "ServiceAx2", ConfigurationStatus.Running );

            engine.FullStaticResolutionOnly( res =>
               {
                   res.CheckAllBlockingServicesAre( "ServiceA,ServiceAx1,ServiceAx2" );
               } );
        }
        public void LayerCreationTest()
        {
            YodiiEngine e = new YodiiEngine( new YodiiEngineHostMock() );

            IConfigurationLayer layer = e.Configuration.Layers.Create( "TestConfig" );
            Assert.That( layer.Items.Count == 0 );
            Assert.That( layer.LayerName == "TestConfig" );

            string pluginIdentifier;
            IYodiiEngineResult result;

            // Add a random plugin GUID
            pluginIdentifier = Guid.NewGuid().ToString();
            result = layer.Items.Add( pluginIdentifier, ConfigurationStatus.Disabled );
            Assert.That( result.Success, Is.True );
            Assert.That( layer.Items.Count == 1 );
            Assert.That( layer.Items[pluginIdentifier], Is.InstanceOf<ConfigurationItem>() );

            // Add another random plugin GUID
            pluginIdentifier = Guid.NewGuid().ToString();
            result = layer.Items.Add( pluginIdentifier, ConfigurationStatus.Runnable );
            Assert.That( result.Success, Is.True );
            Assert.That( layer.Items.Count == 2 );
            Assert.That( layer.Items[pluginIdentifier], Is.InstanceOf<ConfigurationItem>() );

            // Remove last plugin GUID
            result = layer.Items.Remove( pluginIdentifier );
            Assert.That( result.Success, Is.True );
            Assert.That( layer.Items.Count == 1 );

            // Add some service
            pluginIdentifier = "Yodii.ManagerService";
            result = layer.Items.Add( pluginIdentifier, ConfigurationStatus.Runnable );
            Assert.That( result.Success, Is.True );
            Assert.That( layer.Items.Count == 2 );
            Assert.That( layer.Items[pluginIdentifier], Is.InstanceOf<ConfigurationItem>() );
        }