Merge remote-tracking branch 'upstream/release-3.1.8' into feature/AddStyleCopAnalyzers

# Conflicts:
#	src/Ocelot/Configuration/ServiceProviderConfiguration.cs
This commit is contained in:
Philip Wood
2018-03-03 16:28:19 +00:00
70 changed files with 2373 additions and 481 deletions

View File

@ -36,7 +36,6 @@ namespace Ocelot.Configuration.Builder
private readonly List<DownstreamHostAndPort> _downstreamAddresses;
private string _upstreamHost;
private string _key;
public DownstreamReRouteBuilder()
{
_downstreamAddresses = new List<DownstreamHostAndPort>();

View File

@ -4,6 +4,7 @@ namespace Ocelot.Configuration.Builder
{
private string _serviceDiscoveryProviderHost;
private int _serviceDiscoveryProviderPort;
private string _type;
public ServiceProviderConfigurationBuilder WithServiceDiscoveryProviderHost(string serviceDiscoveryProviderHost)
{
@ -17,9 +18,15 @@ namespace Ocelot.Configuration.Builder
return this;
}
public ServiceProviderConfigurationBuilder WithServiceDiscoveryProviderType(string type)
{
_type = type;
return this;
}
public ServiceProviderConfiguration Build()
{
return new ServiceProviderConfiguration(_serviceDiscoveryProviderHost,_serviceDiscoveryProviderPort);
return new ServiceProviderConfiguration(_type, _serviceDiscoveryProviderHost, _serviceDiscoveryProviderPort);
}
}
}
}

View File

@ -7,12 +7,14 @@ namespace Ocelot.Configuration.Creator
{
public ServiceProviderConfiguration Create(FileGlobalConfiguration globalConfiguration)
{
//todo log or return error here dont just default to something that wont work..
var serviceProviderPort = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0;
return new ServiceProviderConfigurationBuilder()
.WithServiceDiscoveryProviderHost(globalConfiguration?.ServiceDiscoveryProvider?.Host)
.WithServiceDiscoveryProviderPort(serviceProviderPort)
.Build();
.WithServiceDiscoveryProviderHost(globalConfiguration?.ServiceDiscoveryProvider?.Host)
.WithServiceDiscoveryProviderPort(serviceProviderPort)
.WithServiceDiscoveryProviderType(globalConfiguration?.ServiceDiscoveryProvider?.Type)
.Build();
}
}
}
}

View File

@ -4,5 +4,6 @@ namespace Ocelot.Configuration.File
{
public string Host {get;set;}
public int Port { get; set; }
public string Type { get; set; }
}
}
}

View File

