Skip to content

Commit

Permalink
Merge pull request #4 from jordansjones/version-1_x_x
Browse files Browse the repository at this point in the history
Version 1 x x
  • Loading branch information
jordansjones committed Jul 4, 2015
2 parents d026aa9 + c2799f2 commit 63f504c
Show file tree
Hide file tree
Showing 71 changed files with 1,722 additions and 225 deletions.
16 changes: 16 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
### New in 1.0.0 (Release 2015/07/03)
* New: `EndpointVerificationStrategy.ClusterMembers` - Similar verification as `EndpointVerificationStrategy.Any` but also adds verified cluster members to the `EndpointPool`.
* New: `IEtcdClient.Statistics`
* `GetLeaderStatistics` - Retrieve the statistical information for leader of the etcd cluster
* `GetServerStatistics` - Retrieve the statistical information for the server (Which server depends on how the `EndpointPool` was built)
* `GetStoreStatistics` - Retrieve the etcd backing store statistics (For which server depends on how the `EndpointPool` was built)
* Breaking Change: `IEtcdClient.Enqueue` has been moved to `IEtcdClient.Atomic.Enqueue`
* Breaking Change: `IKeyDataValueConverter` overhaul
* `object ReadString(string value)` has been refactored into `T Read<T>(string value)`
* `string WriteString(object value)` has been refactored into `string Write<T>(T value)`
* Change: The following have been annotated with `[Serializable]`
* `Endpoint`
* `EndpointPool`
* `EndpointRoutingStrategy`
* `EndpointVerificationStrategy`

### New in 0.2.1 (Released 2015/05/07)
* Fixed: `NullReferenceException` thrown when a `WebException` occurs due to a client connection problem.

Expand Down
4 changes: 2 additions & 2 deletions meta/Draft.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<copyright>Copyright 2015 Jordan S. Jones</copyright>
<dependencies>
<group targetFramework="net45">
<dependency id="Flurl" version="1.0.6" />
<dependency id="Flurl.Http" version="0.5.0" />
<dependency id="Flurl" version="1.0.8" />
<dependency id="Flurl.Http" version="0.6.2" />
<dependency id="Newtonsoft.Json" version="6.0.8" />
<dependency id="Rx-Core" version="2.2.5" />
<dependency id="Rx-Interfaces" version="2.2.5" />
Expand Down
6 changes: 6 additions & 0 deletions source/Draft/Constants.Etcd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ internal static partial class Etcd

public const string Path_Stats = "/v2/stats";

public const string Path_Stats_Leader = Path_Stats + "/leader";

public const string Path_Stats_Self = Path_Stats + "/self";

public const string Path_Stats_Store = Path_Stats + "/store";

