From fbfe58c749696b0eb54d7ade84f9eaf7627e533d Mon Sep 17 00:00:00 2001 From: Tim Vernum Date: Mon, 13 Jan 2020 16:28:14 +1100 Subject: [PATCH] Update validation messages --- .../src/main/java/org/elasticsearch/license/License.java | 7 ++++--- .../test/java/org/elasticsearch/license/LicenseTests.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/License.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/License.java index 9b88b81325b85..210beaaedecaf 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/License.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/License.java @@ -422,15 +422,16 @@ private void validate() { private static void validateLimits(String type, int maxNodes, int maxResourceUnits) { if (LicenseType.isEnterprise(type)) { if (maxResourceUnits == -1) { - throw new IllegalStateException("maxResourceUnits must be set for enterprise licenses"); + throw new IllegalStateException("maxResourceUnits must be set for enterprise licenses (type=[" + type + "])"); } else if (maxNodes != -1) { - throw new IllegalStateException("maxNodes may not be set for enterprise licenses"); + throw new IllegalStateException("maxNodes may not be set for enterprise licenses (type=[" + type + "])"); } } else { if (maxNodes == -1) { throw new IllegalStateException("maxNodes has to be set"); } else if (maxResourceUnits != -1) { - throw new IllegalStateException("maxResourceUnits may only be set for enterprise licenses"); + throw new IllegalStateException("maxResourceUnits may only be set for enterprise licenses (not permitted for type=[" + + type + "])"); } } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseTests.java index e1eb1d76bdad9..05f54383eedd3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseTests.java @@ -121,14 +121,14 @@ public void testThatEnterpriseLicenseMayNotHaveMaxNodes() throws Exception { .maxNodes(randomIntBetween(1, 50)) .maxResourceUnits(randomIntBetween(10, 500)); final IllegalStateException ex = expectThrows(IllegalStateException.class, builder::build); - assertThat(ex, TestMatchers.throwableWithMessage("maxNodes may not be set for enterprise licenses")); + assertThat(ex, TestMatchers.throwableWithMessage("maxNodes may not be set for enterprise licenses (type=[enterprise])")); } public void testThatEnterpriseLicenseMustHaveMaxResourceUnits() throws Exception { License.Builder builder = randomLicense(License.LicenseType.ENTERPRISE) .maxResourceUnits(-1); final IllegalStateException ex = expectThrows(IllegalStateException.class, builder::build); - assertThat(ex, TestMatchers.throwableWithMessage("maxResourceUnits must be set for enterprise licenses")); + assertThat(ex, TestMatchers.throwableWithMessage("maxResourceUnits must be set for enterprise licenses (type=[enterprise])")); } public void testThatRegularLicensesMustHaveMaxNodes() throws Exception { @@ -145,7 +145,8 @@ public void testThatRegularLicensesMayNotHaveMaxResourceUnits() throws Exception .maxResourceUnits(randomIntBetween(10, 500)) .maxNodes(randomIntBetween(1, 50)); final IllegalStateException ex = expectThrows(IllegalStateException.class, builder::build); - assertThat(ex, TestMatchers.throwableWithMessage("maxResourceUnits may only be set for enterprise licenses")); + assertThat(ex, TestMatchers.throwableWithMessage("maxResourceUnits may only be set for enterprise licenses (not permitted " + + "for type=[" + type.getTypeName() + "])")); } public void testLicenseToAndFromXContentForEveryLicenseType() throws Exception {