plying around with service providers

This commit is contained in:
Tom Gardham-Pallister
2017-02-01 19:34:55 +00:00
parent 0e92976df8
commit 24dbb958e3
12 changed files with 314 additions and 46 deletions

View File

@ -7,6 +7,7 @@ using Ocelot.Configuration.File;
using Ocelot.Configuration.Parser;
using Ocelot.Configuration.Validator;
using Ocelot.Responses;
using Ocelot.ServiceDiscovery;
using Ocelot.Utilities;
using Ocelot.Values;
@ -104,7 +105,22 @@ namespace Ocelot.Configuration.Creator
//ideal world we would get the host and port, then make the request using it, then release the connection to the lb
Func<HostAndPort> downstreamHostAndPortFunc = () => new HostAndPort(reRoute.DownstreamHost.Trim('/'), reRoute.DownstreamPort);
Func<HostAndPort> downstreamHostAndPortFunc = () => {
//service provider factory takes the reRoute
//can return no service provider (just use ocelot config)
//can return consol service provider
//returns a service provider
//we call get on the service provider
//could reutrn services from consol or just configuration.json
//this returns a list of services and we take the first one
var hostAndPort = new HostAndPort(reRoute.DownstreamHost.Trim('/'), reRoute.DownstreamPort);
var services = new List<Service>();
var serviceProvider = new NoServiceProvider(services);
var service = serviceProvider.Get();
var firstHostAndPort = service[0].HostAndPort;
return firstHostAndPort;
};
if (isAuthenticated)
{

View File

@ -0,0 +1,10 @@
using System.Collections.Generic;
using Ocelot.Values;
namespace Ocelot.ServiceDiscovery
{
public interface IServiceProvider
{
List<Service> Get();
}
}

View File

@ -0,0 +1,9 @@
using Ocelot.Configuration;
namespace Ocelot.ServiceDiscovery
{
public interface IServiceProviderFactory
{
Ocelot.ServiceDiscovery.IServiceProvider Get(ReRoute reRoute);
}
}

View File

@ -0,0 +1,20 @@
using System.Collections.Generic;
using Ocelot.Values;
namespace Ocelot.ServiceDiscovery
{
public class NoServiceProvider : IServiceProvider
{
private List<Service> _services;
public NoServiceProvider(List<Service> services)
{
_services = services;
}
public List<Service> Get()
{
return _services;
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using Ocelot.Configuration;
namespace Ocelot.ServiceDiscovery
{
public class ServiceProviderFactory : IServiceProviderFactory
{
public Ocelot.ServiceDiscovery.IServiceProvider Get(ReRoute reRoute)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,13 @@
namespace Ocelot.Values
{
public class Service
{
public Service(string name, HostAndPort hostAndPort)
{
Name = name;
HostAndPort = hostAndPort;
}
public string Name {get; private set;}
public HostAndPort HostAndPort {get; private set;}
}
}