public async Task LoadAndGenerateAlarms(RunMode mode)
        {
            if (_hasRun)
            {
                // there is loads of state etc. and you get duplicate alarms
                // shouldn't happen in real life but I discovered it in tests
                throw new InvalidOperationException($"{nameof(LoadAndGenerateAlarms)} can only be called once");
            }

            try
            {
                _hasRun = true;
                _logger.Info($"Starting {mode}");

                var config = _configLoader.LoadConfig();
                ConfigValidator.Validate(config);

                if (mode == RunMode.GenerateAlarms || mode == RunMode.DryRun)
                {
                    await GenerateAlarms(config, mode);
                }

                if (mode == RunMode.GenerateAlarms)
                {
                    await LogOrphanedAlarms();
                }

                _logger.Detail("Done");
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in run");
                throw;
            }
        }
        public async Task <IList <ProvisioningReport> > GetReports()
        {
            try
            {
                Console.WriteLine("Starting");

                var config = _configLoader.LoadConfig();
                ConfigValidator.Validate(config);
                foreach (var alertingGroup in config.AlertingGroups)
                {
                    await _tableNamePopulator.PopulateDynamoTableNames(alertingGroup);
                }

                var groupsRequiringReports = config.AlertingGroups
                                             .Where(x => x.ReportTargets.Any());

                var provisioningReports = new List <ProvisioningReport>();
                foreach (var alertingGroup in groupsRequiringReports)
                {
                    var report = await GenerateAlertingGroupReport(alertingGroup);

                    provisioningReports.Add(report);
                }

                Console.WriteLine("Finished Reading Reports");

                return(provisioningReports);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                throw;
            }
        }
Esempio n. 3
0
 public void AddSubscriber(Building subscriber)
 {
     if (loader == null)
     {
         if (!subscribers.Contains(subscriber))
         {
             subscribers.Add(subscriber);
         }
         else
         {
             Debug.LogWarning($"BuildConfigObserver already contains subscriber: {subscriber}");
         }
     }
     else
     {
         subscriber.LoadConfig(loader.LoadConfig(subscriber.ConfigName));
     }
 }
Esempio n. 4
0
        public async Task LoadAndGenerateAlarms(RunMode mode)
        {
            try
            {
                _logger.Info($"Starting {mode}");

                var config = _configLoader.LoadConfig();
                ConfigValidator.Validate(config);

                if (mode == RunMode.GenerateAlarms || mode == RunMode.DryRun)
                {
                    await GenerateAlarms(config, mode);
                }

                _logger.Detail("Done");
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in run");
                throw;
            }
        }
Esempio n. 5
0
        public IEnumerable <IEnumerable <Configuration> > LoadConfigPhases(String rootDir, String includeGlob)
        {
            rootDir = Path.GetFullPath(rootDir);

            var matcher = new Matcher();

            matcher.AddInclude(includeGlob);
            var results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(rootDir)));

            //Load all configs and find named configs
            var noNameConfigs = new List <Configuration>();
            var namedConfigs  = new Dictionary <String, Configuration>();

            foreach (var result in results.Files)
            {
                var fullPath = Path.Combine(rootDir, result.Path);

                var config     = new Configuration(fullPath);
                var configJobj = configLoader.LoadConfig(fullPath);
                if (configJobj != null)
                {
                    using var reader = configJobj.CreateReader();
                    Newtonsoft.Json.JsonSerializer.CreateDefault().Populate(reader, config);
                }

                var name = config.Resources?.Name;
                if (name != null)
                {
                    namedConfigs.Add(name, config);
                }
                else
                {
                    noNameConfigs.Add(config);
                }
            }

            //Find all configs that have a loaded dependency
            var independentConfigs = new List <Configuration>();
            var dependentConfigs   = new Dictionary <String, List <Configuration> >();

            foreach (var config in noNameConfigs.Concat(namedConfigs.Values))
            {
                //If this config has a dependency and the dependency is loaded defer it to later.
                var dependency = config.Resources?.DependsOn;
                if (dependency != null && namedConfigs.ContainsKey(dependency))
                {
                    if (!dependentConfigs.TryGetValue(dependency, out var configs))
                    {
                        configs = new List <Configuration>();
                        dependentConfigs.Add(dependency, configs);
                    }
                    configs.Add(config);
                }
                else
                {
                    independentConfigs.Add(config);
                }
            }

            //First return all the independent configs
            yield return(independentConfigs);

            //Next walk through all the processed configs, find the dependencies and return those
            //Continue in this manner until the dependent configs have all been processed
            var processedConfigs = independentConfigs;

            while (dependentConfigs.Count > 0)
            {
                var nextConfigReturnValue = new List <Configuration>();
                foreach (var config in processedConfigs)
                {
                    var name = config.Resources.Name;
                    if (name != null && dependentConfigs.TryGetValue(name, out var items))
                    {
                        nextConfigReturnValue.AddRange(items);
                        dependentConfigs.Remove(name);
                    }
                }

                yield return(nextConfigReturnValue);

                processedConfigs = nextConfigReturnValue;
            }
        }
Esempio n. 6
0
 [Factory(Scope.SingleInstance)] ValueTask <Config> CreateConfig(IConfigLoader configLoader) => configLoader.LoadConfig();
Esempio n. 7
0
 public void Load(string path)
 {
     _data = _loader.LoadConfig <Data>(path);
 }