@ -17,8 +17,8 @@ namespace Ocelot.Configuration.Repository
public ConsulFileConfigurationRepository(Cache.IOcelotCache<FileConfiguration> cache, ServiceProviderConfiguration serviceProviderConfig)
{
var consulHost = string.IsNullOrEmpty(serviceProviderConfig?.ServiceProviderHost) ? "localhost" : serviceProviderConfig?.ServiceProviderHost;
var consulPort = serviceProviderConfig?.ServiceProviderPort ?? 8500;
var consulHost = string.IsNullOrEmpty(serviceProviderConfig?.Host) ? "localhost" : serviceProviderConfig?.Host;
var consulPort = serviceProviderConfig?.Port ?? 8500;
var configuration = new ConsulRegistryConfiguration(consulHost, consulPort, _ocelotConfiguration);
_cache = cache;
_consul = new ConsulClient(c =>

View File

@ -2,13 +2,15 @@
{
public class ServiceProviderConfiguration
{
public ServiceProviderConfiguration(string serviceProviderHost, int serviceProviderPort)
public ServiceProviderConfiguration(string type, string host, int port)
{
ServiceProviderHost = serviceProviderHost;
ServiceProviderPort = serviceProviderPort;
Host = host;
Port = port;
Type = type;
}
public string ServiceProviderHost { get; private set; }
public int ServiceProviderPort { get; private set; }
public string Host { get; private set; }
public int Port { get; private set; }
public string Type { get; private set; }
}
}

View File

@ -30,7 +30,7 @@ namespace Ocelot.Configuration.Validator
RuleForEach(configuration => configuration.Aggregates)
.Must((config, aggregateReRoute) => AllReRoutesForAggregateExist(aggregateReRoute, config.ReRoutes))
.WithMessage((config, aggregateReRoute) => $"ReRoutes for {nameof(aggregateReRoute)} {aggregateReRoute.UpstreamPathTemplate} either do not exist or do not have correct Key property");
.WithMessage((config, aggregateReRoute) => $"ReRoutes for {nameof(aggregateReRoute)} {aggregateReRoute.UpstreamPathTemplate} either do not exist or do not have correct ServiceName property");
RuleForEach(configuration => configuration.Aggregates)
.Must((config, aggregateReRoute) => DoesNotContainReRoutesWithSpecificRequestIdKeys(aggregateReRoute, config.ReRoutes))

View File

@ -99,7 +99,6 @@ namespace Ocelot.DependencyInjection
_services.TryAddSingleton<ILoadBalancerFactory, LoadBalancerFactory>();
_services.TryAddSingleton<ILoadBalancerHouse, LoadBalancerHouse>();
_services.TryAddSingleton<IOcelotLoggerFactory, AspDotNetLoggerFactory>();
_services.TryAddSingleton<IUrlBuilder, UrlBuilder>();
_services.TryAddSingleton<IRemoveOutputHeaders, RemoveOutputHeaders>();
_services.TryAddSingleton<IOcelotConfigurationProvider, OcelotConfigurationProvider>();
_services.TryAddSingleton<IClaimToThingConfigurationParser, ClaimToThingConfigurationParser>();

View File

@ -1,4 +1,5 @@
using Ocelot.Responses;
/*
using Ocelot.Responses;
using Ocelot.Values;
namespace Ocelot.DownstreamUrlCreator
@ -8,3 +9,4 @@ namespace Ocelot.DownstreamUrlCreator
Response<DownstreamUrl> Build(string downstreamPath, string downstreamScheme, ServiceHostAndPort downstreamHostAndPort);
}
}
*/

View File

@ -5,6 +5,7 @@ using Ocelot.Infrastructure.RequestData;
using Ocelot.Logging;
using Ocelot.Middleware;
using System;
using System.Linq;
using Ocelot.DownstreamRouteFinder.Middleware;
namespace Ocelot.DownstreamUrlCreator.Middleware
@ -14,16 +15,13 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
private readonly OcelotRequestDelegate _next;
private readonly IDownstreamPathPlaceholderReplacer _replacer;
private readonly IOcelotLogger _logger;
private readonly IUrlBuilder _urlBuilder;
public DownstreamUrlCreatorMiddleware(OcelotRequestDelegate next,
IOcelotLoggerFactory loggerFactory,
IDownstreamPathPlaceholderReplacer replacer,
IUrlBuilder urlBuilder)
IDownstreamPathPlaceholderReplacer replacer)
{
_next = next;
_replacer = replacer;
_urlBuilder = urlBuilder;
_logger = loggerFactory.CreateLogger<DownstreamUrlCreatorMiddleware>();
}
@ -40,11 +38,32 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
return;
}
var uriBuilder = new UriBuilder(context.DownstreamRequest.RequestUri)
UriBuilder uriBuilder;
//todo - feel this is a bit crap the way we build the url dont see why we need this builder thing..maybe i blew my own brains out
// when i originally wrote it..
if (context.ServiceProviderConfiguration.Type == "ServiceFabric" && context.DownstreamReRoute.UseServiceDiscovery)
{
Path = dsPath.Data.Value,
Scheme = context.DownstreamReRoute.DownstreamScheme
};
_logger.LogInformation("DownstreamUrlCreatorMiddleware - going to try set service fabric path");
var scheme = context.DownstreamReRoute.DownstreamScheme;
var host = context.DownstreamRequest.RequestUri.Host;
var port = context.DownstreamRequest.RequestUri.Port;
var serviceFabricPath = $"/{context.DownstreamReRoute.ServiceName + dsPath.Data.Value}";
_logger.LogInformation("DownstreamUrlCreatorMiddleware - service fabric path is {proxyUrl}", serviceFabricPath);
var uri = new Uri($"{scheme}://{host}:{port}{serviceFabricPath}?cmd=instance");
uriBuilder = new UriBuilder(uri);
}
else
{
uriBuilder = new UriBuilder(context.DownstreamRequest.RequestUri)
{
Path = dsPath.Data.Value,
Scheme = context.DownstreamReRoute.DownstreamScheme
};
}
context.DownstreamRequest.RequestUri = uriBuilder.Uri;

