Skip to content

Commit f50fa93

Browse files
committed
Merge remote-tracking branch 'origin/feature/cluster-pending-tasks' into develop
Conflicts: src/Nest/Nest.csproj
2 parents b13edf3 + 6c0521c commit f50fa93

File tree

11 files changed

+237
-14
lines changed

11 files changed

+237
-14
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Elasticsearch.Net;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace Nest
8+
{
9+
internal static class ClusterPendingTasksPathInfo
10+
{
11+
public static void Update(ElasticsearchPathInfo<ClusterPendingTasksRequestParameters> pathInfo)
12+
{
13+
pathInfo.HttpMethod = PathInfoHttpMethod.GET;
14+
}
15+
}
16+
17+
public interface IClusterPendingTasksRequest : IRequest<ClusterPendingTasksRequestParameters>
18+
{
19+
}
20+
21+
public partial class ClusterPendingTasksRequest
22+
: BasePathRequest<ClusterPendingTasksRequestParameters>, IClusterPendingTasksRequest
23+
{
24+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<ClusterPendingTasksRequestParameters> pathInfo)
25+
{
26+
ClusterPendingTasksPathInfo.Update(pathInfo);
27+
}
28+
}
29+
30+
public partial class ClusterPendingTasksDescriptor
31+
: BasePathDescriptor<ClusterPendingTasksDescriptor, ClusterPendingTasksRequestParameters>, IClusterPendingTasksRequest
32+
{
33+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<ClusterPendingTasksRequestParameters> pathInfo)
34+
{
35+
ClusterPendingTasksPathInfo.Update(pathInfo);
36+
}
37+
}
38+
}

src/Nest/DSL/_Descriptors.generated.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ public ClusterHealthDescriptor WaitForStatus(WaitForStatus wait_for_status)
10851085
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/cluster-pending.html
10861086
///</pre>
10871087
///</summary>
1088-
public partial class ClusterPendingTasksDescriptor : BaseRequest<ClusterPendingTasksRequestParameters>
1088+
public partial class ClusterPendingTasksDescriptor
10891089
{
10901090

10911091

@@ -1105,12 +1105,6 @@ public ClusterPendingTasksDescriptor MasterTimeout(string master_timeout)
11051105
return this;
11061106
}
11071107

1108-
1109-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<ClusterPendingTasksRequestParameters> pathInfo)
1110-
{
1111-
throw new NotImplementedException();
1112-
}
1113-
11141108

11151109
}
11161110

src/Nest/DSL/_Requests.generated.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ public WaitForStatus WaitForStatus
10191019
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/cluster-pending.html
10201020
///</pre>
10211021
///</summary>
1022-
public partial class ClusterPendingTasksRequest : BasePathRequest<ClusterPendingTasksRequestParameters>
1022+
public partial class ClusterPendingTasksRequest
10231023
{
10241024

10251025
///<summary>Return local information, do not retrieve the state from master node (default: false)</summary>
@@ -1037,12 +1037,6 @@ public string MasterTimeout
10371037
set { this.Request.RequestParameters.AddQueryString("master_timeout", value); }
10381038
}
10391039

1040-
1041-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<ClusterPendingTasksRequestParameters> pathInfo)
1042-
{
1043-
throw new NotImplementedException();
1044-
}
1045-
10461040
}
10471041

