Skip to content

Commit

Permalink
Merge pull request #82 from Drawaes/maintMode
Browse files Browse the repository at this point in the history
Maint mode
  • Loading branch information
Drawaes authored Apr 10, 2017
2 parents a4e3c83 + 82f1259 commit 0bca657
Show file tree
Hide file tree
Showing 59 changed files with 277 additions and 368 deletions.
4 changes: 2 additions & 2 deletions .EditorConfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ASP.NET Core EditorConfig file
# ASP.NET Core EditorConfig file

# NOTE: This file focuses on settings Visual Studio 2017 supports natively. For example, VS does not support insert_final_newline.
# We do use it, but it's harder to enforce without a separate VS extension or an editor that supports it.
Expand Down Expand Up @@ -26,7 +26,7 @@ indent_size = 2
# .NET Code Style Settings
# See https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
# REVIEW: Should these be errors? warnings? suggestions?
[*.cs,*.vb]
[{*.cs,*.vb}]
dotnet_sort_system_directives_first = true

# Don't use 'this.'/'Me.' prefix for anything
Expand Down
7 changes: 5 additions & 2 deletions CondenserDotNet.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.9
VisualStudioVersion = 15.0.26403.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CB18CD55-85E2-46FC-A55B-7DE23EABFAE5}"
EndProject
Expand All @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{35C5
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{32AEF73B-E6B6-48DF-BF84-16FFB8A9DF04}"
ProjectSection(SolutionItems) = preProject
.EditorConfig = .EditorConfig
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
common.props = common.props
Expand Down Expand Up @@ -67,9 +68,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Release Notes", "Release No
releasenotes\2.1.2.props = releasenotes\2.1.2.props
releasenotes\2.1.3.props = releasenotes\2.1.3.props
releasenotes\2.2.0.props = releasenotes\2.2.0.props
releasenotes\2.3.0.props = releasenotes\2.3.0.props
releasenotes\2.4.0.props = releasenotes\2.4.0.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Condenser.FullFramework", "test\Condenser.FullFramework\Condenser.FullFramework.csproj", "{6E7DD120-4D6A-4BB0-B78C-AA5D5D4CFB78}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Condenser.FullFramework", "test\Condenser.FullFramework\Condenser.FullFramework.csproj", "{6E7DD120-4D6A-4BB0-B78C-AA5D5D4CFB78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
12 changes: 12 additions & 0 deletions releasenotes/2.4.0.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<PropertyGroup>
<PackageReleaseNotes>
* Added a callback on the leadership to give current leader
* Added maint mode enable/disable on the service manager
* Added middleware
* Puts it in maint mode
* Performs the cleanshutdown
* Takes it out of maint mode after startup
</PackageReleaseNotes>
</PropertyGroup>
</Project>
8 changes: 8 additions & 0 deletions src/CondenserDotNet.Client/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>", Scope = "member", Target = "~P:CondenserDotNet.Client.DataContracts.HealthCheck.tls_skip_verify")]

2 changes: 1 addition & 1 deletion src/CondenserDotNet.Client/HealthConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public HealthCheck Build(IServiceManager manager)
if (Url == null) return null;
if (!Uri.TryCreate(Url, UriKind.Absolute, out Uri uri))
{
string scheme = manager.ProtocolSchemeTag ?? "http";
var scheme = manager.ProtocolSchemeTag ?? "http";
var builder = new UriBuilder(scheme, manager.ServiceAddress, manager.ServicePort, Url);
uri = builder.Uri;
}
Expand Down
12 changes: 5 additions & 7 deletions src/CondenserDotNet.Client/Leadership/LeaderWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private async Task TryForElection()
{
_electedLeaderEvent.Set(true);
}
for (int i = 0; i < 2; i++)
for (var i = 0; i < 2; i++)
{
leaderResult = await _serviceManager.Client.GetAsync($"{KeyPath}{_keyToWatch}?index={consulIndex}");
if (!leaderResult.IsSuccessStatusCode)
Expand Down Expand Up @@ -93,22 +93,20 @@ private async Task TryForElection()
}
}

private StringContent GetServiceInformation()
{
return HttpUtils.GetStringContent(new InformationService()
private StringContent GetServiceInformation() =>
HttpUtils.GetStringContent(new InformationService()
{
Address = _serviceManager.ServiceAddress,
ID = _serviceManager.ServiceId,
Port = _serviceManager.ServicePort,
Service = _serviceManager.ServiceName,
Tags = _serviceManager.RegisteredService.Tags.ToArray()
});
}

private StringContent GetCreateSession()
{
string[] checks = new string[_serviceManager.RegisteredService.Checks.Count + 1];
for (int i = 0; i < _serviceManager.RegisteredService.Checks.Count; i++)
var checks = new string[_serviceManager.RegisteredService.Checks.Count + 1];
for (var i = 0; i < _serviceManager.RegisteredService.Checks.Count; i++)
{
checks[i] = _serviceManager.RegisteredService.Checks[i].Name;
}
Expand Down
25 changes: 25 additions & 0 deletions src/CondenserDotNet.Client/MaintenanceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace CondenserDotNet.Client
{
public static class MaintenanceExtensions
{
private const string _url = "/v1/agent/service/maintenance/";

public static Task EnableMaintenanceModeAsync(this IServiceManager manager, string reason)
{
var url = _url + $"{manager.ServiceId}?enable=true&reason={Uri.EscapeDataString(reason)}";
return manager.Client.PutAsync(url, null);
}

public static Task DisableMaintenanceModeAsync(this IServiceManager manager)
{
var url = _url + $"{manager.ServiceId}?enable=false";
return manager.Client.PutAsync(url, new StringContent(string.Empty));
}
}
}
3 changes: 1 addition & 2 deletions src/CondenserDotNet.Client/RegistrationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static IServiceManager AddHttpHealthCheck(this IServiceManager serviceMan
{
serviceManager.HealthConfig.Url = url;
serviceManager.HealthConfig.IntervalInSeconds = intervalInSeconds;

return serviceManager;
}

Expand Down Expand Up @@ -82,7 +81,7 @@ public static async Task<bool> RegisterServiceAsync(this IServiceManager service
}
if (s.Checks.Count > 1)
{
for (int i = 0; i < s.Checks.Count; i++)
for (var i = 0; i < s.Checks.Count; i++)
{
s.Checks[i].Name = $"service:{s.ID}:{i + 1}";
if (serviceManager.DeregisterIfCriticalAfter != default(TimeSpan))
Expand Down
2 changes: 1 addition & 1 deletion src/CondenserDotNet.Client/ServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void Dispose(bool disposing)
_disposed = true;
}
}

~ServiceManager() => Dispose(false);
}
}
2 changes: 1 addition & 1 deletion src/CondenserDotNet.Client/ServiceManagerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ServiceManagerConfig
public static int GetNextAvailablePort()
{
var l = new TcpListener(IPAddress.Loopback, 0);
int port = 0;
var port = 0;
try
{
l.Start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ namespace CondenserDotNet.Client.Services
public class NoServiceInstanceFoundException : Exception
{
public NoServiceInstanceFoundException(string serviceName, Exception innerException)
: base($"Unable to find an instance of the service {serviceName}", innerException)
{
ServiceName = serviceName;
}
: base($"Unable to find an instance of the service {serviceName}", innerException) => ServiceName = serviceName;

public string ServiceName { get; }
public override string ToString() => Message;
Expand Down
5 changes: 2 additions & 3 deletions src/CondenserDotNet.Client/Services/ServiceWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ internal class ServiceWatcher : IDisposable
private static int s_getServiceDelay = 3000;
private Action<List<InformationServiceSet>> _listCallback;

internal ServiceWatcher(string serviceName, HttpClient client,
IRoutingStrategy<InformationServiceSet> routingStrategy, ILogger logger)
internal ServiceWatcher(string serviceName, HttpClient client, IRoutingStrategy<InformationServiceSet> routingStrategy, ILogger logger)
{
_serviceName = serviceName;
_logger = logger;
Expand Down Expand Up @@ -69,7 +68,7 @@ private async Task WatcherLoop(HttpClient client)
{
try
{
string consulIndex = "0";
var consulIndex = "0";
while (!_cancelationToken.Token.IsCancellationRequested)
{
var result = await client.GetAsync(_url + consulIndex, _cancelationToken.Token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ namespace CondenserDotNet.Configuration
{
public static class ConfigurationRegistryExtensions
{
public static Task<bool> SetKeyJsonAsync<T>(this IConfigurationRegistry self, string key, T value)
{
return self.SetKeyAsync(key, JsonConvert.SerializeObject(value));
}
public static Task<bool> SetKeyJsonAsync<T>(this IConfigurationRegistry self, string key, T value) => self.SetKeyAsync(key, JsonConvert.SerializeObject(value));
}
}
10 changes: 2 additions & 8 deletions src/CondenserDotNet.Configuration/ConfigurationRegistrySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ public class ConfigurationRegistrySource : IConfigurationSource
{
private readonly IConfigurationRegistry _configurationRegistry;

public ConfigurationRegistrySource(IConfigurationRegistry configurationRegistry)
{
_configurationRegistry = configurationRegistry;
}
public ConfigurationRegistrySource(IConfigurationRegistry configurationRegistry) => _configurationRegistry = configurationRegistry;

public IConfigurationProvider Build(IConfigurationBuilder builder)
{
return new ConfigurationRegistryProvider(_configurationRegistry);
}
public IConfigurationProvider Build(IConfigurationBuilder builder) => new ConfigurationRegistryProvider(_configurationRegistry);
}
}
11 changes: 4 additions & 7 deletions src/CondenserDotNet.Configuration/Consul/ConsulRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ public ConsulRegistry(IOptions<ConsulRegistryConfig> agentConfig)
/// This returns a flattened list of all the loaded keys
/// </summary>
public IEnumerable<string> AllKeys => _configKeys.SelectMany(x => x.Keys);
public void UpdateKeyParser(IKeyParser parser)
{
_parser = parser;
}
public void UpdateKeyParser(IKeyParser parser) => _parser = parser;

/// <summary>
/// This loads the keys from a path. They are not updated.
Expand Down Expand Up @@ -95,7 +92,7 @@ private async Task WatchingLoop(int indexOfDictionary, string keyPath)
try
{
var consulIndex = "0";
string url = $"{ConsulKeyPath}{keyPath}?recurse&wait=300s&index=";
var url = $"{ConsulKeyPath}{keyPath}?recurse&wait=300s&index=";
while (true)
{
var response = await _httpClient.GetAsync(url + consulIndex, _disposed.Token);
Expand Down Expand Up @@ -184,7 +181,7 @@ public bool TryGetValue(string key, out string value)
{
lock (_configKeys)
{
for (int i = _configKeys.Count - 1; i >= 0; i--)
for (var i = _configKeys.Count - 1; i >= 0; i--)
{
if (_configKeys[i].TryGetValue(key, out value))
{
Expand Down Expand Up @@ -244,7 +241,7 @@ public static string GetConsulIndex(HttpResponseMessage response)

public static string StripFrontAndBackSlashes(string inputString)
{
int startIndex = inputString.StartsWith("/") ? 1 : 0;
var startIndex = inputString.StartsWith("/") ? 1 : 0;
return inputString.Substring(startIndex, (inputString.Length - startIndex) - (inputString.EndsWith("/") ? 1 : 0));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -52,10 +52,7 @@ private void VisitJObject(JObject jObject)
}
}

private void VisitProperty(JProperty property)
{
VisitToken(property.Value);
}
private void VisitProperty(JProperty property) => VisitToken(property.Value);

private void VisitToken(JToken token)
{
Expand Down
15 changes: 4 additions & 11 deletions src/CondenserDotNet.Configuration/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ namespace CondenserDotNet.Configuration
public static class ServiceCollectionExtensions
{

public static IServiceCollection ConfigureReloadable<TConfig>(this IServiceCollection self,
IConfiguration configuration, IConfigurationRegistry registry)
where TConfig : class
{
return self.ConfigureReloadable<TConfig>(configuration, registry, typeof(TConfig).Name);
}
public static IServiceCollection ConfigureReloadable<TConfig>(this IServiceCollection self, IConfiguration configuration, IConfigurationRegistry registry)
where TConfig : class =>
self.ConfigureReloadable<TConfig>(configuration, registry, typeof(TConfig).Name);

public static IServiceCollection ConfigureReloadable<TConfig>(this IServiceCollection self,
IConfiguration configuration, IConfigurationRegistry registry,
string sectionName)
public static IServiceCollection ConfigureReloadable<TConfig>(this IServiceCollection self, IConfiguration configuration, IConfigurationRegistry registry, string sectionName)
where TConfig : class
{
var initialised = false;
Expand All @@ -28,13 +23,11 @@ public static IServiceCollection ConfigureReloadable<TConfig>(this IServiceColle
var section = configuration.GetSection(sectionName);
section.Bind(config);
};
if (!initialised)
{
registry.AddWatchOnEntireConfig(bind);
initialised = true;
}
bind();
});

Expand Down
20 changes: 4 additions & 16 deletions src/CondenserDotNet.Core/DataContracts/InformationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ public class InformationService : IEquatable<InformationService>

public bool Equals(InformationService other)
{
if (Address != other.Address)
{
return false;
}
if (Port != other.Port)
{
return false;
}
if (Service != other.Service)
{
return false;
}
if (ID != other.ID)
{
return false;
}
if (Address != other.Address) return false;
if (Port != other.Port) return false;
if (Service != other.Service) return false;
if (ID != other.ID) return false;
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/CondenserDotNet.Core/HttpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static string GetConsulIndex(this HttpResponseMessage response)

public static string StripFrontAndBackSlashes(string inputString)
{
int startIndex = inputString.StartsWith("/") ? 1 : 0;
var startIndex = inputString.StartsWith("/") ? 1 : 0;
return inputString.Substring(startIndex, (inputString.Length - startIndex) - (inputString.EndsWith("/") ? 1 : 0));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/CondenserDotNet.Core/ServiceUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public static class ServiceUtils

public static string[] RoutesFromTags(string[] tags)
{
int returnCount = 0;
for (int i = 0; i < tags.Length; i++)
var returnCount = 0;
for (var i = 0; i < tags.Length; i++)
{
if (!tags[i].StartsWith(UrlPrefix))
{
Expand All @@ -17,7 +17,7 @@ public static string[] RoutesFromTags(string[] tags)
}
var returnValues = new string[returnCount];
returnCount = 0;
for (int i = 0; i < tags.Length; i++)
for (var i = 0; i < tags.Length; i++)
{
if (!tags[i].StartsWith(UrlPrefix))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static Task WriteBodyAsync(this IPipeConnection connection, HttpContext c

private static async Task WriteBody(this IPipeConnection connection, HttpContext context)
{
long bytesToWrite = context.Request.ContentLength.Value;
var bytesToWrite = context.Request.ContentLength.Value;
while (bytesToWrite > 0)
{
var buffer = connection.Output.Alloc(1024);
Expand Down
Loading

0 comments on commit 0bca657

Please sign in to comment.