View File

@ -1,4 +1,5 @@
using System;
/*
using System;
using System.Collections.Generic;
using Ocelot.Errors;
using Ocelot.Responses;
@ -29,7 +30,7 @@ namespace Ocelot.DownstreamUrlCreator
{
Host = downstreamHostAndPort.DownstreamHost,
Path = downstreamPath,
Scheme = downstreamScheme
Scheme = downstreamScheme,
};
if (downstreamHostAndPort.DownstreamPort > 0)
@ -43,3 +44,4 @@ namespace Ocelot.DownstreamUrlCreator
}
}
}
*/

View File

@ -17,6 +17,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers
public async Task<Response<ServiceHostAndPort>> Lease()
{
//todo no point spinning a task up here, also first or default could be null..
var service = await Task.FromResult(_services.FirstOrDefault());
return new OkResponse<ServiceHostAndPort>(service.HostAndPort);
}

View File

@ -18,7 +18,7 @@ namespace Ocelot.ServiceDiscovery
{
if (reRoute.UseServiceDiscovery)
{
return GetServiceDiscoveryProvider(reRoute.ServiceName, serviceConfig.ServiceProviderHost, serviceConfig.ServiceProviderPort);
return GetServiceDiscoveryProvider(serviceConfig, reRoute.ServiceName);
}
var services = new List<Service>();
@ -33,9 +33,15 @@ namespace Ocelot.ServiceDiscovery
return new ConfigurationServiceProvider(services);
}
private IServiceDiscoveryProvider GetServiceDiscoveryProvider(string keyOfServiceInConsul, string providerHostName, int providerPort)
private IServiceDiscoveryProvider GetServiceDiscoveryProvider(ServiceProviderConfiguration serviceConfig, string serviceName)
{
var consulRegistryConfiguration = new ConsulRegistryConfiguration(providerHostName, providerPort, keyOfServiceInConsul);
if (serviceConfig.Type == "ServiceFabric")
{
var config = new ServiceFabricConfiguration(serviceConfig.Host, serviceConfig.Port, serviceName);
return new ServiceFabricServiceDiscoveryProvider(config);
}
var consulRegistryConfiguration = new ConsulRegistryConfiguration(serviceConfig.Host, serviceConfig.Port, serviceName);
return new ConsulServiceDiscoveryProvider(consulRegistryConfiguration, _factory);
}
}

View File

@ -0,0 +1,16 @@
namespace Ocelot.ServiceDiscovery
{
public class ServiceFabricConfiguration
{
public ServiceFabricConfiguration(string hostName, int port, string serviceName)
{
HostName = hostName;
Port = port;
ServiceName = serviceName;
}
public string ServiceName { get; private set; }
public string HostName { get; private set; }
public int Port { get; private set; }
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Ocelot.Values;
namespace Ocelot.ServiceDiscovery
{
public class ServiceFabricServiceDiscoveryProvider : IServiceDiscoveryProvider
{
private readonly ServiceFabricConfiguration _configuration;
public ServiceFabricServiceDiscoveryProvider(ServiceFabricConfiguration configuration)
{
_configuration = configuration;
}
public async Task<List<Service>> Get()
{
return new List<Service>
{
new Service(_configuration.ServiceName,
new ServiceHostAndPort(_configuration.HostName, _configuration.Port),
"doesnt matter with service fabric",
"doesnt matter with service fabric",
new List<string>())
};
}
}
}