Skip to content

Commit 62770f0

Browse files
committed
Support for reindex rethrottle
Closes #1986
1 parent c19bca1 commit 62770f0

File tree

5 files changed

+243
-0
lines changed

5 files changed

+243
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Elasticsearch.Net;
4+
5+
namespace Nest
6+
{
7+
public partial interface IElasticClient
8+
{
9+
/// <inheritdoc/>
10+
IReindexRethrottleResponse ReindexRethrottle(Func<ReindexRethrottleDescriptor, IReindexRethrottleRequest> selector);
11+
12+
/// <inheritdoc/>
13+
IReindexRethrottleResponse ReindexRethrottle(IReindexRethrottleRequest request);
14+
15+
/// <inheritdoc/>
16+
Task<IReindexRethrottleResponse> ReindexRethrottleAsync(Func<ReindexRethrottleDescriptor, IReindexRethrottleRequest> selector);
17+
18+
/// <inheritdoc/>
19+
Task<IReindexRethrottleResponse> ReindexRethrottleAsync(IReindexRethrottleRequest request);
20+
}
21+
22+
public partial class ElasticClient
23+
{
24+
/// <inheritdoc/>
25+
public IReindexRethrottleResponse ReindexRethrottle(Func<ReindexRethrottleDescriptor, IReindexRethrottleRequest> selector) =>
26+
this.ReindexRethrottle(selector.InvokeOrDefault(new ReindexRethrottleDescriptor()));
27+
28+
/// <inheritdoc/>
29+
public IReindexRethrottleResponse ReindexRethrottle(IReindexRethrottleRequest request) =>
30+
this.Dispatcher.Dispatch<IReindexRethrottleRequest, ReindexRethrottleRequestParameters, ReindexRethrottleResponse>(
31+
request,
32+
(p, d) => this.LowLevelDispatch.ReindexRethrottleDispatch<ReindexRethrottleResponse>(p)
33+
);
34+
35+
/// <inheritdoc/>
36+
public Task<IReindexRethrottleResponse> ReindexRethrottleAsync(Func<ReindexRethrottleDescriptor, IReindexRethrottleRequest> selector) =>
37+
this.ReindexRethrottleAsync(selector.InvokeOrDefault(new ReindexRethrottleDescriptor()));
38+
39+
/// <inheritdoc/>
40+
public Task<IReindexRethrottleResponse> ReindexRethrottleAsync(IReindexRethrottleRequest request) =>
41+
this.Dispatcher.DispatchAsync<IReindexRethrottleRequest, ReindexRethrottleRequestParameters, ReindexRethrottleResponse, IReindexRethrottleResponse>(
42+
request,
43+
(p, d) => this.LowLevelDispatch.ReindexRethrottleDispatchAsync<ReindexRethrottleResponse>(p)
44+
);
45+
}
46+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
public class ReindexNode
7+
{
8+
[JsonProperty("name")]
9+
public string Name { get; internal set; }
10+
11+
[JsonProperty("transport_address")]
12+
public string TransportAddress { get; internal set; }
13+
14+
[JsonProperty("host")]
15+
public string Host { get; internal set; }
16+
17+
[JsonProperty("ip")]
18+
public string Ip { get; internal set; }
19+
20+
[JsonProperty("roles")]
21+
public IEnumerable<string> Roles { get; internal set; }
22+
23+
[JsonProperty("attributes")]
24+
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))]
25+
public Dictionary<string, string> Attributes { get; internal set; }
26+
27+
[JsonProperty("tasks")]
28+
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))]
29+
public Dictionary<TaskId, ReindexTask> Tasks { get; internal set; }
30+
}
31+
32+
33+
public class ReindexTask
34+
{
35+
[JsonProperty("node")]
36+
public string Node { get; internal set; }
37+
38+
[JsonProperty("id")]
39+
public long Id { get; internal set; }
40+
41+
[JsonProperty("type")]
42+
public string Type { get; internal set; }
43+
44+
[JsonProperty("action")]
45+
public string Action { get; internal set; }
46+
47+
[JsonProperty("status")]
48+
public ReindexStatus Status { get; internal set; }
49+
50+
[JsonProperty("description")]
51+
public string Description { get; internal set; }
52+
53+
[JsonProperty("start_time_in_millis")]
54+
public long StartTimeInMilliseconds { get; internal set; }
55+
56+
[JsonProperty("running_time_in_nanos")]
57+
public long RunningTimeInNanoseconds { get; internal set; }
58+
}
59+
60+
public class ReindexStatus
61+
{
62+
[JsonProperty("total")]
63+
public long Total { get; internal set; }
64+
65+
[JsonProperty("updated")]
66+
public long Updated { get; internal set; }
67+
68+
[JsonProperty("created")]
69+
public long Created { get; internal set; }
70+
71+
[JsonProperty("deleted")]
72+
public long Deleted { get; internal set; }
73+
74+
[JsonProperty("batches")]
75+
public long Batches { get; internal set; }
76+
77+
[JsonProperty("version_conflicts")]
78+
public long VersionConflicts { get; internal set; }
79+
80+
[JsonProperty("noops")]
81+
public long Noops { get; internal set; }
82+
83+
[JsonProperty("retries")]
84+
public long Retries { get; internal set; }
85+
86+
[JsonProperty("throttled_millis")]
87+
public long ThrottledInMilliseconds { get; internal set; }
88+
89+
[JsonProperty("requests_per_second")]
90+
public long RequestsPerSecond { get; internal set; }
91+
92+
[JsonProperty("throttled_until_millis")]
93+
public long ThrottledUntilInMilliseconds { get; internal set; }
94+
}
95+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
[JsonObject(MemberSerialization.OptIn)]
7+
public interface IReindexRethrottleResponse : IResponse
8+
{
9+
[JsonProperty("nodes")]
10+
IEnumerable<ReindexNode> Nodes { get; set; }
11+
}
12+
13+
public class ReindexRethrottleResponse : ResponseBase, IReindexRethrottleResponse
14+
{
15+
public IEnumerable<ReindexNode> Nodes { get; set; }
16+
}
17+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Elasticsearch.Net;
5+
using FluentAssertions;
6+
using Nest;
7+
using Tests.Document.Multiple.Reindex;
8+
using Tests.Framework;
9+
using Tests.Framework.Integration;
10+
using Tests.Framework.MockData;
11+
using Xunit;
12+
using static Nest.Infer;
13+
14+
namespace Tests.Document.Multiple.ReindexRethrottle
15+
{
16+
[Collection(IntegrationContext.Reindex)]
17+
public class ReindexRethrottleApiTests
18+
: ApiIntegrationTestBase<IReindexRethrottleResponse, IReindexRethrottleRequest, ReindexRethrottleDescriptor, ReindexRethrottleRequest>
19+
{
20+
private readonly TaskId _taskId = "rhtoNesNR4aXVIY2bRR4GQ:13056";
21+
22+
public ReindexRethrottleApiTests(ReindexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
23+
24+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
25+
{
26+
}
27+
28+
protected override void OnBeforeCall(IElasticClient client)
29+
{
30+
base.OnBeforeCall(client);
31+
}
32+
33+
protected override LazyResponses ClientUsage() => Calls(
34+
fluent: (client, f) => client.ReindexRethrottle(f),
35+
fluentAsync: (client, f) => client.ReindexRethrottleAsync(f),
36+
request: (client, r) => client.ReindexRethrottle(r),
37+
requestAsync: (client, r) => client.ReindexRethrottleAsync(r)
38+
);
39+
protected override void OnAfterCall(IElasticClient client) => client.Refresh(CallIsolatedValue);
40+
41+
protected override bool ExpectIsValid => true;
42+
protected override int ExpectStatusCode => 200;
43+
protected override HttpMethod HttpMethod => HttpMethod.POST;
44+
45+
46+
protected override string UrlPath => $"/_reindex/rhtoNesNR4aXVIY2bRR4GQ%3A13056/_rethrottle";
47+
48+
protected override bool SupportsDeserialization => false;
49+
50+
protected override Func<ReindexRethrottleDescriptor, IReindexRethrottleRequest> Fluent => d => d
51+
.TaskId(_taskId);
52+
53+
protected override ReindexRethrottleRequest Initializer => new ReindexRethrottleRequest(_taskId);
54+
55+
protected override void ExpectResponse(IReindexRethrottleResponse response)
56+
{
57+
}
58+
59+
protected override object ExpectJson => null;
60+
}
61+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Threading.Tasks;
2+
using Nest;
3+
using Tests.Framework;
4+
using Tests.Framework.MockData;
5+
using static Tests.Framework.UrlTester;
6+
7+
namespace Tests.Document.Multiple.ReindexRethrottle
8+
{
9+
public class ReindexRethrottleUrlTests : IUrlTests
10+
{
11+
private readonly TaskId _taskId = "rhtoNesNR4aXVIY2bRR4GQ:13056";
12+
13+
[U] public async Task Urls()
14+
{
15+
await POST($"/_reindex/rhtoNesNR4aXVIY2bRR4GQ%3A13056/_rethrottle")
16+
.Fluent(c => c.ReindexRethrottle(f=>f.TaskId(_taskId)))
17+
.Request(c => c.ReindexRethrottle(new ReindexRethrottleRequest(_taskId)))
18+
.FluentAsync(c => c.ReindexRethrottleAsync(f=>f.TaskId(_taskId)))
19+
.RequestAsync(c => c.ReindexRethrottleAsync(new ReindexRethrottleRequest(_taskId)))
20+
;
21+
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)