Adding support for STANDARD license
Original commit: elastic/x-pack-elasticsearch@1671d8ade3
This commit is contained in:
parent
55b9569f7b
commit
86ed96b83b
|
@ -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;
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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() && status.getMode().isPaid();
|
* return status.getLicenseState() != LicenseState.DISABLED &&
|
||||||
|
* (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.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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()) {
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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}.
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -51,6 +51,7 @@ 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[] {
|
||||||
|
@ -65,7 +66,9 @@ public class ShieldLicensee extends AbstractLicenseeComponent<ShieldLicensee> im
|
||||||
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[] {
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue