Skip to content

Commit 66671e1

Browse files
codebrainStuart Cam
authored andcommitted
Implement Forget Follower API (#3939)
Implement Forget Follower API
1 parent d3fbc2a commit 66671e1

File tree

11 files changed

+259
-1
lines changed

11 files changed

+259
-1
lines changed

src/CodeGeneration/ApiGenerator/Configuration/CodeConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public static class CodeConfiguration
2424
"monitoring.bulk.json",
2525

2626
"ccr.follow_info.json",
27-
"ccr.forget_follower.json"
2827
};
2928

3029

src/Elasticsearch.Net/Api/RequestParameters/RequestParameters.CrossClusterReplication.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public class FollowIndexStatsRequestParameters : RequestParameters<FollowIndexSt
5151
public override HttpMethod DefaultHttpMethod => HttpMethod.GET;
5252
}
5353

54+
///<summary>Request options for ForgetFollowerIndex <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
55+
public class ForgetFollowerIndexRequestParameters : RequestParameters<ForgetFollowerIndexRequestParameters>
56+
{
57+
public override HttpMethod DefaultHttpMethod => HttpMethod.POST;
58+
}
59+
5460
///<summary>Request options for GetAutoFollowPattern <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html</para></summary>
5561
public class GetAutoFollowPatternRequestParameters : RequestParameters<GetAutoFollowPatternRequestParameters>
5662
{

src/Elasticsearch.Net/ElasticLowLevelClient.CrossClusterReplication.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ public TResponse FollowIndexStats<TResponse>(string index, FollowIndexStatsReque
7575
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
7676
public Task<TResponse> FollowIndexStatsAsync<TResponse>(string index, FollowIndexStatsRequestParameters requestParameters = null, CancellationToken ctx = default)
7777
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, Url($"{index:index}/_ccr/stats"), ctx, null, RequestParams(requestParameters));
78+
///<summary>POST on /{index}/_ccr/forget_follower <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
79+
///<param name = "index">the name of the leader index for which specified follower retention leases should be removed</param>
80+
///<param name = "body">the name and UUID of the follower index, the name of the cluster containing the follower index, and the alias from the perspective of that cluster for the remote cluster containing the leader index</param>
81+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
82+
public TResponse ForgetFollowerIndex<TResponse>(string index, PostData body, ForgetFollowerIndexRequestParameters requestParameters = null)
83+
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(POST, Url($"{index:index}/_ccr/forget_follower"), body, RequestParams(requestParameters));
84+
///<summary>POST on /{index}/_ccr/forget_follower <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
85+
///<param name = "index">the name of the leader index for which specified follower retention leases should be removed</param>
86+
///<param name = "body">the name and UUID of the follower index, the name of the cluster containing the follower index, and the alias from the perspective of that cluster for the remote cluster containing the leader index</param>
87+
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
88+
public Task<TResponse> ForgetFollowerIndexAsync<TResponse>(string index, PostData body, ForgetFollowerIndexRequestParameters requestParameters = null, CancellationToken ctx = default)
89+
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/_ccr/forget_follower"), ctx, body, RequestParams(requestParameters));
7890
///<summary>GET on /_ccr/auto_follow <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html</para></summary>
7991
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
8092
public TResponse GetAutoFollowPattern<TResponse>(GetAutoFollowPatternRequestParameters requestParameters = null)

src/Nest/Descriptors.CrossClusterReplication.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,32 @@ public FollowIndexStatsDescriptor Index<TOther>()
107107
// Request parameters
108108
}
109109

