Skip to content

Commit 1e67a39

Browse files
committed
Merge remote-tracking branch 'origin/feature/nodes-shutdown' into develop
Conflicts: src/Nest/Nest.csproj
2 parents 15aaddd + f61cffd commit 1e67a39

File tree

8 files changed

+147
-19
lines changed

8 files changed

+147
-19
lines changed

Diff for: src/Nest/DSL/NodesShutdownDescriptor.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Elasticsearch.Net;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
8+
namespace Nest
9+
{
10+
internal static class NodesShutdownPathInfo
11+
{
12+
public static void Update(ElasticsearchPathInfo<NodesShutdownRequestParameters> pathInfo)
13+
{
14+
pathInfo.HttpMethod = PathInfoHttpMethod.POST;
15+
}
16+
}
17+
18+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
19+
public interface INodesShutdownRequest : INodeIdOptionalPath<NodesShutdownRequestParameters>
20+
{
21+
}
22+
23+
public partial class NodesShutdownRequest
24+
: NodeIdOptionalPathBase<NodesShutdownRequestParameters>, INodesShutdownRequest
25+
{
26+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<NodesShutdownRequestParameters> pathInfo)
27+
{
28+
NodesShutdownPathInfo.Update(pathInfo);
29+
}
30+
}
31+
32+
public partial class NodesShutdownDescriptor
33+
: NodeIdOptionalDescriptor<NodesShutdownDescriptor, NodesShutdownRequestParameters>, INodesShutdownRequest
34+
{
35+
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<NodesShutdownRequestParameters> pathInfo)
36+
{
37+
NodesShutdownPathInfo.Update(pathInfo);
38+
}
39+
}
40+
}

Diff for: src/Nest/DSL/_Descriptors.generated.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -4467,7 +4467,7 @@ public NodesInfoDescriptor Human(bool human = true)
44674467
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/cluster-nodes-shutdown.html
44684468
///</pre>
44694469
///</summary>
4470-
public partial class NodesShutdownDescriptor : BaseRequest<NodesShutdownRequestParameters>
4470+
public partial class NodesShutdownDescriptor
44714471
{
44724472

44734473

@@ -4487,12 +4487,6 @@ public NodesShutdownDescriptor Exit(bool exit = true)
44874487
return this;
44884488
}
44894489

4490-
4491-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<NodesShutdownRequestParameters> pathInfo)
4492-
{
4493-
throw new NotImplementedException();
4494-
}
4495-
44964490

44974491
}
44984492

Diff for: src/Nest/DSL/_Requests.generated.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -4031,7 +4031,7 @@ public bool Human
40314031
///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/cluster-nodes-shutdown.html
40324032
///</pre>
40334033
///</summary>
4034-
public partial class NodesShutdownRequest : BasePathRequest<NodesShutdownRequestParameters>
4034+
public partial class NodesShutdownRequest
40354035
{
40364036

40374037
///<summary>Set the delay for the operation (default: 1s)</summary>
@@ -4049,12 +4049,6 @@ public bool Exit
40494049
set { this.Request.RequestParameters.AddQueryString("exit", value); }
40504050
}
40514051

4052-
4053-
protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<NodesShutdownRequestParameters> pathInfo)
4054-
{
4055-
throw new NotImplementedException();
4056-
}
4057-
40584052
}
40594053

40604054

Diff for: src/Nest/Domain/Responses/NodesShutDownResponse.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
10+
public interface INodesShutdownResponse : IResponse
11+
{
12+
string ClusterName { get; set; }
13+
Dictionary<string, Dictionary<string, string>> Nodes { get; set; }
14+
}
15+
16+
[JsonObject]
17+
public class NodesShutdownResponse : BaseResponse, INodesShutdownResponse
18+
{
19+
[JsonProperty("cluster_name")]
20+
public string ClusterName { get; set; }
21+
22+
[JsonProperty("nodes")]
23+
public Dictionary<string, Dictionary<string, string>> Nodes { get; set; }
24+
}
25+
}

Diff for: src/Nest/ElasticClient-Nodes.cs

+43-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using System;
1+
using Elasticsearch.Net;
2+
using System;
23
using System.Collections.Generic;
3-
using System.Threading.Tasks;
4-
using Elasticsearch.Net;
54
using System.IO;
65
using System.Linq;
6+
using System.Text;
7+
using System.Text.RegularExpressions;
8+
using System.Threading.Tasks;
79

