netstandard2.0 support

This commit is contained in:
David Nissimoff 2018-05-10 16:12:36 -07:00
parent aa3de16464
commit b1641e003c
17 changed files with 128 additions and 82 deletions

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Ocelot.Configuration.File; using Ocelot.Configuration.File;
using Ocelot.Infrastructure; using Ocelot.Infrastructure;
using Ocelot.Infrastructure.Extensions;
using Ocelot.Logging; using Ocelot.Logging;
using Ocelot.Middleware; using Ocelot.Middleware;
using Ocelot.Responses; using Ocelot.Responses;

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Ocelot.Infrastructure.Extensions;
namespace Ocelot.Configuration.File namespace Ocelot.Configuration.File
{ {

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Ocelot.Infrastructure.Extensions;
namespace Ocelot.Configuration.File namespace Ocelot.Configuration.File
{ {

View File

@ -49,7 +49,7 @@ namespace Ocelot.Configuration
if (test != null) if (test != null)
{ {
var node = (INode)test; var node = (INode)test;
var result = node.Accept(new UpdateFileConfiguration(fileConfiguration)); var result = await node.Accept(new UpdateFileConfiguration(fileConfiguration));
if (result.GetType() == typeof(Rafty.Concensus.ErrorResponse<UpdateFileConfiguration>)) if (result.GetType() == typeof(Rafty.Concensus.ErrorResponse<UpdateFileConfiguration>))
{ {
return new BadRequestObjectResult("There was a problem. This error message sucks raise an issue in GitHub."); return new BadRequestObjectResult("There was a problem. This error message sucks raise an issue in GitHub.");

View File

@ -3,6 +3,7 @@ namespace Ocelot.Headers
using System.Collections.Generic; using System.Collections.Generic;
using Ocelot.Configuration.Creator; using Ocelot.Configuration.Creator;
using Ocelot.Infrastructure; using Ocelot.Infrastructure;
using Ocelot.Infrastructure.Extensions;
using Ocelot.Logging; using Ocelot.Logging;
using Ocelot.Middleware; using Ocelot.Middleware;

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Ocelot.Infrastructure.Extensions
{
/// <summary>
/// Trivial implementations of methods present in .NET Core 2 but not supported on .NET Standard 2.0.
/// </summary>
internal static class NetCoreSupportExtensions
{
internal static void AppendJoin<T>(this StringBuilder builder, char separator, IEnumerable<T> values)
{
builder.Append(string.Join(separator.ToString(), values));
}
internal static string[] Split(this string input, string separator, StringSplitOptions options = StringSplitOptions.None)
{
return input.Split(new[] { separator }, options);
}
internal static bool StartsWith(this string input, char value)
{
return input.StartsWith(value.ToString());
}
internal static bool EndsWith(this string input, char value)
{
return input.EndsWith(value.ToString());
}
}
}

View File

@ -35,7 +35,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers
{ {
if (stickySession.Expiry < DateTime.UtcNow) if (stickySession.Expiry < DateTime.UtcNow)
{ {
_stored.Remove(stickySession.Key, out _); _stored.TryRemove(stickySession.Key, out _);
_loadBalancer.Release(stickySession.HostAndPort); _loadBalancer.Release(stickySession.HostAndPort);
} }
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion> <RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
<NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion> <NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion>
<NoPackageAnalysis>true</NoPackageAnalysis> <NoPackageAnalysis>true</NoPackageAnalysis>
@ -25,14 +25,22 @@
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" /> <PackageReference Include="Butterfly.Client" Version="0.0.8" />
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="FluentValidation" Version="7.5.2" /> <PackageReference Include="FluentValidation" Version="7.5.2" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.4.0" /> <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" /> <PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.MiddlewareAnalysis" Version="2.0.2" />
<PackageReference Include="Microsoft.Data.SQLite" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.0.1">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.1" />
@ -48,6 +56,6 @@
<PackageReference Include="Polly" Version="5.8.0" /> <PackageReference Include="Polly" Version="5.8.0" />
<PackageReference Include="Pivotal.Discovery.Client" Version="1.1.0" /> <PackageReference Include="Pivotal.Discovery.Client" Version="1.1.0" />
<PackageReference Include="IdentityServer4" Version="2.1.3" /> <PackageReference Include="IdentityServer4" Version="2.1.3" />
<PackageReference Include="Rafty" Version="0.4.2" /> <PackageReference Include="Rafty" Version="0.4.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using Rafty.FiniteStateMachine; using Rafty.FiniteStateMachine;
using Rafty.Infrastructure; using Rafty.Infrastructure;
@ -17,7 +18,7 @@ namespace Ocelot.Raft
_id = nodeId.Id.Replace("/","").Replace(":",""); _id = nodeId.Id.Replace("/","").Replace(":","");
} }
public void Handle(LogEntry log) public Task Handle(LogEntry log)
{ {
try try
{ {
@ -28,6 +29,8 @@ namespace Ocelot.Raft
{ {
Console.WriteLine(exception); Console.WriteLine(exception);
} }
return Task.CompletedTask;
} }
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ocelot.Configuration; using Ocelot.Configuration;
using Ocelot.Middleware; using Ocelot.Middleware;
@ -35,7 +36,7 @@ namespace Ocelot.Raft
public string Id {get; private set;} public string Id {get; private set;}
public RequestVoteResponse Request(RequestVote requestVote) public async Task<RequestVoteResponse> Request(RequestVote requestVote)
{ {
if(_token == null) if(_token == null)
{ {
@ -48,7 +49,7 @@ namespace Ocelot.Raft
var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/requestvote", content).GetAwaiter().GetResult(); var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/requestvote", content).GetAwaiter().GetResult();
if(response.IsSuccessStatusCode) if(response.IsSuccessStatusCode)
{ {
return JsonConvert.DeserializeObject<RequestVoteResponse>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), _jsonSerializerSettings); return JsonConvert.DeserializeObject<RequestVoteResponse>(await response.Content.ReadAsStringAsync(), _jsonSerializerSettings);
} }
else else
{ {
@ -56,7 +57,7 @@ namespace Ocelot.Raft
} }
} }
public AppendEntriesResponse Request(AppendEntries appendEntries) public async Task<AppendEntriesResponse> Request(AppendEntries appendEntries)
{ {
try try
{ {
@ -71,7 +72,7 @@ namespace Ocelot.Raft
var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/appendEntries", content).GetAwaiter().GetResult(); var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/appendEntries", content).GetAwaiter().GetResult();
if(response.IsSuccessStatusCode) if(response.IsSuccessStatusCode)
{ {
return JsonConvert.DeserializeObject<AppendEntriesResponse>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(),_jsonSerializerSettings); return JsonConvert.DeserializeObject<AppendEntriesResponse>(await response.Content.ReadAsStringAsync(), _jsonSerializerSettings);
} }
else else
{ {
@ -85,7 +86,7 @@ namespace Ocelot.Raft
} }
} }
public Response<T> Request<T>(T command) public async Task<Response<T>> Request<T>(T command)
where T : ICommand where T : ICommand
{ {
Console.WriteLine("SENDING REQUEST...."); Console.WriteLine("SENDING REQUEST....");
@ -107,7 +108,7 @@ namespace Ocelot.Raft
else else
{ {
Console.WriteLine("REQUEST NOT OK...."); Console.WriteLine("REQUEST NOT OK....");
return new ErrorResponse<T>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), command); return new ErrorResponse<T>(await response.Content.ReadAsStringAsync(), command);
} }
} }

View File

@ -1,3 +1,4 @@
using System.Threading.Tasks;
using Ocelot.Configuration.Setter; using Ocelot.Configuration.Setter;
using Rafty.FiniteStateMachine; using Rafty.FiniteStateMachine;
using Rafty.Log; using Rafty.Log;
@ -14,12 +15,12 @@ namespace Ocelot.Raft
_setter = setter; _setter = setter;
} }
public void Handle(LogEntry log) public async Task Handle(LogEntry log)
{ {
//todo - handle an error //todo - handle an error
//hack it to just cast as at the moment we know this is the only command :P //hack it to just cast as at the moment we know this is the only command :P
var hack = (UpdateFileConfiguration)log.CommandData; var hack = (UpdateFileConfiguration)log.CommandData;
_setter.Set(hack.Configuration).GetAwaiter().GetResult(); await _setter.Set(hack.Configuration);
} }
} }
} }

View File

@ -5,6 +5,7 @@ using Newtonsoft.Json;
using System; using System;
using Rafty.Infrastructure; using Rafty.Infrastructure;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
namespace Ocelot.Raft namespace Ocelot.Raft
{ {
@ -40,9 +41,7 @@ namespace Ocelot.Raft
} }
} }
public int LastLogIndex public Task<int> LastLogIndex()
{
get
{ {
lock(_lock) lock(_lock)
{ {
@ -61,14 +60,11 @@ namespace Ocelot.Raft
} }
} }
return result; return Task.FromResult(result);
}
} }
} }
public long LastLogTerm public Task<long> LastLogTerm ()
{
get
{ {
lock(_lock) lock(_lock)
{ {
@ -91,14 +87,11 @@ namespace Ocelot.Raft
} }
} }
return result; return Task.FromResult(result);
}
} }
} }
public int Count public Task<int> Count ()
{
get
{ {
lock(_lock) lock(_lock)
{ {
@ -117,12 +110,11 @@ namespace Ocelot.Raft
} }
} }
return result; return Task.FromResult(result);
}
} }
} }
public int Apply(LogEntry log) public Task<int> Apply(LogEntry log)
{ {
lock(_lock) lock(_lock)
{ {
@ -145,13 +137,13 @@ namespace Ocelot.Raft
using(var command = new SqliteCommand(sql, connection)) using(var command = new SqliteCommand(sql, connection))
{ {
var result = command.ExecuteScalar(); var result = command.ExecuteScalar();
return Convert.ToInt32(result); return Task.FromResult(Convert.ToInt32(result));
} }
} }
} }
} }
public void DeleteConflictsFromThisLog(int index, LogEntry logEntry) public Task DeleteConflictsFromThisLog(int index, LogEntry logEntry)
{ {
lock(_lock) lock(_lock)
{ {
@ -180,9 +172,11 @@ namespace Ocelot.Raft
} }
} }
} }
return Task.CompletedTask;
} }
public LogEntry Get(int index) public Task<LogEntry> Get(int index)
{ {
lock(_lock) lock(_lock)
{ {
@ -199,13 +193,13 @@ namespace Ocelot.Raft
TypeNameHandling = TypeNameHandling.All TypeNameHandling = TypeNameHandling.All
}; };
var log = JsonConvert.DeserializeObject<LogEntry>(data, jsonSerializerSettings); var log = JsonConvert.DeserializeObject<LogEntry>(data, jsonSerializerSettings);
return log; return Task.FromResult(log);
} }
} }
} }
} }
public System.Collections.Generic.List<(int index, LogEntry logEntry)> GetFrom(int index) public Task<List<(int index, LogEntry logEntry)>> GetFrom(int index)
{ {
lock(_lock) lock(_lock)
{ {
@ -235,11 +229,11 @@ namespace Ocelot.Raft
} }
} }
return logsToReturn; return Task.FromResult(logsToReturn);
} }
} }
public long GetTermAtIndex(int index) public Task<long> GetTermAtIndex(int index)
{ {
lock(_lock) lock(_lock)
{ {
@ -264,11 +258,11 @@ namespace Ocelot.Raft
} }
} }
return result; return Task.FromResult(result);
} }
} }
public void Remove(int indexOfCommand) public Task Remove(int indexOfCommand)
{ {
lock(_lock) lock(_lock)
{ {
@ -284,6 +278,8 @@ namespace Ocelot.Raft
} }
} }
} }
return Task.CompletedTask;
} }
} }
} }

