Skip to content

Commit

Permalink
Implement Forget Follower API (#3939)
Browse files Browse the repository at this point in the history
Implement Forget Follower API
  • Loading branch information
codebrain authored Jul 16, 2019
1 parent ecad8ee commit afa29be
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static class CodeConfiguration
"monitoring.bulk.json",

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class FollowIndexStatsRequestParameters : RequestParameters<FollowIndexSt
public override HttpMethod DefaultHttpMethod => HttpMethod.GET;
}

///<summary>Request options for ForgetFollowerIndex <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
public class ForgetFollowerIndexRequestParameters : RequestParameters<ForgetFollowerIndexRequestParameters>
{
public override HttpMethod DefaultHttpMethod => HttpMethod.POST;
}

///<summary>Request options for GetAutoFollowPattern <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html</para></summary>
public class GetAutoFollowPatternRequestParameters : RequestParameters<GetAutoFollowPatternRequestParameters>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ public TResponse FollowIndexStats<TResponse>(string index, FollowIndexStatsReque
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public Task<TResponse> FollowIndexStatsAsync<TResponse>(string index, FollowIndexStatsRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(GET, Url($"{index:index}/_ccr/stats"), ctx, null, RequestParams(requestParameters));
///<summary>POST on /{index}/_ccr/forget_follower <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
///<param name = "index">the name of the leader index for which specified follower retention leases should be removed</param>
///<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>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse ForgetFollowerIndex<TResponse>(string index, PostData body, ForgetFollowerIndexRequestParameters requestParameters = null)
where TResponse : class, IElasticsearchResponse, new() => DoRequest<TResponse>(POST, Url($"{index:index}/_ccr/forget_follower"), body, RequestParams(requestParameters));
///<summary>POST on /{index}/_ccr/forget_follower <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
///<param name = "index">the name of the leader index for which specified follower retention leases should be removed</param>
///<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>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public Task<TResponse> ForgetFollowerIndexAsync<TResponse>(string index, PostData body, ForgetFollowerIndexRequestParameters requestParameters = null, CancellationToken ctx = default)
where TResponse : class, IElasticsearchResponse, new() => DoRequestAsync<TResponse>(POST, Url($"{index:index}/_ccr/forget_follower"), ctx, body, RequestParams(requestParameters));
///<summary>GET on /_ccr/auto_follow <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html</para></summary>
///<param name = "requestParameters">Request specific configuration such as querystring parameters &amp; request specific connection settings.</param>
public TResponse GetAutoFollowPattern<TResponse>(GetAutoFollowPatternRequestParameters requestParameters = null)
Expand Down
26 changes: 26 additions & 0 deletions src/Nest/Descriptors.CrossClusterReplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ public FollowIndexStatsDescriptor Index<TOther>()
// Request parameters
}

///<summary>descriptor for ForgetFollowerIndex <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
public partial class ForgetFollowerIndexDescriptor : RequestDescriptorBase<ForgetFollowerIndexDescriptor, ForgetFollowerIndexRequestParameters, IForgetFollowerIndexRequest>, IForgetFollowerIndexRequest
{
internal override ApiUrls ApiUrls => ApiUrlsLookups.CrossClusterReplicationForgetFollowerIndex;
///<summary>/{index}/_ccr/forget_follower</summary>
///<param name = "index">this parameter is required</param>
public ForgetFollowerIndexDescriptor(IndexName index): base(r => r.Required("index", index))
{
}

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

// values part of the url path
IndexName IForgetFollowerIndexRequest.Index => Self.RouteValues.Get<IndexName>("index");
///<summary>the name of the leader index for which specified follower retention leases should be removed</summary>
public ForgetFollowerIndexDescriptor Index(IndexName index) => Assign(index, (a, v) => a.RouteValues.Required("index", v));
///<summary>a shortcut into calling Index(typeof(TOther))</summary>
public ForgetFollowerIndexDescriptor Index<TOther>()
where TOther : class => Assign(typeof(TOther), (a, v) => a.RouteValues.Required("index", (IndexName)v));
// Request parameters
}

///<summary>descriptor for GetAutoFollowPattern <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html</para></summary>
public partial class GetAutoFollowPatternDescriptor : RequestDescriptorBase<GetAutoFollowPatternDescriptor, GetAutoFollowPatternRequestParameters, IGetAutoFollowPatternRequest>, IGetAutoFollowPatternRequest
{
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 @@ -109,6 +109,30 @@ internal CrossClusterReplicationNamespace(ElasticClient client): base(client)
/// </summary>
public Task<FollowIndexStatsResponse> FollowIndexStatsAsync(IFollowIndexStatsRequest request, CancellationToken ct = default) => DoRequestAsync<IFollowIndexStatsRequest, FollowIndexStatsResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
/// <para></para>
/// <a href = "http://www.elastic.co/guide/en/elasticsearch/reference/current">http://www.elastic.co/guide/en/elasticsearch/reference/current</a>
/// </summary>
public ForgetFollowerIndexResponse ForgetFollowerIndex(IndexName index, Func<ForgetFollowerIndexDescriptor, IForgetFollowerIndexRequest> selector) => ForgetFollowerIndex(selector.InvokeOrDefault(new ForgetFollowerIndexDescriptor(index: index)));
/// <summary>
/// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
/// <para></para>
/// <a href = "http://www.elastic.co/guide/en/elasticsearch/reference/current">http://www.elastic.co/guide/en/elasticsearch/reference/current</a>
/// </summary>
public Task<ForgetFollowerIndexResponse> ForgetFollowerIndexAsync(IndexName index, Func<ForgetFollowerIndexDescriptor, IForgetFollowerIndexRequest> selector, CancellationToken ct = default) => ForgetFollowerIndexAsync(selector.InvokeOrDefault(new ForgetFollowerIndexDescriptor(index: index)), ct);
/// <summary>
/// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
/// <para></para>
/// <a href = "http://www.elastic.co/guide/en/elasticsearch/reference/current">http://www.elastic.co/guide/en/elasticsearch/reference/current</a>
/// </summary>
public ForgetFollowerIndexResponse ForgetFollowerIndex(IForgetFollowerIndexRequest request) => DoRequest<IForgetFollowerIndexRequest, ForgetFollowerIndexResponse>(request, request.RequestParameters);
/// <summary>
/// <c>POST</c> request to the <c>ccr.forget_follower</c> API, read more about this API online:
/// <para></para>
/// <a href = "http://www.elastic.co/guide/en/elasticsearch/reference/current">http://www.elastic.co/guide/en/elasticsearch/reference/current</a>
/// </summary>
public Task<ForgetFollowerIndexResponse> ForgetFollowerIndexAsync(IForgetFollowerIndexRequest request, CancellationToken ct = default) => DoRequestAsync<IForgetFollowerIndexRequest, ForgetFollowerIndexResponse>(request, request.RequestParameters, ct);
/// <summary>
/// <c>GET</c> request to the <c>ccr.get_auto_follow_pattern</c> API, read more about this API online:
/// <para></para>
/// <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>
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 @@ -139,6 +139,39 @@ protected FollowIndexStatsRequest(): base()
// Request parameters
}

[InterfaceDataContract]
public partial interface IForgetFollowerIndexRequest : IRequest<ForgetFollowerIndexRequestParameters>
{
[IgnoreDataMember]
IndexName Index
{
get;
}
}

///<summary>Request for ForgetFollowerIndex <para>http://www.elastic.co/guide/en/elasticsearch/reference/current</para></summary>
public partial class ForgetFollowerIndexRequest : PlainRequestBase<ForgetFollowerIndexRequestParameters>, IForgetFollowerIndexRequest
{
protected IForgetFollowerIndexRequest Self => this;
internal override ApiUrls ApiUrls => ApiUrlsLookups.CrossClusterReplicationForgetFollowerIndex;
///<summary>/{index}/_ccr/forget_follower</summary>
///<param name = "index">this parameter is required</param>
public ForgetFollowerIndexRequest(IndexName index): base(r => r.Required("index", index))
{
}

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

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

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

namespace Nest
{
[MapsApi("ccr.forget_follower.json")]
[ReadAs(typeof(ForgetFollowerIndexRequest))]
public partial interface IForgetFollowerIndexRequest
{
/// <summary>
/// The name of the cluster containing the follower index.
/// </summary>
[DataMember(Name = "follower_cluster")]
string FollowerCluster { get; set; }

/// <summary>
/// The name of the follower index.
/// </summary>
[DataMember(Name = "follower_index")]
IndexName FollowerIndex { get; set; }

/// <summary>
/// The UUID of the follower index.
/// </summary>
[DataMember(Name = "follower_index_uuid")]
string FollowerIndexUUID { get; set; }

/// <summary>
/// The alias (from the perspective of the cluster containing the follower index) of the remote cluster containing the leader index.
/// </summary>
[DataMember(Name = "leader_remote_cluster")]
string LeaderRemoteCluster { get; set; }
}

/// <inheritdoc cref="IForgetFollowerIndexRequest"/>
public partial class ForgetFollowerIndexRequest
{
/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerCluster"/>
public string FollowerCluster { get; set; }

/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerIndex"/>
public IndexName FollowerIndex { get; set; }

/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerIndexUUID"/>
public string FollowerIndexUUID { get; set; }

/// <inheritdoc cref="IForgetFollowerIndexRequest.LeaderRemoteCluster"/>
public string LeaderRemoteCluster { get; set; }
}

/// <inheritdoc cref="IForgetFollowerIndexRequest"/>
public partial class ForgetFollowerIndexDescriptor
{
string IForgetFollowerIndexRequest.FollowerCluster { get; set; }
IndexName IForgetFollowerIndexRequest.FollowerIndex { get; set; }
string IForgetFollowerIndexRequest.FollowerIndexUUID { get; set; }
string IForgetFollowerIndexRequest.LeaderRemoteCluster { get; set; }

/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerCluster"/>
public ForgetFollowerIndexDescriptor FollowerCluster(string followerCluster) =>
Assign(followerCluster, (a, v) => a.FollowerCluster = v);

/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerIndex"/>
public ForgetFollowerIndexDescriptor FollowerIndex(IndexName followerIndex) =>
Assign(followerIndex, (a, v) => a.FollowerIndex = v);

/// <inheritdoc cref="IForgetFollowerIndexRequest.FollowerIndexUUID"/>
public ForgetFollowerIndexDescriptor FollowerIndexUUID(string followerIndexUUID) =>
Assign(followerIndexUUID, (a, v) => a.FollowerIndexUUID = v);

/// <inheritdoc cref="IForgetFollowerIndexRequest.LeaderRemoteCluster"/>
public ForgetFollowerIndexDescriptor LeaderRemoteCluster(string leaderRemoteCluster) =>
Assign(leaderRemoteCluster, (a, v) => a.LeaderRemoteCluster = v);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.Serialization;

namespace Nest
{
public class ForgetFollowerIndexResponse : ResponseBase
{
[DataMember(Name ="_shards")]
public ShardStatistics Shards { get; internal set; }
}
}
1 change: 1 addition & 0 deletions src/Nest/_Generated/ApiUrlsLookup.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal static class ApiUrlsLookups
internal static ApiUrls CrossClusterReplicationDeleteAutoFollowPattern = new ApiUrls(new[]{"_ccr/auto_follow/{name}"});
internal static ApiUrls CrossClusterReplicationCreateFollowIndex = new ApiUrls(new[]{"{index}/_ccr/follow"});
internal static ApiUrls CrossClusterReplicationFollowIndexStats = new ApiUrls(new[]{"{index}/_ccr/stats"});
internal static ApiUrls CrossClusterReplicationForgetFollowerIndex = new ApiUrls(new[]{"{index}/_ccr/forget_follower"});
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"});
internal static ApiUrls CrossClusterReplicationCreateAutoFollowPattern = new ApiUrls(new[]{"_ccr/auto_follow/{name}"});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using Elasticsearch.Net;
using Nest;
using Tests.Core.ManagedElasticsearch.Clusters;
using Tests.Framework.EndpointTests;
using Tests.Framework.EndpointTests.TestState;

namespace Tests.XPack.CrossClusterReplication.Follow.ForgetFollowerIndex
{
public class ForgetFollowerIndexApiTests : ApiTestBase<XPackCluster, ForgetFollowerIndexResponse, IForgetFollowerIndexRequest, ForgetFollowerIndexDescriptor, ForgetFollowerIndexRequest>
{
public ForgetFollowerIndexApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override object ExpectJson { get; } = new
{
follower_index = "follower-index",
follower_cluster = "follower-cluster",
leader_remote_cluster ="leader-remote-cluster",
follower_index_uuid = "follower-index-uuid",
};

protected override ForgetFollowerIndexDescriptor NewDescriptor() => new ForgetFollowerIndexDescriptor("index");

protected override Func<ForgetFollowerIndexDescriptor, IForgetFollowerIndexRequest> Fluent => d => d
.Index("index")
.FollowerIndex("follower-index")
.FollowerCluster("follower-cluster")
.LeaderRemoteCluster("leader-remote-cluster")
.FollowerIndexUUID("follower-index-uuid")
;

protected override HttpMethod HttpMethod => HttpMethod.POST;

protected override ForgetFollowerIndexRequest Initializer => new ForgetFollowerIndexRequest("index")
{
FollowerIndex = "follower-index",
FollowerCluster = "follower-cluster",
LeaderRemoteCluster ="leader-remote-cluster",
FollowerIndexUUID = "follower-index-uuid",
};

protected override bool SupportsDeserialization => false;
protected override string UrlPath => "/index/_ccr/forget_follower";

protected override LazyResponses ClientUsage() => Calls(
(client, f) => client.CrossClusterReplication.ForgetFollowerIndex("index", f),
(client, f) => client.CrossClusterReplication.ForgetFollowerIndexAsync("index", f),
(client, r) => client.CrossClusterReplication.ForgetFollowerIndex(r),
(client, r) => client.CrossClusterReplication.ForgetFollowerIndexAsync(r)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Threading.Tasks;
using Elastic.Xunit.XunitPlumbing;
using Nest;
using Tests.Framework.EndpointTests;

namespace Tests.XPack.CrossClusterReplication.Follow.ForgetFollowerIndex
{
public class ForgetFollowerIndexUrlTests : UrlTestsBase
{
[U] public override async Task Urls()
{
var name = "x";
await UrlTester.POST($"/{name}/_ccr/forget_follower")
.Fluent(c => c.CrossClusterReplication.ForgetFollowerIndex(name, d => d))
.Request(c => c.CrossClusterReplication.ForgetFollowerIndex(new ForgetFollowerIndexRequest(name)))
.FluentAsync(c => c.CrossClusterReplication.ForgetFollowerIndexAsync(name, d => d))
.RequestAsync(c => c.CrossClusterReplication.ForgetFollowerIndexAsync(new ForgetFollowerIndexRequest(name)));

}
}
}

0 comments on commit afa29be

Please sign in to comment.