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

Add CCR Follow Info API #3927

Merged
merged 6 commits into from
Jul 16, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static class CodeConfiguration
"indices.freeze.json",
"indices.unfreeze.json",

"ccr.follow_info.json",
"ccr.forget_follower.json"
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public string WaitForActiveShards
}
}

///<summary>Request options for FollowInfo <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</para></summary>
public class FollowInfoRequestParameters : RequestParameters<FollowInfoRequestParameters>
{
public override HttpMethod DefaultHttpMethod => HttpMethod.GET;
}

///<summary>Request options for FollowIndexStats <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html</para></summary>
public class FollowIndexStatsRequestParameters : RequestParameters<FollowIndexStatsRequestParameters>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public TResponse CreateFollowIndex<TResponse>(string index, PostData body, Creat
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public Task<TResponse> CreateFollowIndexAsync<TResponse>(string index, PostData body, CreateFollowIndexRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(PUT, Url($"{index:index}/_ccr/follow"), ctx, body, RequestParams(requestParameters));
///<summary>GET on /{index}/_ccr/info <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</para></summary>
///<param name = "index">A comma-separated list of index patterns; use `_all` to perform the operation on all indices</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse FollowInfo<TResponse>(string index, FollowInfoRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(GET, Url($"{index:index}/_ccr/info"), null, RequestParams(requestParameters));
///<summary>GET on /{index}/_ccr/info <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</para></summary>
///<param name = "index">A comma-separated list of index patterns; use `_all` to perform the operation on all indices</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public Task<TResponse> FollowInfoAsync<TResponse>(string index, FollowInfoRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, Url($"{index:index}/_ccr/info"), ctx, null, RequestParams(requestParameters));
///<summary>GET on /{index}/_ccr/stats <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html</para></summary>
///<param name = "index">A comma-separated list of index patterns; use `_all` to perform the operation on all indices</param>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
Expand Down
28 changes: 28 additions & 0 deletions src/Nest/Descriptors.CrossClusterReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ public CreateFollowIndexDescriptor Index<TOther>()
public CreateFollowIndexDescriptor WaitForActiveShards(string waitforactiveshards) => Qs("wait_for_active_shards", waitforactiveshards);
}

///<summary>descriptor for FollowInfo <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</para></summary>
public partial class FollowInfoDescriptor : RequestDescriptorBase<FollowInfoDescriptor, FollowInfoRequestParameters, IFollowInfoRequest>, IFollowInfoRequest
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.CrossClusterReplicationFollowInfo;
///<summary>/{index}/_ccr/info</summary>
///<param name = "index">this parameter is required</param>
public FollowInfoDescriptor(Indices index): base(r => r.Required("index", index))
{
}

///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
[SerializationConstructor]
protected FollowInfoDescriptor(): base()
{
}

// values part of the url path
Indices IFollowInfoRequest.Index => Self.RouteValues.Get<Indices>("index");
///<summary>A comma-separated list of index patterns; use `_all` to perform the operation on all indices</summary>
public FollowInfoDescriptor Index(Indices index) => Assign(index, (a, v) => a.RouteValues.Required("index", v));
///<summary>a shortcut into calling Index(typeof(TOther))</summary>
public FollowInfoDescriptor Index<TOther>()
where TOther : class => Assign(typeof(TOther), (a, v) => a.RouteValues.Required("index", (Indices)v));
///<summary>A shortcut into calling Index(Indices.All)</summary>
public FollowInfoDescriptor AllIndices() => Index(Indices.All);
// Request parameters
}

