Adding support for STANDARD license

Original commit: elastic/x-pack-elasticsearch@1671d8ade3
This commit is contained in:
Chris Earle 2016-03-28 00:36:37 -04:00
parent 55b9569f7b
commit 86ed96b83b
11 changed files with 41 additions and 33 deletions

View File

@ -80,6 +80,7 @@ public class License implements ToXContent {
public enum OperationMode { public enum OperationMode {
TRIAL, TRIAL,
BASIC, BASIC,
STANDARD,
GOLD, GOLD,
PLATINUM; PLATINUM;
@ -92,6 +93,8 @@ public class License implements ToXContent {
return TRIAL; return TRIAL;
case "basic": case "basic":
return BASIC; return BASIC;
case "standard":
return STANDARD;
case "silver": case "silver":
case "gold": case "gold":
return GOLD; return GOLD;

View File

@ -28,6 +28,11 @@ public class LicenseOperationModeTests extends ESTestCase {
assertResolve(OperationMode.BASIC, "bAsIc", "basic"); 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() { public void testResolveGold() {
// assert expected (2.x+) variant (note: no different 1.x variant of GOLD) // assert expected (2.x+) variant (note: no different 1.x variant of GOLD)
assertResolve(OperationMode.GOLD, "SiLvEr", "gOlD", "silver", "gold"); assertResolve(OperationMode.GOLD, "SiLvEr", "gOlD", "silver", "gold");
@ -41,8 +46,7 @@ public class LicenseOperationModeTests extends ESTestCase {
} }
public void testResolveUnknown() { public void testResolveUnknown() {
// standard will hopefully trip the upcoming standard license to add the test here for FWC String[] types = { "unknown", "fake" };
String[] types = { "standard", "unknown", "fake" };
for (String type : types) { for (String type : types) {
try { try {

View File

@ -45,7 +45,8 @@ public interface Licensee {
* whenever checking different parts of the {@code Status}: * whenever checking different parts of the {@code Status}:
* <pre> * <pre>
* Status status = this.status; * Status status = this.status;
* return status.getLicenseState().isActive() &amp;&amp; status.getMode().isPaid(); * return status.getLicenseState() != LicenseState.DISABLED &amp;&amp;
* (status.getMode() == OperationMode.TRAIL || status.getMode == OperationMode.PLATINUM);
* </pre> * </pre>
* Otherwise the license has the potential to change in-between both checks. * Otherwise the license has the potential to change in-between both checks.
*/ */

View File

@ -35,6 +35,7 @@ public class GraphLicensee extends AbstractLicenseeComponent<GraphLicensee> {
public String[] acknowledgmentMessages(License currentLicense, License newLicense) { public String[] acknowledgmentMessages(License currentLicense, License newLicense) {
switch (newLicense.operationMode()) { switch (newLicense.operationMode()) {
case BASIC: case BASIC:
case STANDARD:
case GOLD: case GOLD:
if (currentLicense != null) { if (currentLicense != null) {
switch (currentLicense.operationMode()) { switch (currentLicense.operationMode()) {

View File

@ -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}. * @return Never {@code null}.
*/ */
public static OperationMode randomTrialGoldOrPlatinumMode() { public static OperationMode randomTrialStandardGoldOrPlatinumMode() {
return randomFrom(OperationMode.TRIAL, OperationMode.GOLD, OperationMode.PLATINUM); return randomFrom(OperationMode.TRIAL, OperationMode.STANDARD, OperationMode.GOLD, OperationMode.PLATINUM);
} }
/** /**

View File

@ -54,6 +54,7 @@ public class MarvelLicensee extends AbstractLicenseeComponent<MarvelLicensee> im
if (currentLicense != null) { if (currentLicense != null) {
switch (currentLicense.operationMode()) { switch (currentLicense.operationMode()) {
case TRIAL: case TRIAL:
case STANDARD:
case GOLD: case GOLD:
case PLATINUM: case PLATINUM:
return new String[] { return new String[] {
@ -101,12 +102,8 @@ public class MarvelLicensee extends AbstractLicenseeComponent<MarvelLicensee> im
/** /**
* Determine if the current license allows the retention of indices to be modified. * Determine if the current license allows the retention of indices to be modified.
* <p> * <p>
* Only users with the following license types can update the retention period: * Only users with a non-{@link OperationMode#BASIC} license can update the retention period.
* <ul> * <p>
* <li>{@link OperationMode#PLATINUM}</li>
* <li>{@link OperationMode#GOLD}</li>
* <li>{@link OperationMode#TRIAL}</li>
* </ul>
* Note: This does not consider the <em>state</em> of the license so that any change is remembered for when they fix their license. * Note: This does not consider the <em>state</em> 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}. * @return {@code true} if the user is allowed to modify the retention. Otherwise {@code false}.

View File

@ -6,7 +6,6 @@
package org.elasticsearch.marvel.license; package org.elasticsearch.marvel.license;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.core.License.OperationMode;
import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase; import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase;
import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.LicenseState;
@ -35,7 +34,7 @@ public class MarvelLicenseeTests extends AbstractLicenseeTestCase {
} }
public void testAcknowledgementMessagesToTrialGoldOrPlatinumFromAnyIsNoOp() { public void testAcknowledgementMessagesToTrialGoldOrPlatinumFromAnyIsNoOp() {
assertEmptyAck(randomMode(), randomTrialGoldOrPlatinumMode(), licensee); assertEmptyAck(randomMode(), randomTrialStandardGoldOrPlatinumMode(), licensee);
} }
public void testAcknowledgementMessagesToBasicFromNotBasicNotesLimits() { public void testAcknowledgementMessagesToBasicFromNotBasicNotesLimits() {

View File

@ -51,27 +51,30 @@ public class ShieldLicensee extends AbstractLicenseeComponent<ShieldLicensee> im
if (currentLicense != null) { if (currentLicense != null) {
switch (currentLicense.operationMode()) { switch (currentLicense.operationMode()) {
case TRIAL: case TRIAL:
case STANDARD:
case GOLD: case GOLD:
case PLATINUM: case PLATINUM:
return new String[] { return new String[] {
"The following Shield functionality will be disabled: authentication, authorization, ip filtering, " + "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.", "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", "Field and document level access control will be disabled",
"Custom realms will be ignored" "Custom realms will be ignored"
}; };
} }
} }
break; break;
case GOLD: case GOLD:
if (currentLicense != null) { if (currentLicense != null) {
switch (currentLicense.operationMode()) { 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 TRIAL:
case PLATINUM: case PLATINUM:
return new String[] { return new String[] {
"Field and document level access control will be disabled", "Field and document level access control will be disabled",
"Custom realms will be ignored" "Custom realms will be ignored"
}; };
} }
} }
break; break;
@ -84,7 +87,7 @@ public class ShieldLicensee extends AbstractLicenseeComponent<ShieldLicensee> im
// we rely on the initial licensee state to be enabled with trial operation mode // 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 // to ensure no operation is blocked due to not registering the licensee on a
// tribe node // tribe node
if (!isTribeNode) { if (isTribeNode == false) {
super.doStart(); super.doStart();
} }
} }

View File

@ -66,15 +66,15 @@ public class ShieldLicenseeTests extends AbstractLicenseeTestCase {
assertEmptyAck(randomMode(), randomTrialOrPlatinumMode(), this::buildLicensee); assertEmptyAck(randomMode(), randomTrialOrPlatinumMode(), this::buildLicensee);
} }
public void testAcknowledgementMessagesFromTrialGoldOrPlatinumToBasicNotesLimits() { public void testAcknowledgementMessagesFromTrialStandardGoldOrPlatinumToBasicNotesLimits() {
String[] messages = ackLicenseChange(randomTrialGoldOrPlatinumMode(), OperationMode.BASIC, this::buildLicensee); String[] messages = ackLicenseChange(randomTrialStandardGoldOrPlatinumMode(), OperationMode.BASIC, this::buildLicensee);
// leaving messages up to inspection // leaving messages up to inspection
assertThat(messages.length, equalTo(3)); assertThat(messages.length, equalTo(3));
} }
public void testAcknowledgementMessagesFromTrialOrPlatinumToGoldNotesLimits() { public void testAcknowledgementMessagesFromBasicStandardTrialOrPlatinumToGoldNotesLimits() {
String[] messages = ackLicenseChange(randomTrialOrPlatinumMode(), OperationMode.GOLD, this::buildLicensee); String[] messages = ackLicenseChange(randomModeExcept(OperationMode.GOLD), OperationMode.GOLD, this::buildLicensee);
// leaving messages up to inspection // leaving messages up to inspection
assertThat(messages.length, equalTo(2)); assertThat(messages.length, equalTo(2));

View File

@ -44,6 +44,7 @@ public class WatcherLicensee extends AbstractLicenseeComponent<WatcherLicensee>
if (currentLicense != null) { if (currentLicense != null) {
switch (currentLicense.operationMode()) { switch (currentLicense.operationMode()) {
case TRIAL: case TRIAL:
case STANDARD:
case GOLD: case GOLD:
case PLATINUM: case PLATINUM:
return new String[] { "Watcher will be disabled" }; return new String[] { "Watcher will be disabled" };
@ -73,6 +74,7 @@ public class WatcherLicensee extends AbstractLicenseeComponent<WatcherLicensee>
* <ul> * <ul>
* <li>{@link OperationMode#PLATINUM}</li> * <li>{@link OperationMode#PLATINUM}</li>
* <li>{@link OperationMode#GOLD}</li> * <li>{@link OperationMode#GOLD}</li>
* <li>{@link OperationMode#STANDARD}</li>
* <li>{@link OperationMode#TRIAL}</li> * <li>{@link OperationMode#TRIAL}</li>
* </ul> * </ul>
* *
@ -82,9 +84,6 @@ public class WatcherLicensee extends AbstractLicenseeComponent<WatcherLicensee>
// status is volatile, so a local variable is used for a consistent view // status is volatile, so a local variable is used for a consistent view
Status localStatus = status; Status localStatus = status;
OperationMode operationMode = localStatus.getMode(); return localStatus.getLicenseState() != LicenseState.DISABLED && localStatus.getMode() != OperationMode.BASIC;
boolean licensed = operationMode == TRIAL || operationMode == GOLD || operationMode == PLATINUM;
return licensed && localStatus.getLicenseState() != LicenseState.DISABLED;
} }
} }

View File

@ -16,7 +16,7 @@ public class LicenseTests extends AbstractLicenseeTestCase {
private SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry(); private SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry();
public void testPlatinumGoldTrialLicenseCanDoEverything() throws Exception { public void testPlatinumGoldTrialLicenseCanDoEverything() throws Exception {
licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode());
WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry);
licenseeRegistry.register(watcherLicensee); licenseeRegistry.register(watcherLicensee);
@ -41,7 +41,7 @@ public class LicenseTests extends AbstractLicenseeTestCase {
} }
public void testExpiredPlatinumGoldTrialLicenseIsRestricted() throws Exception { public void testExpiredPlatinumGoldTrialLicenseIsRestricted() throws Exception {
licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode());
WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry);
licenseeRegistry.register(watcherLicensee); licenseeRegistry.register(watcherLicensee);
licenseeRegistry.disable(); licenseeRegistry.disable();
@ -56,12 +56,12 @@ public class LicenseTests extends AbstractLicenseeTestCase {
assertLicenseBasicOrNoneOrExpiredBehaviour(watcherLicensee); assertLicenseBasicOrNoneOrExpiredBehaviour(watcherLicensee);
licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode());
assertLicenseGoldPlatinumTrialBehaviour(watcherLicensee); assertLicenseGoldPlatinumTrialBehaviour(watcherLicensee);
} }
public void testDowngradingToBasicLicenseWorks() { public void testDowngradingToBasicLicenseWorks() {
licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode());
WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry);
licenseeRegistry.register(watcherLicensee); licenseeRegistry.register(watcherLicensee);
@ -72,14 +72,14 @@ public class LicenseTests extends AbstractLicenseeTestCase {
} }
public void testUpgradingExpiredLicenseWorks() { public void testUpgradingExpiredLicenseWorks() {
licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode());
WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); WatcherLicensee watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry);
licenseeRegistry.register(watcherLicensee); licenseeRegistry.register(watcherLicensee);
licenseeRegistry.disable(); licenseeRegistry.disable();
assertLicenseBasicOrNoneOrExpiredBehaviour(watcherLicensee); assertLicenseBasicOrNoneOrExpiredBehaviour(watcherLicensee);
licenseeRegistry.setOperationMode(randomTrialGoldOrPlatinumMode()); licenseeRegistry.setOperationMode(randomTrialStandardGoldOrPlatinumMode());
assertLicenseGoldPlatinumTrialBehaviour(watcherLicensee); assertLicenseGoldPlatinumTrialBehaviour(watcherLicensee);
} }