Ejemplo n.º 1
0
 public async Task Handle(LogEntry log)
 {
     //todo - handle an error
     //hack it to just cast as at the moment we know this is the only command :P
     var hack = (UpdateFileConfiguration)log.CommandData;
     await _setter.Set(hack.Configuration);
 }
        public async Task <IActionResult> Post([FromBody] RouteRule routeRule)
        {
            try {
                var repo = await _repo.Get();

                var fileConfiguration = repo.Data;
                var reRoute           = fileConfiguration.ReRoutes.Where(r => r.Key == routeRule.ApiGwSuffix).FirstOrDefault();
                if (reRoute == null)
                {
                    var fileReRoute = ObjectConverter.ConvertToFileReRoute(routeRule);
                    fileConfiguration.ReRoutes.Add(fileReRoute);
                    var response = await _setter.Set(fileConfiguration);

                    if (response.IsError)
                    {
                        return(new BadRequestObjectResult(response.Errors));
                    }
                }
                else
                {
                    return(new BadRequestObjectResult("Add FileReRoute Failed, Key is duplicate."));
                }

                return(new OkObjectResult("OK"));
            }
            catch (Exception e) {
                _logger.Log(LogLevel.Error, "Post Method Happen Error For RerouteController.");
                return(new BadRequestObjectResult($"{e.Message}:{e.StackTrace}"));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] FileConfiguration fileConfiguration)
        {
            //todo - this code is a bit shit sort it out..
            var test = _provider.GetService(typeof(INode));

            if (test != null)
            {
                var node   = (INode)test;
                var result = node.Accept(new UpdateFileConfiguration(fileConfiguration));
                if (result.GetType() == typeof(Rafty.Concensus.ErrorResponse <UpdateFileConfiguration>))
                {
                    return(new BadRequestObjectResult("There was a problem. This error message sucks raise an issue in GitHub."));
                }

                return(new OkObjectResult(result.Command.Configuration));
            }

            var response = await _setter.Set(fileConfiguration);

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

            return(new OkObjectResult(fileConfiguration));
        }
Ejemplo n.º 4
0
        private static async Task <Response> SetUpConfigFromConsul(IApplicationBuilder builder, IFileConfigurationRepository consulFileConfigRepo, IFileConfigurationSetter setter, IOptions <FileConfiguration> fileConfig)
        {
            Response config = null;

            var ocelotConfigurationRepository =
                (IOcelotConfigurationRepository)builder.ApplicationServices.GetService(
                    typeof(IOcelotConfigurationRepository));
            var ocelotConfigurationCreator =
                (IOcelotConfigurationCreator)builder.ApplicationServices.GetService(
                    typeof(IOcelotConfigurationCreator));

            var fileConfigFromConsul = await consulFileConfigRepo.Get();

            if (fileConfigFromConsul.Data == null)
            {
                config = await setter.Set(fileConfig.Value);
            }
            else
            {
                var ocelotConfig = await ocelotConfigurationCreator.Create(fileConfigFromConsul.Data);

                if (ocelotConfig.IsError)
                {
                    return(new ErrorResponse(ocelotConfig.Errors));
                }
                config = await ocelotConfigurationRepository.AddOrReplace(ocelotConfig.Data);

                //todo - this starts the poller if it has been registered...please this is so bad.
                var hack = builder.ApplicationServices.GetService(typeof(ConsulFileConfigurationPoller));
            }

            return(new OkResponse());
        }
Ejemplo n.º 5
0
        public void Handle(LogEntry log)
        {
            //todo - handle an error
            //hack it to just cast as at the moment we know this is the only command :P
            var hack = (UpdateFileConfiguration)log.CommandData;

            _setter.Set(hack.Configuration).GetAwaiter().GetResult();;
        }
Ejemplo n.º 6
0
        private static async Task SetFileConfig(IFileConfigurationSetter fileConfigSetter, IOptionsMonitor <FileConfiguration> fileConfig)
        {
            var response = await fileConfigSetter.Set(fileConfig.CurrentValue);

            if (IsError(response))
            {
                ThrowToStopOcelotStarting(response);
            }
        }