///<summary>descriptor for FollowIndexStats <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html</para></summary>
public partial class FollowIndexStatsDescriptor : RequestDescriptorBase<FollowIndexStatsDescriptor, FollowIndexStatsRequestParameters, IFollowIndexStatsRequest>, IFollowIndexStatsRequest
{
Expand Down
24 changes: 24 additions & 0 deletions src/Nest/ElasticClient.CrossClusterReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ internal CrossClusterReplicationNamespace(ElasticClient client): base(client)
/// </summary>
public Task<CreateFollowIndexResponse> CreateFollowIndexAsync(ICreateFollowIndexRequest request, CancellationToken ct = default) => DoRequestAsync<ICreateFollowIndexRequest, CreateFollowIndexResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>GET</c> request to the <c>ccr.follow_info</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</a>
/// </summary>
public FollowInfoResponse FollowInfo(Indices index, Func<FollowInfoDescriptor, IFollowInfoRequest> selector = null) => FollowInfo(selector.InvokeOrDefault(new FollowInfoDescriptor(index: index)));
/// <summary>
/// <c>GET</c> request to the <c>ccr.follow_info</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</a>
/// </summary>
public Task<FollowInfoResponse> FollowInfoAsync(Indices index, Func<FollowInfoDescriptor, IFollowInfoRequest> selector = null, CancellationToken ct = default) => FollowInfoAsync(selector.InvokeOrDefault(new FollowInfoDescriptor(index: index)), ct);
/// <summary>
/// <c>GET</c> request to the <c>ccr.follow_info</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</a>
/// </summary>
public FollowInfoResponse FollowInfo(IFollowInfoRequest request) => DoRequest<IFollowInfoRequest, FollowInfoResponse>(request, request.RequestParameters);
/// <summary>
/// <c>GET</c> request to the <c>ccr.follow_info</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</a>
/// </summary>
public Task<FollowInfoResponse> FollowInfoAsync(IFollowInfoRequest request, CancellationToken ct = default) => DoRequestAsync<IFollowInfoRequest, FollowInfoResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>GET</c> request to the <c>ccr.follow_stats</c> API, read more about this API online:
/// <para></para>
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html</a>
Expand Down
33 changes: 33 additions & 0 deletions src/Nest/Requests.CrossClusterReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,39 @@ public string WaitForActiveShards
}
}

[InterfaceDataContract]
public partial interface IFollowInfoRequest : IRequest<FollowInfoRequestParameters>
{
[IgnoreDataMember]
Indices Index
{
get;
}
}

///<summary>Request for FollowInfo <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</para></summary>
public partial class FollowInfoRequest : PlainRequestBase<FollowInfoRequestParameters>, IFollowInfoRequest
{
protected IFollowInfoRequest Self => this;
internal override ApiUrls ApiUrls => ApiUrlsLookups.CrossClusterReplicationFollowInfo;
///<summary>/{index}/_ccr/info</summary>
///<param name = "index">this parameter is required</param>
public FollowInfoRequest(Indices index): base(r => r.Required("index", index))
{
}

///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
[SerializationConstructor]
protected FollowInfoRequest(): base()
{
}

// values part of the url path
[IgnoreDataMember]
Indices IFollowInfoRequest.Index => Self.RouteValues.Get<Indices>("index");
// Request parameters
}

[InterfaceDataContract]
public partial interface IFollowIndexStatsRequest : IRequest<FollowIndexStatsRequestParameters>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Runtime.Serialization;

