Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TomPallister authored Aug 12, 2018
1 parent 4e22b3c commit cbd0af6
Show file tree
Hide file tree
Showing 23 changed files with 6 additions and 1,437 deletions.
16 changes: 0 additions & 16 deletions src/Ocelot/Configuration/FileConfigurationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
using Microsoft.AspNetCore.Mvc;
using Ocelot.Configuration.File;
using Ocelot.Configuration.Setter;
using Ocelot.Raft;

namespace Ocelot.Configuration
{
using Rafty.Concensus.Node;
using Repository;

[Authorize]
Expand Down Expand Up @@ -44,20 +42,6 @@ public async Task<IActionResult> Post([FromBody]FileConfiguration fileConfigurat
{
try
{
//todo - this code is a bit shit sort it out..
var test = _provider.GetService(typeof(INode));
if (test != null)
{
var node = (INode)test;
var result = await node.Accept(new UpdateFileConfiguration(fileConfiguration));
if (result.GetType() == typeof(Rafty.Infrastructure.ErrorResponse<UpdateFileConfiguration>))
{
return new BadRequestObjectResult("There was a problem. This error message sucks raise an issue in GitHub.");
}

return new OkObjectResult(result.Command.Configuration);
}

var response = await _setter.Set(fileConfiguration);

if (response.IsError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ namespace Ocelot.DependencyInjection
{
public interface IOcelotAdministrationBuilder
{
IOcelotAdministrationBuilder AddRafty();
}
}
29 changes: 5 additions & 24 deletions src/Ocelot/DependencyInjection/OcelotAdministrationBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.Raft;
using Rafty.Concensus;
using Rafty.FiniteStateMachine;
using Rafty.Infrastructure;
using Rafty.Log;

namespace Ocelot.DependencyInjection
{
using Rafty.Concensus.Node;

public class OcelotAdministrationBuilder : IOcelotAdministrationBuilder
{
private readonly IServiceCollection _services;
private readonly IConfiguration _configurationRoot;
private IServiceCollection Services { get; }
private IConfiguration ConfigurationRoot { get; }

public OcelotAdministrationBuilder(IServiceCollection services, IConfiguration configurationRoot)
{
_configurationRoot = configurationRoot;
_services = services;
}

public IOcelotAdministrationBuilder AddRafty()
{
var settings = new InMemorySettings(4000, 6000, 100, 10000);
_services.AddSingleton<ILog, SqlLiteLog>();
_services.AddSingleton<IFiniteStateMachine, OcelotFiniteStateMachine>();
_services.AddSingleton<ISettings>(settings);
_services.AddSingleton<IPeersProvider, FilePeersProvider>();
_services.AddSingleton<INode, Node>();
_services.Configure<FilePeers>(_configurationRoot);
return this;
ConfigurationRoot = configurationRoot;
Services = services;
}
}
}
34 changes: 0 additions & 34 deletions src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
using Ocelot.Configuration.Setter;
using Ocelot.Responses;
using Ocelot.Logging;
using Rafty.Concensus;
using Rafty.Infrastructure;
using Ocelot.Middleware.Pipeline;
using Rafty.Concensus.Node;
using Microsoft.Extensions.DependencyInjection;

public static class OcelotMiddlewareExtensions
Expand All @@ -42,11 +39,6 @@ public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder

CreateAdministrationArea(builder, configuration);

if (UsingRafty(builder))
{
SetUpRafty(builder);
}

ConfigureDiagnosticListener(builder);

return CreateOcelotPipeline(builder, pipelineConfiguration);
Expand Down Expand Up @@ -77,26 +69,6 @@ rest of asp.net..
return builder;
}

private static bool UsingRafty(IApplicationBuilder builder)
{
var node = builder.ApplicationServices.GetService<INode>();
if (node != null)
{
return true;
}

return false;
}

private static void SetUpRafty(IApplicationBuilder builder)
{
var applicationLifetime = builder.ApplicationServices.GetService<IApplicationLifetime>();
applicationLifetime.ApplicationStopping.Register(() => OnShutdown(builder));
var node = builder.ApplicationServices.GetService<INode>();
var nodeId = builder.ApplicationServices.GetService<NodeId>();
node.Start(nodeId);
}

private static async Task<IInternalConfiguration> CreateConfiguration(IApplicationBuilder builder)
{
// make configuration from file system?
Expand Down Expand Up @@ -207,11 +179,5 @@ private static void ConfigureDiagnosticListener(IApplicationBuilder builder)
var diagnosticListener = builder.ApplicationServices.GetService<DiagnosticListener>();
diagnosticListener.SubscribeWithAdapter(listener);
}

private static void OnShutdown(IApplicationBuilder app)
{
var node = app.ApplicationServices.GetService<INode>();
node.Stop();
}
}
}
1 change: 0 additions & 1 deletion src/Ocelot/Ocelot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.0" />
<PackageReference Include="Polly" Version="6.0.1" />
<PackageReference Include="IdentityServer4" Version="2.2.0" />
<PackageReference Include="Rafty" Version="0.4.4" />
</ItemGroup>
</Project>
17 changes: 0 additions & 17 deletions src/Ocelot/Raft/BearerToken.cs

This file was deleted.

7 changes: 0 additions & 7 deletions src/Ocelot/Raft/ExcludeFromCoverageAttribute.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/Ocelot/Raft/FakeCommand.cs

This file was deleted.

8 changes: 0 additions & 8 deletions src/Ocelot/Raft/FilePeer.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/Ocelot/Raft/FilePeers.cs

This file was deleted.

47 changes: 0 additions & 47 deletions src/Ocelot/Raft/FilePeersProvider.cs

This file was deleted.

131 changes: 0 additions & 131 deletions src/Ocelot/Raft/HttpPeer.cs

This file was deleted.

Loading

0 comments on commit cbd0af6

Please sign in to comment.