diff --git a/src/Nest.Tests.Integration/Cluster/StateTests.cs b/src/Nest.Tests.Integration/Cluster/StateTests.cs new file mode 100644 index 00000000000..87d241b3ed1 --- /dev/null +++ b/src/Nest.Tests.Integration/Cluster/StateTests.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using NUnit.Framework; + +namespace Nest.Tests.Integration.Cluster +{ + [TestFixture] + public class StateTests : IntegrationTests + { + [Test] + public void SimpleState() + { + var r = this._client.ClusterState(ClusterStateInfo.All); + Assert.True(r.IsValid); + Assert.NotNull(r.ClusterName); + Assert.NotNull(r.MasterNode); + Assert.NotNull(r.Metadata); + Assert.NotNull(r.Metadata.Indices); + Assert.True(r.Metadata.Indices.Count > 0); + Assert.NotNull(r.Nodes); + Assert.True(r.Nodes.Count > 0); + Assert.NotNull(r.RoutingNodes); + Assert.True(r.RoutingNodes.Nodes.Count > 0); + Assert.NotNull(r.RoutingTable); + } + [Test] + public void StateWithoutMetadata() + { + var r = this._client.ClusterState(ClusterStateInfo.ExcludeMetadata); + Assert.IsNull(r.Metadata); + } + [Test] + public void StateWithoutNodes() + { + var r = this._client.ClusterState(ClusterStateInfo.ExcludeNodes); + Assert.IsNull(r.Nodes); + } + [Test] + public void StateWithoutRoutingTable() + { + var r = this._client.ClusterState(ClusterStateInfo.ExcludeRoutingTable); + Assert.IsNull(r.RoutingTable); + } + //[Test] + //public void StateWithoutBlocks() + //{ + // var r = this._client.ClusterState(ClusterStateInfo.ExcludeRoutingTable); + // Assert.IsNull(r.Blocks); + //} + } +} \ No newline at end of file diff --git a/src/Nest.Tests.Integration/Nest.Tests.Integration.csproj b/src/Nest.Tests.Integration/Nest.Tests.Integration.csproj index 68b5ca07f78..1438ce17d2e 100644 --- a/src/Nest.Tests.Integration/Nest.Tests.Integration.csproj +++ b/src/Nest.Tests.Integration/Nest.Tests.Integration.csproj @@ -64,6 +64,7 @@ + diff --git a/src/Nest/Domain/Responses/ClusterStateResponse.cs b/src/Nest/Domain/Responses/ClusterStateResponse.cs new file mode 100644 index 00000000000..11595394fd9 --- /dev/null +++ b/src/Nest/Domain/Responses/ClusterStateResponse.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Nest +{ + public interface IClusterStateResponse : IResponse + { + string ClusterName { get; } + string MasterNode { get; } + Dictionary Nodes { get; } + MetadataState Metadata { get; } + RoutingTableState RoutingTable { get; } + RoutingNodesState RoutingNodes { get; } + } + + [JsonObject] + public class ClusterStateResponse : BaseResponse, IClusterStateResponse + { + public ClusterStateResponse() + { + this.IsValid = true; + } + [JsonProperty("cluster_name")] + public string ClusterName { get; internal set; } + [JsonProperty("master_node")] + public string MasterNode { get; internal set; } + + [JsonProperty("nodes")] + public Dictionary Nodes { get; internal set; } + + [JsonProperty("metadata")] + public MetadataState Metadata { get; internal set; } + + [JsonProperty("routing_table")] + public RoutingTableState RoutingTable { get; internal set; } + + [JsonProperty("routing_nodes")] + public RoutingNodesState RoutingNodes { get; internal set; } + } +} diff --git a/src/Nest/Domain/State/ClusterState.cs b/src/Nest/Domain/State/ClusterState.cs new file mode 100644 index 00000000000..9fb5e97b136 --- /dev/null +++ b/src/Nest/Domain/State/ClusterState.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + public class NodeState + { + [JsonProperty("name")] + public string Name { get; internal set; } + + [JsonProperty("transport_address")] + public string TransportAddress { get; internal set; } + + [JsonProperty("attributes")] + public Dictionary Attributes { get; internal set; } + } + + public class RoutingTableState + { + [JsonProperty("indices")] + public Dictionary Indices { get; internal set; } + } + + public class IndexRoutingTable + { + [JsonProperty("shards")] + public Dictionary> Shards { get; internal set; } + } + + public class RoutingShard + { + [JsonProperty("state")] + public string State { get; internal set; } + + [JsonProperty("primary")] + public bool Primary { get; internal set; } + + [JsonProperty("node")] + public string Node { get; internal set; } + + [JsonProperty("relocating_node")] + public string RelocatingNode { get; internal set; } + + [JsonProperty("shard")] + public int Shard { get; internal set; } + + [JsonProperty("index")] + public string Index { get; internal set; } + } + + public class RoutingNodesState + { + [JsonProperty("unassigned")] + public List Unassigned { get; internal set; } + + [JsonProperty("nodes")] + public Dictionary> Nodes { get; internal set; } + } + + public class MetadataState + { + //[JsonProperty("templates")] + //public ?? Templates { get; internal set; } + + [JsonProperty("indices")] + public Dictionary Indices { get; internal set; } + } + + public class MetadataIndexState + { + [JsonProperty("state")] + public string State { get; internal set; } + + [JsonProperty("settings")] + public Dictionary Settings { get; internal set; } + + //[JsonProperty("mappings")] + //public Dictionary Mappings { get; internal set; } + + //[JsonProperty("aliases")] + //public ?? Aliases { get; internal set; } + } +} diff --git a/src/Nest/Domain/Stats/NodeStats.cs b/src/Nest/Domain/Stats/NodeStats.cs index 2e87abcd395..5c4aa62d6a2 100644 --- a/src/Nest/Domain/Stats/NodeStats.cs +++ b/src/Nest/Domain/Stats/NodeStats.cs @@ -74,34 +74,34 @@ public class IndexStoreStats : StoreStats [JsonProperty("throttle_time")] public string ThrottleTime { get; internal set; } [JsonProperty("throttle_time_in_millis")] - public int ThrottleTimeInMilliseconds { get; internal set; } + public long ThrottleTimeInMilliseconds { get; internal set; } } [JsonObject] public class IndexCacheStats { [JsonProperty(PropertyName = "field_evictions")] - public int FieldEvictions { get; internal set; } + public long FieldEvictions { get; internal set; } [JsonProperty(PropertyName = "field_size")] public string FieldSize { get; internal set; } [JsonProperty(PropertyName = "field_size_in_bytes")] - public int FieldSizeInBytes { get; internal set; } + public long FieldSizeInBytes { get; internal set; } [JsonProperty(PropertyName = "filter_count")] - public int FilterCount { get; internal set; } + public long FilterCount { get; internal set; } [JsonProperty(PropertyName = "filter_evictions")] - public int FilterEvictions { get; internal set; } + public long FilterEvictions { get; internal set; } [JsonProperty(PropertyName = "filter_size")] public string FilterSize { get; internal set; } [JsonProperty(PropertyName = "filter_size_in_bytes")] - public int FilterSizeInBytes { get; internal set; } + public long FilterSizeInBytes { get; internal set; } [JsonProperty(PropertyName = "bloom_size")] public string BloomSize { get; internal set; } [JsonProperty(PropertyName = "bloom_size_in_bytes")] - public int BloomSizeInBytes { get; internal set; } + public long BloomSizeInBytes { get; internal set; } [JsonProperty(PropertyName = "id_cache_size")] public string IDCacheSize { get; internal set; } [JsonProperty(PropertyName = "id_cache_size_in_bytes")] - public int IDCacheSizeInBytes { get; internal set; } + public long IDCacheSizeInBytes { get; internal set; } } } @@ -114,6 +114,8 @@ public class UptimeStats public string Uptime { get; internal set; } [JsonProperty("uptime_in_millis")] public long UptimeInMilliseconds { get; internal set; } + [JsonProperty("load_average")] + public float[] LoadAverage { get; internal set; } } [JsonObject] @@ -190,15 +192,15 @@ public class CPUStats [JsonProperty("sys")] public string System { get; internal set; } [JsonProperty("sys_in_millis")] - public int SystemInMilliseconds { get; internal set; } + public long SystemInMilliseconds { get; internal set; } [JsonProperty("user")] public string User { get; internal set; } [JsonProperty("user_in_millis")] - public int UserInMilliseconds { get; internal set; } + public long UserInMilliseconds { get; internal set; } [JsonProperty("total")] public string Total { get; internal set; } [JsonProperty("total_in_millis")] - public int TotalInMilliseconds { get; internal set; } + public long TotalInMilliseconds { get; internal set; } } [JsonObject] @@ -207,11 +209,11 @@ public class MemoryStats [JsonProperty("resident")] public string Resident { get; internal set; } [JsonProperty("resident_in_bytes")] - public int ResidentInBytes { get; internal set; } + public long ResidentInBytes { get; internal set; } [JsonProperty("share")] public string Share { get; internal set; } [JsonProperty("share_in_bytes")] - public int ShareInBytes { get; internal set; } + public long ShareInBytes { get; internal set; } [JsonProperty("total_virtual")] public string TotalVirtual { get; internal set; } [JsonProperty("total_virtual_in_bytes")] @@ -259,19 +261,19 @@ public class JVMPool [JsonProperty("used")] public string Used { get; internal set; } [JsonProperty("")] - public int UsedInBytes { get; internal set; } + public long UsedInBytes { get; internal set; } [JsonProperty("max")] public string Max { get; internal set; } [JsonProperty("max_in_bytes")] - public int MaxInBytes { get; internal set; } + public long MaxInBytes { get; internal set; } [JsonProperty("peak_used")] public string PeakUsed { get; internal set; } [JsonProperty("peak_used_in_bytes")] - public int PeakUsedInBytes { get; internal set; } + public long PeakUsedInBytes { get; internal set; } [JsonProperty("peak_max")] public string PeakMax { get; internal set; } [JsonProperty("peak_max_in_bytes")] - public int PeakMaxInBytes { get; internal set; } + public long PeakMaxInBytes { get; internal set; } } } @@ -299,7 +301,7 @@ public class GarbageCollectorStats [JsonProperty("collection_time")] public string CollectionTime { get; internal set; } [JsonProperty("collection_time_in_millis")] - public int CollectionTimeInMilliseconds { get; internal set; } + public long CollectionTimeInMilliseconds { get; internal set; } } [JsonObject] @@ -322,17 +324,17 @@ public class NodeBufferPool public class ThreadCountStats { [JsonProperty("threads")] - public int Threads { get; internal set; } + public long Threads { get; internal set; } [JsonProperty("queue")] - public int Queue { get; internal set; } + public long Queue { get; internal set; } [JsonProperty("active")] - public int Active { get; internal set; } + public long Active { get; internal set; } [JsonProperty("rejected")] - public int Rejected { get; internal set; } + public long Rejected { get; internal set; } [JsonProperty("largest")] - public int Largest { get; internal set; } + public long Largest { get; internal set; } [JsonProperty("completed")] - public int Completed { get; internal set; } + public long Completed { get; internal set; } } [JsonObject] @@ -345,25 +347,25 @@ public class NetworkStats public class TCPStats { [JsonProperty("active_opens")] - public int ActiveOpens { get; internal set; } + public long ActiveOpens { get; internal set; } [JsonProperty("passive_opens")] - public int PassiceOpens { get; internal set; } + public long PassiceOpens { get; internal set; } [JsonProperty("curr_estab")] - public int CurrentEstablished { get; internal set; } + public long CurrentEstablished { get; internal set; } [JsonProperty("in_segs")] - public int InSegments { get; internal set; } + public long InSegments { get; internal set; } [JsonProperty("out_segs")] - public int OutSegments { get; internal set; } + public long OutSegments { get; internal set; } [JsonProperty("retrans_segs")] - public int RetransmittedSegments { get; internal set; } + public long RetransmittedSegments { get; internal set; } [JsonProperty("estab_resets")] - public int EstablishedResets { get; internal set; } + public long EstablishedResets { get; internal set; } [JsonProperty("attempt_fails")] - public int AttemptFails { get; internal set; } + public long AttemptFails { get; internal set; } [JsonProperty("in_errs")] - public int InErrors { get; internal set; } + public long InErrors { get; internal set; } [JsonProperty("out_rsts")] - public int OutResets { get; internal set; } + public long OutResets { get; internal set; } } } @@ -397,9 +399,9 @@ public class DatumStats [JsonProperty("available_in_bytes")] public long AvailableInBytes { get; internal set; } [JsonProperty("disk_reads")] - public int DiskReads { get; internal set; } + public long DiskReads { get; internal set; } [JsonProperty("disk_writes")] - public int DiskWrites { get; internal set; } + public long DiskWrites { get; internal set; } [JsonProperty("disk_read_size")] public string DiskReadSize { get; internal set; } [JsonProperty("disk_read_size_in_bytes")] diff --git a/src/Nest/ElasticClient-State.cs b/src/Nest/ElasticClient-State.cs new file mode 100644 index 00000000000..de4b66855f5 --- /dev/null +++ b/src/Nest/ElasticClient-State.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; + +namespace Nest +{ + public partial class ElasticClient + { + /// + /// Gets the health status of the cluster. + /// + public IClusterStateResponse ClusterState(ClusterStateInfo stateInfo, IEnumerable indices = null) + { + var path = this.PathResolver.CreateClusterPath("state"); + + var options = new List(); + if (indices != null && indices.HasAny() && (!stateInfo.HasFlag(ClusterStateInfo.ExcludeMetadata))) + { + options.Add("filter_indices=" + string.Join(",", indices)); + } + + + if (stateInfo.HasFlag(ClusterStateInfo.ExcludeNodes)) + options.Add("filter_nodes=true"); + if (stateInfo.HasFlag(ClusterStateInfo.ExcludeRoutingTable)) + options.Add("filter_routing_table=true"); + if (stateInfo.HasFlag(ClusterStateInfo.ExcludeMetadata)) + options.Add("filter_metadata=true"); + if (stateInfo.HasFlag(ClusterStateInfo.ExcludeBlocks)) + options.Add("filter_blocks=true"); + + path += "?" + string.Join("&", options); + + var status = this.Connection.GetSync(path); + var r = this.ToParsedResponse(status); + return r; + } + } +} diff --git a/src/Nest/Enums/ClusterStateInfo.cs b/src/Nest/Enums/ClusterStateInfo.cs new file mode 100644 index 00000000000..2affdec576e --- /dev/null +++ b/src/Nest/Enums/ClusterStateInfo.cs @@ -0,0 +1,14 @@ +using System; + +namespace Nest +{ + [Flags] + public enum ClusterStateInfo + { + All = 0, + ExcludeNodes = 1 << 1, + ExcludeRoutingTable = 1 << 2, + ExcludeMetadata = 1 << 3, + ExcludeBlocks = 1 << 4 + } +} diff --git a/src/Nest/IElasticClient.cs b/src/Nest/IElasticClient.cs index 94bbcce211e..53558824c50 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -317,6 +317,7 @@ Task RegisterPercolatorAsync( IIndicesShardResponse Snapshot(IEnumerable indices); IIndicesShardResponse Snapshot(string index); IIndicesShardResponse Snapshot() where T : class; + IClusterStateResponse ClusterState(ClusterStateInfo stateInfo, IEnumerable indices = null); IGlobalStatsResponse Stats(); IGlobalStatsResponse Stats(StatsParams parameters); IStatsResponse Stats(IEnumerable indices); diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index c3f92a419d5..1b3397480fa 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -69,6 +69,8 @@ + + @@ -79,6 +81,8 @@ + +