Skip to content

Commit 145f314

Browse files
committed
Merge pull request #292 from NickCraver/master
Support for /_cluster/state APIs
2 parents 30e5a5d + 4de2c90 commit 145f314

File tree

9 files changed

+271
-36
lines changed

9 files changed

+271
-36
lines changed

Diff for: src/Nest.Tests.Integration/Cluster/StateTests.cs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
4+
namespace Nest.Tests.Integration.Cluster
5+
{
6+
[TestFixture]
7+
public class StateTests : IntegrationTests
8+
{
9+
[Test]
10+
public void SimpleState()
11+
{
12+
var r = this._client.ClusterState(ClusterStateInfo.All);
13+
Assert.True(r.IsValid);
14+
Assert.NotNull(r.ClusterName);
15+
Assert.NotNull(r.MasterNode);
16+
Assert.NotNull(r.Metadata);
17+
Assert.NotNull(r.Metadata.Indices);
18+
Assert.True(r.Metadata.Indices.Count > 0);
19+
Assert.NotNull(r.Nodes);
20+
Assert.True(r.Nodes.Count > 0);
21+
Assert.NotNull(r.RoutingNodes);
22+
Assert.True(r.RoutingNodes.Nodes.Count > 0);
23+
Assert.NotNull(r.RoutingTable);
24+
}
25+
[Test]
26+
public void StateWithoutMetadata()
27+
{
28+
var r = this._client.ClusterState(ClusterStateInfo.ExcludeMetadata);
29+
Assert.IsNull(r.Metadata);
30+
}
31+
[Test]
32+
public void StateWithoutNodes()
33+
{
34+
var r = this._client.ClusterState(ClusterStateInfo.ExcludeNodes);
35+
Assert.IsNull(r.Nodes);
36+
}
37+
[Test]
38+
public void StateWithoutRoutingTable()
39+
{
40+
var r = this._client.ClusterState(ClusterStateInfo.ExcludeRoutingTable);
41+
Assert.IsNull(r.RoutingTable);
42+
}
43+
//[Test]
44+
//public void StateWithoutBlocks()
45+
//{
46+
// var r = this._client.ClusterState(ClusterStateInfo.ExcludeRoutingTable);
47+
// Assert.IsNull(r.Blocks);
48+
//}
49+
}
50+
}

Diff for: src/Nest.Tests.Integration/Nest.Tests.Integration.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Compile Include="Indices\Analysis\Analyzers\AnalyzerTest.cs" />
6565
<Compile Include="Indices\Analysis\Analyzers\AnalyzerTestResult.cs" />
6666
<Compile Include="Indices\Analysis\Analyzers\AnalyzerTests.cs" />
67+
<Compile Include="Cluster\StateTests.cs" />
6768
<Compile Include="IntegrationTests.cs" />
6869
<Compile Include="Cluster\HealthTests.cs" />
6970
<Compile Include="Cluster\NodeTests.cs" />

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

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
public interface IClusterStateResponse : IResponse
7+
{
8+
string ClusterName { get; }
9+
string MasterNode { get; }
10+
Dictionary<string, NodeState> Nodes { get; }
11+
MetadataState Metadata { get; }
12+
RoutingTableState RoutingTable { get; }
13+
RoutingNodesState RoutingNodes { get; }
14+
}
15+
16+
[JsonObject]
17+
public class ClusterStateResponse : BaseResponse, IClusterStateResponse
18+
{
19+
public ClusterStateResponse()
20+
{
21+
this.IsValid = true;
22+
}
23+
[JsonProperty("cluster_name")]
24+
public string ClusterName { get; internal set; }
25+
[JsonProperty("master_node")]
26+
public string MasterNode { get; internal set; }
27+
28+
[JsonProperty("nodes")]
29+
public Dictionary<string, NodeState> Nodes { get; internal set; }
30+
31+
[JsonProperty("metadata")]
32+
public MetadataState Metadata { get; internal set; }
33+
34+
[JsonProperty("routing_table")]
35+
public RoutingTableState RoutingTable { get; internal set; }
36+
37+
[JsonProperty("routing_nodes")]
38+
public RoutingNodesState RoutingNodes { get; internal set; }
39+
}
40+
}

