removed some async we dont need

This commit is contained in:
Tom Pallister
2018-04-13 17:16:43 +01:00
parent 060dd1dc78
commit f88e1f65ef
16 changed files with 58 additions and 59 deletions

View File

@ -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();
}
}

View File

@ -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)
{
@ -29,4 +27,4 @@ namespace Ocelot.Configuration.Provider
return new OkResponse<IOcelotConfiguration>(repoConfig.Data);
}
}
}
}

View File

@ -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)
Cache.IOcelotCache<FileConfiguration> cache,
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);
}

View File

@ -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);
}
}
}

View File

@ -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();
}
}
}

View File

@ -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);

View File

@ -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
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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();