Merge pull request elastic/elasticsearch#2902 from rjernst/license_state_removal
Internal: Removed LicenseState enum Original commit: elastic/x-pack-elasticsearch@13abacbb78
This commit is contained in:
commit
d734d483c5
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.license.core.License.OperationMode;
|
import org.elasticsearch.license.core.License.OperationMode;
|
||||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
|
||||||
|
|
||||||
public class GraphLicensee extends AbstractLicenseeComponent {
|
public class GraphLicensee extends AbstractLicenseeComponent {
|
||||||
|
|
||||||
|
@ -60,6 +59,6 @@ public class GraphLicensee extends AbstractLicenseeComponent {
|
||||||
|
|
||||||
boolean licensed = operationMode == OperationMode.TRIAL || operationMode == OperationMode.PLATINUM;
|
boolean licensed = operationMode == OperationMode.TRIAL || operationMode == OperationMode.PLATINUM;
|
||||||
|
|
||||||
return licensed && localStatus.getLicenseState() != LicenseState.DISABLED;
|
return licensed && localStatus.isActive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
|
||||||
*/
|
|
||||||
package org.elasticsearch.license.plugin.core;
|
|
||||||
|
|
||||||
import org.elasticsearch.license.core.License;
|
|
||||||
import org.elasticsearch.xpack.scheduler.SchedulerEngine;
|
|
||||||
|
|
||||||
|
|
||||||
public class LicenseSchedule implements SchedulerEngine.Schedule {
|
|
||||||
|
|
||||||
private final License license;
|
|
||||||
|
|
||||||
LicenseSchedule(License license) {
|
|
||||||
this.license = license;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long nextScheduledTimeAfter(long startTime, long time) {
|
|
||||||
long nextScheduledTime = -1;
|
|
||||||
switch (LicenseState.resolve(license, time)) {
|
|
||||||
case ENABLED:
|
|
||||||
nextScheduledTime = license.expiryDate();
|
|
||||||
break;
|
|
||||||
case GRACE_PERIOD:
|
|
||||||
nextScheduledTime = license.expiryDate() + LicenseState.GRACE_PERIOD_DURATION.getMillis();
|
|
||||||
break;
|
|
||||||
case DISABLED:
|
|
||||||
if (license.issueDate() > time) {
|
|
||||||
// when we encounter a license with a future issue date
|
|
||||||
// which can happen with autogenerated license,
|
|
||||||
// we want to schedule a notification on the license issue date
|
|
||||||
// so the license is notificed once it is valid
|
|
||||||
// see https://github.com/elastic/x-plugins/issues/983
|
|
||||||
nextScheduledTime = license.issueDate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return nextScheduledTime;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -62,6 +62,11 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
|
||||||
// pkg private for tests
|
// pkg private for tests
|
||||||
static final TimeValue TRIAL_LICENSE_DURATION = TimeValue.timeValueHours(30 * 24);
|
static final TimeValue TRIAL_LICENSE_DURATION = TimeValue.timeValueHours(30 * 24);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duration of grace period after a license has expired
|
||||||
|
*/
|
||||||
|
public static final TimeValue GRACE_PERIOD_DURATION = days(7);
|
||||||
|
|
||||||
private final ClusterService clusterService;
|
private final ClusterService clusterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -310,12 +315,15 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Licensee.Status licenseeStatus() {
|
public Licensee.Status licenseeStatus(License license) {
|
||||||
final License license = getLicense();
|
|
||||||
if (license == null) {
|
if (license == null) {
|
||||||
return Licensee.Status.MISSING;
|
return new Licensee.Status(License.OperationMode.MISSING, false);
|
||||||
}
|
}
|
||||||
return new Licensee.Status(license.operationMode(), LicenseState.resolve(license, clock.millis()));
|
long time = clock.millis();
|
||||||
|
boolean active = time >= license.issueDate() &&
|
||||||
|
time < license.expiryDate() + GRACE_PERIOD_DURATION.getMillis();
|
||||||
|
|
||||||
|
return new Licensee.Status(license.operationMode(), active);
|
||||||
}
|
}
|
||||||
|
|
||||||
public License getLicense() {
|
public License getLicense() {
|
||||||
|
@ -433,18 +441,22 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
|
||||||
}
|
}
|
||||||
if (license != null) {
|
if (license != null) {
|
||||||
logger.debug("notifying [{}] listeners", registeredLicensees.size());
|
logger.debug("notifying [{}] listeners", registeredLicensees.size());
|
||||||
final LicenseState licenseState = LicenseState.resolve(license, clock.millis());
|
long time = clock.millis();
|
||||||
Licensee.Status status = new Licensee.Status(license.operationMode(), licenseState);
|
boolean active = time >= license.issueDate() &&
|
||||||
|
time < license.expiryDate() + GRACE_PERIOD_DURATION.getMillis();
|
||||||
|
|
||||||
|
Licensee.Status status = new Licensee.Status(license.operationMode(), active);
|
||||||
for (InternalLicensee licensee : registeredLicensees) {
|
for (InternalLicensee licensee : registeredLicensees) {
|
||||||
licensee.onChange(status);
|
licensee.onChange(status);
|
||||||
}
|
}
|
||||||
switch (status.getLicenseState()) {
|
if (active) {
|
||||||
case ENABLED:
|
if (time < license.expiryDate()) {
|
||||||
logger.debug("license [{}] - valid", license.uid()); break;
|
logger.debug("license [{}] - valid", license.uid());
|
||||||
case GRACE_PERIOD:
|
} else {
|
||||||
logger.warn("license [{}] - grace", license.uid()); break;
|
logger.warn("license [{}] - grace", license.uid());
|
||||||
case DISABLED:
|
}
|
||||||
logger.warn("license [{}] - expired", license.uid()); break;
|
} else {
|
||||||
|
logger.warn("license [{}] - expired", license.uid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,7 +476,7 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
|
||||||
if (license.equals(previousLicense) == false) {
|
if (license.equals(previousLicense) == false) {
|
||||||
currentLicense.set(license);
|
currentLicense.set(license);
|
||||||
license.setOperationModeFileWatcher(operationModeFileWatcher);
|
license.setOperationModeFileWatcher(operationModeFileWatcher);
|
||||||
scheduler.add(new SchedulerEngine.Job(LICENSE_JOB, new LicenseSchedule(license)));
|
scheduler.add(new SchedulerEngine.Job(LICENSE_JOB, nextLicenseCheck(license)));
|
||||||
for (ExpirationCallback expirationCallback : expirationCallbacks) {
|
for (ExpirationCallback expirationCallback : expirationCallbacks) {
|
||||||
scheduler.add(new SchedulerEngine.Job(expirationCallback.getId(),
|
scheduler.add(new SchedulerEngine.Job(expirationCallback.getId(),
|
||||||
(startTime, now) ->
|
(startTime, now) ->
|
||||||
|
@ -479,6 +491,25 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pkg private for tests
|
||||||
|
static SchedulerEngine.Schedule nextLicenseCheck(License license) {
|
||||||
|
return (startTime, time) -> {
|
||||||
|
if (time < license.issueDate()) {
|
||||||
|
// when we encounter a license with a future issue date
|
||||||
|
// which can happen with autogenerated license,
|
||||||
|
// we want to schedule a notification on the license issue date
|
||||||
|
// so the license is notificed once it is valid
|
||||||
|
// see https://github.com/elastic/x-plugins/issues/983
|
||||||
|
return license.issueDate();
|
||||||
|
} else if (time < license.expiryDate()) {
|
||||||
|
return license.expiryDate();
|
||||||
|
} else if (time < license.expiryDate() + GRACE_PERIOD_DURATION.getMillis()) {
|
||||||
|
return license.expiryDate() + GRACE_PERIOD_DURATION.getMillis();
|
||||||
|
}
|
||||||
|
return -1; // license is expired, no need to check again
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private void initLicensee(Licensee licensee) {
|
private void initLicensee(Licensee licensee) {
|
||||||
logger.debug("initializing licensee [{}]", licensee.id());
|
logger.debug("initializing licensee [{}]", licensee.id());
|
||||||
final ClusterState clusterState = clusterService.state();
|
final ClusterState clusterState = clusterService.state();
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
|
||||||
*/
|
|
||||||
package org.elasticsearch.license.plugin.core;
|
|
||||||
|
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
|
||||||
import org.elasticsearch.license.core.License;
|
|
||||||
|
|
||||||
import static org.elasticsearch.license.plugin.core.LicenseService.days;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* States of a registered licensee
|
|
||||||
* based on the current license
|
|
||||||
*/
|
|
||||||
public enum LicenseState {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Active license is valid.
|
|
||||||
*
|
|
||||||
* When license expires
|
|
||||||
* changes to {@link #GRACE_PERIOD}
|
|
||||||
*/
|
|
||||||
ENABLED,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Active license expired
|
|
||||||
* but grace period has not.
|
|
||||||
*
|
|
||||||
* When grace period expires
|
|
||||||
* changes to {@link #DISABLED}.
|
|
||||||
* When valid license is installed
|
|
||||||
* changes back to {@link #ENABLED}
|
|
||||||
*/
|
|
||||||
GRACE_PERIOD,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grace period for active license
|
|
||||||
* expired.
|
|
||||||
*
|
|
||||||
* When a valid license is installed
|
|
||||||
* changes to {@link #ENABLED}, otherwise
|
|
||||||
* remains unchanged
|
|
||||||
*/
|
|
||||||
DISABLED;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Duration of grace period after a license has expired
|
|
||||||
*/
|
|
||||||
public static final TimeValue GRACE_PERIOD_DURATION = days(7);
|
|
||||||
|
|
||||||
public static LicenseState resolve(final License license, long time) {
|
|
||||||
if (license == null) {
|
|
||||||
return DISABLED;
|
|
||||||
}
|
|
||||||
if (license.issueDate() > time) {
|
|
||||||
return DISABLED;
|
|
||||||
}
|
|
||||||
if (license.expiryDate() > time) {
|
|
||||||
return ENABLED;
|
|
||||||
}
|
|
||||||
if ((license.expiryDate() + GRACE_PERIOD_DURATION.getMillis()) > time) {
|
|
||||||
return GRACE_PERIOD;
|
|
||||||
}
|
|
||||||
return DISABLED;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -44,69 +44,60 @@ 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() != LicenseState.DISABLED &&
|
* return status.isActive() &&
|
||||||
* (status.getMode() == OperationMode.TRAIL || status.getMode == OperationMode.PLATINUM);
|
* (status.getMode() == OperationMode.TRIAL || 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.
|
||||||
*/
|
*/
|
||||||
class Status {
|
class Status {
|
||||||
|
|
||||||
public static Status ENABLED = new Status(OperationMode.TRIAL, LicenseState.ENABLED);
|
public static Status ENABLED = new Status(OperationMode.TRIAL, true);
|
||||||
public static Status MISSING = new Status(OperationMode.MISSING, LicenseState.DISABLED);
|
public static Status MISSING = new Status(OperationMode.MISSING, false);
|
||||||
|
|
||||||
private final OperationMode mode;
|
private final OperationMode mode;
|
||||||
private final LicenseState licenseState;
|
private final boolean active;
|
||||||
|
|
||||||
public Status(OperationMode mode, LicenseState licenseState) {
|
public Status(OperationMode mode, boolean active) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.licenseState = licenseState;
|
this.active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the operation mode of the license
|
* Returns the operation mode of the license
|
||||||
* responsible for the current <code>licenseState</code>
|
* responsible for the current <code>licenseState</code>
|
||||||
* <p>
|
* <p>
|
||||||
* Note: Knowing the mode does not indicate whether the {@link #getLicenseState() state} is disabled. If that matters (e.g.,
|
* Note: Knowing the mode does not indicate whether the license is active. If that matters (e.g.,
|
||||||
* disabling services when a license becomes disabled), then you should check it as well!
|
* disabling services when a license becomes disabled), then check {@link #isActive()}.
|
||||||
*/
|
*/
|
||||||
public OperationMode getMode() {
|
public OperationMode getMode() {
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns true if the license is within the issue date and grace period, or false otherwise */
|
||||||
* When a license is active, the state is
|
public boolean isActive() {
|
||||||
* {@link LicenseState#ENABLED}, upon license expiry
|
return active;
|
||||||
* the state changes to {@link LicenseState#GRACE_PERIOD}
|
|
||||||
* and after the grace period has ended the state changes
|
|
||||||
* to {@link LicenseState#DISABLED}
|
|
||||||
*/
|
|
||||||
public LicenseState getLicenseState() {
|
|
||||||
return licenseState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
Status status = (Status) o;
|
Status status = (Status) o;
|
||||||
return Objects.equals(mode, status.mode) && Objects.equals(licenseState, status.licenseState);
|
return active == status.active &&
|
||||||
|
mode == status.mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(mode, licenseState);
|
return Objects.hash(mode, active);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
switch (licenseState) {
|
if (active) {
|
||||||
case DISABLED:
|
return mode.name().toLowerCase(Locale.ROOT);
|
||||||
return "disabled " + mode.name().toLowerCase(Locale.ROOT);
|
} else {
|
||||||
case GRACE_PERIOD:
|
return "disabled " + mode.name().toLowerCase(Locale.ROOT);
|
||||||
return mode.name().toLowerCase(Locale.ROOT) + " grace period";
|
|
||||||
default:
|
|
||||||
return mode.name().toLowerCase(Locale.ROOT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.license.core.License;
|
import org.elasticsearch.license.core.License;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseService;
|
import org.elasticsearch.license.plugin.core.LicenseService;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||||
import org.elasticsearch.xpack.MockNetty3Plugin;
|
import org.elasticsearch.xpack.MockNetty3Plugin;
|
||||||
|
@ -124,40 +123,40 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
|
||||||
wipeAllLicenses();
|
wipeAllLicenses();
|
||||||
internalCluster().startNode();
|
internalCluster().startNode();
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
assertLicenseState(LicenseState.ENABLED);
|
assertLicenseState(true);
|
||||||
logger.info("--> restart node");
|
logger.info("--> restart node");
|
||||||
internalCluster().fullRestart();
|
internalCluster().fullRestart();
|
||||||
ensureYellow();
|
ensureYellow();
|
||||||
logger.info("--> await node for enabled");
|
logger.info("--> await node for enabled");
|
||||||
assertLicenseState(LicenseState.ENABLED);
|
assertLicenseState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClusterRestartWhileGrace() throws Exception {
|
public void testClusterRestartWhileGrace() throws Exception {
|
||||||
wipeAllLicenses();
|
wipeAllLicenses();
|
||||||
internalCluster().startNode();
|
internalCluster().startNode();
|
||||||
assertLicenseState(LicenseState.ENABLED);
|
assertLicenseState(true);
|
||||||
putLicense(TestUtils.generateSignedLicense(TimeValue.timeValueMillis(0)));
|
putLicense(TestUtils.generateSignedLicense(TimeValue.timeValueMillis(0)));
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
assertLicenseState(LicenseState.GRACE_PERIOD);
|
assertLicenseState(true);
|
||||||
logger.info("--> restart node");
|
logger.info("--> restart node");
|
||||||
internalCluster().fullRestart();
|
internalCluster().fullRestart();
|
||||||
ensureYellow();
|
ensureYellow();
|
||||||
logger.info("--> await node for grace_period");
|
logger.info("--> await node for grace_period");
|
||||||
assertLicenseState(LicenseState.GRACE_PERIOD);
|
assertLicenseState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClusterRestartWhileExpired() throws Exception {
|
public void testClusterRestartWhileExpired() throws Exception {
|
||||||
wipeAllLicenses();
|
wipeAllLicenses();
|
||||||
internalCluster().startNode();
|
internalCluster().startNode();
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
assertLicenseState(LicenseState.ENABLED);
|
assertLicenseState(true);
|
||||||
putLicense(TestUtils.generateExpiredLicense(System.currentTimeMillis() - LicenseState.GRACE_PERIOD_DURATION.getMillis()));
|
putLicense(TestUtils.generateExpiredLicense(System.currentTimeMillis() - LicenseService.GRACE_PERIOD_DURATION.getMillis()));
|
||||||
assertLicenseState(LicenseState.DISABLED);
|
assertLicenseState(false);
|
||||||
logger.info("--> restart node");
|
logger.info("--> restart node");
|
||||||
internalCluster().fullRestart();
|
internalCluster().fullRestart();
|
||||||
ensureYellow();
|
ensureYellow();
|
||||||
logger.info("--> await node for disabled");
|
logger.info("--> await node for disabled");
|
||||||
assertLicenseState(LicenseState.DISABLED);
|
assertLicenseState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClusterNotRecovered() throws Exception {
|
public void testClusterNotRecovered() throws Exception {
|
||||||
|
@ -165,13 +164,13 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
|
||||||
internalCluster().startNode(nodeSettingsBuilder(0).put("discovery.zen.minimum_master_nodes", 2).put("node.master", true));
|
internalCluster().startNode(nodeSettingsBuilder(0).put("discovery.zen.minimum_master_nodes", 2).put("node.master", true));
|
||||||
logger.info("--> start second master out of two [recovered state]");
|
logger.info("--> start second master out of two [recovered state]");
|
||||||
internalCluster().startNode(nodeSettingsBuilder(1).put("discovery.zen.minimum_master_nodes", 2).put("node.master", true));
|
internalCluster().startNode(nodeSettingsBuilder(1).put("discovery.zen.minimum_master_nodes", 2).put("node.master", true));
|
||||||
assertLicenseState(LicenseState.ENABLED);
|
assertLicenseState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertLicenseState(LicenseState state) throws InterruptedException {
|
private void assertLicenseState(boolean active) throws InterruptedException {
|
||||||
boolean success = awaitBusy(() -> {
|
boolean success = awaitBusy(() -> {
|
||||||
for (LicenseService service : internalCluster().getDataNodeInstances(LicenseService.class)) {
|
for (LicenseService service : internalCluster().getDataNodeInstances(LicenseService.class)) {
|
||||||
if (service.licenseeStatus().getLicenseState() == state) {
|
if (service.licenseeStatus(service.getLicense()).isActive() == active) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +182,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
|
||||||
private void assertOperationMode(License.OperationMode operationMode) throws InterruptedException {
|
private void assertOperationMode(License.OperationMode operationMode) throws InterruptedException {
|
||||||
boolean success = awaitBusy(() -> {
|
boolean success = awaitBusy(() -> {
|
||||||
for (LicenseService service : internalCluster().getDataNodeInstances(LicenseService.class)) {
|
for (LicenseService service : internalCluster().getDataNodeInstances(LicenseService.class)) {
|
||||||
if (service.licenseeStatus().getMode() == operationMode) {
|
if (service.licenseeStatus(service.getLicense()).getMode() == operationMode) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,15 +122,6 @@ public abstract class AbstractLicenseeTestCase extends ESTestCase {
|
||||||
return randomValueOtherThan(mode, AbstractLicenseeTestCase::randomMode);
|
return randomValueOtherThan(mode, AbstractLicenseeTestCase::randomMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Randomly get {@link LicenseState#ENABLED} or {@link LicenseState#GRACE_PERIOD}.
|
|
||||||
*
|
|
||||||
* @return Never {@code null}.
|
|
||||||
*/
|
|
||||||
public static LicenseState randomEnabledOrGracePeriodState() {
|
|
||||||
return randomFrom(LicenseState.ENABLED, LicenseState.GRACE_PERIOD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a random value from the {@code values} that passes {@code filter}.
|
* Get a random value from the {@code values} that passes {@code filter}.
|
||||||
*
|
*
|
||||||
|
@ -163,10 +154,10 @@ public abstract class AbstractLicenseeTestCase extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable(Licensee licensee) {
|
public void disable(Licensee licensee) {
|
||||||
licensee.onChange(new Licensee.Status(operationMode, LicenseState.DISABLED));
|
licensee.onChange(new Licensee.Status(operationMode, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable(Licensee licensee) {
|
public void enable(Licensee licensee) {
|
||||||
licensee.onChange(new Licensee.Status(operationMode, randomEnabledOrGracePeriodState()));
|
licensee.onChange(new Licensee.Status(operationMode, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
|
||||||
ClusterState newState = ClusterState.builder(new ClusterName("a")).metaData(metaData).build();
|
ClusterState newState = ClusterState.builder(new ClusterName("a")).metaData(metaData).build();
|
||||||
licenseService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState));
|
licenseService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState));
|
||||||
assertThat(licensee.statuses.size(), equalTo(1));
|
assertThat(licensee.statuses.size(), equalTo(1));
|
||||||
assertTrue(licensee.statuses.get(0).getLicenseState() == LicenseState.ENABLED);
|
assertTrue(licensee.statuses.get(0).isActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoNotificationOnExistingLicense() throws Exception {
|
public void testNoNotificationOnExistingLicense() throws Exception {
|
||||||
|
|
|
@ -43,7 +43,6 @@ public class LicenseRegistrationTests extends AbstractLicenseServiceTestCase {
|
||||||
setInitialState(TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)), licensee);
|
setInitialState(TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)), licensee);
|
||||||
licenseService.start();
|
licenseService.start();
|
||||||
assertThat(licensee.statuses.size(), equalTo(1));
|
assertThat(licensee.statuses.size(), equalTo(1));
|
||||||
final LicenseState licenseState = licensee.statuses.get(0).getLicenseState();
|
assertTrue(licensee.statuses.get(0).isActive());
|
||||||
assertTrue(licenseState == LicenseState.ENABLED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.license.core.License;
|
import org.elasticsearch.license.core.License;
|
||||||
import org.elasticsearch.license.plugin.TestUtils;
|
import org.elasticsearch.license.plugin.TestUtils;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
import org.elasticsearch.xpack.scheduler.SchedulerEngine;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
@ -16,12 +17,12 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
public class LicenseScheduleTests extends ESTestCase {
|
public class LicenseScheduleTests extends ESTestCase {
|
||||||
|
|
||||||
private License license;
|
private License license;
|
||||||
private LicenseSchedule schedule;
|
private SchedulerEngine.Schedule schedule;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setuo() throws Exception {
|
public void setuo() throws Exception {
|
||||||
license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(12));
|
license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(12));
|
||||||
schedule = new LicenseSchedule(license);
|
schedule = LicenseService.nextLicenseCheck(license);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnabledLicenseSchedule() throws Exception {
|
public void testEnabledLicenseSchedule() throws Exception {
|
||||||
|
@ -32,13 +33,13 @@ public class LicenseScheduleTests extends ESTestCase {
|
||||||
|
|
||||||
public void testGraceLicenseSchedule() throws Exception {
|
public void testGraceLicenseSchedule() throws Exception {
|
||||||
long triggeredTime = license.expiryDate() + between(1,
|
long triggeredTime = license.expiryDate() + between(1,
|
||||||
((int) LicenseState.GRACE_PERIOD_DURATION.getMillis()));
|
((int) LicenseService.GRACE_PERIOD_DURATION.getMillis()));
|
||||||
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
|
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
|
||||||
equalTo(license.expiryDate() + LicenseState.GRACE_PERIOD_DURATION.getMillis()));
|
equalTo(license.expiryDate() + LicenseService.GRACE_PERIOD_DURATION.getMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExpiredLicenseSchedule() throws Exception {
|
public void testExpiredLicenseSchedule() throws Exception {
|
||||||
long triggeredTime = license.expiryDate() + LicenseState.GRACE_PERIOD_DURATION.getMillis() +
|
long triggeredTime = license.expiryDate() + LicenseService.GRACE_PERIOD_DURATION.getMillis() +
|
||||||
randomIntBetween(1, 1000);
|
randomIntBetween(1, 1000);
|
||||||
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
|
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
|
||||||
equalTo(-1L));
|
equalTo(-1L));
|
||||||
|
|
|
@ -28,19 +28,19 @@ public class LicensesNotificationTests extends AbstractLicenseServiceTestCase {
|
||||||
setInitialState(license, assertingLicensees);
|
setInitialState(license, assertingLicensees);
|
||||||
licenseService.start();
|
licenseService.start();
|
||||||
for (int i = 0; i < assertingLicensees.length; i++) {
|
for (int i = 0; i < assertingLicensees.length; i++) {
|
||||||
assertLicenseStates(assertingLicensees[i], LicenseState.ENABLED);
|
assertLicenseStates(assertingLicensees[i], true);
|
||||||
}
|
}
|
||||||
clock.fastForward(TimeValue.timeValueMillis(license.expiryDate() - clock.millis()));
|
clock.fastForward(TimeValue.timeValueMillis(license.expiryDate() - clock.millis()));
|
||||||
final LicensesMetaData licensesMetaData = new LicensesMetaData(license);
|
final LicensesMetaData licensesMetaData = new LicensesMetaData(license);
|
||||||
licenseService.onUpdate(licensesMetaData);
|
licenseService.onUpdate(licensesMetaData);
|
||||||
for (AssertingLicensee assertingLicensee : assertingLicensees) {
|
for (AssertingLicensee assertingLicensee : assertingLicensees) {
|
||||||
assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD);
|
assertLicenseStates(assertingLicensee, true);
|
||||||
}
|
}
|
||||||
clock.fastForward(TimeValue.timeValueMillis((license.expiryDate() +
|
clock.fastForward(TimeValue.timeValueMillis((license.expiryDate() +
|
||||||
LicenseState.GRACE_PERIOD_DURATION.getMillis()) - clock.millis()));
|
LicenseService.GRACE_PERIOD_DURATION.getMillis()) - clock.millis()));
|
||||||
licenseService.onUpdate(licensesMetaData);
|
licenseService.onUpdate(licensesMetaData);
|
||||||
for (AssertingLicensee assertingLicensee : assertingLicensees) {
|
for (AssertingLicensee assertingLicensee : assertingLicensees) {
|
||||||
assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD, LicenseState.DISABLED);
|
assertLicenseStates(assertingLicensee, true, false);
|
||||||
}
|
}
|
||||||
clock.setTime(new DateTime(DateTimeZone.UTC));
|
clock.setTime(new DateTime(DateTimeZone.UTC));
|
||||||
final License newLicense = TestUtils.generateSignedLicense(TimeValue.timeValueHours(2));
|
final License newLicense = TestUtils.generateSignedLicense(TimeValue.timeValueHours(2));
|
||||||
|
@ -48,12 +48,11 @@ public class LicensesNotificationTests extends AbstractLicenseServiceTestCase {
|
||||||
LicensesMetaData licensesMetaData1 = new LicensesMetaData(newLicense);
|
LicensesMetaData licensesMetaData1 = new LicensesMetaData(newLicense);
|
||||||
licenseService.onUpdate(licensesMetaData1);
|
licenseService.onUpdate(licensesMetaData1);
|
||||||
for (AssertingLicensee assertingLicensee : assertingLicensees) {
|
for (AssertingLicensee assertingLicensee : assertingLicensees) {
|
||||||
assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD, LicenseState.DISABLED,
|
assertLicenseStates(assertingLicensee, true, false, true);
|
||||||
LicenseState.ENABLED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertLicenseStates(AssertingLicensee licensee, LicenseState... states) {
|
private void assertLicenseStates(AssertingLicensee licensee, boolean... states) {
|
||||||
StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
msg.append("Actual: ");
|
msg.append("Actual: ");
|
||||||
msg.append(dumpLicensingStates(licensee.statuses));
|
msg.append(dumpLicensingStates(licensee.statuses));
|
||||||
|
@ -61,7 +60,7 @@ public class LicensesNotificationTests extends AbstractLicenseServiceTestCase {
|
||||||
msg.append(dumpLicensingStates(states));
|
msg.append(dumpLicensingStates(states));
|
||||||
assertThat(msg.toString(), licensee.statuses.size(), equalTo(states.length));
|
assertThat(msg.toString(), licensee.statuses.size(), equalTo(states.length));
|
||||||
for (int i = 0; i < states.length; i++) {
|
for (int i = 0; i < states.length; i++) {
|
||||||
assertThat(msg.toString(), licensee.statuses.get(i).getLicenseState(), equalTo(states[i]));
|
assertThat(msg.toString(), licensee.statuses.get(i).isActive(), equalTo(states[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,18 +69,18 @@ public class LicensesNotificationTests extends AbstractLicenseServiceTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String dumpLicensingStates(Licensee.Status... statuses) {
|
private String dumpLicensingStates(Licensee.Status... statuses) {
|
||||||
LicenseState[] states = new LicenseState[statuses.length];
|
boolean[] states = new boolean[statuses.length];
|
||||||
for (int i = 0; i < statuses.length; i++) {
|
for (int i = 0; i < statuses.length; i++) {
|
||||||
states[i] = statuses[i].getLicenseState();
|
states[i] = statuses[i].isActive();
|
||||||
}
|
}
|
||||||
return dumpLicensingStates(states);
|
return dumpLicensingStates(states);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String dumpLicensingStates(LicenseState... states) {
|
private String dumpLicensingStates(boolean... states) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("[");
|
sb.append("[");
|
||||||
for (int i = 0; i < states.length; i++) {
|
for (int i = 0; i < states.length; i++) {
|
||||||
sb.append(states[i].name());
|
sb.append(states[i]);
|
||||||
if (i != states.length - 1) {
|
if (i != states.length - 1) {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.LoggerMessageFormat;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.license.core.License.OperationMode;
|
import org.elasticsearch.license.core.License.OperationMode;
|
||||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code MonitoringLicensee} determines whether certain features of Monitoring are enabled or disabled.
|
* {@code MonitoringLicensee} determines whether certain features of Monitoring are enabled or disabled.
|
||||||
|
@ -73,7 +72,7 @@ public class MonitoringLicensee extends AbstractLicenseeComponent {
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return status.getLicenseState() != LicenseState.DISABLED;
|
return status.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,7 +86,7 @@ public class MonitoringLicensee extends AbstractLicenseeComponent {
|
||||||
* @return {@code true} as long as the license is valid. Otherwise {@code false}.
|
* @return {@code true} as long as the license is valid. Otherwise {@code false}.
|
||||||
*/
|
*/
|
||||||
public boolean collectionEnabled() {
|
public boolean collectionEnabled() {
|
||||||
return status.getLicenseState() != LicenseState.DISABLED;
|
return status.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,7 +97,7 @@ public class MonitoringLicensee extends AbstractLicenseeComponent {
|
||||||
* @return {@code true} as long as the license is valid. Otherwise {@code false}.
|
* @return {@code true} as long as the license is valid. Otherwise {@code false}.
|
||||||
*/
|
*/
|
||||||
public boolean cleaningEnabled() {
|
public boolean cleaningEnabled() {
|
||||||
return status.getLicenseState() != LicenseState.DISABLED;
|
return status.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.license.core.License;
|
import org.elasticsearch.license.core.License;
|
||||||
import org.elasticsearch.license.plugin.Licensing;
|
import org.elasticsearch.license.plugin.Licensing;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseService;
|
import org.elasticsearch.license.plugin.core.LicenseService;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
|
||||||
import org.elasticsearch.license.plugin.core.Licensee;
|
import org.elasticsearch.license.plugin.core.Licensee;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.rest.RestHandler;
|
import org.elasticsearch.rest.RestHandler;
|
||||||
|
@ -110,7 +109,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
||||||
|
|
||||||
final License license = createTestingLicense(issueDate, expiryDate);
|
final License license = createTestingLicense(issueDate, expiryDate);
|
||||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||||
service.onChange(license.operationMode(), LicenseState.ENABLED);
|
service.onChange(license.operationMode(), true);
|
||||||
}
|
}
|
||||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||||
service.update(license);
|
service.update(license);
|
||||||
|
@ -123,7 +122,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
||||||
|
|
||||||
final License license = createTestingLicense(issueDate, expiryDate);
|
final License license = createTestingLicense(issueDate, expiryDate);
|
||||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||||
service.onChange(license.operationMode(), LicenseState.GRACE_PERIOD);
|
service.onChange(license.operationMode(), true);
|
||||||
}
|
}
|
||||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||||
service.update(license);
|
service.update(license);
|
||||||
|
@ -136,7 +135,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
||||||
|
|
||||||
final License license = createTestingLicense(issueDate, expiryDate);
|
final License license = createTestingLicense(issueDate, expiryDate);
|
||||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||||
service.onChange(license.operationMode(), LicenseState.DISABLED);
|
service.onChange(license.operationMode(), false);
|
||||||
}
|
}
|
||||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||||
service.update(license);
|
service.update(license);
|
||||||
|
@ -149,7 +148,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
||||||
|
|
||||||
final License license = createTestingLicense(issueDate, expiryDate);
|
final License license = createTestingLicense(issueDate, expiryDate);
|
||||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||||
service.onChange(license.operationMode(), LicenseState.DISABLED);
|
service.onChange(license.operationMode(), false);
|
||||||
}
|
}
|
||||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||||
service.update(license);
|
service.update(license);
|
||||||
|
@ -238,14 +237,14 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
||||||
this.licensees = licensees;
|
this.licensees = licensees;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onChange(License.OperationMode operationMode, LicenseState state) {
|
public void onChange(License.OperationMode operationMode, boolean active) {
|
||||||
for (Licensee licensee : licensees) {
|
for (Licensee licensee : licensees) {
|
||||||
licensee.onChange(new Licensee.Status(operationMode, state));
|
licensee.onChange(new Licensee.Status(operationMode, active));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Licensee.Status licenseeStatus() {
|
public Licensee.Status licenseeStatus(License license) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.license.core.License;
|
import org.elasticsearch.license.core.License;
|
||||||
import org.elasticsearch.license.plugin.Licensing;
|
import org.elasticsearch.license.plugin.Licensing;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseService;
|
import org.elasticsearch.license.plugin.core.LicenseService;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
|
||||||
import org.elasticsearch.license.plugin.core.Licensee;
|
import org.elasticsearch.license.plugin.core.Licensee;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.rest.RestHandler;
|
import org.elasticsearch.rest.RestHandler;
|
||||||
|
@ -39,7 +38,6 @@ import static java.util.Collections.emptyList;
|
||||||
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
|
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.isOneOf;
|
|
||||||
|
|
||||||
@ClusterScope(scope = SUITE, transportClientRatio = 0, numClientNodes = 0)
|
@ClusterScope(scope = SUITE, transportClientRatio = 0, numClientNodes = 0)
|
||||||
public class LicenseIntegrationTests extends MonitoringIntegTestCase {
|
public class LicenseIntegrationTests extends MonitoringIntegTestCase {
|
||||||
|
@ -56,15 +54,15 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnableDisableLicense() {
|
public void testEnableDisableLicense() {
|
||||||
assertThat(getLicensee().getStatus().getLicenseState(), isOneOf(LicenseState.ENABLED, LicenseState.GRACE_PERIOD));
|
assertTrue(getLicensee().getStatus().isActive());
|
||||||
assertThat(getLicensee().collectionEnabled(), is(true));
|
assertThat(getLicensee().collectionEnabled(), is(true));
|
||||||
disableLicensing();
|
disableLicensing();
|
||||||
|
|
||||||
assertThat(getLicensee().getStatus().getLicenseState(), equalTo(LicenseState.DISABLED));
|
assertThat(getLicensee().getStatus().isActive(), equalTo(false));
|
||||||
assertThat(getLicensee().collectionEnabled(), is(false));
|
assertThat(getLicensee().collectionEnabled(), is(false));
|
||||||
enableLicensing();
|
enableLicensing();
|
||||||
|
|
||||||
assertThat(getLicensee().getStatus().getLicenseState(), isOneOf(LicenseState.ENABLED, LicenseState.GRACE_PERIOD));
|
assertTrue(getLicensee().getStatus().isActive());
|
||||||
assertThat(getLicensee().collectionEnabled(), is(true));
|
assertThat(getLicensee().collectionEnabled(), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,19 +132,18 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase {
|
||||||
|
|
||||||
public void enable() {
|
public void enable() {
|
||||||
for (Licensee licensee : licensees) {
|
for (Licensee licensee : licensees) {
|
||||||
licensee.onChange(new Licensee.Status(License.OperationMode.BASIC,
|
licensee.onChange(new Licensee.Status(License.OperationMode.BASIC, true));
|
||||||
randomBoolean() ? LicenseState.ENABLED : LicenseState.GRACE_PERIOD));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable() {
|
public void disable() {
|
||||||
for (Licensee licensee : licensees) {
|
for (Licensee licensee : licensees) {
|
||||||
licensee.onChange(new Licensee.Status(License.OperationMode.BASIC, LicenseState.DISABLED));
|
licensee.onChange(new Licensee.Status(License.OperationMode.BASIC, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Licensee.Status licenseeStatus() {
|
public Licensee.Status licenseeStatus(License license) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack.monitoring.license;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
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.Licensee.Status;
|
import org.elasticsearch.license.plugin.core.Licensee.Status;
|
||||||
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
||||||
|
|
||||||
|
@ -46,19 +45,19 @@ public class MonitoringLicenseeTests extends AbstractLicenseeTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCollectionEnabledIsTrueForActiveState() {
|
public void testCollectionEnabledIsTrueForActiveState() {
|
||||||
assertEnabled(randomEnabledOrGracePeriodState(), MonitoringLicensee::collectionEnabled, true);
|
assertEnabled(true, MonitoringLicensee::collectionEnabled, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCollectionEnabledIsFalseForInactiveState() {
|
public void testCollectionEnabledIsFalseForInactiveState() {
|
||||||
assertEnabled(LicenseState.DISABLED, MonitoringLicensee::collectionEnabled, false);
|
assertEnabled(false, MonitoringLicensee::collectionEnabled, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCleaningEnabledIsTrueForActiveState() {
|
public void testCleaningEnabledIsTrueForActiveState() {
|
||||||
assertEnabled(randomEnabledOrGracePeriodState(), MonitoringLicensee::cleaningEnabled, true);
|
assertEnabled(true, MonitoringLicensee::cleaningEnabled, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCleaningEnabledIsFalseForInactiveState() {
|
public void testCleaningEnabledIsFalseForInactiveState() {
|
||||||
assertEnabled(LicenseState.DISABLED, MonitoringLicensee::cleaningEnabled, false);
|
assertEnabled(false, MonitoringLicensee::cleaningEnabled, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllowUpdateRetentionIsTrueForNotBasic() {
|
public void testAllowUpdateRetentionIsTrueForNotBasic() {
|
||||||
|
@ -77,19 +76,19 @@ public class MonitoringLicenseeTests extends AbstractLicenseeTestCase {
|
||||||
/**
|
/**
|
||||||
* Assert that the {@link #licensee} is {@code predicate}d as {@code expected} when setting the {@code state}.
|
* Assert that the {@link #licensee} is {@code predicate}d as {@code expected} when setting the {@code state}.
|
||||||
*
|
*
|
||||||
* @param state The state that should cause the {@code expected} {@code predicate}.
|
* @param active The state that should cause the {@code expected} {@code predicate}.
|
||||||
* @param predicate The method to invoke (expected to be an instance method).
|
* @param predicate The method to invoke (expected to be an instance method).
|
||||||
* @param expected The expected outcome given the {@code state} and {@code predicate}.
|
* @param expected The expected outcome given the {@code state} and {@code predicate}.
|
||||||
*/
|
*/
|
||||||
private void assertEnabled(LicenseState state, Predicate<MonitoringLicensee> predicate, boolean expected) {
|
private void assertEnabled(boolean active, Predicate<MonitoringLicensee> predicate, boolean expected) {
|
||||||
Status status = mock(Status.class);
|
Status status = mock(Status.class);
|
||||||
when(status.getLicenseState()).thenReturn(state);
|
when(status.isActive()).thenReturn(active);
|
||||||
|
|
||||||
licensee.onChange(status);
|
licensee.onChange(status);
|
||||||
|
|
||||||
assertThat(predicate.test(licensee), equalTo(expected));
|
assertThat(predicate.test(licensee), equalTo(expected));
|
||||||
|
|
||||||
verify(status).getLicenseState();
|
verify(status).isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
package org.elasticsearch.xpack.security;
|
package org.elasticsearch.xpack.security;
|
||||||
|
|
||||||
import org.elasticsearch.license.core.License.OperationMode;
|
import org.elasticsearch.license.core.License.OperationMode;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
|
||||||
import org.elasticsearch.license.plugin.core.Licensee.Status;
|
import org.elasticsearch.license.plugin.core.Licensee.Status;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@ public class SecurityLicenseState {
|
||||||
* @return true if the license allows for the stats and health APIs to be used.
|
* @return true if the license allows for the stats and health APIs to be used.
|
||||||
*/
|
*/
|
||||||
public boolean statsAndHealthEnabled() {
|
public boolean statsAndHealthEnabled() {
|
||||||
return status.getLicenseState() != LicenseState.DISABLED;
|
return status.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.license.core.License.OperationMode;
|
import org.elasticsearch.license.core.License.OperationMode;
|
||||||
import org.elasticsearch.license.plugin.Licensing;
|
import org.elasticsearch.license.plugin.Licensing;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseService;
|
import org.elasticsearch.license.plugin.core.LicenseService;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
|
||||||
import org.elasticsearch.license.plugin.core.Licensee;
|
import org.elasticsearch.license.plugin.core.Licensee;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.rest.RestHandler;
|
import org.elasticsearch.rest.RestHandler;
|
||||||
|
@ -309,13 +308,13 @@ public class LicensingTests extends SecurityIntegTestCase {
|
||||||
|
|
||||||
void enable(OperationMode operationMode) {
|
void enable(OperationMode operationMode) {
|
||||||
for (Licensee licensee : licensees) {
|
for (Licensee licensee : licensees) {
|
||||||
licensee.onChange(new Licensee.Status(operationMode, LicenseState.ENABLED));
|
licensee.onChange(new Licensee.Status(operationMode, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void disable(OperationMode operationMode) {
|
void disable(OperationMode operationMode) {
|
||||||
for (Licensee licensee : licensees) {
|
for (Licensee licensee : licensees) {
|
||||||
licensee.onChange(new Licensee.Status(operationMode, LicenseState.DISABLED));
|
licensee.onChange(new Licensee.Status(operationMode, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ package org.elasticsearch.xpack.security;
|
||||||
|
|
||||||
import org.elasticsearch.license.core.License;
|
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.LicenseState;
|
|
||||||
import org.elasticsearch.license.plugin.core.Licensee;
|
import org.elasticsearch.license.plugin.core.Licensee;
|
||||||
import org.elasticsearch.xpack.security.SecurityLicenseState.EnabledRealmType;
|
import org.elasticsearch.xpack.security.SecurityLicenseState.EnabledRealmType;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
@ -31,8 +30,7 @@ public class SecurityLicenseStateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testBasic() {
|
public void testBasic() {
|
||||||
SecurityLicenseState licenseState = new SecurityLicenseState();
|
SecurityLicenseState licenseState = new SecurityLicenseState();
|
||||||
licenseState.updateStatus(new Licensee.Status(License.OperationMode.BASIC,
|
licenseState.updateStatus(new Licensee.Status(License.OperationMode.BASIC, true));
|
||||||
randomBoolean() ? LicenseState.ENABLED : LicenseState.GRACE_PERIOD));
|
|
||||||
|
|
||||||
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(false));
|
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(false));
|
||||||
assertThat(licenseState.ipFilteringEnabled(), is(false));
|
assertThat(licenseState.ipFilteringEnabled(), is(false));
|
||||||
|
@ -44,7 +42,7 @@ public class SecurityLicenseStateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testBasicExpired() {
|
public void testBasicExpired() {
|
||||||
SecurityLicenseState licenseState = new SecurityLicenseState();
|
SecurityLicenseState licenseState = new SecurityLicenseState();
|
||||||
licenseState.updateStatus(new Licensee.Status(License.OperationMode.BASIC, LicenseState.DISABLED));
|
licenseState.updateStatus(new Licensee.Status(License.OperationMode.BASIC, false));
|
||||||
|
|
||||||
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(false));
|
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(false));
|
||||||
assertThat(licenseState.ipFilteringEnabled(), is(false));
|
assertThat(licenseState.ipFilteringEnabled(), is(false));
|
||||||
|
@ -56,8 +54,7 @@ public class SecurityLicenseStateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testStandard() {
|
public void testStandard() {
|
||||||
SecurityLicenseState licenseState = new SecurityLicenseState();
|
SecurityLicenseState licenseState = new SecurityLicenseState();
|
||||||
licenseState.updateStatus(new Licensee.Status(OperationMode.STANDARD,
|
licenseState.updateStatus(new Licensee.Status(OperationMode.STANDARD, true));
|
||||||
randomBoolean() ? LicenseState.ENABLED : LicenseState.GRACE_PERIOD));
|
|
||||||
|
|
||||||
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
||||||
assertThat(licenseState.ipFilteringEnabled(), is(false));
|
assertThat(licenseState.ipFilteringEnabled(), is(false));
|
||||||
|
@ -69,7 +66,7 @@ public class SecurityLicenseStateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testStandardExpired() {
|
public void testStandardExpired() {
|
||||||
SecurityLicenseState licenseState = new SecurityLicenseState();
|
SecurityLicenseState licenseState = new SecurityLicenseState();
|
||||||
licenseState.updateStatus(new Licensee.Status(OperationMode.STANDARD, LicenseState.DISABLED));
|
licenseState.updateStatus(new Licensee.Status(OperationMode.STANDARD, false));
|
||||||
|
|
||||||
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
||||||
assertThat(licenseState.ipFilteringEnabled(), is(false));
|
assertThat(licenseState.ipFilteringEnabled(), is(false));
|
||||||
|
@ -81,8 +78,7 @@ public class SecurityLicenseStateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testGold() {
|
public void testGold() {
|
||||||
SecurityLicenseState licenseState = new SecurityLicenseState();
|
SecurityLicenseState licenseState = new SecurityLicenseState();
|
||||||
licenseState.updateStatus(new Licensee.Status(License.OperationMode.GOLD,
|
licenseState.updateStatus(new Licensee.Status(License.OperationMode.GOLD, true));
|
||||||
randomBoolean() ? LicenseState.ENABLED : LicenseState.GRACE_PERIOD));
|
|
||||||
|
|
||||||
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
||||||
assertThat(licenseState.ipFilteringEnabled(), is(true));
|
assertThat(licenseState.ipFilteringEnabled(), is(true));
|
||||||
|
@ -94,7 +90,7 @@ public class SecurityLicenseStateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testGoldExpired() {
|
public void testGoldExpired() {
|
||||||
SecurityLicenseState licenseState = new SecurityLicenseState();
|
SecurityLicenseState licenseState = new SecurityLicenseState();
|
||||||
licenseState.updateStatus(new Licensee.Status(License.OperationMode.GOLD, LicenseState.DISABLED));
|
licenseState.updateStatus(new Licensee.Status(License.OperationMode.GOLD, false));
|
||||||
|
|
||||||
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
||||||
assertThat(licenseState.ipFilteringEnabled(), is(true));
|
assertThat(licenseState.ipFilteringEnabled(), is(true));
|
||||||
|
@ -106,8 +102,7 @@ public class SecurityLicenseStateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testPlatinum() {
|
public void testPlatinum() {
|
||||||
SecurityLicenseState licenseState = new SecurityLicenseState();
|
SecurityLicenseState licenseState = new SecurityLicenseState();
|
||||||
licenseState.updateStatus(new Licensee.Status(License.OperationMode.PLATINUM,
|
licenseState.updateStatus(new Licensee.Status(License.OperationMode.PLATINUM, true));
|
||||||
randomBoolean() ? LicenseState.ENABLED : LicenseState.GRACE_PERIOD));
|
|
||||||
|
|
||||||
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
||||||
assertThat(licenseState.ipFilteringEnabled(), is(true));
|
assertThat(licenseState.ipFilteringEnabled(), is(true));
|
||||||
|
@ -119,7 +114,7 @@ public class SecurityLicenseStateTests extends ESTestCase {
|
||||||
|
|
||||||
public void testPlatinumExpired() {
|
public void testPlatinumExpired() {
|
||||||
SecurityLicenseState licenseState = new SecurityLicenseState();
|
SecurityLicenseState licenseState = new SecurityLicenseState();
|
||||||
licenseState.updateStatus(new Licensee.Status(License.OperationMode.PLATINUM, LicenseState.DISABLED));
|
licenseState.updateStatus(new Licensee.Status(License.OperationMode.PLATINUM, false));
|
||||||
|
|
||||||
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
assertThat(licenseState.authenticationAndAuthorizationEnabled(), is(true));
|
||||||
assertThat(licenseState.ipFilteringEnabled(), is(true));
|
assertThat(licenseState.ipFilteringEnabled(), is(true));
|
||||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.license.core.License.OperationMode;
|
import org.elasticsearch.license.core.License.OperationMode;
|
||||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
||||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
|
||||||
|
|
||||||
public class WatcherLicensee extends AbstractLicenseeComponent {
|
public class WatcherLicensee extends AbstractLicenseeComponent {
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ public class WatcherLicensee extends AbstractLicenseeComponent {
|
||||||
// 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;
|
||||||
|
|
||||||
if (localStatus.getLicenseState() == LicenseState.DISABLED) {
|
if (localStatus.isActive() == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ package org.elasticsearch.xpack.watcher.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;
|
||||||
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.Licensee;
|
|
||||||
import org.elasticsearch.xpack.watcher.WatcherLicensee;
|
import org.elasticsearch.xpack.watcher.WatcherLicensee;
|
||||||
|
|
||||||
import static org.elasticsearch.license.core.License.OperationMode.BASIC;
|
import static org.elasticsearch.license.core.License.OperationMode.BASIC;
|
||||||
|
|
Loading…
Reference in New Issue