110+
///<summary>descriptor for ForgetFollowerIndex <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
111+
public partial class ForgetFollowerIndexDescriptor : RequestDescriptorBase<ForgetFollowerIndexDescriptor, ForgetFollowerIndexRequestParameters, IForgetFollowerIndexRequest>, IForgetFollowerIndexRequest
112+
{
113+
internal override ApiUrls ApiUrls => ApiUrlsLookups.CrossClusterReplicationForgetFollowerIndex;
114+
///<summary>/{index}/_ccr/forget_follower</summary>
115+
///<param name = "index">this parameter is required</param>
116+
public ForgetFollowerIndexDescriptor(IndexName index): base(r => r.Required("index", index))
117+
{
118+
}
119+
120+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
121+
[SerializationConstructor]
122+
protected ForgetFollowerIndexDescriptor(): base()
123+
{
124+
}
125+
126+
// values part of the url path
127+
IndexName IForgetFollowerIndexRequest.Index => Self.RouteValues.Get<IndexName>("index");
128+
///<summary>the name of the leader index for which specified follower retention leases should be removed</summary>
129+
public ForgetFollowerIndexDescriptor Index(IndexName index) => Assign(index, (a, v) => a.RouteValues.Required("index", v));
130+
///<summary>a shortcut into calling Index(typeof(TOther))</summary>
131+
public ForgetFollowerIndexDescriptor Index<TOther>()
132+
where TOther : class => Assign(typeof(TOther), (a, v) => a.RouteValues.Required("index", (IndexName)v));
133+
// Request parameters
134+
}
135+
110136
///<summary>descriptor for GetAutoFollowPattern <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html</para></summary>
111137
public partial class GetAutoFollowPatternDescriptor : RequestDescriptorBase<GetAutoFollowPatternDescriptor, GetAutoFollowPatternRequestParameters, IGetAutoFollowPatternRequest>, IGetAutoFollowPatternRequest
112138
{

src/Nest/ElasticClient.CrossClusterReplication.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ internal CrossClusterReplicationNamespace(ElasticClient client): base(client)
109109
/// </summary>
110110
public Task<FollowIndexStatsResponse> FollowIndexStatsAsync(IFollowIndexStatsRequest request, CancellationToken ct = default) => DoRequestAsync<IFollowIndexStatsRequest, FollowIndexStatsResponse>(request, request.RequestParameters, ct);
111111
/// <summary>
112+
/// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
113+
/// <para></para>
114+
/// <a href = "http://www.elastic.co/guide/en/elasticsearch/reference/current">http://www.elastic.co/guide/en/elasticsearch/reference/current</a>
115+
/// </summary>
116+
public ForgetFollowerIndexResponse ForgetFollowerIndex(IndexName index, Func<ForgetFollowerIndexDescriptor, IForgetFollowerIndexRequest> selector) => ForgetFollowerIndex(selector.InvokeOrDefault(new ForgetFollowerIndexDescriptor(index: index)));
117+
/// <summary>
118+
/// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
119+
/// <para></para>
120+
/// <a href = "http://www.elastic.co/guide/en/elasticsearch/reference/current">http://www.elastic.co/guide/en/elasticsearch/reference/current</a>
121+
/// </summary>
122+
public Task<ForgetFollowerIndexResponse> ForgetFollowerIndexAsync(IndexName index, Func<ForgetFollowerIndexDescriptor, IForgetFollowerIndexRequest> selector, CancellationToken ct = default) => ForgetFollowerIndexAsync(selector.InvokeOrDefault(new ForgetFollowerIndexDescriptor(index: index)), ct);
123+
/// <summary>
124+
/// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
125+
/// <para></para>
126+
/// <a href = "http://www.elastic.co/guide/en/elasticsearch/reference/current">http://www.elastic.co/guide/en/elasticsearch/reference/current</a>
127+
/// </summary>
128+
public ForgetFollowerIndexResponse ForgetFollowerIndex(IForgetFollowerIndexRequest request) => DoRequest<IForgetFollowerIndexRequest, ForgetFollowerIndexResponse>(request, request.RequestParameters);
129+
/// <summary>
130+
/// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
131+
/// <para></para>
132+
/// <a href = "http://www.elastic.co/guide/en/elasticsearch/reference/current">http://www.elastic.co/guide/en/elasticsearch/reference/current</a>
133+
/// </summary>
134+
public Task<ForgetFollowerIndexResponse> ForgetFollowerIndexAsync(IForgetFollowerIndexRequest request, CancellationToken ct = default) => DoRequestAsync<IForgetFollowerIndexRequest, ForgetFollowerIndexResponse>(request, request.RequestParameters, ct);
135+
/// <summary>
112136
/// <c>GET</c> request to the <c>ccr.get_auto_follow_pattern</c> API, read more about this API online:
113137
/// <para></para>
114138
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html</a>

src/Nest/Requests.CrossClusterReplication.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,39 @@ protected FollowIndexStatsRequest(): base()
139139
// Request parameters
140140
}
141141

