Skip to content

Commit e007934

Browse files
authored
Add Voting Config Exclusions APIs (#4738)
Relates: #4718, elastic/elasticsearch#55760 This commit adds the voting config exclusions APIs to the high level client. Custom response builder types are required because the APIs return \n as the response, which the client will attempt to deserialize to a response object.
1 parent 15f401a commit e007934

File tree

11 files changed

+361
-0
lines changed

11 files changed

+361
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.IO;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Elasticsearch.Net;
9+
using Elasticsearch.Net.Specification.ClusterApi;
10+
11+
namespace Nest
12+
{
13+
[MapsApi("cluster.delete_voting_config_exclusions")]
14+
public partial interface IDeleteVotingConfigExclusionsRequest { }
15+
16+
public partial class DeleteVotingConfigExclusionsRequest
17+
{
18+
protected sealed override void RequestDefaults(DeleteVotingConfigExclusionsRequestParameters parameters) =>
19+
parameters.CustomResponseBuilder = new DeleteVotingConfigExclusionsResponseBuilder();
20+
}
21+
22+
public partial class DeleteVotingConfigExclusionsDescriptor
23+
{
24+
protected sealed override void RequestDefaults(DeleteVotingConfigExclusionsRequestParameters parameters) =>
25+
parameters.CustomResponseBuilder = new DeleteVotingConfigExclusionsResponseBuilder();
26+
}
27+
28+
/// <summary>
29+
/// Response is a single newline character, so skip trying to deserialize to an object
30+
/// </summary>
31+
internal class DeleteVotingConfigExclusionsResponseBuilder : CustomResponseBuilderBase
32+
{
33+
public override object DeserializeResponse(IElasticsearchSerializer builtInSerializer, IApiCallDetails response, Stream stream) =>
34+
new DeleteVotingConfigExclusionsResponse();
35+
36+
public override Task<object> DeserializeResponseAsync(IElasticsearchSerializer builtInSerializer, IApiCallDetails response, Stream stream, CancellationToken ctx = default) =>
37+
Task.FromResult<object>(new DeleteVotingConfigExclusionsResponse());
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace Nest
6+
{
7+
public class DeleteVotingConfigExclusionsResponse : ResponseBase
8+
{
9+
}
10+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.IO;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Elasticsearch.Net;
9+
using Elasticsearch.Net.Specification.ClusterApi;
10+
11+
namespace Nest
12+
{
13+
[MapsApi("cluster.post_voting_config_exclusions")]
14+
public partial interface IPostVotingConfigExclusionsRequest { }
15+
16+
public partial class PostVotingConfigExclusionsRequest
17+
{
18+
protected sealed override void RequestDefaults(PostVotingConfigExclusionsRequestParameters parameters) =>
19+
parameters.CustomResponseBuilder = new PostVotingConfigExclusionsResponseBuilder();
20+
}
21+
22+
public partial class PostVotingConfigExclusionsDescriptor
23+
{
24+
protected sealed override void RequestDefaults(PostVotingConfigExclusionsRequestParameters parameters) =>
25+
parameters.CustomResponseBuilder = new PostVotingConfigExclusionsResponseBuilder();
26+
}
27+
28+
/// <summary>
29+
/// Response is a single newline character, so skip trying to deserialize to an object
30+
/// </summary>
31+
internal class PostVotingConfigExclusionsResponseBuilder : CustomResponseBuilderBase
32+
{
33+
public override object DeserializeResponse(IElasticsearchSerializer builtInSerializer, IApiCallDetails response, Stream stream) =>
34+
new PostVotingConfigExclusionsResponse();
35+
36+
public override Task<object> DeserializeResponseAsync(IElasticsearchSerializer builtInSerializer, IApiCallDetails response, Stream stream, CancellationToken ctx = default) =>
37+
Task.FromResult<object>(new PostVotingConfigExclusionsResponse());
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace Nest
6+
{
7+
public class PostVotingConfigExclusionsResponse : ResponseBase
8+
{
9+
}
10+
}

src/Nest/Descriptors.Cluster.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public partial class ClusterAllocationExplainDescriptor : RequestDescriptorBase<
4242
public ClusterAllocationExplainDescriptor IncludeYesDecisions(bool? includeyesdecisions = true) => Qs("include_yes_decisions", includeyesdecisions);
4343
}
4444

45+
///<summary>Descriptor for DeleteVotingConfigExclusions <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</para></summary>
46+
public partial class DeleteVotingConfigExclusionsDescriptor : RequestDescriptorBase<DeleteVotingConfigExclusionsDescriptor, DeleteVotingConfigExclusionsRequestParameters, IDeleteVotingConfigExclusionsRequest>, IDeleteVotingConfigExclusionsRequest
47+
{
48+
internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterDeleteVotingConfigExclusions;
49+
// values part of the url path
50+
// Request parameters
51+
///<summary>Specifies whether to wait for all excluded nodes to be removed from the cluster before clearing the voting configuration exclusions list.</summary>
52+
public DeleteVotingConfigExclusionsDescriptor WaitForRemoval(bool? waitforremoval = true) => Qs("wait_for_removal", waitforremoval);
53+
}
54+
4555
///<summary>Descriptor for GetSettings <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html</para></summary>
4656
public partial class ClusterGetSettingsDescriptor : RequestDescriptorBase<ClusterGetSettingsDescriptor, ClusterGetSettingsRequestParameters, IClusterGetSettingsRequest>, IClusterGetSettingsRequest
4757
{
@@ -119,6 +129,20 @@ public partial class ClusterPendingTasksDescriptor : RequestDescriptorBase<Clust
119129
public ClusterPendingTasksDescriptor MasterTimeout(Time mastertimeout) => Qs("master_timeout", mastertimeout);
120130
}
121131

132+
///<summary>Descriptor for PostVotingConfigExclusions <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</para></summary>
133+
public partial class PostVotingConfigExclusionsDescriptor : RequestDescriptorBase<PostVotingConfigExclusionsDescriptor, PostVotingConfigExclusionsRequestParameters, IPostVotingConfigExclusionsRequest>, IPostVotingConfigExclusionsRequest
134+
{
135+
internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterPostVotingConfigExclusions;
136+
// values part of the url path
137+
// Request parameters
138+
///<summary>A comma-separated list of the persistent ids of the nodes to exclude from the voting configuration. If specified, you may not also specify ?node_names.</summary>
139+
public PostVotingConfigExclusionsDescriptor NodeIds(string nodeids) => Qs("node_ids", nodeids);
140+
///<summary>A comma-separated list of the names of the nodes to exclude from the voting configuration. If specified, you may not also specify ?node_ids.</summary>
141+
public PostVotingConfigExclusionsDescriptor NodeNames(string nodenames) => Qs("node_names", nodenames);
142+
///<summary>Explicit operation timeout</summary>
143+
public PostVotingConfigExclusionsDescriptor Timeout(Time timeout) => Qs("timeout", timeout);
144+
}
145+
122146
///<summary>Descriptor for PutSettings <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html</para></summary>
123147
public partial class ClusterPutSettingsDescriptor : RequestDescriptorBase<ClusterPutSettingsDescriptor, ClusterPutSettingsRequestParameters, IClusterPutSettingsRequest>, IClusterPutSettingsRequest
124148
{

src/Nest/ElasticClient.Cluster.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ internal ClusterNamespace(ElasticClient client): base(client)
6161
/// </summary>
6262
public Task<ClusterAllocationExplainResponse> AllocationExplainAsync(IClusterAllocationExplainRequest request, CancellationToken ct = default) => DoRequestAsync<IClusterAllocationExplainRequest, ClusterAllocationExplainResponse>(request, request.RequestParameters, ct);
6363
/// <summary>
64+
/// <c>DELETE</c> request to the <c>cluster.delete_voting_config_exclusions</c> API, read more about this API online:
65+
/// <para></para>
66+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</a>
67+
/// </summary>
68+
public DeleteVotingConfigExclusionsResponse DeleteVotingConfigExclusions(Func<DeleteVotingConfigExclusionsDescriptor, IDeleteVotingConfigExclusionsRequest> selector = null) => DeleteVotingConfigExclusions(selector.InvokeOrDefault(new DeleteVotingConfigExclusionsDescriptor()));
69+
/// <summary>
70+
/// <c>DELETE</c> request to the <c>cluster.delete_voting_config_exclusions</c> API, read more about this API online:
71+
/// <para></para>
72+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</a>
73+
/// </summary>
74+
public Task<DeleteVotingConfigExclusionsResponse> DeleteVotingConfigExclusionsAsync(Func<DeleteVotingConfigExclusionsDescriptor, IDeleteVotingConfigExclusionsRequest> selector = null, CancellationToken ct = default) => DeleteVotingConfigExclusionsAsync(selector.InvokeOrDefault(new DeleteVotingConfigExclusionsDescriptor()), ct);
75+
/// <summary>
76+
/// <c>DELETE</c> request to the <c>cluster.delete_voting_config_exclusions</c> API, read more about this API online:
77+
/// <para></para>
78+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</a>
79+
/// </summary>
80+
public DeleteVotingConfigExclusionsResponse DeleteVotingConfigExclusions(IDeleteVotingConfigExclusionsRequest request) => DoRequest<IDeleteVotingConfigExclusionsRequest, DeleteVotingConfigExclusionsResponse>(request, request.RequestParameters);
81+
/// <summary>
82+
/// <c>DELETE</c> request to the <c>cluster.delete_voting_config_exclusions</c> API, read more about this API online:
83+
/// <para></para>
84+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</a>
85+
/// </summary>
86+
public Task<DeleteVotingConfigExclusionsResponse> DeleteVotingConfigExclusionsAsync(IDeleteVotingConfigExclusionsRequest request, CancellationToken ct = default) => DoRequestAsync<IDeleteVotingConfigExclusionsRequest, DeleteVotingConfigExclusionsResponse>(request, request.RequestParameters, ct);
87+
/// <summary>
6488
/// <c>GET</c> request to the <c>cluster.get_settings</c> API, read more about this API online:
6589
/// <para></para>
6690
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html</a>
@@ -133,6 +157,30 @@ internal ClusterNamespace(ElasticClient client): base(client)
133157
/// </summary>
134158
public Task<ClusterPendingTasksResponse> PendingTasksAsync(IClusterPendingTasksRequest request, CancellationToken ct = default) => DoRequestAsync<IClusterPendingTasksRequest, ClusterPendingTasksResponse>(request, request.RequestParameters, ct);
135159
/// <summary>
160+
/// <c>POST</c> request to the <c>cluster.post_voting_config_exclusions</c> API, read more about this API online:
161+
/// <para></para>
162+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</a>
163+
/// </summary>
164+
public PostVotingConfigExclusionsResponse PostVotingConfigExclusions(Func<PostVotingConfigExclusionsDescriptor, IPostVotingConfigExclusionsRequest> selector = null) => PostVotingConfigExclusions(selector.InvokeOrDefault(new PostVotingConfigExclusionsDescriptor()));
165+
/// <summary>
166+
/// <c>POST</c> request to the <c>cluster.post_voting_config_exclusions</c> API, read more about this API online:
167+
/// <para></para>
168+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</a>
169+
/// </summary>
170+
public Task<PostVotingConfigExclusionsResponse> PostVotingConfigExclusionsAsync(Func<PostVotingConfigExclusionsDescriptor, IPostVotingConfigExclusionsRequest> selector = null, CancellationToken ct = default) => PostVotingConfigExclusionsAsync(selector.InvokeOrDefault(new PostVotingConfigExclusionsDescriptor()), ct);
171+
/// <summary>
172+
/// <c>POST</c> request to the <c>cluster.post_voting_config_exclusions</c> API, read more about this API online:
173+
/// <para></para>
174+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</a>
175+
/// </summary>
176+
public PostVotingConfigExclusionsResponse PostVotingConfigExclusions(IPostVotingConfigExclusionsRequest request) => DoRequest<IPostVotingConfigExclusionsRequest, PostVotingConfigExclusionsResponse>(request, request.RequestParameters);
177+
/// <summary>
178+
/// <c>POST</c> request to the <c>cluster.post_voting_config_exclusions</c> API, read more about this API online:
179+
/// <para></para>
180+
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</a>
181+
/// </summary>
182+
public Task<PostVotingConfigExclusionsResponse> PostVotingConfigExclusionsAsync(IPostVotingConfigExclusionsRequest request, CancellationToken ct = default) => DoRequestAsync<IPostVotingConfigExclusionsRequest, PostVotingConfigExclusionsResponse>(request, request.RequestParameters, ct);
183+
/// <summary>
136184
/// <c>PUT</c> request to the <c>cluster.put_settings</c> API, read more about this API online:
137185
/// <para></para>
138186
/// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html">https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html</a>

src/Nest/Requests.Cluster.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ public bool? IncludeYesDecisions
5858
}
5959
}
6060

61+
[InterfaceDataContract]
62+
public partial interface IDeleteVotingConfigExclusionsRequest : IRequest<DeleteVotingConfigExclusionsRequestParameters>
63+
{
64+
}
65+
66+
///<summary>Request for DeleteVotingConfigExclusions <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</para></summary>
67+
public partial class DeleteVotingConfigExclusionsRequest : PlainRequestBase<DeleteVotingConfigExclusionsRequestParameters>, IDeleteVotingConfigExclusionsRequest
68+
{
69+
protected IDeleteVotingConfigExclusionsRequest Self => this;
70+
internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterDeleteVotingConfigExclusions;
71+
// values part of the url path
72+
// Request parameters
73+
///<summary>Specifies whether to wait for all excluded nodes to be removed from the cluster before clearing the voting configuration exclusions list.</summary>
74+
public bool? WaitForRemoval
75+
{
76+
get => Q<bool? >("wait_for_removal");
77+
set => Q("wait_for_removal", value);
78+
}
79+
}
80+
6181
[InterfaceDataContract]
6282
public partial interface IClusterGetSettingsRequest : IRequest<ClusterGetSettingsRequestParameters>
6383
{
@@ -234,6 +254,46 @@ public Time MasterTimeout
234254
}
235255
}
236256

257+
[InterfaceDataContract]
258+
public partial interface IPostVotingConfigExclusionsRequest : IRequest<PostVotingConfigExclusionsRequestParameters>
259+
{
260+
}
261+
262+
///<summary>Request for PostVotingConfigExclusions <para>https://www.elastic.co/guide/en/elasticsearch/reference/master/voting-config-exclusions.html</para></summary>
263+
public partial class PostVotingConfigExclusionsRequest : PlainRequestBase<PostVotingConfigExclusionsRequestParameters>, IPostVotingConfigExclusionsRequest
264+
{
265+
protected IPostVotingConfigExclusionsRequest Self => this;
266+
internal override ApiUrls ApiUrls => ApiUrlsLookups.ClusterPostVotingConfigExclusions;
267+
// values part of the url path
268+
// Request parameters
269+
///<summary>
270+
/// A comma-separated list of the persistent ids of the nodes to exclude from the voting configuration. If specified, you may not also specify
271+
/// ?node_names.
272+
///</summary>
273+
public string NodeIds
274+
{
275+
get => Q<string>("node_ids");
276+
set => Q("node_ids", value);
277+
}
278+
279+
///<summary>
280+
/// A comma-separated list of the names of the nodes to exclude from the voting configuration. If specified, you may not also specify
281+
/// ?node_ids.
282+
///</summary>
283+
public string NodeNames
284+
{
285+
get => Q<string>("node_names");
286+
set => Q("node_names", value);
287+
}
288+
289+
///<summary>Explicit operation timeout</summary>
290+
public Time Timeout
291+
{
292+
get => Q<Time>("timeout");
293+
set => Q("timeout", value);
294+
}
295+
}
296+
237297
[InterfaceDataContract]
238298
public partial interface IClusterPutSettingsRequest : IRequest<ClusterPutSettingsRequestParameters>
239299
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System;
6+
using System.Threading;
7+
using Elasticsearch.Net;
8+
using FluentAssertions;
9+
using Nest;
10+
using Tests.Cluster.TaskManagement.GetTask;
11+
using Tests.Core.Extensions;
12+
using Tests.Core.ManagedElasticsearch.Clusters;
13+
using Tests.Core.ManagedElasticsearch.NodeSeeders;
14+
using Tests.Domain;
15+
using Tests.Framework.EndpointTests;
16+
using Tests.Framework.EndpointTests.TestState;
17+
18+
namespace Tests.Cluster.VotingConfigExclusions.DeleteVotingConfigExclusions
19+
{
20+
public class DeleteVotingConfigExclusionsApiTests : ApiIntegrationTestBase<WritableCluster, DeleteVotingConfigExclusionsResponse, IDeleteVotingConfigExclusionsRequest, DeleteVotingConfigExclusionsDescriptor, DeleteVotingConfigExclusionsRequest>
21+
{
22+
public DeleteVotingConfigExclusionsApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
23+
24+
protected override bool ExpectIsValid => true;
25+
protected override int ExpectStatusCode => 200;
26+
27+
protected override Func<DeleteVotingConfigExclusionsDescriptor, IDeleteVotingConfigExclusionsRequest> Fluent => s => s
28+
.WaitForRemoval();
29+
30+
protected override HttpMethod HttpMethod => HttpMethod.DELETE;
31+
32+
protected override DeleteVotingConfigExclusionsRequest Initializer => new DeleteVotingConfigExclusionsRequest { WaitForRemoval = true };
33+
protected override string UrlPath => $"/_cluster/voting_config_exclusions?wait_for_removal=true";
34+
35+
protected override LazyResponses ClientUsage() => Calls(
36+
(client, f) => client.Cluster.DeleteVotingConfigExclusions(f),
37+
(client, f) => client.Cluster.DeleteVotingConfigExclusionsAsync(f),
38+
(client, r) => client.Cluster.DeleteVotingConfigExclusions(r),
39+
(client, r) => client.Cluster.DeleteVotingConfigExclusionsAsync(r)
40+
);
41+
42+
protected override void ExpectResponse(DeleteVotingConfigExclusionsResponse response) => response.ShouldBeValid();
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Threading.Tasks;
6+
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
7+
using Nest;
8+
using Tests.Framework.EndpointTests;
9+
using static Tests.Framework.EndpointTests.UrlTester;
10+
11+
namespace Tests.Cluster.VotingConfigExclusions.DeleteVotingConfigExclusions
12+
{
13+
public class DeleteingVotingConfigExclusionsTests : UrlTestsBase
14+
{
15+
[U] public override async Task Urls() =>
16+
await DELETE("/_cluster/voting_config_exclusions")
17+
.Fluent(c => c.Cluster.DeleteVotingConfigExclusions())
18+
.Request(c => c.Cluster.DeleteVotingConfigExclusions(new DeleteVotingConfigExclusionsRequest()))
19+
.FluentAsync(c => c.Cluster.DeleteVotingConfigExclusionsAsync())
20+
.RequestAsync(c => c.Cluster.DeleteVotingConfigExclusionsAsync(new DeleteVotingConfigExclusionsRequest()));
21+
}
22+
}

0 commit comments

Comments
 (0)