Diff for: src/Nest/Domain/State/ClusterState.cs

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Newtonsoft.Json;
6+
7+
namespace Nest
8+
{
9+
public class NodeState
10+
{
11+
[JsonProperty("name")]
12+
public string Name { get; internal set; }
13+
14+
[JsonProperty("transport_address")]
15+
public string TransportAddress { get; internal set; }
16+
17+
[JsonProperty("attributes")]
18+
public Dictionary<string, string> Attributes { get; internal set; }
19+
}
20+
21+
public class RoutingTableState
22+
{
23+
[JsonProperty("indices")]
24+
public Dictionary<string, IndexRoutingTable> Indices { get; internal set; }
25+
}
26+
27+
public class IndexRoutingTable
28+
{
29+
[JsonProperty("shards")]
30+
public Dictionary<string, List<RoutingShard>> Shards { get; internal set; }
31+
}
32+
33+
public class RoutingShard
34+
{
35+
[JsonProperty("state")]
36+
public string State { get; internal set; }
37+
38+
[JsonProperty("primary")]
39+
public bool Primary { get; internal set; }
40+
41+
[JsonProperty("node")]
42+
public string Node { get; internal set; }
43+
44+
[JsonProperty("relocating_node")]
45+
public string RelocatingNode { get; internal set; }
46+
47+
[JsonProperty("shard")]
48+
public int Shard { get; internal set; }
49+
50+
[JsonProperty("index")]
51+
public string Index { get; internal set; }
52+
}
53+
54+
public class RoutingNodesState
55+
{
56+
[JsonProperty("unassigned")]
57+
public List<RoutingShard> Unassigned { get; internal set; }
58+
59+
[JsonProperty("nodes")]
60+
public Dictionary<string, List<RoutingShard>> Nodes { get; internal set; }
61+
}
62+
63+
public class MetadataState
64+
{
65+
//[JsonProperty("templates")]
66+
//public ?? Templates { get; internal set; }
67+
68+
[JsonProperty("indices")]
69+
public Dictionary<string, MetadataIndexState> Indices { get; internal set; }
70+
}
71+
72+
public class MetadataIndexState
73+
{
74+
[JsonProperty("state")]
75+
public string State { get; internal set; }
76+
77+
[JsonProperty("settings")]
78+
public Dictionary<string, string> Settings { get; internal set; }
79+
80+
//[JsonProperty("mappings")]
81+
//public Dictionary<string, MetadataIndexStateMapping> Mappings { get; internal set; }
82+
83+
//[JsonProperty("aliases")]
84+
//public ?? Aliases { get; internal set; }
85+
}
86+
}

Diff for: src/Nest/Domain/Stats/NodeStats.cs

+38-36
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,34 @@ public class IndexStoreStats : StoreStats
7474
[JsonProperty("throttle_time")]
7575
public string ThrottleTime { get; internal set; }
7676
[JsonProperty("throttle_time_in_millis")]
77-
public int ThrottleTimeInMilliseconds { get; internal set; }
77+
public long ThrottleTimeInMilliseconds { get; internal set; }
7878
}
7979

