Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support for Retrieving Nodes that support Mesh Capable Service #248

Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Consul.Test/CatalogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,37 @@ public async Task Catalog_GetTaggedAddressesService()
Assert.True(services.Response[0].ServiceTaggedAddresses.ContainsKey("lan"));
}

[Fact]
public async Task Catalog_GetNodesForMeshCapableService()
{
var svcID = KVTest.GenerateTestKeyName();
var registration = new CatalogRegistration
{
Datacenter = "dc1",
Node = "foobar",
Address = "192.168.10.10",
Service = new AgentService
{
ID = svcID,
Service = "redis",
Tags = new[] { "master", "v1" },
Port = 8000,
TaggedAddresses = new Dictionary<string, ServiceTaggedAddress>
{
{"lan", new ServiceTaggedAddress {Address = "127.0.0.1", Port = 80}},
{"wan", new ServiceTaggedAddress {Address = "192.168.10.10", Port = 8000}}
}
}
};

await _client.Catalog.Register(registration);

var services = await _client.Catalog.NodesForMeshCapableService("redis");

Assert.True(services.Response.Length == 0);

}

[Fact]
public async Task Catalog_EnableTagOverride()
{
Expand Down
39 changes: 39 additions & 0 deletions Consul/Catalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Consul.Filtering;
using Newtonsoft.Json;

namespace Consul
Expand Down Expand Up @@ -237,6 +238,44 @@ public Task<QueryResult<CatalogService[]>> Service(string service, string tag, Q
return req.Execute(ct);
}

/// <summary>
/// Returns the nodes providing a mesh-capable service in a given datacenter.
/// </summary>
/// <param name="service">The service ID</param>
/// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
/// <returns>A list of service instances</returns>
public Task<QueryResult<CatalogService[]>> NodesForMeshCapableService(string service, CancellationToken ct = default)
{
return NodesForMeshCapableService(service, QueryOptions.Default, null, ct);
}

/// <summary>
/// Returns the nodes providing a mesh-capable service in a given datacenter.
/// </summary>
/// <param name="service">The service ID</param>
/// <param name="filter">Specifies the expression used to filter the queries results prior to returning the data</param>
/// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
/// <returns>A list of service instances</returns>
public Task<QueryResult<CatalogService[]>> NodesForMeshCapableService(string service, Filter filter, CancellationToken ct = default)
{
return NodesForMeshCapableService(service, QueryOptions.Default, filter, ct);
}

/// <summary>
/// Returns the nodes providing a mesh-capable service in a given datacenter.
/// </summary>
/// <param name="service">The service ID</param>
/// <param name="q">Customized Query options</param>
/// <param name="filter">Specifies the expression used to filter the queries results prior to returning the data</param>
/// <param name="ct">Cancellation token for long poll request. If set, OperationCanceledException will be thrown if the request is cancelled before completing</param>
/// <returns>A list of service instances</returns>
public Task<QueryResult<CatalogService[]>> NodesForMeshCapableService(string service, QueryOptions q, Filter filter, CancellationToken ct = default)
{
var req = _client.Get<CatalogService[]>(string.Format("/v1/catalog/connect/{0}", service), q, filter);

return req.Execute(ct);
}

/// <summary>
/// Node is used to query for service information about a single node
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions Consul/Interfaces/ICatalogEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Consul.Filtering;

namespace Consul
{
Expand All @@ -44,5 +45,8 @@ public interface ICatalogEndpoint
Task<QueryResult<CatalogService[]>> Service(string service, string tag, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<Dictionary<string, string[]>>> Services(CancellationToken ct = default);
Task<QueryResult<Dictionary<string, string[]>>> Services(QueryOptions q, CancellationToken ct = default);
Task<QueryResult<CatalogService[]>> NodesForMeshCapableService(string service, Filter filter, CancellationToken ct = default);
Task<QueryResult<CatalogService[]>> NodesForMeshCapableService(string service, QueryOptions q, Filter filter, CancellationToken ct = default);
Task<QueryResult<CatalogService[]>> NodesForMeshCapableService(string service, CancellationToken ct = default);
}
}