public const string Path_Version = "/version";

}
Expand Down
15 changes: 8 additions & 7 deletions source/Draft/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ namespace Draft
public static class Converters
{

private static IKeyDataValueConverter _default;

internal static readonly JsonValueConverter JsonConverter = new JsonValueConverter();

internal static readonly StringValueConverter StringConverter = new StringValueConverter();

static Converters()
{
Default = Json;
}

/// <summary>
/// The default converter.
/// </summary>
public static IKeyDataValueConverter Default { get; internal set; }
public static IKeyDataValueConverter Default
{
get { return _default ?? Json; }
internal set { _default = value; }
}

/// <summary>
/// Json based converter.
/// </summary>
public static IJsonKeyDataValueConverter Json
public static IKeyDataValueConverter Json
{
get { return JsonConverter; }
}
Expand Down
31 changes: 23 additions & 8 deletions source/Draft/Draft-Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Flurl, Version=1.0.7.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.1.0.7\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Flurl.dll</HintPath>
<Reference Include="Flurl, Version=1.0.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.1.0.8\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Flurl.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Flurl.Http, Version=0.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.0.6.0\lib\net45\Flurl.Http.dll</HintPath>
<Reference Include="Flurl.Http, Version=0.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.0.6.2\lib\net45\Flurl.Http.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -78,6 +78,8 @@
<Compile Include="Endpoints\VerificationStrategy.None.cs" />
<Compile Include="Endpoints\VerificationStrategy.All.cs" />
<Compile Include="Endpoints\VerificationStrategy.Any.cs" />
<Compile Include="Endpoints\VerificationStrategy.ClusterMembers.cs" />
<Compile Include="Exceptions\BadRequestException.cs" />
<Compile Include="Exceptions\ClientInternalException.cs" />
<Compile Include="Exceptions\DirectoryNotEmptyException.cs" />
<Compile Include="Exceptions\EtcdException.cs" />
Expand Down Expand Up @@ -106,6 +108,7 @@
<Compile Include="Exceptions\PreviousValueRequiredException.cs" />
<Compile Include="Exceptions\RaftInternalException.cs" />
<Compile Include="Exceptions\RootIsReadOnlyException.cs" />
<Compile Include="Exceptions\ServiceUnavailableException.cs" />
<Compile Include="Exceptions\StandbyInternalException.cs" />
<Compile Include="Exceptions\TestFailedException.cs" />
<Compile Include="Exceptions\TimeoutNotANumberException.cs" />
Expand All @@ -121,6 +124,7 @@
<Compile Include="Helpers\FormBodyBuilder.cs" />
<Compile Include="Helpers\IRandom.cs" />
<Compile Include="Helpers\StaticRandom.cs" />
<Compile Include="Helpers\NormalizedPathSegment.cs" />
<Compile Include="Json\EtcdErrorCodeConverter.cs" />
<Compile Include="Requests\Cluster\CreateMemberRequest.cs" />
<Compile Include="Requests\Cluster\DeleteMemberRequest.cs" />
Expand All @@ -134,6 +138,12 @@
<Compile Include="Requests\Cluster\UpdateMemberPeerUrlsRequest.cs" />
<Compile Include="Requests\GetVersionRequest.cs" />
<Compile Include="Requests\IGetVersionRequest.cs" />
<Compile Include="Requests\Statistics\GetLeaderStatisticsRequest.cs" />
<Compile Include="Requests\Statistics\GetSelfStatisticsRequest.cs" />
<Compile Include="Requests\Statistics\GetStoreStatisticsRequest.cs" />
<Compile Include="Requests\Statistics\IGetLeaderStatisticsRequest.cs" />
<Compile Include="Requests\Statistics\IGetServerStatisticsRequest.cs" />
<Compile Include="Requests\Statistics\IGetStoreStatisticsRequest.cs" />
<Compile Include="Responses\Cluster\ClusterMember.cs" />
<Compile Include="Responses\Cluster\ClusterMemberCollection.cs" />
<Compile Include="Responses\Cluster\IClusterMember.cs" />
Expand All @@ -143,6 +153,13 @@
<Compile Include="Responses\IEtcdVersion.cs" />
<Compile Include="Responses\IHaveAValueConverter.cs" />
<Compile Include="Responses\IHaveResponseHeaders.cs" />
<Compile Include="Responses\Statistics\IFollowerCounts.cs" />
<Compile Include="Responses\Statistics\IFollowerLatency.cs" />
<Compile Include="Responses\Statistics\IFollowerStatistics.cs" />
<Compile Include="Responses\Statistics\ILeaderInfo.cs" />
<Compile Include="Responses\Statistics\ILeaderStatistics.cs" />
<Compile Include="Responses\Statistics\IServerStatistics.cs" />
<Compile Include="Responses\Statistics\IStoreStatistics.cs" />
<Compile Include="ValueConverters\JsonValueConverter.cs" />
<Compile Include="ValueConverters\StringValueConverter.cs" />
<Compile Include="Etcd.cs" />
Expand Down Expand Up @@ -197,9 +214,7 @@
<Compile Include="Constants.ErrorCode.cs" />
<None Include="packages.Draft-Net45.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Requests\Statistics\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
37 changes: 35 additions & 2 deletions source/Draft/Endpoints/Endpoint.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
using System;
using System.Linq;
using System.Runtime.Serialization;

namespace Draft.Endpoints
{
/// <summary>
/// Represents a verified etcd endpoint.
/// </summary>
[Serializable, DataContract]
public sealed class Endpoint : IEquatable<Endpoint>
{

/// <summary>
/// Initializes a new <see cref="Endpoint" /> class with default values for <see cref="Availability" /> and
/// <see cref="Uri" />.
/// </summary>
public Endpoint()
: this(default(Uri), default(EndpointAvailability)) {}

/// <summary>
/// Initializes a new <see cref="Endpoint" /> class with the specified <paramref name="availability" /> and
/// <paramref name="uri" />.
Expand All @@ -24,11 +33,13 @@ public Endpoint(Uri uri, EndpointAvailability availability)
/// <summary>
/// <see cref="EndpointAvailability" /> value of this etcd endpoint.
/// </summary>
[DataMember(Order = 1)]
public EndpointAvailability Availability { get; private set; }

/// <summary>
/// Is <c>true</c> when <see cref="Availability" /><c> == </c><see cref="EndpointAvailability.Online" />.
/// </summary>
[IgnoreDataMember]
public bool IsOnline
{
get { return Availability == EndpointAvailability.Online; }
Expand All @@ -37,16 +48,37 @@ public bool IsOnline
/// <summary>
/// <see cref="Uri" /> value of this etcd endpoint.
/// </summary>
[DataMember(Order = 2)]
public Uri Uri { get; private set; }

/// <summary>
/// Creates a new <see cref="Endpoint" /> instance with the specified <paramref name="availability" /> value.
/// </summary>
/// <returns>A new <see cref="Endpoint" /> instance with the specified <paramref name="availability" /> value.</returns>
public Endpoint WithEndpointAvailability(EndpointAvailability availability)
{
return new Endpoint(Uri, availability);
}

/// <summary>
/// Creates a new <see cref="Endpoint" /> instance with the specified <paramref name="uri" /> value.
/// </summary>
/// <returns>A new <see cref="Endpoint" /> instance with the specified <paramref name="uri" /> value.</returns>
public Endpoint WithUri(Uri uri)
{
return new Endpoint(uri, Availability);
}

#region Equality

/// <summary>
/// Determines whether the specified <see cref="Endpoint" /> is equal to the current <see cref="Endpoint" />.
/// </summary>
public bool Equals(Endpoint other)
{
if (ReferenceEquals(null, other)) { return false; }
if (ReferenceEquals(this, other)) { return true; }
return Availability == other.Availability && Equals(Uri, other.Uri);
return Equals(Uri, other.Uri);
}

/// <summary>
Expand All @@ -64,7 +96,7 @@ public override bool Equals(object obj)
/// </summary>
public override int GetHashCode()
{
unchecked { return ((int) Availability * 397) ^ (Uri != null ? Uri.GetHashCode() : 0); }
unchecked { return (Uri != null ? Uri.GetHashCode() : 0); }
}

/// <summary>
Expand All @@ -83,5 +115,6 @@ public override int GetHashCode()
return !Equals(left, right);
}

#endregion
}
}
13 changes: 7 additions & 6 deletions source/Draft/Endpoints/EndpointPool.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

using Flurl;

Expand All @@ -9,6 +10,7 @@ namespace Draft.Endpoints
/// <summary>
/// Pool of Etcd Endpoints
/// </summary>
[Serializable, DataContract]
public sealed partial class EndpointPool
{

Expand All @@ -18,23 +20,22 @@ internal EndpointPool(IEnumerable<Endpoint> endpoints, EndpointRoutingStrategy r
RoutingStrategy = routingStrategy;
}

[DataMember(Order = 1)]
internal List<Endpoint> AllEndpoints { get; private set; }

[IgnoreDataMember]
internal Endpoint[] OnlineEndpoints
{
get { return AllEndpoints.Where(x => x.IsOnline).ToArray(); }
}

[DataMember(Order = 2)]
internal EndpointRoutingStrategy RoutingStrategy { get; private set; }

internal Url GetEndpointUrl(params string[] pathParts)
{
pathParts = pathParts ?? new string[0];

var keyPath = string.Join("/", pathParts.Select(x => x.TrimStart('/').TrimEnd('/')));

return RoutingStrategy.Select(keyPath, OnlineEndpoints).Uri.ToUrl()
.AppendPathSegment(keyPath);
var pathSegment = new NormalizedPathSegment(pathParts);
return pathSegment.ToUrl(RoutingStrategy.Select(pathSegment.Value, OnlineEndpoints).Uri);
}

}
Expand Down
9 changes: 9 additions & 0 deletions source/Draft/Endpoints/EndpointRoutingStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System;
using System.Linq;
using System.Runtime.Serialization;

namespace Draft.Endpoints
{
/// <summary>
/// Represents a strategy for selecting which etcd endpoint to use for http calls.
/// </summary>
[Serializable, DataContract]
public abstract class EndpointRoutingStrategy
{

[IgnoreDataMember]
internal static EndpointRoutingStrategy Default
{
get { return First; }
Expand All @@ -24,15 +27,19 @@ internal static EndpointRoutingStrategy Default

#region Built-in strategies

[IgnoreDataMember]
private static readonly Lazy<EndpointRoutingStrategy> LazyFirst = new Lazy<EndpointRoutingStrategy>(() => new RoutingStrategyFirst());

[IgnoreDataMember]
private static readonly Lazy<EndpointRoutingStrategy> LazyRandom = new Lazy<EndpointRoutingStrategy>(() => new RoutingStrategyRandom());

[IgnoreDataMember]
private static readonly Lazy<EndpointRoutingStrategy> LazyRoundRobin = new Lazy<EndpointRoutingStrategy>(() => new RoutingStrategyRoundRobin());

/// <summary>
/// Uses the first <see cref="Endpoint" />.
/// </summary>
[IgnoreDataMember]
public static EndpointRoutingStrategy First
{
get { return LazyFirst.Value; }
Expand All @@ -41,6 +48,7 @@ public static EndpointRoutingStrategy First
/// <summary>
/// Uses a randomly selected <see cref="Endpoint" />.
/// </summary>
[IgnoreDataMember]
public static EndpointRoutingStrategy Random
{
get { return LazyRandom.Value; }
Expand All @@ -49,6 +57,7 @@ public static EndpointRoutingStrategy Random
/// <summary>
/// Uses a round-robin patter for selecting the <see cref="Endpoint" />.
/// </summary>
[IgnoreDataMember]
public static EndpointRoutingStrategy RoundRobin
{
get { return LazyRoundRobin.Value; }
Expand Down
Loading

0 comments on commit 63f504c

Please sign in to comment.