namespace Nest
{
public class FollowConfig
{
[DataMember(Name = "max_read_request_operation_count")]
public int MaximumReadRequestOperationCount { get; internal set; }

[DataMember(Name = "max_read_request_size")]
public string MaximumReadRequestSize { get; internal set; }

[DataMember(Name = "max_outstanding_read_requests")]
public int MaximumOutstandingReadRequests { get; internal set; }

[DataMember(Name = "max_write_request_operation_count")]
public int MaximumWriteRequestOperationCount { get; internal set; }

[DataMember(Name = "max_write_request_size")]
public string MaximumWriteRequestSize { get; internal set; }

[DataMember(Name = "max_outstanding_write_requests")]
public int MaximumOutstandingWriteRequests { get; internal set; }

[DataMember(Name = "max_write_buffer_count")]
public int MaximumWriteBufferCount { get; internal set; }

[DataMember(Name = "max_write_buffer_size")]
public string MaximumWriteBufferSize { get; internal set; }

[DataMember(Name = "max_retry_delay")]
public Time MaximumRetryDelay { get; internal set; }

[DataMember(Name = "read_poll_timeout")]
public Time ReadPollTimeout { get; internal set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Nest
{
/// <summary>
/// Retrieves information about all follower indices.
/// </summary>
[MapsApi("ccr.follow_info.json")]
public partial interface IFollowInfoRequest { }

/// <inheritdoc cref="IFollowInfoRequest" />
public partial class FollowInfoRequest { }

/// <inheritdoc cref="IFollowInfoRequest" />
public partial class FollowInfoDescriptor { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Elasticsearch.Net;

namespace Nest
{
public class FollowInfoResponse : ResponseBase
{
[DataMember(Name = "follower_indices")]
public IReadOnlyCollection<FollowerInfo> FollowerIndices { get; internal set; } = EmptyReadOnly<FollowerInfo>.Collection;
}

public class FollowerInfo
{
[DataMember(Name = "follower_index")]
public string FollowerIndex { get; internal set; }

[DataMember(Name = "remote_cluster")]
public string RemoteCluster { get; internal set; }

[DataMember(Name = "leader_index")]
public string LeaderIndex { get; internal set; }

[DataMember(Name = "status")]
public FollowerIndexStatus Status { get; internal set; }

[DataMember(Name = "parameters")]
public FollowConfig Parameters { get; internal set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Runtime.Serialization;
using Elasticsearch.Net;

namespace Nest
{
[StringEnum]
public enum FollowerIndexStatus
{
[EnumMember(Value = "active")]
Active,

[EnumMember(Value = "paused")]
Paused
}
}
1 change: 1 addition & 0 deletions src/Nest/_Generated/ApiUrlsLookup.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls CatThreadPool = new ApiUrls(new[]{"_cat/thread_pool", "_cat/thread_pool/{thread_pool_patterns}"});
internal static ApiUrls CrossClusterReplicationDeleteAutoFollowPattern = new ApiUrls(new[]{"_ccr/auto_follow/{name}"});
internal static ApiUrls CrossClusterReplicationCreateFollowIndex = new ApiUrls(new[]{"{index}/_ccr/follow"});
internal static ApiUrls CrossClusterReplicationFollowInfo = new ApiUrls(new[]{"{index}/_ccr/info"});
internal static ApiUrls CrossClusterReplicationFollowIndexStats = new ApiUrls(new[]{"{index}/_ccr/stats"});
internal static ApiUrls CrossClusterReplicationGetAutoFollowPattern = new ApiUrls(new[]{"_ccr/auto_follow", "_ccr/auto_follow/{name}"});
internal static ApiUrls CrossClusterReplicationPauseFollowIndex = new ApiUrls(new[]{"{index}/_ccr/pause_follow"});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class CrossClusterReplicationFollowTests : CoordinatedIntegrationTestBase
private const string FollowIndexStep = nameof(FollowIndexStep);
private const string FollowStatsAgainStep = nameof(FollowStatsAgainStep);
private const string FollowStatsStep = nameof(FollowStatsStep);
private const string FollowInfoStep = nameof(FollowInfoStep);
private const string IndexDataStep = nameof(IndexDataStep);
private const string PauseFollowStep = nameof(PauseFollowStep);
private const string PauseForCloseStep = nameof(PauseForCloseStep);
Expand Down Expand Up @@ -158,6 +159,17 @@ public CrossClusterReplicationFollowTests(XPackCluster cluster, EndpointUsage us
(v, c, r) => c.CrossClusterReplication.FollowIndexStatsAsync(r)
)
},
{
FollowInfoStep, u =>
u.Calls<FollowInfoDescriptor, FollowInfoRequest, IFollowInfoRequest, FollowInfoResponse>(
v => new FollowInfoRequest(CopyIndex(v)),
(v, d) => d,
(v, c, f) => c.CrossClusterReplication.FollowInfo(CopyIndex(v), f),
(v, c, f) => c.CrossClusterReplication.FollowInfoAsync(CopyIndex(v), f),
(v, c, r) => c.CrossClusterReplication.FollowInfo(r),
(v, c, r) => c.CrossClusterReplication.FollowInfoAsync(r)
)
},
{
DeleteOriginalIndicesStep, u => u.Calls<DeleteIndexDescriptor, DeleteIndexRequest, IDeleteIndexRequest, DeleteIndexResponse>
(
Expand Down Expand Up @@ -271,6 +283,18 @@ [I] public async Task FollowStatsResponse() => await Assert<FollowIndexStatsResp
}
});

[I] public async Task FollowInfoResponse() => await Assert<FollowInfoResponse>(FollowInfoStep, r =>
{
r.IsValid.Should().BeTrue();
codebrain marked this conversation as resolved.
Show resolved Hide resolved
r.FollowerIndices.Should().NotBeNull();
r.FollowerIndices.Should().NotBeEmpty();
var first = r.FollowerIndices.First();
first.FollowerIndex.Should().NotBeNullOrWhiteSpace();
first.RemoteCluster.Should().NotBeNullOrWhiteSpace();
first.LeaderIndex.Should().NotBeNullOrWhiteSpace();
first.Parameters.Should().NotBeNull();
});

[I] public async Task GlobalStatsResponse() => await Assert<CcrStatsResponse>(GlobalStatsStep, r =>
{
r.IsValid.Should().BeTrue();
Expand Down