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 {
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;

View File

@ -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 {

View File

@ -45,7 +45,8 @@ public interface Licensee {
* whenever checking different parts of the {@code Status}:
* <pre>
* 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>
* 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) {
switch (newLicense.operationMode()) {
case BASIC:
case STANDARD:
case GOLD:
if (currentLicense != null) {
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}.
*/
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);
}
/**

View File

@ -54,6 +54,7 @@ public class MarvelLicensee extends AbstractLicenseeComponent<MarvelLicensee> 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<MarvelLicensee> im
/**
* Determine if the current license allows the retention of indices to be modified.
* <p>
* Only users with the following license types can update the retention period:
* <ul>
* <li>{@link OperationMode#PLATINUM}</li>
* <li>{@link OperationMode#GOLD}</li>
* <li>{@link OperationMode#TRIAL}</li>
* </ul>
* Only users with a non-{@link OperationMode#BASIC} license can update the retention period.
* <p>
* 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}.

View File

@ -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() {

View File

@ -51,27 +51,30 @@ public class ShieldLicensee extends AbstractLicenseeComponent<ShieldLicensee> 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<ShieldLicensee> 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();
}
}

View File

@ -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));

View File

@ -44,6 +44,7 @@ public class WatcherLicensee extends AbstractLicenseeComponent<WatcherLicensee>
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<WatcherLicensee>
* <ul>
* <li>{@link OperationMode#PLATINUM}</li>
* <li>{@link OperationMode#GOLD}</li>
* <li>{@link OperationMode#STANDARD}</li>
* <li>{@link OperationMode#TRIAL}</li>
* </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 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;
}
}

View File

@ -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);
}