add orchestrators
This commit is contained in:
parent
4362eb0dce
commit
68f6c4988a
8
src/ApiGateways/ApiGw-Base/Enums/OrchestratorType.cs
Normal file
8
src/ApiGateways/ApiGw-Base/Enums/OrchestratorType.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace OcelotApiGw.Enums
|
||||||
|
{
|
||||||
|
public enum OrchestratorType
|
||||||
|
{
|
||||||
|
K8S,
|
||||||
|
SF
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using OcelotApiGw.Enums;
|
||||||
|
|
||||||
|
namespace OcelotApiGw.Orchestrators
|
||||||
|
{
|
||||||
|
public interface IOrchestratorStrategy
|
||||||
|
{
|
||||||
|
OrchestratorType OrchestratorType { get; }
|
||||||
|
|
||||||
|
IConfigurationBuilder ConfigureOrchestrator(IConfigurationBuilder builder);
|
||||||
|
}
|
||||||
|
}
|
18
src/ApiGateways/ApiGw-Base/Orchestrators/Kubernetes.cs
Normal file
18
src/ApiGateways/ApiGw-Base/Orchestrators/Kubernetes.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using OcelotApiGw.Enums;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace OcelotApiGw.Orchestrators
|
||||||
|
{
|
||||||
|
public class Kubernetes : IOrchestratorStrategy
|
||||||
|
{
|
||||||
|
public OrchestratorType OrchestratorType => OrchestratorType.K8S;
|
||||||
|
|
||||||
|
public IConfigurationBuilder ConfigureOrchestrator(IConfigurationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.AddJsonFile(Path.Combine("configuration", "configuration.json"));
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
src/ApiGateways/ApiGw-Base/Orchestrators/ServiceFabric.cs
Normal file
25
src/ApiGateways/ApiGw-Base/Orchestrators/ServiceFabric.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using OcelotApiGw.Enums;
|
||||||
|
using OcelotApiGw.Services;
|
||||||
|
|
||||||
|
namespace OcelotApiGw.Orchestrators
|
||||||
|
{
|
||||||
|
public class ServiceFabric : IOrchestratorStrategy
|
||||||
|
{
|
||||||
|
private readonly ISettingService _settingService;
|
||||||
|
|
||||||
|
public ServiceFabric(ISettingService settingService)
|
||||||
|
{
|
||||||
|
_settingService = settingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrchestratorType OrchestratorType => OrchestratorType.SF;
|
||||||
|
|
||||||
|
public IConfigurationBuilder ConfigureOrchestrator(IConfigurationBuilder builder)
|
||||||
|
{
|
||||||
|
var config = _settingService.GetConfiguration();
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,5 @@
|
|||||||
using System;
|
using Microsoft.AspNetCore;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace OcelotApiGw
|
namespace OcelotApiGw
|
||||||
{
|
{
|
||||||
@ -18,14 +10,9 @@ namespace OcelotApiGw
|
|||||||
BuildWebHost(args).Run();
|
BuildWebHost(args).Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebHost BuildWebHost(string[] args)
|
public static IWebHost BuildWebHost(string[] args) =>
|
||||||
{
|
WebHost.CreateDefaultBuilder(args)
|
||||||
IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args);
|
.UseStartup<Startup>()
|
||||||
builder.ConfigureServices(s => s.AddSingleton(builder))
|
.Build();
|
||||||
.ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
|
|
||||||
.UseStartup<Startup>();
|
|
||||||
IWebHost host = builder.Build();
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
src/ApiGateways/ApiGw-Base/Services/ISettingService.cs
Normal file
7
src/ApiGateways/ApiGw-Base/Services/ISettingService.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace OcelotApiGw.Services
|
||||||
|
{
|
||||||
|
public interface ISettingService
|
||||||
|
{
|
||||||
|
string GetConfiguration();
|
||||||
|
}
|
||||||
|
}
|
50
src/ApiGateways/ApiGw-Base/Services/SettingService.cs
Normal file
50
src/ApiGateways/ApiGw-Base/Services/SettingService.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OcelotApiGw.Services
|
||||||
|
{
|
||||||
|
public class SettingService : ISettingService
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
|
public SettingService(HttpClient httpClient, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_httpClient = httpClient;
|
||||||
|
_configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetConfiguration()
|
||||||
|
{
|
||||||
|
var strings = new List<string>();
|
||||||
|
|
||||||
|
var tasks = new Func<Task>[]
|
||||||
|
{
|
||||||
|
async () => {
|
||||||
|
var res = await _httpClient.GetStringAsync(_configuration.GetValue<string>("MobilMarketing"));
|
||||||
|
strings.Add(res);
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
var res = await _httpClient.GetStringAsync(_configuration.GetValue<string>("MobilShopping"));
|
||||||
|
strings.Add(res);
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
var res = await _httpClient.GetStringAsync(_configuration.GetValue<string>("WebMarketing"));
|
||||||
|
strings.Add(res);
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
var res = await _httpClient.GetStringAsync(_configuration.GetValue<string>("WebShopping"));
|
||||||
|
strings.Add(res);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.WaitAll(tasks.Select(task => task()).ToArray());
|
||||||
|
|
||||||
|
return string.Concat(strings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,66 +5,68 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Ocelot.DependencyInjection;
|
using Ocelot.DependencyInjection;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
|
using OcelotApiGw.Enums;
|
||||||
|
using OcelotApiGw.Orchestrators;
|
||||||
|
using OcelotApiGw.Services;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OcelotApiGw
|
namespace OcelotApiGw
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
private readonly IConfiguration _cfg;
|
|
||||||
|
|
||||||
public Startup(IConfiguration configuration)
|
public Startup(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_cfg = configuration;
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
var identityUrl = _cfg.GetValue<string>("IdentityUrl");
|
var identityUrl = _configuration.GetValue<string>("IdentityUrl");
|
||||||
var authenticationProviderKey = "IdentityApiKey";
|
var authenticationProviderKey = "IdentityApiKey";
|
||||||
|
|
||||||
services.AddCors(options =>
|
services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("CorsPolicy",
|
options.AddPolicy("CorsPolicy", builder =>
|
||||||
builder => builder.AllowAnyOrigin()
|
builder.AllowAnyOrigin()
|
||||||
.AllowAnyMethod()
|
.AllowAnyMethod()
|
||||||
.AllowAnyHeader()
|
.AllowAnyHeader()
|
||||||
.AllowCredentials());
|
.AllowCredentials());
|
||||||
|
})
|
||||||
|
.AddTransient<IOrchestratorStrategy, Kubernetes>()
|
||||||
|
.AddTransient<IOrchestratorStrategy, ServiceFabric>()
|
||||||
|
.AddAuthentication()
|
||||||
|
.AddJwtBearer(authenticationProviderKey, options =>
|
||||||
|
{
|
||||||
|
options.Authority = identityUrl;
|
||||||
|
options.RequireHttpsMetadata = false;
|
||||||
|
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
|
||||||
|
{
|
||||||
|
ValidAudiences = new[] { "orders", "basket", "locations", "marketing", "mobileshoppingagg", "webshoppingagg" }
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddAuthentication()
|
services.AddHttpClient<ISettingService, SettingService>();
|
||||||
.AddJwtBearer(authenticationProviderKey, x =>
|
|
||||||
{
|
|
||||||
x.Authority = identityUrl;
|
|
||||||
x.RequireHttpsMetadata = false;
|
|
||||||
x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
|
|
||||||
{
|
|
||||||
ValidAudiences = new[] { "orders", "basket", "locations", "marketing", "mobileshoppingagg", "webshoppingagg" }
|
|
||||||
};
|
|
||||||
x.Events = new Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerEvents()
|
|
||||||
{
|
|
||||||
OnAuthenticationFailed = async ctx =>
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
},
|
|
||||||
OnTokenValidated = async ctx =>
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
},
|
|
||||||
|
|
||||||
OnMessageReceived = async ctx =>
|
var orchestratorType = _configuration.GetValue<OrchestratorType>("OrchestratorType");
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddOcelot(_cfg);
|
var config = new ConfigurationBuilder()
|
||||||
|
.AddConfiguration(_configuration);
|
||||||
|
|
||||||
|
var cfg = services.BuildServiceProvider()
|
||||||
|
.GetServices<IOrchestratorStrategy>()
|
||||||
|
.Single(strategy => strategy.OrchestratorType == orchestratorType)
|
||||||
|
.ConfigureOrchestrator(config)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
services.AddOcelot(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
var pathBase = _cfg["PATH_BASE"];
|
var pathBase = _configuration.GetValue<string>("PATH_BASE");
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(pathBase))
|
if (!string.IsNullOrEmpty(pathBase))
|
||||||
{
|
{
|
||||||
app.UsePathBase(pathBase);
|
app.UsePathBase(pathBase);
|
||||||
@ -75,11 +77,11 @@ namespace OcelotApiGw
|
|||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
loggerFactory.AddConsole(_cfg.GetSection("Logging"));
|
loggerFactory.AddConsole(_configuration.GetSection("Logging"));
|
||||||
|
|
||||||
app.UseCors("CorsPolicy");
|
app.UseCors("CorsPolicy")
|
||||||
|
.UseOcelot()
|
||||||
app.UseOcelot().Wait();
|
.Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
30
src/Web/WebMVC/wwwroot/js/site.min.js
vendored
30
src/Web/WebMVC/wwwroot/js/site.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user