Example #1
0
 /// <summary>
 /// Creates a new instance of ConfigurationChangingEventArgs for a <see cref="IConfigurationLayerCollection.Clear"/>.
 /// </summary>
 /// <param name="finalConfiguration">New empty FinalConfiguration. Must be empty otherwise an exception is thrown.</param>
 public ConfigurationChangingEventArgs(FinalConfiguration finalConfiguration)
 {
     if (finalConfiguration == null || finalConfiguration.Items.Count > 0)
     {
         throw new ArgumentException("Must be not null and empty.", "finalConfiguration");
     }
     _finalConfiguration       = finalConfiguration;
     _finalConfigurationChange = FinalConfigurationChange.Cleared;
 }
 internal ConfigurationManager( YodiiEngine engine )
 {
     Engine = engine;
     _configurationLayerCollection = new ConfigurationLayerCollection( this );
     _finalConfiguration = new FinalConfiguration();
 }
 IYodiiEngineResult OnConfigurationChanging( Dictionary<string, FinalConfigurationItem> final, Func<FinalConfiguration, ConfigurationChangingEventArgs> createChangingEvent )
 {
     FinalConfiguration finalConfiguration = new FinalConfiguration( final );
     if( Engine.IsRunning )
     {
         Tuple<IYodiiEngineStaticOnlyResult,ConfigurationSolver> t = Engine.StaticResolutionByConfigurationManager( finalConfiguration );
         if( t.Item1 != null )
         {
             Debug.Assert( !t.Item1.Success );
             Debug.Assert( t.Item1.Engine == Engine );
             return t.Item1;
         }
         return OnConfigurationChangingForExternalWorld( createChangingEvent( finalConfiguration ) ) ?? Engine.OnConfigurationChanging( t.Item2 );
     }
     return OnConfigurationChangingForExternalWorld( createChangingEvent( finalConfiguration ) ) ?? Engine.SuccessResult;
 }
Example #4
0
 /// <summary>
 /// Creates a new instance of ConfigurationChangingEventArgs when change is triggered by a ConfigurationItem.
 /// </summary>
 /// <param name="finalConfiguration">New FinalConfiguration</param>
 /// <param name="finalConfigurationChanged">Details of changes in the new FinalConfiguration</param>
 /// <param name="configurationItem">Item that provoked this change</param>
 public ConfigurationChangingEventArgs(FinalConfiguration finalConfiguration, FinalConfigurationChange finalConfigurationChanged, IConfigurationItem configurationItem)
 {
     _finalConfiguration       = finalConfiguration;
     _finalConfigurationChange = finalConfigurationChanged;
     _configurationItemChanged = configurationItem;
 }