810
namespace Nest
911
{
1012
using NodesHotThreadConverter = Func<IElasticsearchResponse, Stream, NodesHotThreadsResponse>;
11-
using System.Text.RegularExpressions;
12-
using System.Text;
1313

1414
public partial class ElasticClient
1515
{
@@ -134,6 +134,44 @@ public Task<INodesHotThreadsResponse> NodesHotThreadsAsync(INodesHotThreadsReque
134134
);
135135
}
136136

137+
/// <inheritdoc />
138+
public INodesShutdownResponse NodesShutdown(Func<NodesShutdownDescriptor, NodesShutdownDescriptor> nodesShutdownSelector = null)
139+
{
140+
nodesShutdownSelector = nodesShutdownSelector ?? (s => s);
141+
return this.Dispatch<NodesShutdownDescriptor, NodesShutdownRequestParameters, NodesShutdownResponse>(
142+
nodesShutdownSelector,
143+
(p, d) => this.RawDispatch.NodesShutdownDispatch<NodesShutdownResponse>(p)
144+
);
145+
}
146+
147+
/// <inheritdoc />
148+
public Task<INodesShutdownResponse> NodesShutdownAsync(Func<NodesShutdownDescriptor, NodesShutdownDescriptor> nodesShutdownSelector = null)
149+
{
150+
nodesShutdownSelector = nodesShutdownSelector ?? (s => s);
151+
return this.DispatchAsync<NodesShutdownDescriptor, NodesShutdownRequestParameters, NodesShutdownResponse, INodesShutdownResponse>(
152+
nodesShutdownSelector,
153+
(p, d) => this.RawDispatch.NodesShutdownDispatchAsync<NodesShutdownResponse>(p)
154+
);
155+
}
156+
157+
/// <inheritdoc />
158+
public INodesShutdownResponse NodesShutdown(INodesShutdownRequest nodesShutdownRequest)
159+
{
160+
return this.Dispatch<INodesShutdownRequest, NodesShutdownRequestParameters, NodesShutdownResponse>(
161+
nodesShutdownRequest,
162+
(p, d) => this.RawDispatch.NodesShutdownDispatch<NodesShutdownResponse>(p)
163+
);
164+
}
165+
166+
/// <inheritdoc />
167+
public Task<INodesShutdownResponse> NodesShutdownAsync(INodesShutdownRequest nodesShutdownRequest)
168+
{
169+
return this.DispatchAsync<INodesShutdownRequest, NodesShutdownRequestParameters, NodesShutdownResponse, INodesShutdownResponse>(
170+
nodesShutdownRequest,
171+
(p, d) => this.RawDispatch.NodesShutdownDispatchAsync<NodesShutdownResponse>(p)
172+
);
173+
}
174+
137175
/// <summary>
138176
/// Because the nodes.hot_threads endpoint returns plain text instead of JSON, we have to
139177
/// manually parse the response text into a typed response object.

Diff for: src/Nest/IElasticClient.cs

+16
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,22 @@ Task<IIndicesResponse> DeleteMappingAsync<T>(Func<DeleteMappingDescriptor<T>, De
629629
/// <inheritdoc />
630630
Task<INodesHotThreadsResponse> NodesHotThreadsAsync(INodesHotThreadsRequest nodesHotThreadsRequest);
631631

632+
/// <summary>
633+
/// Allows to shutdown one or more (or all) nodes in the cluster.
634+
/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/cluster-nodes-shutdown.html#cluster-nodes-shutdown
635+
/// </summary>
636+
/// <param name="nodesShutdownSelector">A descriptor that describes the nodes shutdown operation</param>
637+
INodesShutdownResponse NodesShutdown(Func<NodesShutdownDescriptor, NodesShutdownDescriptor> nodesShutdownSelector = null);
638+
639+
/// <inheritdoc />
640+
Task<INodesShutdownResponse> NodesShutdownAsync(Func<NodesShutdownDescriptor, NodesShutdownDescriptor> nodesShutdownSelector = null);
641+
642+
/// <inheritdoc />
643+
INodesShutdownResponse NodesShutdown(INodesShutdownRequest nodesShutdownRequest);
644+
645+
/// <inheritdoc />
646+
Task<INodesShutdownResponse> NodesShutdownAsync(INodesShutdownRequest nodesShutdownRequest);
647+
632648
/// <summary>
633649
/// Used to check if the index (indices) exists or not.
634650
/// <para> </para>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-exists.html

Diff for: src/Nest/Nest.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
<Compile Include="DSL\ClusterStatsDescriptor.cs" />
182182
<Compile Include="DSL\TemplateExistsDescriptor.cs" />
183183
<Compile Include="Domain\Responses\PingResponse.cs" />
184+
<Compile Include="Domain\Responses\NodesShutdownResponse.cs" />
184185
<Compile Include="DSL\Filter\GeoShapeCircleFilterDescriptor.cs" />
185186
<Compile Include="DSL\Filter\GeoShapeMultiLineStringFilterDescriptor.cs" />
186187
<Compile Include="DSL\Filter\GeoShapeMultiPointFilterDescriptor.cs" />
@@ -194,6 +195,7 @@
194195
<Compile Include="DSL\MultiPercolate\IPercolateOperation.cs" />
195196
<Compile Include="DSL\MultiPercolateDescriptor.cs" />
196197
<Compile Include="DSL\NodesHotThreadsDescriptor.cs" />
198+
<Compile Include="DSL\NodesShutdownDescriptor.cs" />
197199
<Compile Include="DSL\Paths\IndexOptionalNamePathDescriptor.cs" />
198200
<Compile Include="DSL\Paths\IndicesOptionalTypesNamePathDecriptor.cs" />
199201
<Compile Include="DSL\PingDescriptor.cs" />

Diff for: src/Tests/Nest.Tests.Unit/Cluster/NodeTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,24 @@ public void NodeStatsSpecificNodeWithFlags()
5959
url.AbsolutePath.Should().StartWith("/_nodes/127.0.0.1/stats/network%2Chttp");
6060
}
6161

62+
[Test]
63+
public void NodesShutdown()
64+
{
65+
var r = this._client.NodesShutdown();
66+
var status = r.ConnectionStatus;
67+
status.RequestUrl.Should().EndWith("/_shutdown");
68+
}
69+
70+
[Test]
71+
public void NodesShutdownSpecificNodeWithFlags()
72+
{
73+
var r = this._client.NodesShutdown(n => n
74+
.NodeId("mynode")
75+
.Delay("10s")
76+
.Exit(false)
77+
);
78+
var status = r.ConnectionStatus;
79+
status.RequestUrl.Should().EndWith("/_cluster/nodes/mynode/_shutdown?delay=10s&exit=false");
80+
}
6281
}
6382
}

0 commit comments

Comments
 (0)