mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
removed some async we dont need
This commit is contained in:
parent
060dd1dc78
commit
f88e1f65ef
@ -1,11 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Provider
|
||||
{
|
||||
public interface IOcelotConfigurationProvider
|
||||
{
|
||||
Task<Response<IOcelotConfiguration>> Get();
|
||||
Response<IOcelotConfiguration> Get();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Provider
|
||||
@ -17,9 +15,9 @@ namespace Ocelot.Configuration.Provider
|
||||
_config = repo;
|
||||
}
|
||||
|
||||
public async Task<Response<IOcelotConfiguration>> Get()
|
||||
public Response<IOcelotConfiguration> Get()
|
||||
{
|
||||
var repoConfig = await _config.Get();
|
||||
var repoConfig = _config.Get();
|
||||
|
||||
if (repoConfig.IsError)
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using Consul;
|
||||
using Newtonsoft.Json;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Infrastructure.Consul;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.ServiceDiscovery.Configuration;
|
||||
|
||||
@ -15,16 +16,22 @@ namespace Ocelot.Configuration.Repository
|
||||
private readonly ConsulClient _consul;
|
||||
private const string OcelotConfiguration = "OcelotConfiguration";
|
||||
private readonly Cache.IOcelotCache<FileConfiguration> _cache;
|
||||
private readonly IOcelotLogger _logger;
|
||||
|
||||
public ConsulFileConfigurationRepository(
|
||||
Cache.IOcelotCache<FileConfiguration> cache,
|
||||
ServiceProviderConfiguration serviceProviderConfig,
|
||||
IConsulClientFactory factory)
|
||||
ServiceProviderConfiguration serviceProviderConfiguration,
|
||||
IConsulClientFactory factory,
|
||||
IOcelotLoggerFactory loggerFactory)
|
||||
{
|
||||
var consulHost = string.IsNullOrEmpty(serviceProviderConfig?.Host) ? "localhost" : serviceProviderConfig?.Host;
|
||||
var consulPort = serviceProviderConfig?.Port ?? 8500;
|
||||
var config = new ConsulRegistryConfiguration(consulHost, consulPort, OcelotConfiguration, serviceProviderConfig?.Token);
|
||||
_logger = loggerFactory.CreateLogger<ConsulFileConfigurationRepository>();
|
||||
_cache = cache;
|
||||
|
||||
var consulHost = string.IsNullOrEmpty(serviceProviderConfiguration?.Host) ? "localhost" : serviceProviderConfiguration?.Host;
|
||||
var consulPort = serviceProviderConfiguration?.Port ?? 8500;
|
||||
var token = serviceProviderConfiguration?.Token;
|
||||
var config = new ConsulRegistryConfiguration(consulHost, consulPort, OcelotConfiguration, token);
|
||||
|
||||
_consul = factory.Get(config);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Repository
|
||||
{
|
||||
public interface IOcelotConfigurationRepository
|
||||
{
|
||||
Task<Response<IOcelotConfiguration>> Get();
|
||||
Task<Response> AddOrReplace(IOcelotConfiguration ocelotConfiguration);
|
||||
Response<IOcelotConfiguration> Get();
|
||||
Response AddOrReplace(IOcelotConfiguration ocelotConfiguration);
|
||||
}
|
||||
}
|
@ -12,19 +12,19 @@ namespace Ocelot.Configuration.Repository
|
||||
|
||||
private IOcelotConfiguration _ocelotConfiguration;
|
||||
|
||||
public Task<Response<IOcelotConfiguration>> Get()
|
||||
public Response<IOcelotConfiguration> Get()
|
||||
{
|
||||
return Task.FromResult<Response<IOcelotConfiguration>>(new OkResponse<IOcelotConfiguration>(_ocelotConfiguration));
|
||||
return new OkResponse<IOcelotConfiguration>(_ocelotConfiguration);
|
||||
}
|
||||
|
||||
public Task<Response> AddOrReplace(IOcelotConfiguration ocelotConfiguration)
|
||||
public Response AddOrReplace(IOcelotConfiguration ocelotConfiguration)
|
||||
{
|
||||
lock (LockObject)
|
||||
{
|
||||
_ocelotConfiguration = ocelotConfiguration;
|
||||
}
|
||||
|
||||
return Task.FromResult<Response>(new OkResponse());
|
||||
return new OkResponse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,10 @@ namespace Ocelot.Configuration.Setter
|
||||
private readonly IOcelotConfigurationCreator _configCreator;
|
||||
private readonly IFileConfigurationRepository _repo;
|
||||
|
||||
public FileConfigurationSetter(IOcelotConfigurationRepository configRepo,
|
||||
IOcelotConfigurationCreator configCreator, IFileConfigurationRepository repo)
|
||||
public FileConfigurationSetter(
|
||||
IOcelotConfigurationRepository configRepo,
|
||||
IOcelotConfigurationCreator configCreator,
|
||||
IFileConfigurationRepository repo)
|
||||
{
|
||||
_configRepo = configRepo;
|
||||
_configCreator = configCreator;
|
||||
@ -33,7 +35,7 @@ namespace Ocelot.Configuration.Setter
|
||||
|
||||
if(!config.IsError)
|
||||
{
|
||||
await _configRepo.AddOrReplace(config.Data);
|
||||
_configRepo.AddOrReplace(config.Data);
|
||||
}
|
||||
|
||||
return new ErrorResponse(config.Errors);
|
||||
|
@ -1,7 +1,3 @@
|
||||
using Butterfly.Client.Tracing;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
|
||||
namespace Ocelot.DependencyInjection
|
||||
{
|
||||
using CacheManager.Core;
|
||||
@ -22,7 +18,6 @@ namespace Ocelot.DependencyInjection
|
||||
using Ocelot.Configuration.Validator;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.UrlMatcher;
|
||||
using Ocelot.DownstreamUrlCreator;
|
||||
using Ocelot.DownstreamUrlCreator.UrlTemplateReplacer;
|
||||
using Ocelot.Headers;
|
||||
using Ocelot.Infrastructure.Claims.Parser;
|
||||
@ -44,16 +39,16 @@ namespace Ocelot.DependencyInjection
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using IdentityServer4.AccessTokenValidation;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using Butterfly.Client.AspNetCore;
|
||||
using Ocelot.Infrastructure;
|
||||
using Ocelot.Infrastructure.Consul;
|
||||
using Butterfly.Client.Tracing;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
|
||||
public class OcelotBuilder : IOcelotBuilder
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
|
||||
|
||||
var upstreamHost = context.HttpContext.Request.Headers["Host"];
|
||||
|
||||
var configuration = await _configProvider.Get();
|
||||
var configuration = _configProvider.Get();
|
||||
|
||||
if (configuration.IsError)
|
||||
{
|
||||
|
@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
using Ocelot.Infrastructure.Extensions;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Logging;
|
||||
@ -36,7 +33,7 @@ namespace Ocelot.Errors.Middleware
|
||||
{
|
||||
try
|
||||
{
|
||||
await TrySetGlobalRequestId(context);
|
||||
TrySetGlobalRequestId(context);
|
||||
|
||||
Logger.LogDebug("ocelot pipeline started");
|
||||
|
||||
@ -56,12 +53,12 @@ namespace Ocelot.Errors.Middleware
|
||||
Logger.LogDebug("ocelot pipeline finished");
|
||||
}
|
||||
|
||||
private async Task TrySetGlobalRequestId(DownstreamContext context)
|
||||
private void TrySetGlobalRequestId(DownstreamContext context)
|
||||
{
|
||||
//try and get the global request id and set it for logs...
|
||||
//should this basically be immutable per request...i guess it should!
|
||||
//first thing is get config
|
||||
var configuration = await _provider.Get();
|
||||
var configuration = _provider.Get();
|
||||
|
||||
if(configuration.IsError)
|
||||
{
|
||||
|
@ -4,7 +4,6 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@ -89,7 +88,7 @@
|
||||
{
|
||||
var deps = GetDependencies(builder);
|
||||
|
||||
var ocelotConfiguration = await deps.provider.Get();
|
||||
var ocelotConfiguration = deps.provider.Get();
|
||||
|
||||
if (ConfigurationNotSetUp(ocelotConfiguration))
|
||||
{
|
||||
@ -101,7 +100,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
return await GetOcelotConfigAndReturn(deps.provider);
|
||||
return GetOcelotConfigAndReturn(deps.provider);
|
||||
}
|
||||
|
||||
private static async Task<Response> SetConfig(IApplicationBuilder builder, IOptions<FileConfiguration> fileConfiguration, IFileConfigurationSetter setter, IOcelotConfigurationProvider provider, IFileConfigurationRepository repo)
|
||||
@ -137,9 +136,9 @@
|
||||
return (fileConfiguration, setter, provider, repo);
|
||||
}
|
||||
|
||||
private static async Task<IOcelotConfiguration> GetOcelotConfigAndReturn(IOcelotConfigurationProvider provider)
|
||||
private static IOcelotConfiguration GetOcelotConfigAndReturn(IOcelotConfigurationProvider provider)
|
||||
{
|
||||
var ocelotConfiguration = await provider.Get();
|
||||
var ocelotConfiguration = provider.Get();
|
||||
|
||||
if(ocelotConfiguration == null || ocelotConfiguration.Data == null || ocelotConfiguration.IsError)
|
||||
{
|
||||
@ -187,7 +186,7 @@
|
||||
return new ErrorResponse(ocelotConfig.Errors);
|
||||
}
|
||||
|
||||
config = await ocelotConfigurationRepository.AddOrReplace(ocelotConfig.Data);
|
||||
config = ocelotConfigurationRepository.AddOrReplace(ocelotConfig.Data);
|
||||
|
||||
if (config.IsError)
|
||||
{
|
||||
|
@ -28,8 +28,7 @@ namespace Ocelot.Raft
|
||||
_options = options;
|
||||
_peers = new List<IPeer>();
|
||||
|
||||
//todo - sort out async nonsense..
|
||||
var config = _provider.Get().GetAwaiter().GetResult();
|
||||
var config = _provider.Get();
|
||||
foreach (var item in _options.Value.Peers)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
|
@ -22,6 +22,12 @@ namespace Ocelot.ManualTest
|
||||
.AddJsonFile("appsettings.json", true, true)
|
||||
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
|
||||
.AddJsonFile("ocelot.json")
|
||||
|
||||
//.AddOcelot();
|
||||
//load all the ocelot.xxx.json files that are not environments from asp.net core
|
||||
//merge them into megaconfig
|
||||
//save megaconfig to disk as ocelot.json
|
||||
//then add to asp.net config stuff..
|
||||
.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s => {
|
||||
|
@ -49,7 +49,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
private void WhenIGetTheConfiguration()
|
||||
{
|
||||
_getResult = _repo.Get().Result;
|
||||
_getResult = _repo.Get();
|
||||
}
|
||||
|
||||
private void GivenThereIsASavedConfiguration()
|
||||
@ -65,7 +65,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
private void WhenIAddOrReplaceTheConfig()
|
||||
{
|
||||
_result = _repo.AddOrReplace(_config).Result;
|
||||
_result = _repo.AddOrReplace(_config);
|
||||
}
|
||||
|
||||
private void ThenNoErrorsAreReturned()
|
||||
|
@ -56,12 +56,12 @@ namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
_configurationRepository
|
||||
.Setup(x => x.Get())
|
||||
.ReturnsAsync(config);
|
||||
.Returns(config);
|
||||
}
|
||||
|
||||
private void WhenIGetTheConfig()
|
||||
{
|
||||
_result = _ocelotConfigurationProvider.Get().Result;
|
||||
_result = _ocelotConfigurationProvider.Get();
|
||||
}
|
||||
|
||||
private void TheFollowingIsReturned(Response<IOcelotConfiguration> expected)
|
||||
|
@ -79,7 +79,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
||||
_config = config;
|
||||
_provider
|
||||
.Setup(x => x.Get())
|
||||
.ReturnsAsync(new OkResponse<IOcelotConfiguration>(_config));
|
||||
.Returns(new OkResponse<IOcelotConfiguration>(_config));
|
||||
}
|
||||
|
||||
private void GivenTheDownStreamRouteFinderReturns(DownstreamRoute downstreamRoute)
|
||||
|
@ -134,7 +134,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
{
|
||||
var ex = new Exception("outer", new Exception("inner"));
|
||||
_provider
|
||||
.Setup(x => x.Get()).ThrowsAsync(ex);
|
||||
.Setup(x => x.Get()).Throws(ex);
|
||||
}
|
||||
|
||||
private void ThenAnExceptionIsThrown()
|
||||
@ -146,7 +146,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
{
|
||||
var response = new Responses.ErrorResponse<IOcelotConfiguration>(new FakeError());
|
||||
_provider
|
||||
.Setup(x => x.Get()).ReturnsAsync(response);
|
||||
.Setup(x => x.Get()).Returns(response);
|
||||
}
|
||||
|
||||
private void TheRequestIdIsSet(string key, string value)
|
||||
@ -158,7 +158,7 @@ namespace Ocelot.UnitTests.Errors
|
||||
{
|
||||
var response = new Responses.OkResponse<IOcelotConfiguration>(config);
|
||||
_provider
|
||||
.Setup(x => x.Get()).ReturnsAsync(response);
|
||||
.Setup(x => x.Get()).Returns(response);
|
||||
}
|
||||
|
||||
private void GivenAnExceptionWillNotBeThrownDownstream()
|
||||
|
Loading…
x
Reference in New Issue
Block a user