From d39b4c22ac5b314e22e4eab629cd3b35fb858aec Mon Sep 17 00:00:00 2001 From: Stuart Cam Date: Wed, 22 May 2019 18:37:46 +1000 Subject: [PATCH 1/2] Initial commit, extra properties and integration tests --- .../XPack/Info/XPackInfo/XPackInfoResponse.cs | 15 ++++ .../Info/XPackUsage/XPackUsageResponse.cs | 79 ++++++++++++++++++- .../Tests/XPack/Info/XPackInfoApiTests.cs | 64 +++++++++++++++ .../Tests/XPack/Info/XPackInfoUrlTests.cs | 28 +++++++ 4 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs create mode 100644 src/Tests/Tests/XPack/Info/XPackInfoUrlTests.cs diff --git a/src/Nest/XPack/Info/XPackInfo/XPackInfoResponse.cs b/src/Nest/XPack/Info/XPackInfo/XPackInfoResponse.cs index 8f63e8b811e..a8b3904abee 100644 --- a/src/Nest/XPack/Info/XPackInfo/XPackInfoResponse.cs +++ b/src/Nest/XPack/Info/XPackInfo/XPackInfoResponse.cs @@ -55,18 +55,33 @@ public class MinimalLicenseInformation public class XPackFeatures { + [JsonProperty("ccr")] + public XPackFeature Ccr { get; internal set; } + [JsonProperty("graph")] public XPackFeature Graph { get; internal set; } + [JsonProperty("ilm")] + public XPackFeature Ilm { get; internal set; } + + [JsonProperty("logstash")] + public XPackFeature Logstash { get; internal set; } + [JsonProperty("ml")] public XPackFeature MachineLearning { get; internal set; } [JsonProperty("monitoring")] public XPackFeature Monitoring { get; internal set; } + [JsonProperty("rollup")] + public XPackFeature Rollup { get; internal set; } + [JsonProperty("security")] public XPackFeature Security { get; internal set; } + [JsonProperty("sql")] + public XPackFeature Sql { get; internal set; } + [JsonProperty("watcher")] public XPackFeature Watcher { get; internal set; } } diff --git a/src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs b/src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs index 5e01c002f67..10b1b04a93a 100644 --- a/src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs +++ b/src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs @@ -5,30 +5,87 @@ namespace Nest { public interface IXPackUsageResponse : IResponse { - [JsonProperty("watcher")] - AlertingUsage Alerting { get; } + [JsonProperty("ccr")] + CcrUsage Ccr { get; } [JsonProperty("graph")] XPackUsage Graph { get; } + [JsonProperty("logstash")] + XPackUsage Logstash { get; } + [JsonProperty("ml")] MachineLearningUsage MachineLearning { get; } [JsonProperty("monitoring")] MonitoringUsage Monitoring { get; } + [JsonProperty("rollup")] + XPackUsage Rollup { get; } + [JsonProperty("security")] SecurityUsage Security { get; } + + [JsonProperty("sql")] + SqlUsage Sql { get; } + + [JsonProperty("watcher")] + AlertingUsage Alerting { get; } + } + + public class SqlUsage : XPackUsage + { + [JsonProperty("features")] + public IReadOnlyDictionary Features { get; set; } = EmptyReadOnly.Dictionary; + + [JsonProperty("queries")] + public IReadOnlyDictionary Queries { get; set; } = EmptyReadOnly.Dictionary; + } + + public class QueryUsage + { + [JsonProperty("total")] + public int Total { get; internal set; } + + [JsonProperty("paging")] + public int Paging { get; internal set; } + + [JsonProperty("failed")] + public int Failed { get; internal set; } + + [JsonProperty("count")] + public int? Count { get; internal set; } + } + + public class CcrUsage : XPackUsage + { + [JsonProperty("auto_follow_patterns_count")] + public int AutoFollowPatternsCount { get; internal set; } + + [JsonProperty("follower_indices_count")] + public int FollowerIndicesCount { get; internal set; } } public class XPackUsageResponse : ResponseBase, IXPackUsageResponse { + [JsonProperty("sql")] + public SqlUsage Sql { get; internal set; } + + [JsonProperty("rollup")] + public XPackUsage Rollup { get; internal set; } + + [JsonProperty("ccr")] + public CcrUsage Ccr { get; internal set; } + [JsonProperty("watcher")] public AlertingUsage Alerting { get; internal set; } [JsonProperty("graph")] public XPackUsage Graph { get; internal set; } + [JsonProperty("logstash")] + public XPackUsage Logstash { get; internal set; } + [JsonProperty("ml")] public MachineLearningUsage MachineLearning { get; internal set; } @@ -41,7 +98,10 @@ public class XPackUsageResponse : ResponseBase, IXPackUsageResponse public class XPackUsage { + [JsonProperty("available")] public bool Available { get; internal set; } + + [JsonProperty("enabled")] public bool Enabled { get; internal set; } } @@ -59,6 +119,9 @@ public class SecurityUsage : XPackUsage [JsonProperty("realms")] public IReadOnlyDictionary Realms { get; internal set; } = EmptyReadOnly.Dictionary; + [JsonProperty("role_mapping")] + public IReadOnlyDictionary RoleMapping { get; internal set; } = EmptyReadOnly.Dictionary; + [JsonProperty("roles")] public IReadOnlyDictionary Roles { get; internal set; } = EmptyReadOnly.Dictionary; @@ -68,6 +131,15 @@ public class SecurityUsage : XPackUsage [JsonProperty("system_key")] public SecurityFeatureToggle SystemKey { get; internal set; } + public class RoleMappingUsage + { + [JsonProperty("enabled")] + public int Enabled { get; internal set; } + + [JsonProperty("size")] + public int Size { get; internal set; } + } + public class AuditUsage : SecurityFeatureToggle { [JsonProperty("outputs")] @@ -158,6 +230,9 @@ public class AlertingCount public class MonitoringUsage : XPackUsage { + [JsonProperty("collection_enabled")] + public bool CollectionEnabled { get; internal set; } + [JsonProperty("enabled_exporters")] public IReadOnlyDictionary EnabledExporters { get; set; } = EmptyReadOnly.Dictionary; } diff --git a/src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs b/src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs new file mode 100644 index 00000000000..2cf943a4492 --- /dev/null +++ b/src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs @@ -0,0 +1,64 @@ +using System.Threading.Tasks; +using Elastic.Xunit.XunitPlumbing; +using FluentAssertions; +using Nest; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Framework; +using Tests.Framework.EndpointTests.TestState; +using Tests.Framework.Integration; + +namespace Tests.XPack.Info +{ + [SkipVersion("<6.8.0", "All APIs exist in Elasticsearch 6.8.0")] + public class XPackInfoApiTests : CoordinatedIntegrationTestBase + { + private const string XPackInfoStep = nameof(XPackInfoStep); + private const string XPackUsageStep = nameof(XPackUsageStep); + + public XPackInfoApiTests(XPackCluster cluster, EndpointUsage usage) : base(new CoordinatedUsage(cluster, usage) + { + { + XPackInfoStep, u => u.Calls( + v => new XPackInfoRequest(), + (v, d) => d, + (v, c, f) => c.XPackInfo(f), + (v, c, f) => c.XPackInfoAsync(f), + (v, c, r) => c.XPackInfo(r), + (v, c, r) => c.XPackInfoAsync(r) + ) + }, + { + XPackUsageStep, u => u.Calls( + v => new XPackUsageRequest(), + (v, d) => d, + (v, c, f) => c.XPackUsage(f), + (v, c, f) => c.XPackUsageAsync(f), + (v, c, r) => c.XPackUsage(r), + (v, c, r) => c.XPackUsageAsync(r) + ) + }, + }) { } + + [I] public async Task XPackInfoResponse() => await Assert(XPackInfoStep, (v, r) => + { + r.IsValid.Should().BeTrue(); + r.ApiCall.HttpStatusCode.Should().Be(200); + }); + + [I] public async Task XPackUsageResponse() => await Assert(XPackUsageStep, (v, r) => + { + r.IsValid.Should().BeTrue(); + r.ApiCall.HttpStatusCode.Should().Be(200); + + r.Ccr.Should().NotBeNull(); + r.Graph.Should().NotBeNull(); + r.Logstash.Should().NotBeNull(); + r.MachineLearning.Should().NotBeNull(); + r.Monitoring.Should().NotBeNull(); + r.Rollup.Should().NotBeNull(); + r.Security.Should().NotBeNull(); + r.Sql.Should().NotBeNull(); + r.Alerting.Should().NotBeNull(); + }); + } +} diff --git a/src/Tests/Tests/XPack/Info/XPackInfoUrlTests.cs b/src/Tests/Tests/XPack/Info/XPackInfoUrlTests.cs new file mode 100644 index 00000000000..296d3c36930 --- /dev/null +++ b/src/Tests/Tests/XPack/Info/XPackInfoUrlTests.cs @@ -0,0 +1,28 @@ +using System.Threading.Tasks; +using Elastic.Xunit.XunitPlumbing; +using Nest; +using Tests.Framework; +using static Tests.Framework.UrlTester; + +namespace Tests.XPack.Info +{ + public class XPackInfoUrlTests : UrlTestsBase + { + [U] public override async Task Urls() + { + await GET("/_xpack") + .Fluent(c => c.XPackInfo()) + .Request(c => c.XPackInfo()) + .FluentAsync(c => c.XPackInfoAsync()) + .RequestAsync(c => c.XPackInfoAsync()) + ; + + await GET("/_xpack/usage") + .Fluent(c => c.XPackUsage()) + .Request(c => c.XPackUsage()) + .FluentAsync(c => c.XPackUsageAsync()) + .RequestAsync(c => c.XPackUsageAsync()) + ; + } + } +} From 9d4089358d23b4abba2a9aedc2a52673a646f179 Mon Sep 17 00:00:00 2001 From: Stuart Cam Date: Thu, 23 May 2019 12:18:47 +1000 Subject: [PATCH 2/2] Improve response format and complete integration test assertions --- .../Info/XPackUsage/XPackUsageResponse.cs | 12 ++++++++ .../Tests/XPack/Info/XPackInfoApiTests.cs | 28 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs b/src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs index 10b1b04a93a..e216b0da554 100644 --- a/src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs +++ b/src/Nest/XPack/Info/XPackUsage/XPackUsageResponse.cs @@ -203,12 +203,24 @@ public class AlertingUsage : XPackUsage [JsonProperty("execution")] public AlertingExecution Execution { get; internal set; } + [JsonProperty("watch")] + public AlertingInput Watch { get; internal set; } + public class AlertingExecution { [JsonProperty("actions")] public IReadOnlyDictionary Actions { get; internal set; } = EmptyReadOnly.Dictionary; } + public class AlertingInput + { + [JsonProperty("input")] + public IReadOnlyDictionary Input { get; internal set; } = EmptyReadOnly.Dictionary; + + [JsonProperty("trigger")] + public IReadOnlyDictionary Trigger { get; internal set; } = EmptyReadOnly.Dictionary; + } + public class ExecutionAction { [JsonProperty("total")] diff --git a/src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs b/src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs index 2cf943a4492..3a1503016f0 100644 --- a/src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs +++ b/src/Tests/Tests/XPack/Info/XPackInfoApiTests.cs @@ -36,13 +36,28 @@ public XPackInfoApiTests(XPackCluster cluster, EndpointUsage usage) : base(new C (v, c, r) => c.XPackUsage(r), (v, c, r) => c.XPackUsageAsync(r) ) - }, + } }) { } [I] public async Task XPackInfoResponse() => await Assert(XPackInfoStep, (v, r) => { r.IsValid.Should().BeTrue(); r.ApiCall.HttpStatusCode.Should().Be(200); + + r.Build.Should().NotBeNull(); + r.Features.Should().NotBeNull(); + r.Features.Ccr.Should().NotBeNull(); + r.Features.Graph.Should().NotBeNull(); + r.Features.Ilm.Should().NotBeNull(); + r.Features.Logstash.Should().NotBeNull(); + r.Features.MachineLearning.Should().NotBeNull(); + r.Features.MachineLearning.NativeCodeInformation.Should().NotBeNull(); + r.Features.Monitoring.Should().NotBeNull(); + r.Features.Rollup.Should().NotBeNull(); + r.Features.Security.Should().NotBeNull(); + r.Features.Sql.Should().NotBeNull(); + r.Features.Watcher.Should().NotBeNull(); + r.License.Should().NotBeNull(); }); [I] public async Task XPackUsageResponse() => await Assert(XPackUsageStep, (v, r) => @@ -54,11 +69,22 @@ [I] public async Task XPackUsageResponse() => await Assert(X r.Graph.Should().NotBeNull(); r.Logstash.Should().NotBeNull(); r.MachineLearning.Should().NotBeNull(); + r.MachineLearning.Datafeeds.Should().NotBeNull(); + r.MachineLearning.Jobs.Should().NotBeNull(); r.Monitoring.Should().NotBeNull(); + r.Monitoring.EnabledExporters.Should().NotBeNull(); r.Rollup.Should().NotBeNull(); r.Security.Should().NotBeNull(); + r.Security.Roles.Should().NotBeNull(); + r.Security.Realms.Should().NotBeNull(); + r.Security.RoleMapping.Should().NotBeNull(); r.Sql.Should().NotBeNull(); + r.Sql.Features.Should().NotBeNull(); + r.Sql.Queries.Should().NotBeNull(); r.Alerting.Should().NotBeNull(); + r.Alerting.Count.Should().NotBeNull(); + r.Alerting.Execution.Should().NotBeNull(); + r.Alerting.Watch.Should().NotBeNull(); }); } }