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,6 +51,7 @@ public class ShieldLicensee extends AbstractLicenseeComponent<ShieldLicensee> im
if (currentLicense != null) {
switch (currentLicense.operationMode()) {
case TRIAL:
case STANDARD:
case GOLD:
case PLATINUM:
return new String[] {
@ -65,7 +66,9 @@ public class ShieldLicensee extends AbstractLicenseeComponent<ShieldLicensee> im
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[] {
@ -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);
}