From 86ed96b83be7c043c204db95e4b8c0ad1814990e Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Mon, 28 Mar 2016 00:36:37 -0400 Subject: [PATCH] Adding support for STANDARD license Original commit: elastic/x-pack-elasticsearch@1671d8ade36aae48d730ed03c411a0174a25e9d6 --- .../org/elasticsearch/license/core/License.java | 3 +++ .../license/core/LicenseOperationModeTests.java | 8 ++++++-- .../elasticsearch/license/plugin/core/Licensee.java | 3 ++- .../elasticsearch/graph/license/GraphLicensee.java | 1 + .../plugin/core/AbstractLicenseeTestCase.java | 7 ++++--- .../marvel/license/MarvelLicensee.java | 9 +++------ .../marvel/license/MarvelLicenseeTests.java | 3 +-- .../shield/license/ShieldLicensee.java | 13 ++++++++----- .../shield/license/ShieldLicenseeTests.java | 8 ++++---- .../watcher/license/WatcherLicensee.java | 7 +++---- .../elasticsearch/watcher/license/LicenseTests.java | 12 ++++++------ 11 files changed, 41 insertions(+), 33 deletions(-) diff --git a/elasticsearch/license/base/src/main/java/org/elasticsearch/license/core/License.java b/elasticsearch/license/base/src/main/java/org/elasticsearch/license/core/License.java index 97f0a3a23b2..1b37a55166c 100644 --- a/elasticsearch/license/base/src/main/java/org/elasticsearch/license/core/License.java +++ b/elasticsearch/license/base/src/main/java/org/elasticsearch/license/core/License.java @@ -80,6 +80,7 @@ public class License implements ToXContent { public enum OperationMode { TRIAL, BASIC, + STANDARD, GOLD, PLATINUM; @@ -92,6 +93,8 @@ public class License implements ToXContent { return TRIAL; case "basic": return BASIC; + case "standard": + return STANDARD; case "silver": case "gold": return GOLD; diff --git a/elasticsearch/license/base/src/test/java/org/elasticsearch/license/core/LicenseOperationModeTests.java b/elasticsearch/license/base/src/test/java/org/elasticsearch/license/core/LicenseOperationModeTests.java index 9eaf477169a..12022a712cb 100644 --- a/elasticsearch/license/base/src/test/java/org/elasticsearch/license/core/LicenseOperationModeTests.java +++ b/elasticsearch/license/base/src/test/java/org/elasticsearch/license/core/LicenseOperationModeTests.java @@ -28,6 +28,11 @@ public class LicenseOperationModeTests extends ESTestCase { assertResolve(OperationMode.BASIC, "bAsIc", "basic"); } + public void testResolveStandard() { + // assert expected (2.x+) variant (note: no 1.x variant of STANDARD) + assertResolve(OperationMode.STANDARD, "StAnDARd", "standard"); + } + public void testResolveGold() { // assert expected (2.x+) variant (note: no different 1.x variant of GOLD) assertResolve(OperationMode.GOLD, "SiLvEr", "gOlD", "silver", "gold"); @@ -41,8 +46,7 @@ public class LicenseOperationModeTests extends ESTestCase { } public void testResolveUnknown() { - // standard will hopefully trip the upcoming standard license to add the test here for FWC - String[] types = { "standard", "unknown", "fake" }; + String[] types = { "unknown", "fake" }; for (String type : types) { try { diff --git a/elasticsearch/license/plugin-api/src/main/java/org/elasticsearch/license/plugin/core/Licensee.java b/elasticsearch/license/plugin-api/src/main/java/org/elasticsearch/license/plugin/core/Licensee.java index 27432b4ce8c..3e32e0aa5e8 100644 --- a/elasticsearch/license/plugin-api/src/main/java/org/elasticsearch/license/plugin/core/Licensee.java +++ b/elasticsearch/license/plugin-api/src/main/java/org/elasticsearch/license/plugin/core/Licensee.java @@ -45,7 +45,8 @@ public interface Licensee { * whenever checking different parts of the {@code Status}: *
      * Status status = this.status;
-     * return status.getLicenseState().isActive() && status.getMode().isPaid();
+     * return status.getLicenseState() != LicenseState.DISABLED &&
+     *        (status.getMode() == OperationMode.TRAIL || status.getMode == OperationMode.PLATINUM);
      * 
* Otherwise the license has the potential to change in-between both checks. */ diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphLicensee.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphLicensee.java index 5b6e66ec8e8..9848e4679b0 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphLicensee.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/graph/license/GraphLicensee.java @@ -35,6 +35,7 @@ public class GraphLicensee extends AbstractLicenseeComponent { public String[] acknowledgmentMessages(License currentLicense, License newLicense) { switch (newLicense.operationMode()) { case BASIC: + case STANDARD: case GOLD: if (currentLicense != null) { switch (currentLicense.operationMode()) { diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java index 1a8eedd98c4..8e7a247c0fe 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java @@ -107,12 +107,13 @@ public abstract class AbstractLicenseeTestCase extends ESTestCase { } /** - * Randomly get {@link OperationMode#TRIAL}, {@link OperationMode#GOLD}, or {@link OperationMode#PLATINUM}. + * Randomly get {@link OperationMode#TRIAL}, {@link OperationMode#STANDARD}, {@link OperationMode#GOLD}, or + * {@link OperationMode#PLATINUM}. * * @return Never {@code null}. */ - public static OperationMode randomTrialGoldOrPlatinumMode() { - return randomFrom(OperationMode.TRIAL, OperationMode.GOLD, OperationMode.PLATINUM); + public static OperationMode randomTrialStandardGoldOrPlatinumMode() { + return randomFrom(OperationMode.TRIAL, OperationMode.STANDARD, OperationMode.GOLD, OperationMode.PLATINUM); } /** diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/MarvelLicensee.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/MarvelLicensee.java index d435366320f..36bea73ef90 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/MarvelLicensee.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/license/MarvelLicensee.java @@ -54,6 +54,7 @@ public class MarvelLicensee extends AbstractLicenseeComponent im if (currentLicense != null) { switch (currentLicense.operationMode()) { case TRIAL: + case STANDARD: case GOLD: case PLATINUM: return new String[] { @@ -101,12 +102,8 @@ public class MarvelLicensee extends AbstractLicenseeComponent im /** * Determine if the current license allows the retention of indices to be modified. *

- * Only users with the following license types can update the retention period: - *

    - *
  • {@link OperationMode#PLATINUM}
  • - *
  • {@link OperationMode#GOLD}
  • - *
  • {@link OperationMode#TRIAL}
  • - *
+ * Only users with a non-{@link OperationMode#BASIC} license can update the retention period. + *

* Note: This does not consider the state of the license so that any change is remembered for when they fix their license. * * @return {@code true} if the user is allowed to modify the retention. Otherwise {@code false}. diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java index ea7754bebe0..6462e003259 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/MarvelLicenseeTests.java @@ -6,7 +6,6 @@ package org.elasticsearch.marvel.license; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase; import org.elasticsearch.license.plugin.core.LicenseState; @@ -35,7 +34,7 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase { } public void testAcknowledgementMessagesToTrialGoldOrPlatinumFromAnyIsNoOp() { - assertEmptyAck(randomMode(), randomTrialGoldOrPlatinumMode(), licensee); + assertEmptyAck(randomMode(), randomTrialStandardGoldOrPlatinumMode(), licensee); } public void testAcknowledgementMessagesToBasicFromNotBasicNotesLimits() { diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java index 7befc95f4c6..0592a0273dc 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java @@ -51,27 +51,30 @@ public class ShieldLicensee extends AbstractLicenseeComponent im if (currentLicense != null) { switch (currentLicense.operationMode()) { case TRIAL: + case STANDARD: case GOLD: case PLATINUM: - return new String[] { + return new String[] { "The following Shield functionality will be disabled: authentication, authorization, ip filtering, " + "auditing, SSL will be disabled on node restart. Please restart your node after applying the license.", "Field and document level access control will be disabled", "Custom realms will be ignored" - }; + }; } } break; case GOLD: if (currentLicense != null) { switch (currentLicense.operationMode()) { - case BASIC: // though technically it was already disabled, it's not bad to remind them + case BASIC: + case STANDARD: + // ^^ though technically it was already disabled, it's not bad to remind them case TRIAL: case PLATINUM: return new String[] { "Field and document level access control will be disabled", "Custom realms will be ignored" - }; + }; } } break; @@ -84,7 +87,7 @@ public class ShieldLicensee extends AbstractLicenseeComponent im // we rely on the initial licensee state to be enabled with trial operation mode // to ensure no operation is blocked due to not registering the licensee on a // tribe node - if (!isTribeNode) { + if (isTribeNode == false) { super.doStart(); } } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java index bf22fea70a1..f8f3b2f4724 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/license/ShieldLicenseeTests.java @@ -66,15 +66,15 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase { assertEmptyAck(randomMode(), randomTrialOrPlatinumMode(), this::buildLicensee); } - public void testAcknowledgementMessagesFromTrialGoldOrPlatinumToBasicNotesLimits() { - String[] messages = ackLicenseChange(randomTrialGoldOrPlatinumMode(), OperationMode.BASIC, this::buildLicensee); + public void testAcknowledgementMessagesFromTrialStandardGoldOrPlatinumToBasicNotesLimits() { + String[] messages = ackLicenseChange(randomTrialStandardGoldOrPlatinumMode(), OperationMode.BASIC, this::buildLicensee); // leaving messages up to inspection assertThat(messages.length, equalTo(3)); } - public void testAcknowledgementMessagesFromTrialOrPlatinumToGoldNotesLimits() { - String[] messages = ackLicenseChange(randomTrialOrPlatinumMode(), OperationMode.GOLD, this::buildLicensee); + public void testAcknowledgementMessagesFromBasicStandardTrialOrPlatinumToGoldNotesLimits() { + String[] messages = ackLicenseChange(randomModeExcept(OperationMode.GOLD), OperationMode.GOLD, this::buildLicensee); // leaving messages up to inspection assertThat(messages.length, equalTo(2)); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/WatcherLicensee.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/WatcherLicensee.java index 2e4569183dc..c936d7ddc3d 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/WatcherLicensee.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/watcher/license/WatcherLicensee.java @@ -44,6 +44,7 @@ public class WatcherLicensee extends AbstractLicenseeComponent if (currentLicense != null) { switch (currentLicense.operationMode()) { case TRIAL: + case STANDARD: case GOLD: case PLATINUM: return new String[] { "Watcher will be disabled" }; @@ -73,6 +74,7 @@ public class WatcherLicensee extends AbstractLicenseeComponent *

    *
  • {@link OperationMode#PLATINUM}
  • *
  • {@link OperationMode#GOLD}
  • + *
  • {@link OperationMode#STANDARD}
  • *
  • {@link OperationMode#TRIAL}
  • *
* @@ -82,9 +84,6 @@ public class WatcherLicensee extends AbstractLicenseeComponent // status is volatile, so a local variable is used for a consistent view Status localStatus = status; - OperationMode operationMode = localStatus.getMode(); - boolean licensed = operationMode == TRIAL || operationMode == GOLD || operationMode == PLATINUM; - - return licensed && localStatus.getLicenseState() != LicenseState.DISABLED; + return localStatus.getLicenseState() != LicenseState.DISABLED && localStatus.getMode() != OperationMode.BASIC; } } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java index 742d8454915..c47a8ac4457 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java @@ -16,7 +16,7 @@ public class LicenseTests extends AbstractLicenseeTestCase { private SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry(); public void testPlatinumGoldTrialLicenseCanDoEverything() throws Exception { - licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); + licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode()); WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); licenseeRegistry.register(watcherLicensee); @@ -41,7 +41,7 @@ public class LicenseTests extends AbstractLicenseeTestCase { } public void testExpiredPlatinumGoldTrialLicenseIsRestricted() throws Exception { - licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); + licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode()); WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); licenseeRegistry.register(watcherLicensee); licenseeRegistry.disable(); @@ -56,12 +56,12 @@ public class LicenseTests extends AbstractLicenseeTestCase { assertLicenseBasicOrNoneOrExpiredBehaviour(watcherLicensee); - licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); + licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode()); assertLicenseGoldPlatinumTrialBehaviour(watcherLicensee); } public void testDowngradingToBasicLicenseWorks() { - licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); + licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode()); WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); licenseeRegistry.register(watcherLicensee); @@ -72,14 +72,14 @@ public class LicenseTests extends AbstractLicenseeTestCase { } public void testUpgradingExpiredLicenseWorks() { - licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); + licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode()); WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); licenseeRegistry.register(watcherLicensee); licenseeRegistry.disable(); assertLicenseBasicOrNoneOrExpiredBehaviour(watcherLicensee); - licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); + licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode()); assertLicenseGoldPlatinumTrialBehaviour(watcherLicensee); }