Example #5
0
 /// <summary>
 /// Creates a new instance of ConfigurationChangingEventArgs when change is triggered by a ConfigurationLayer.
 /// </summary>
 /// <param name="finalConfiguration">New FinalConfiguration</param>
 /// <param name="finalConfigurationChanged">Details of changes in the new FinalConfiguration</param>
 /// <param name="configurationLayer">Layer that provoked this change</param>
 public ConfigurationChangingEventArgs(FinalConfiguration finalConfiguration, FinalConfigurationChange finalConfigurationChanged, IConfigurationLayer configurationLayer)
 {
     _finalConfiguration        = finalConfiguration;
     _finalConfigurationChange  = finalConfigurationChanged;
     _configurationLayerChanged = configurationLayer;
 }
        ServiceData RegisterService( FinalConfiguration finalConfig, IServiceInfo s )
        {
            ServiceData data;
            if( _services.TryGetValue( s.ServiceFullName, out data ) ) return data;

            //Set default status
            ConfigurationStatus serviceStatus = finalConfig.GetStatus( s.ServiceFullName );
            // Handle generalization.
            ServiceData dataGen = null;
            if( s.Generalization != null )
            {
                dataGen = RegisterService( finalConfig, s.Generalization );
            }
            Debug.Assert( (s.Generalization == null) == (dataGen == null) );
            if( dataGen == null )
            {
                data = new ServiceData( this, s, serviceStatus );
                _serviceFamilies.Add( data.Family );
            }
            else
            {
                data = new ServiceData( s, dataGen, serviceStatus );
            }
            _services.Add( s.ServiceFullName, data );
            return data;
        }
        IYodiiEngineStaticOnlyResult StaticResolution( FinalConfiguration finalConfig, IDiscoveredInfo info, bool createStaticSolvedConfigOnSuccess )
        {
            // Registering all Services.
            Step = Engine.ConfigurationSolverStep.RegisterServices;
            {
                // In order to be deterministic, works on an ordered list of IServiceInfo to build the graph.
                List<IServiceInfo> orderedServicesInfo = info.ServiceInfos.Where( s => s != null && !String.IsNullOrWhiteSpace( s.ServiceFullName ) ).OrderBy( s => s.ServiceFullName ).ToList();
                if( _revertServicesOrder ) orderedServicesInfo.Reverse();
                foreach( IServiceInfo sI in orderedServicesInfo )
                {
                    // This creates services and applies solved configuration to them: directly disabled services
                    // and specializations disabled by their generalizations' configuration are handled.
                    RegisterService( finalConfig, sI );
                }
                _orderedServices = orderedServicesInfo.Select( s => _services[s.ServiceFullName] ).ToArray();
            }

            // Service trees have been built.
            // We can now instantiate plugin data.
            Step = Engine.ConfigurationSolverStep.RegisterPlugins;
            {
                // In order to be deterministic, works on an ordered list of IPluginInfo to build the graph.
                List<IPluginInfo> orderedPluginsInfo = info.PluginInfos.Where( p => p != null ).OrderBy( p => p.PluginFullName ).ToList();
                if( _revertPluginsOrder ) orderedPluginsInfo.Reverse();
                foreach( IPluginInfo p in orderedPluginsInfo )
                {
                    RegisterPlugin( finalConfig, p );
                }
                _orderedPlugins = orderedPluginsInfo.Select( p => _plugins[p.PluginFullName] ).ToArray();
            }
            // All possible plugins are registered. Services without any available plugins are de facto disabled.
            // Propagation for each service is deferred.
            Step = Engine.ConfigurationSolverStep.OnAllPluginsAdded;
            {
                foreach( var f in _serviceFamilies )
                {
                    f.OnAllPluginsAdded();
                }
                ProcessDeferredPropagations();
            }

            // Now, we apply ServiceReference Running constraints from every plugins to their referenced services.
            Step = ConfigurationSolverStep.PropagatePluginStatus;
            {
                foreach( PluginData p in _orderedPlugins )
                {
                    if( p.FinalConfigSolvedStatus == SolvedConfigurationStatus.Running )
                    {
                        p.PropagateRunningStatus();
                    }
                }
                ProcessDeferredPropagations();
            }

            // Finalizes static resolution by computing final Runnable statuses per impact for Optional and Runnable plugins or services.
            Step = ConfigurationSolverStep.InitializeFinalStartableStatus;
            {
                foreach( ServiceData s in _orderedServices ) s.InitializeFinalStartableStatus();
                foreach( PluginData p in _orderedPlugins ) p.InitializeFinalStartableStatus();
            }

            List<PluginData> blockingPlugins = null;
            List<ServiceData> blockingServices = null;
            Step = ConfigurationSolverStep.BlockingDetection;
            {
                // Time to conclude about configuration and to initialize dynamic resolution.
                // Any Plugin that has a ConfigOriginalStatus greater or equal to Runnable and is Disabled leads to an impossible configuration.
                foreach( PluginData p in _orderedPlugins )
                {
                    if( p.Disabled )
                    {
                        if( p.ConfigOriginalStatus >= ConfigurationStatus.Runnable )
                        {
                            if( blockingPlugins == null ) blockingPlugins = new List<PluginData>();
                            blockingPlugins.Add( p );
                        }
                    }
                }

                // Any Service that has a ConfigOriginalStatus greater or equal to Runnable and is Disabled leads to an impossible configuration.
                foreach( ServiceData s in _orderedServices )
                {
                    if( s.Disabled )
                    {
                        if( s.ConfigOriginalStatus >= ConfigurationStatus.Runnable )
                        {
                            if( blockingServices == null ) blockingServices = new List<ServiceData>();
                            blockingServices.Add( s );
                        }
                    }
                }
            }
            if( blockingPlugins != null || blockingServices != null )
            {
                Step = ConfigurationSolverStep.StaticError;
                return new YodiiEngineResult( this, blockingPlugins, blockingServices, _engine );
            }
            Step = ConfigurationSolverStep.WaitingForDynamicResolution;
            if( createStaticSolvedConfigOnSuccess )
            {
                return new YodiiEngineResult( this, _engine );
            }
            return null;
        }
        PluginData RegisterPlugin( FinalConfiguration finalConfig, IPluginInfo p )
        {
            PluginData data;
            if( _plugins.TryGetValue( p.PluginFullName, out data ) ) return data;

            ConfigurationStatus pluginStatus = finalConfig.GetStatus( p.PluginFullName );
            ServiceData service = p.Service != null ? _services[p.Service.ServiceFullName] : null;
            if( service == null ) ++_independentPluginsCount;
            data = new PluginData( this, p, service, pluginStatus );
            _plugins.Add( p.PluginFullName, data );
            return data;
        }
 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 );
 }
 /// <summary>
 /// Creates a new instance of ConfigurationChangingEventArgs when change is triggered by a ConfigurationLayer.
 /// </summary>
 /// <param name="finalConfiguration">New FinalConfiguration</param>
 /// <param name="finalConfigurationChanged">Details of changes in the new FinalConfiguration</param>
 /// <param name="configurationLayer">Layer that provoked this change</param>
 public ConfigurationChangingEventArgs( FinalConfiguration finalConfiguration, FinalConfigurationChange finalConfigurationChanged, IConfigurationLayer configurationLayer )
 {
     _finalConfiguration = finalConfiguration;
     _finalConfigurationChange = finalConfigurationChanged;
     _configurationLayerChanged = configurationLayer;
 }
 /// <summary>
 /// Creates a new instance of ConfigurationChangingEventArgs when change is triggered by a ConfigurationItem.
 /// </summary>
 /// <param name="finalConfiguration">New FinalConfiguration</param>
 /// <param name="finalConfigurationChanged">Details of changes in the new FinalConfiguration</param>
 /// <param name="configurationItem">Item that provoked this change</param>
 public ConfigurationChangingEventArgs( FinalConfiguration finalConfiguration, FinalConfigurationChange finalConfigurationChanged, IConfigurationItem configurationItem )
 {
     _finalConfiguration = finalConfiguration;
     _finalConfigurationChange = finalConfigurationChanged;
     _configurationItemChanged = configurationItem;
 }
 /// <summary>
 /// Creates a new instance of ConfigurationChangingEventArgs for a <see cref="IConfigurationLayerCollection.Clear"/>.
 /// </summary>
 /// <param name="finalConfiguration">New empty FinalConfiguration. Must be empty otherwise an exception is thrown.</param>
 public ConfigurationChangingEventArgs( FinalConfiguration finalConfiguration )
 {
     if( finalConfiguration == null || finalConfiguration.Items.Count > 0 ) throw new ArgumentException( "Must be not null and empty.", "finalConfiguration" );
     _finalConfiguration = finalConfiguration;
     _finalConfigurationChange = FinalConfigurationChange.Cleared;
 }