142+
[InterfaceDataContract]
143+
public partial interface IForgetFollowerIndexRequest : IRequest<ForgetFollowerIndexRequestParameters>
144+
{
145+
[IgnoreDataMember]
146+
IndexName Index
147+
{
148+
get;
149+
}
150+
}
151+
152+
///<summary>Request for ForgetFollowerIndex <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
153+
public partial class ForgetFollowerIndexRequest : PlainRequestBase<ForgetFollowerIndexRequestParameters>, IForgetFollowerIndexRequest
154+
{
155+
protected IForgetFollowerIndexRequest Self => this;
156+
internal override ApiUrls ApiUrls => ApiUrlsLookups.CrossClusterReplicationForgetFollowerIndex;
157+
///<summary>/{index}/_ccr/forget_follower</summary>
158+
///<param name = "index">this parameter is required</param>
159+
public ForgetFollowerIndexRequest(IndexName index): base(r => r.Required("index", index))
160+
{
161+
}
162+
163+
///<summary>Used for serialization purposes, making sure we have a parameterless constructor</summary>
164+
[SerializationConstructor]
165+
protected ForgetFollowerIndexRequest(): base()
166+
{
167+
}
168+
169+
// values part of the url path
170+
[IgnoreDataMember]
171+
IndexName IForgetFollowerIndexRequest.Index => Self.RouteValues.Get<IndexName>("index");
172+
// Request parameters
173+
}
174+
142175
[InterfaceDataContract]
143176
public partial interface IGetAutoFollowPatternRequest : IRequest<GetAutoFollowPatternRequestParameters>
144177
{
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Nest
4+
{
5+
[MapsApi("ccr.forget_follower.json")]
6+
[ReadAs(typeof(ForgetFollowerIndexRequest))]
7+
public partial interface IForgetFollowerIndexRequest
8+
{
9+
/// <summary>
10+
/// The name of the cluster containing the follower index.
11+
/// </summary>
12+
[DataMember(Name = "follower_cluster")]
13+
string FollowerCluster { get; set; }
14+
15+
/// <summary>
16+
/// The name of the follower index.
17+
/// </summary>
18+
[DataMember(Name = "follower_index")]
19+
IndexName FollowerIndex { get; set; }
20+
21+
/// <summary>
22+
/// The UUID of the follower index.
23+
/// </summary>
24+
[DataMember(Name = "follower_index_uuid")]
25+
string FollowerIndexUUID { get; set; }
26+
27+
/// <summary>
28+
/// The alias (from the perspective of the cluster containing the follower index) of the remote cluster containing the leader index.
29+
/// </summary>
30+
[DataMember(Name = "leader_remote_cluster")]
31+
string LeaderRemoteCluster { get; set; }
32+
}
33+
34+
/// <inheritdoc cref="IForgetFollowerIndexRequest"/>
35+
public partial class ForgetFollowerIndexRequest
36+
{
37+
/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerCluster"/>
38+
public string FollowerCluster { get; set; }
39+
40+
/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerIndex"/>
41+
public IndexName FollowerIndex { get; set; }
42+
43+
/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerIndexUUID"/>
44+
public string FollowerIndexUUID { get; set; }
45+
46+
/// <inheritdoc cref="IForgetFollowerIndexRequest.LeaderRemoteCluster"/>
47+
public string LeaderRemoteCluster { get; set; }
48+
}
49+
50+
/// <inheritdoc cref="IForgetFollowerIndexRequest"/>
51+
public partial class ForgetFollowerIndexDescriptor
52+
{
53+
string IForgetFollowerIndexRequest.FollowerCluster { get; set; }
54+
IndexName IForgetFollowerIndexRequest.FollowerIndex { get; set; }
55+
string IForgetFollowerIndexRequest.FollowerIndexUUID { get; set; }
56+
string IForgetFollowerIndexRequest.LeaderRemoteCluster { get; set; }
57+
58+
/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerCluster"/>
59+
public ForgetFollowerIndexDescriptor FollowerCluster(string followerCluster) =>
60+
Assign(followerCluster, (a, v) => a.FollowerCluster = v);
61+
62+
/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerIndex"/>
63+
public ForgetFollowerIndexDescriptor FollowerIndex(IndexName followerIndex) =>
64+
Assign(followerIndex, (a, v) => a.FollowerIndex = v);
65+
66+
/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerIndexUUID"/>
67+
public ForgetFollowerIndexDescriptor FollowerIndexUUID(string followerIndexUUID) =>
68+
Assign(followerIndexUUID, (a, v) => a.FollowerIndexUUID = v);
69+
70+
/// <inheritdoc cref="IForgetFollowerIndexRequest.LeaderRemoteCluster"/>
71+
public ForgetFollowerIndexDescriptor LeaderRemoteCluster(string leaderRemoteCluster) =>
72+
Assign(leaderRemoteCluster, (a, v) => a.LeaderRemoteCluster = v);
73+
}
74+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Nest
4+
{
5+
public class ForgetFollowerIndexResponse : ResponseBase
6+
{
7+
[DataMember(Name ="_shards")]
8+
public ShardStatistics Shards { get; internal set; }
9+
}
10+
}

src/Nest/_Generated/ApiUrlsLookup.generated.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ internal static class ApiUrlsLookups
4242
internal static ApiUrls CrossClusterReplicationDeleteAutoFollowPattern = new ApiUrls(new[]{"_ccr/auto_follow/{name}"});
4343
internal static ApiUrls CrossClusterReplicationCreateFollowIndex = new ApiUrls(new[]{"{index}/_ccr/follow"});
4444
internal static ApiUrls CrossClusterReplicationFollowIndexStats = new ApiUrls(new[]{"{index}/_ccr/stats"});
45+
internal static ApiUrls CrossClusterReplicationForgetFollowerIndex = new ApiUrls(new[]{"{index}/_ccr/forget_follower"});
4546
internal static ApiUrls CrossClusterReplicationGetAutoFollowPattern = new ApiUrls(new[]{"_ccr/auto_follow", "_ccr/auto_follow/{name}"});
4647
internal static ApiUrls CrossClusterReplicationPauseFollowIndex = new ApiUrls(new[]{"{index}/_ccr/pause_follow"});
4748
internal static ApiUrls CrossClusterReplicationCreateAutoFollowPattern = new ApiUrls(new[]{"_ccr/auto_follow/{name}"});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using Elasticsearch.Net;
3+
using Nest;
4+
using Tests.Core.ManagedElasticsearch.Clusters;
5+
using Tests.Framework.EndpointTests;
6+
using Tests.Framework.EndpointTests.TestState;
7+
8+
namespace Tests.XPack.CrossClusterReplication.Follow.ForgetFollowerIndex
9+
{
10+
public class ForgetFollowerIndexApiTests : ApiTestBase<XPackCluster, ForgetFollowerIndexResponse, IForgetFollowerIndexRequest, ForgetFollowerIndexDescriptor, ForgetFollowerIndexRequest>
11+
{
12+
public ForgetFollowerIndexApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
13+
14+
protected override object ExpectJson { get; } = new
15+
{
16+
follower_index = "follower-index",
17+
follower_cluster = "follower-cluster",
18+
leader_remote_cluster ="leader-remote-cluster",
19+
follower_index_uuid = "follower-index-uuid",
20+
};
21+
22+
protected override ForgetFollowerIndexDescriptor NewDescriptor() => new ForgetFollowerIndexDescriptor("index");
23+
24+
protected override Func<ForgetFollowerIndexDescriptor, IForgetFollowerIndexRequest> Fluent => d => d
25+
.Index("index")
26+
.FollowerIndex("follower-index")
27+
.FollowerCluster("follower-cluster")
28+
.LeaderRemoteCluster("leader-remote-cluster")
29+
.FollowerIndexUUID("follower-index-uuid")
30+
;
31+
32+
protected override HttpMethod HttpMethod => HttpMethod.POST;
33+
34+
protected override ForgetFollowerIndexRequest Initializer => new ForgetFollowerIndexRequest("index")
35+
{
36+
FollowerIndex = "follower-index",
37+
FollowerCluster = "follower-cluster",
38+
LeaderRemoteCluster ="leader-remote-cluster",
39+
FollowerIndexUUID = "follower-index-uuid",
40+
};
41+
42+
protected override bool SupportsDeserialization => false;
43+
protected override string UrlPath => "/index/_ccr/forget_follower";
44+
45+
protected override LazyResponses ClientUsage() => Calls(
46+
(client, f) => client.CrossClusterReplication.ForgetFollowerIndex("index", f),
47+
(client, f) => client.CrossClusterReplication.ForgetFollowerIndexAsync("index", f),
48+
(client, r) => client.CrossClusterReplication.ForgetFollowerIndex(r),
49+
(client, r) => client.CrossClusterReplication.ForgetFollowerIndexAsync(r)
50+
);
51+
}
52+
}

0 commit comments

Comments
 (0)