10481042

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
7+
namespace Nest
8+
{
9+
public interface IClusterPendingTasksResponse : IResponse
10+
{
11+
IEnumerable<PendingTask> Tasks { get; set; }
12+
}
13+
14+
[JsonObject]
15+
public class ClusterPendingTasksResponse : BaseResponse, IClusterPendingTasksResponse
16+
{
17+
[JsonProperty("tasks")]
18+
public IEnumerable<PendingTask> Tasks { get; set; }
19+
}
20+
21+
[JsonObject]
22+
public class PendingTask
23+
{
24+
[JsonProperty("insert_order")]
25+
public int InsertOrder { get; set; }
26+
27+
[JsonProperty("priority")]
28+
public string Priority { get; set; }
29+
30+
[JsonProperty("source")]
31+
public string Source { get; set; }
32+
33+
[JsonProperty("time_in_queue_millis")]
34+
public int TimeInQueueMilliseconds { get; set; }
35+
36+
[JsonProperty("time_in_queue")]
37+
public string TimeInQueue { get; set; }
38+
}
39+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Elasticsearch.Net;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Nest
9+
{
10+
public partial class ElasticClient
11+
{
12+
/// <inheritdoc />
13+
public IClusterPendingTasksResponse ClusterPendingTasks(Func<ClusterPendingTasksDescriptor, ClusterPendingTasksDescriptor> pendingTasksSelector = null)
14+
{
15+
pendingTasksSelector = pendingTasksSelector ?? (s => s);
16+
return this.Dispatch<ClusterPendingTasksDescriptor, ClusterPendingTasksRequestParameters, ClusterPendingTasksResponse>(
17+
pendingTasksSelector,
18+
(p, d) => this.RawDispatch.ClusterPendingTasksDispatch<ClusterPendingTasksResponse>(p)
19+
);
20+
}
21+
22+
/// <inheritdoc />
23+
public Task<IClusterPendingTasksResponse> ClusterPendingTasksAsync(Func<ClusterPendingTasksDescriptor, ClusterPendingTasksDescriptor> pendingTasksSelector = null)
24+
{
25+
pendingTasksSelector = pendingTasksSelector ?? (s => s);
26+
return this.DispatchAsync<ClusterPendingTasksDescriptor, ClusterPendingTasksRequestParameters, ClusterPendingTasksResponse, IClusterPendingTasksResponse>(
27+
pendingTasksSelector,
28+
(p, d) => this.RawDispatch.ClusterPendingTasksDispatchAsync<ClusterPendingTasksResponse>(p)
29+
);
30+
}
31+
32+
/// <inheritdoc />
33+
public IClusterPendingTasksResponse ClusterPendingTasks(IClusterPendingTasksRequest pendingTasksRequest)
34+
{
35+
return this.Dispatch<IClusterPendingTasksRequest, ClusterPendingTasksRequestParameters, ClusterPendingTasksResponse>(
36+
pendingTasksRequest,
37+
(p, d) => this.RawDispatch.ClusterPendingTasksDispatch<ClusterPendingTasksResponse>(p)
38+
);
39+
}
40+
41+
/// <inheritdoc />
42+
public Task<IClusterPendingTasksResponse> ClusterPendingTasksAsync(IClusterPendingTasksRequest pendingTasksRequest)
43+
{
44+
return this.DispatchAsync<IClusterPendingTasksRequest, ClusterPendingTasksRequestParameters, ClusterPendingTasksResponse, IClusterPendingTasksResponse>(
45+
pendingTasksRequest,
46+
(p, d) => this.RawDispatch.ClusterPendingTasksDispatchAsync<ClusterPendingTasksResponse>(p)
47+
);
48+
}
49+
}
50+
}

src/Nest/IElasticClient.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,20 @@ Task<IExistsResponse> DocumentExistsAsync<T>(Func<DocumentExistsDescriptor<T>, D
12741274
/// <inheritdoc />
12751275
Task<IClusterGetSettingsResponse> ClusterGetSettingsAsync(IClusterGetSettingsRequest clusterSettingsRequest = null);
12761276

1277+
/// <summary>
1278+
/// Returns a list of any cluster-level changes (e.g. create index, update mapping, allocate or fail shard) which have not yet been executed.
1279+
/// </summary>
1280+
IClusterPendingTasksResponse ClusterPendingTasks(Func<ClusterPendingTasksDescriptor, ClusterPendingTasksDescriptor> pendingTasksSelector = null);
1281+
1282+
/// <inheritdoc />
1283+
Task<IClusterPendingTasksResponse> ClusterPendingTasksAsync(Func<ClusterPendingTasksDescriptor, ClusterPendingTasksDescriptor> pendingTasksSelector = null);
1284+
1285+
/// <inheritdoc />
1286+
IClusterPendingTasksResponse ClusterPendingTasks(IClusterPendingTasksRequest pendingTasksRequest);
1287+
1288+
/// <inheritdoc />
1289+
Task<IClusterPendingTasksResponse> ClusterPendingTasksAsync(IClusterPendingTasksRequest pendingTasksRequest);
1290+
12771291
/// <inheritdoc />
12781292
IExistsResponse AliasExists(Func<AliasExistsDescriptor, AliasExistsDescriptor> selector);
12791293

src/Nest/Nest.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<Compile Include="Domain\Mapping\SubMappings\NormsMapping.cs" />
166166
<Compile Include="Domain\Mapping\SubMappings\MappingTransform.cs" />
167167
<Compile Include="Domain\Responses\ClusterStatsResponse.cs" />
168+
<Compile Include="Domain\Responses\ClusterPendingTasksResponse.cs" />
168169
<Compile Include="Domain\Responses\ExplainResponse.cs" />
169170
<Compile Include="Domain\Responses\GetFieldMappingResponse.cs" />
170171
<Compile Include="Domain\Responses\MultiPercolateResponse.cs" />
@@ -179,6 +180,7 @@
179180
<Compile Include="Domain\Stats\PluginStats.cs" />
180181
<Compile Include="Domain\Stats\SegmentsStats.cs" />
181182
<Compile Include="DSL\ClusterStatsDescriptor.cs" />
183+
<Compile Include="DSL\ClusterPendingTasksDescriptor.cs" />
182184
<Compile Include="DSL\TemplateExistsDescriptor.cs" />
183185
<Compile Include="Domain\Responses\PingResponse.cs" />
184186
<Compile Include="Domain\Responses\NodesShutdownResponse.cs" />
@@ -892,6 +894,7 @@
892894
<Compile Include="Resolvers\Converters\YesNoBoolConverter.cs" />
893895
<Compile Include="Domain\Paths\ElasticsearchPathInfo.cs" />
894896
<Compile Include="ElasticClient-ClusterStats.cs" />
897+
<Compile Include="ElasticClient-ClusterPendingTasks.cs" />
895898
<Compile Include="Resolvers\ExpressionVisitor.cs" />
896899
<Compile Include="Domain\Marker\IndexNameMarker.cs" />
897900
<Compile Include="Domain\Paths\PathInfoHttpMethod.cs" />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FluentAssertions;
2+
using NUnit.Framework;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Nest.Tests.Integration.Cluster
10+
{
11+
[TestFixture]
12+
public class PendingTasksTests : IntegrationTests
13+
{
14+
[Test]
15+
public void PendingTasks()
16+
{
17+
var r = this.Client.ClusterPendingTasks();
18+
r.IsValid.Should().BeTrue();
19+
}
20+
}
21+
}

src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<Compile Include="Aggregations\ParseResponseItemsTests.cs" />
9999
<Compile Include="Attributes\SkipVersionAttribute.cs" />
100100
<Compile Include="Cluster\GetSettingsTests.cs" />
101+
<Compile Include="Cluster\PendingTasksTests.cs" />
101102
<Compile Include="Cluster\PutSettingsTests.cs" />
102103
<Compile Include="Cluster\StatsTest.cs" />
103104
<Compile Include="Connection\Failover\SniffTests.cs" />
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using FluentAssertions;
2+
using NUnit.Framework;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Nest.Tests.Unit.Cluster
11+
{
12+
[TestFixture]
13+
public class PendingTasksTests : BaseJsonTests
14+
{
15+
[Test]
16+
public void RequestUrlTest()
17+
{
18+
var r = this._client.ClusterPendingTasks();
19+
var status = r.ConnectionStatus;
20+
var url = new Uri(status.RequestUrl);
21+
url.AbsolutePath.Should().StartWith("/_cluster/pending_tasks");
22+
}
23+
24+
[Test]
25+
public void ResponseBodyJsonTest()
26+
{
27+
var json = @"{
28+
tasks: [
29+
{
30+
insert_order: 101,
31+
priority: ""URGENT"",
32+
source: ""create-index [foo_9], cause [api]"",
33+
time_in_queue_millis: 86,
34+
time_in_queue: ""86ms""
35+
},
36+
{
37+
insert_order: 46,
38+
priority: ""HIGH"",
39+
source: ""shard-started ([foo_2][1], node[tMTocMvQQgGCkj7QDHl3OA], [P], s[INITIALIZING]), reason [after recovery from gateway]"",
40+
time_in_queue_millis: 842,
41+
time_in_queue: ""842ms""
42+
}
43+
]
44+
}";
45+
46+
var bytes = System.Text.Encoding.UTF8.GetBytes(json);
47+
var stream = new MemoryStream(bytes);
48+
49+
var response = _client.Serializer.Deserialize<ClusterPendingTasksResponse>(stream);
50+
response.Should().NotBeNull();
51+
response.Tasks.Count().ShouldBeEquivalentTo(2);
52+
53+
var task1 = response.Tasks.ElementAt(0);
54+
task1.InsertOrder.ShouldBeEquivalentTo(101);
55+
task1.Priority.ShouldBeEquivalentTo("URGENT");
56+
task1.Source.ShouldBeEquivalentTo("create-index [foo_9], cause [api]");
57+
task1.TimeInQueueMilliseconds.ShouldBeEquivalentTo(86);
58+
task1.TimeInQueue.ShouldBeEquivalentTo("86ms");
59+
60+
var task2 = response.Tasks.ElementAt(1);
61+
task2.InsertOrder.ShouldBeEquivalentTo(46);
62+
task2.Priority.ShouldBeEquivalentTo("HIGH");
63+
task2.Source.ShouldBeEquivalentTo("shard-started ([foo_2][1], node[tMTocMvQQgGCkj7QDHl3OA], [P], s[INITIALIZING]), reason [after recovery from gateway]");
64+
task2.TimeInQueueMilliseconds.ShouldBeEquivalentTo(842);
65+
task2.TimeInQueue.ShouldBeEquivalentTo("842ms");
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)