Пример #1
0
        public IActionResult CreateReRoute(string id, FileReRouteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var validator = new FileReRouteValidator();
            var results   = validator.Validate(model.FileReRoute);

            if (!results.IsValid)
            {
                results.Errors.ToList().ForEach(e => ModelState.AddModelError($"FileReRoute.{e.PropertyName}", e.ErrorMessage));
                return(View(model));
            }

            var routes = _fileConfigRepo.Get().GetAwaiter().GetResult();

            routes.Data.ReRoutes.Add(model.FileReRoute);
            _fileConfigRepo.Set(routes.Data);

            _reload.AddReloadFlag();

            return(RedirectToAction("Index"));
        }
        public IActionResult DeleteReRoute(string id)
        {
            var routes = _fileConfigRepo.Get();
            var route  = routes.Data.ReRoutes.FirstOrDefault(r => id == r.GetId());

            if (route == null)
            {
                return(RedirectToAction("Index"));
            }

            routes.Data.ReRoutes.Remove(route);
            _fileConfigRepo.Set(routes.Data);

            Reload(routes.Data);

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public async Task HandleEventAsync(UpdateFileConfigurationEventEventData eventData)
        {
            Name = eventData.Name;
            if (eventData.Name == _option.GatewayName)
            {
                var config = await _abpFileConfigurationRepository.GetFileConfiguration(eventData.Name);

                await _fileConfigurationRepository.Set(config);
            }
        }
Пример #4
0
        public async Task <IActionResult> CreateReRoute(string id, FileReRouteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var results = ValidateModel(model);

            if (!results.IsValid)
            {
                results.Errors.ToList().ForEach(e => ModelState.AddModelError($"FileReRoute.{e.PropertyName}", e.ErrorMessage));
                return(View(model));
            }

            var routes = await _fileConfigRepo.Get();

            routes.Data.ReRoutes.Add(model.FileReRoute);
            await _fileConfigRepo.Set(routes.Data);

            await _reload.AddReloadFlag();

            return(RedirectToAction("Index"));
        }
Пример #5
0
        private static async Task SetFileConfigInConsul(IApplicationBuilder builder,
                                                        IFileConfigurationRepository fileConfigRepo, IOptions <FileConfiguration> fileConfig,
                                                        IInternalConfigurationCreator internalConfigCreator, IInternalConfigurationRepository internalConfigRepo)
        {
            // get the config from consul.
            var fileConfigFromConsul = await fileConfigRepo.Get();

            if (IsError(fileConfigFromConsul))
            {
                ThrowToStopOcelotStarting(fileConfigFromConsul);
            }
            else if (ConfigNotStoredInConsul(fileConfigFromConsul))
            {
                //there was no config in consul set the file in config in consul
                await fileConfigRepo.Set(fileConfig.Value);
            }
            else
            {
                // create the internal config from consul data
                var internalConfig = await internalConfigCreator.Create(fileConfigFromConsul.Data);

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
                else
                {
                    // add the internal config to the internal repo
                    var response = internalConfigRepo.AddOrReplace(internalConfig.Data);

                    if (IsError(response))
                    {
                        ThrowToStopOcelotStarting(response);
                    }
                }

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
            }

            //todo - this starts the poller if it has been registered...please this is so bad.
            var hack = builder.ApplicationServices.GetService(typeof(ConsulFileConfigurationPoller));
        }
Пример #6
0
        public async Task HandleEventAsync(UpdateFileConfigurationEventEventData eventData)
        {
            Name = eventData.Name;
            if (eventData.Name == _option.GatewayName)
            {
                _logger.LogInformation($"gateway name: {eventData.Name} reload sucess.");
                var fileConfiguration = await _abpFileConfigurationRepository.GetFileConfiguration(eventData.Name);

                var config = await _internalConfigCreator.Create(fileConfiguration);

                if (!config.IsError)
                {
                    _internalConfigRepo.AddOrReplace(config.Data);
                }

                await _fileConfigurationRepository.Set(fileConfiguration);
            }
        }
Пример #7
0
        public async Task <Response> Set(FileConfiguration fileConfig)
        {
            var response = await _repo.Set(fileConfig);

            if (response.IsError)
            {
                return(new ErrorResponse(response.Errors));
            }

            var config = await _configCreator.Create(fileConfig);

            if (!config.IsError)
            {
                internalConfigRepo.AddOrReplace(config.Data);
            }

            return(new ErrorResponse(config.Errors));
        }
        private static async Task SetFileConfigInDataBase(IApplicationBuilder builder,
                                                          IFileConfigurationRepository fileConfigRepo, IOptionsMonitor <FileConfiguration> fileConfig,
                                                          IInternalConfigurationCreator internalConfigCreator, IInternalConfigurationRepository internalConfigRepo)
        {
            // get the config from consul.
            var fileConfigFromDataBase = await fileConfigRepo.Get();

            if (IsError(fileConfigFromDataBase))
            {
                ThrowToStopOcelotStarting(fileConfigFromDataBase);
            }
            //else if (ConfigNotStoredInDataBase(fileConfigFromDataBase))
            //{
            //    //there was no config in consul set the file in config in consul
            //    await fileConfigRepo.Set(fileConfig.CurrentValue);
            //}
            else
            {
                await fileConfigRepo.Set(fileConfigFromDataBase.Data);

                // create the internal config from consul data
                var internalConfig = await internalConfigCreator.Create(fileConfigFromDataBase.Data);

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
                else
                {
                    // add the internal config to the internal repo
                    var response = internalConfigRepo.AddOrReplace(internalConfig.Data);

                    if (IsError(response))
                    {
                        ThrowToStopOcelotStarting(response);
                    }
                }

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// 设置存储配置信息
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="fileConfigRepo"></param>
        /// <param name="internalConfigCreator"></param>
        /// <param name="internalConfigRepo"></param>
        /// <returns></returns>
        private static async Task SetFileConfigInDataBase(IApplicationBuilder builder,
                                                          IFileConfigurationRepository fileConfigRepo,
                                                          IInternalConfigurationCreator internalConfigCreator, IInternalConfigurationRepository internalConfigRepo)
        {
            // 从redis中获取数据
            var fileConfigFromDataBase = await fileConfigRepo.Get();

            if (IsError(fileConfigFromDataBase))
            {
                ThrowToStopOcelotStarting(fileConfigFromDataBase);
            }
            else
            {
                //设置存储
                await fileConfigRepo.Set(fileConfigFromDataBase.Data);

                // create the internal config from consul data
                var internalConfig = await internalConfigCreator.Create(fileConfigFromDataBase.Data);

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
                else
                {
                    //
                    var response = internalConfigRepo.AddOrReplace(internalConfig.Data);

                    if (IsError(response))
                    {
                        ThrowToStopOcelotStarting(response);
                    }
                }

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
            }
        }
        private static async Task SetFileConfigInSqlServer(IApplicationBuilder builder,
                                                           IFileConfigurationRepository fileConfigRepo, IOptionsMonitor <FileConfiguration> fileConfig,
                                                           IInternalConfigurationCreator internalConfigCreator, IInternalConfigurationRepository internalConfigRepo)
        {
            var fileConfigFromSqlServer = await fileConfigRepo.Get();

            if (IsError(fileConfigFromSqlServer))
            {
                ThrowToStopOcelotStarting(fileConfigFromSqlServer);
            }
            else if (ConfigNotStoredInConsul(fileConfigFromSqlServer))
            {
                await fileConfigRepo.Set(fileConfig.CurrentValue);
            }
            else
            {
                var internalConfig = await internalConfigCreator.Create(fileConfigFromSqlServer.Data);

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
                else
                {
                    var response = internalConfigRepo.AddOrReplace(internalConfig.Data);

                    if (IsError(response))
                    {
                        ThrowToStopOcelotStarting(response);
                    }
                }

                if (IsError(internalConfig))
                {
                    ThrowToStopOcelotStarting(internalConfig);
                }
            }
        }
Пример #11
0
 private void WhenISetTheConfiguration()
 {
     _repo.Set(_fileConfiguration);
     _result = _repo.Get().Data;
 }