View File

@ -52,7 +52,7 @@ namespace Ocelot.Requester
if(context.DownstreamReRoute.DangerousAcceptAnyServerCertificateValidator) if(context.DownstreamReRoute.DangerousAcceptAnyServerCertificateValidator)
{ {
httpclientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; httpclientHandler.ServerCertificateCustomValidationCallback = (request, certificate, chain, errors) => true;
_logger _logger
.LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamReRoute, UpstreamPathTemplate: {context.DownstreamReRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {context.DownstreamReRoute.DownstreamPathTemplate}"); .LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamReRoute, UpstreamPathTemplate: {context.DownstreamReRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {context.DownstreamReRoute.DownstreamPathTemplate}");

View File

@ -55,5 +55,6 @@
<PackageReference Include="Consul" Version="0.7.2.4" /> <PackageReference Include="Consul" Version="0.7.2.4" />
<PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" /> <PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" />
<PackageReference Include="Rafty" Version="0.4.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -44,7 +44,7 @@
<PackageReference Include="Shouldly" Version="3.0.0" /> <PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="TestStack.BDDfy" Version="4.3.2" /> <PackageReference Include="TestStack.BDDfy" Version="4.3.2" />
<PackageReference Include="Consul" Version="0.7.2.4" /> <PackageReference Include="Consul" Version="0.7.2.4" />
<PackageReference Include="Rafty" Version="0.4.2" /> <PackageReference Include="Rafty" Version="0.4.3" />
<PackageReference Include="Microsoft.Data.SQLite" Version="2.0.1" /> <PackageReference Include="Microsoft.Data.SQLite" Version="2.0.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -126,14 +126,14 @@ namespace Ocelot.UnitTests.Controllers
{ {
_node _node
.Setup(x => x.Accept(It.IsAny<UpdateFileConfiguration>())) .Setup(x => x.Accept(It.IsAny<UpdateFileConfiguration>()))
.Returns(new Rafty.Concensus.OkResponse<UpdateFileConfiguration>(new UpdateFileConfiguration(new FileConfiguration()))); .ReturnsAsync(new Rafty.Concensus.OkResponse<UpdateFileConfiguration>(new UpdateFileConfiguration(new FileConfiguration())));
} }
private void GivenTheNodeReturnsError() private void GivenTheNodeReturnsError()
{ {
_node _node
.Setup(x => x.Accept(It.IsAny<UpdateFileConfiguration>())) .Setup(x => x.Accept(It.IsAny<UpdateFileConfiguration>()))
.Returns(new Rafty.Concensus.ErrorResponse<UpdateFileConfiguration>("error", new UpdateFileConfiguration(new FileConfiguration()))); .ReturnsAsync(new Rafty.Concensus.ErrorResponse<UpdateFileConfiguration>("error", new UpdateFileConfiguration(new FileConfiguration())));
} }
private void GivenTheConfigSetterReturns(Response response) private void GivenTheConfigSetterReturns(Response response)

View File

@ -49,10 +49,10 @@
<PackageReference Include="TestStack.BDDfy" Version="4.3.2" /> <PackageReference Include="TestStack.BDDfy" Version="4.3.2" />
<PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" /> <PackageReference Include="Butterfly.Client.AspNetCore" Version="0.0.8" />
<PackageReference Include="Rafty" Version="0.4.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="WebSockets\" /> <Folder Include="WebSockets\" />
</ItemGroup> </ItemGroup>
</Project> </Project>