8080
[JsonObject]
8181
public class IndexCacheStats
8282
{
8383
[JsonProperty(PropertyName = "field_evictions")]
84-
public int FieldEvictions { get; internal set; }
84+
public long FieldEvictions { get; internal set; }
8585
[JsonProperty(PropertyName = "field_size")]
8686
public string FieldSize { get; internal set; }
8787
[JsonProperty(PropertyName = "field_size_in_bytes")]
88-
public int FieldSizeInBytes { get; internal set; }
88+
public long FieldSizeInBytes { get; internal set; }
8989
[JsonProperty(PropertyName = "filter_count")]
90-
public int FilterCount { get; internal set; }
90+
public long FilterCount { get; internal set; }
9191
[JsonProperty(PropertyName = "filter_evictions")]
92-
public int FilterEvictions { get; internal set; }
92+
public long FilterEvictions { get; internal set; }
9393
[JsonProperty(PropertyName = "filter_size")]
9494
public string FilterSize { get; internal set; }
9595
[JsonProperty(PropertyName = "filter_size_in_bytes")]
96-
public int FilterSizeInBytes { get; internal set; }
96+
public long FilterSizeInBytes { get; internal set; }
9797
[JsonProperty(PropertyName = "bloom_size")]
9898
public string BloomSize { get; internal set; }
9999
[JsonProperty(PropertyName = "bloom_size_in_bytes")]
100-
public int BloomSizeInBytes { get; internal set; }
100+
public long BloomSizeInBytes { get; internal set; }
101101
[JsonProperty(PropertyName = "id_cache_size")]
102102
public string IDCacheSize { get; internal set; }
103103
[JsonProperty(PropertyName = "id_cache_size_in_bytes")]
104-
public int IDCacheSizeInBytes { get; internal set; }
104+
public long IDCacheSizeInBytes { get; internal set; }
105105
}
106106
}
107107

@@ -114,6 +114,8 @@ public class UptimeStats
114114
public string Uptime { get; internal set; }
115115
[JsonProperty("uptime_in_millis")]
116116
public long UptimeInMilliseconds { get; internal set; }
117+
[JsonProperty("load_average")]
118+
public float[] LoadAverage { get; internal set; }
117119
}
118120

119121
[JsonObject]
@@ -190,15 +192,15 @@ public class CPUStats
190192
[JsonProperty("sys")]
191193
public string System { get; internal set; }
192194
[JsonProperty("sys_in_millis")]
193-
public int SystemInMilliseconds { get; internal set; }
195+
public long SystemInMilliseconds { get; internal set; }
194196
[JsonProperty("user")]
195197
public string User { get; internal set; }
196198
[JsonProperty("user_in_millis")]
197-
public int UserInMilliseconds { get; internal set; }
199+
public long UserInMilliseconds { get; internal set; }
198200
[JsonProperty("total")]
199201
public string Total { get; internal set; }
200202
[JsonProperty("total_in_millis")]
201-
public int TotalInMilliseconds { get; internal set; }
203+
public long TotalInMilliseconds { get; internal set; }
202204
}
203205

204206
[JsonObject]
@@ -207,11 +209,11 @@ public class MemoryStats
207209
[JsonProperty("resident")]
208210
public string Resident { get; internal set; }
209211
[JsonProperty("resident_in_bytes")]
210-
public int ResidentInBytes { get; internal set; }
212+
public long ResidentInBytes { get; internal set; }
211213
[JsonProperty("share")]
212214
public string Share { get; internal set; }
213215
[JsonProperty("share_in_bytes")]
214-
public int ShareInBytes { get; internal set; }
216+
public long ShareInBytes { get; internal set; }
215217
[JsonProperty("total_virtual")]
216218
public string TotalVirtual { get; internal set; }
217219
[JsonProperty("total_virtual_in_bytes")]
@@ -259,19 +261,19 @@ public class JVMPool
259261
[JsonProperty("used")]
260262
public string Used { get; internal set; }
261263
[JsonProperty("")]
262-
public int UsedInBytes { get; internal set; }
264+
public long UsedInBytes { get; internal set; }
263265
[JsonProperty("max")]
264266
public string Max { get; internal set; }
265267
[JsonProperty("max_in_bytes")]
266-
public int MaxInBytes { get; internal set; }
268+
public long MaxInBytes { get; internal set; }
267269
[JsonProperty("peak_used")]
268270
public string PeakUsed { get; internal set; }
269271
[JsonProperty("peak_used_in_bytes")]
270-
public int PeakUsedInBytes { get; internal set; }
272+
public long PeakUsedInBytes { get; internal set; }
271273
[JsonProperty("peak_max")]
272274
public string PeakMax { get; internal set; }
273275
[JsonProperty("peak_max_in_bytes")]
274-
public int PeakMaxInBytes { get; internal set; }
276+
public long PeakMaxInBytes { get; internal set; }
275277
}
276278
}
277279