Ejemplo n.º 7
0
        private static async Task <Response> SetConfig(IApplicationBuilder builder, IOptions <FileConfiguration> fileConfiguration, IFileConfigurationSetter setter, IOcelotConfigurationProvider provider, IFileConfigurationRepository repo)
        {
            if (UsingConsul(repo))
            {
                return(await SetUpConfigFromConsul(builder, repo, setter, fileConfiguration));
            }

            return(await setter.Set(fileConfiguration.Value));
        }
        private static async Task SetFileConfig(IFileConfigurationSetter fileConfigSetter, FileConfiguration fileConfig)
        {
            var response = await fileConfigSetter.Set(fileConfig);

            if (IsError(response))
            {
                ThrowToStopOcelotStarting(response);
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Post([FromBody] FileConfiguration fileConfiguration)
        {
            var response = await _configSetter.Set(fileConfiguration);

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

            return(new OkObjectResult(fileConfiguration));
        }
Ejemplo n.º 10
0
        public async Task ReloadConfig()
        {
            await Task.Run(
                () =>
            {
                var config = _fileConfigRepo.Get();
                _configSetter.Set(config.Data);
            });

            await RemoveReloadFlag();
        }
        public async Task <IActionResult> Post([FromBody] FileConfiguration fileConfiguration)
        {
            try {
                var response = await _setter.Set(fileConfiguration);

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

                return(new OkObjectResult(fileConfiguration));
            }
            catch (Exception e) {
                return(new BadRequestObjectResult($"{e.Message}:{e.StackTrace}"));
            }
        }
Ejemplo n.º 12
0
        public async Task <OperationResult> Post(FileConfiguration fileConfiguration)
        {
            try
            {
                var response = await _setter.Set(fileConfiguration);

                if (response.IsError)
                {
                    return(OperationResult.CreateError(JsonConvert.SerializeObject(response.Errors)));
                }
                return(OperationResult.CreateSuccess("ok", fileConfiguration));
            }
            catch (Exception ex)
            {
                return(OperationResult.CreateError($"{ex.Message}:{ex.StackTrace}"));
            }
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Post([FromBody] FileReRoute fileReRoute)
        {
            try {
                var fileConfiguration = _repo.Get().Result.Data;
                //根据FileReRoute.Key找到要更新的FileReRoute
                //更新FileReRoute

                var response = await _setter.Set(fileConfiguration);

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

                return(new OkObjectResult(fileReRoute));
            }
            catch (Exception e) {
                return(new BadRequestObjectResult($"{e.Message}:{e.StackTrace}"));
            }
        }
Ejemplo n.º 14
0
        private async Task Poll()
        {
            _logger.LogDebug("Started polling consul");

            var fileConfig = await _repo.Get();

            if(fileConfig.IsError)
            {
                _logger.LogDebug($"error geting file config, errors are {string.Join(",", fileConfig.Errors.Select(x => x.Message))}");
                return;
            }

            var asJson = ToJson(fileConfig.Data);

            if(!fileConfig.IsError && asJson != _previousAsJson)
            {
                await _setter.Set(fileConfig.Data);
                _previousAsJson = asJson;
            }

            _logger.LogDebug("Finished polling consul");
        }
Ejemplo n.º 15
0
        public IActionResult ReLoad()
        {
            var getResponse = _configRepo.Get().Result;

            if (getResponse.IsError)
            {
                _logger.Warn("加载Ocelot配置失败: " + JsonConvert.SerializeObject(getResponse.Errors));
                return(BadRequest(getResponse.Errors));
            }

            var setResponse = _setter.Set(getResponse.Data).Result;

            if (setResponse.IsError)
            {
                _logger.Warn("加载Ocelot配置失败: " + JsonConvert.SerializeObject(setResponse.Errors));
                return(BadRequest(setResponse.Errors));
            }

            _logger.Info("加载Ocelot配置成功: " + JsonConvert.SerializeObject(getResponse.Data));

            return(Ok(getResponse.Data));
        }
 private void Reload(FileConfiguration config)
 {
     _configSetter.Set(config);
 }
 public async Task SetConfig(FileConfiguration fileConfig)
 {
     await _configSetter.Set(fileConfig);
 }