Пример #1
0
        private async Task ConvergeConfiguration(KongvergeConfiguration existingConfiguration, KongvergeConfiguration targetConfiguration)
        {
            async Task DeleteService(KongService service)
            {
                await _kongWriter.DeleteService(service.Id);

                _deletedStats.Increment <KongRoute>(service.Routes.Count);
                _deletedStats.Increment <KongPlugin>(service.Plugins.Count + service.Routes.Sum(x => x.Plugins.Count));
            }

            _createdStats = new OperationStats();
            _updatedStats = new OperationStats();
            _deletedStats = new OperationStats();

            await ConvergeChildrenPlugins(null, existingConfiguration.GlobalConfig, targetConfiguration.GlobalConfig);

            await ConvergeObjects(
                null,
                KongService.ObjectName,
                existingConfiguration.Services,
                targetConfiguration.Services,
                DeleteService,
                x => _kongWriter.AddService(x),
                x => _kongWriter.UpdateService(x),
                ConvergeServiceChildren);

            Log.Information($"Created {_createdStats}");
            Log.Information($"Updated {_updatedStats}");
            Log.Information($"Deleted {_deletedStats}");
            if (_updatedStats.Any())
            {
                Log.Verbose("See https://github.com/benjamine/jsondiffpatch/blob/master/docs/deltas.md for delta format");
            }
        }
Пример #2
0
        private async Task ConvergeConfiguration(KongvergeConfiguration existingConfiguration, KongvergeConfiguration targetConfiguration)
        {
            async Task DeleteService(KongService service)
            {
                await _kongWriter.DeleteService(service.Id);

                _deletedStats.Increment <KongRoute>(service.Routes.Count);
                _deletedStats.Increment <KongPlugin>(service.Plugins.Count + service.Routes.Sum(x => x.Plugins.Count));
            }

            _createdStats = new OperationStats();
            _updatedStats = new OperationStats();
            _deletedStats = new OperationStats();

            await ConvergeChildrenPlugins(null, existingConfiguration.GlobalConfig, targetConfiguration.GlobalConfig);

            await ConvergeObjects(
                null,
                KongService.ObjectName,
                existingConfiguration.Services,
                targetConfiguration.Services,
                DeleteService,
                x => _kongWriter.AddService(x),
                x => _kongWriter.UpdateService(x),
                ConvergeServiceChildren);

            Log.Information($"Created {_createdStats}");
            Log.Information($"Updated {_updatedStats}");
            Log.Information($"Deleted {_deletedStats}");
        }
Пример #3
0
        public override async Task <int> DoExecute()
        {
            KongvergeConfiguration targetConfiguration;

            try
            {
                targetConfiguration = await _configReader.ReadConfiguration(Configuration.InputFolder);
            }
            catch (DirectoryNotFoundException ex)
            {
                return(ExitWithCode.Return(ExitCode.InputFolderUnreachable, ex.Message));
            }
            catch (InvalidConfigurationFileException ex)
            {
                return(ExitWithCode.Return(ExitCode.InvalidConfigurationFile, $"Invalid configuration file {ex.Path}{Environment.NewLine}{ex.Message}"));
            }

            var existingConfiguration = await _configBuilder.FromKong(KongReader);

            _createdStats = new OperationStats();
            _updatedStats = new OperationStats();
            _deletedStats = new OperationStats();

            await ConvergeChildrenPlugins(null, existingConfiguration.GlobalConfig, targetConfiguration.GlobalConfig);

            await ConvergeObjects(
                null,
                KongService.ObjectName,
                existingConfiguration.Services,
                targetConfiguration.Services,
                x => _kongWriter.DeleteService(x.Id),
                x => _kongWriter.AddService(x),
                x => _kongWriter.UpdateService(x),
                ConvergeServiceChildren);

            Log.Information($"Created {_createdStats}");
            Log.Information($"Updated {_updatedStats}");
            Log.Information($"Deleted {_deletedStats}");

            return(ExitWithCode.Return(ExitCode.Success));
        }