@@ -299,7 +301,7 @@ public class GarbageCollectorStats
299301
[JsonProperty("collection_time")]
300302
public string CollectionTime { get; internal set; }
301303
[JsonProperty("collection_time_in_millis")]
302-
public int CollectionTimeInMilliseconds { get; internal set; }
304+
public long CollectionTimeInMilliseconds { get; internal set; }
303305
}
304306

305307
[JsonObject]
@@ -322,17 +324,17 @@ public class NodeBufferPool
322324
public class ThreadCountStats
323325
{
324326
[JsonProperty("threads")]
325-
public int Threads { get; internal set; }
327+
public long Threads { get; internal set; }
326328
[JsonProperty("queue")]
327-
public int Queue { get; internal set; }
329+
public long Queue { get; internal set; }
328330
[JsonProperty("active")]
329-
public int Active { get; internal set; }
331+
public long Active { get; internal set; }
330332
[JsonProperty("rejected")]
331-
public int Rejected { get; internal set; }
333+
public long Rejected { get; internal set; }
332334
[JsonProperty("largest")]
333-
public int Largest { get; internal set; }
335+
public long Largest { get; internal set; }
334336
[JsonProperty("completed")]
335-
public int Completed { get; internal set; }
337+
public long Completed { get; internal set; }
336338
}
337339

338340
[JsonObject]
@@ -345,25 +347,25 @@ public class NetworkStats
345347
public class TCPStats
346348
{
347349
[JsonProperty("active_opens")]
348-
public int ActiveOpens { get; internal set; }
350+
public long ActiveOpens { get; internal set; }
349351
[JsonProperty("passive_opens")]
350-
public int PassiceOpens { get; internal set; }
352+
public long PassiceOpens { get; internal set; }
351353
[JsonProperty("curr_estab")]
352-
public int CurrentEstablished { get; internal set; }
354+
public long CurrentEstablished { get; internal set; }
353355
[JsonProperty("in_segs")]
354-
public int InSegments { get; internal set; }
356+
public long InSegments { get; internal set; }
355357
[JsonProperty("out_segs")]
356-
public int OutSegments { get; internal set; }
358+
public long OutSegments { get; internal set; }
357359
[JsonProperty("retrans_segs")]
358-
public int RetransmittedSegments { get; internal set; }
360+
public long RetransmittedSegments { get; internal set; }
359361
[JsonProperty("estab_resets")]
360-
public int EstablishedResets { get; internal set; }
362+
public long EstablishedResets { get; internal set; }
361363
[JsonProperty("attempt_fails")]
362-
public int AttemptFails { get; internal set; }
364+
public long AttemptFails { get; internal set; }
363365
[JsonProperty("in_errs")]
364-
public int InErrors { get; internal set; }
366+
public long InErrors { get; internal set; }
365367
[JsonProperty("out_rsts")]
366-
public int OutResets { get; internal set; }
368+
public long OutResets { get; internal set; }
367369
}
368370
}
369371

@@ -397,9 +399,9 @@ public class DatumStats
397399
[JsonProperty("available_in_bytes")]
398400
public long AvailableInBytes { get; internal set; }
399401
[JsonProperty("disk_reads")]
400-
public int DiskReads { get; internal set; }
402+
public long DiskReads { get; internal set; }
401403
[JsonProperty("disk_writes")]
402-
public int DiskWrites { get; internal set; }
404+
public long DiskWrites { get; internal set; }
403405
[JsonProperty("disk_read_size")]
404406
public string DiskReadSize { get; internal set; }
405407
[JsonProperty("disk_read_size_in_bytes")]

0 commit comments

Comments
 (0)