diff --git a/Consul.Test/CoordinateTest.cs b/Consul.Test/CoordinateTest.cs index 3793c0177..aa33a6326 100644 --- a/Consul.Test/CoordinateTest.cs +++ b/Consul.Test/CoordinateTest.cs @@ -18,6 +18,7 @@ // ----------------------------------------------------------------------- using System; +using System.Net; using System.Threading.Tasks; using Xunit; @@ -73,5 +74,46 @@ public async Task Coordinate_GetNode() Assert.IsType(nodeDetails); Assert.NotEmpty(nodeDetails); } + + [Fact] + public async Task Coordinate_Update() + { + var nodeName = "foo-update-lan"; + var registration = new CatalogRegistration + { + Node = nodeName, + Address = "1.1.1.1" + }; + var register = await _client.Catalog.Register(registration); + var nodeResult = await _client.Catalog.Node(nodeName); + Assert.Equal(HttpStatusCode.OK, nodeResult.StatusCode); + + var coord = new CoordinateEntry + { + Node = nodeName, + Coord = new SerfCoordinate + { + Error = 1.5, + Height = 0.5, + Adjustment = 0.0, + Vec = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, + } + }; + + var response = await _client.Coordinate.Update(coord); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + var q = new QueryOptions { WaitIndex = nodeResult.LastIndex, }; + var newCoordResult = await _client.Coordinate.Node(nodeName, q); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotNull(newCoordResult.Response); + + var newCoord = newCoordResult.Response[0]; + Assert.Equal(coord.Coord.Vec.Count, newCoord.Coord.Vec.Count); + Assert.Equal(coord.Node, newCoord.Node); + Assert.True(Math.Abs(coord.Coord.Height - newCoord.Coord.Height) <= 0.00001); + Assert.True(Math.Abs(coord.Coord.Adjustment - newCoord.Coord.Adjustment) <= 0.00001); + Assert.True(Math.Abs(coord.Coord.Error - newCoord.Coord.Error) <= 0.00001); + } } } diff --git a/Consul/Coordinate.cs b/Consul/Coordinate.cs index 76b527968..ea70009e4 100644 --- a/Consul/Coordinate.cs +++ b/Consul/Coordinate.cs @@ -26,6 +26,7 @@ namespace Consul public class CoordinateEntry { public string Node { get; set; } + public string Segment { get; set; } public SerfCoordinate Coord { get; set; } } @@ -105,6 +106,29 @@ public Task> Node(string node, CancellationToken { return Node(node, QueryOptions.Default, ct); } + + /// + /// Updates the LAN network coordinates for a node in a given datacenter. + /// + /// The coordinate entry to update + /// Customized write options + /// Cancellation Token + /// An empty write result + public Task Update(CoordinateEntry entry, WriteOptions q, CancellationToken ct = default) + { + return _client.Put("/v1/coordinate/update", entry, q).Execute(ct); + } + + /// + /// Updates the LAN network coordinates for a node in a given datacenter. + /// + /// The coordinate entry to update + /// Cancellation Token + /// An empty write result + public Task Update(CoordinateEntry entry, CancellationToken ct = default) + { + return Update(entry, WriteOptions.Default, ct); + } } public partial class ConsulClient : IConsulClient diff --git a/Consul/Interfaces/ICoordinateEndpoint.cs b/Consul/Interfaces/ICoordinateEndpoint.cs index f82dc4b81..6465c38d1 100644 --- a/Consul/Interfaces/ICoordinateEndpoint.cs +++ b/Consul/Interfaces/ICoordinateEndpoint.cs @@ -32,5 +32,7 @@ public interface ICoordinateEndpoint Task> Node(string node, QueryOptions q, CancellationToken ct = default); Task> Node(string node, CancellationToken ct = default); Task> Nodes(QueryOptions q, CancellationToken ct = default); + Task Update(CoordinateEntry entry, WriteOptions q, CancellationToken ct = default); + Task Update(CoordinateEntry entry, CancellationToken ct = default); } }