modify license manager interface to return current license state
Original commit: elastic/x-pack-elasticsearch@9fee416239
This commit is contained in:
parent
3693fc6fc3
commit
91c03c4423
|
@ -12,9 +12,9 @@ import java.util.List;
|
|||
public interface LicensesManagerService {
|
||||
|
||||
/**
|
||||
* @return the id of registered licensees currently in <code>state</code>
|
||||
* @return current {@link LicenseState}
|
||||
*/
|
||||
List<String> licenseesWithState(LicenseState state);
|
||||
LicenseState licenseState();
|
||||
|
||||
/**
|
||||
* @return the currently active license, or {@code null} if no license is currently installed
|
||||
|
|
|
@ -348,14 +348,11 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<String> licenseesWithState(LicenseState state) {
|
||||
List<String> licensees = new ArrayList<>(registeredLicensees.size());
|
||||
for (InternalLicensee licensee : registeredLicensees) {
|
||||
if (licensee.currentLicenseState == state) {
|
||||
licensees.add(licensee.id());
|
||||
public LicenseState licenseState() {
|
||||
if (registeredLicensees.size() > 0) {
|
||||
return registeredLicensees.get(0).currentLicenseState;
|
||||
}
|
||||
}
|
||||
return licensees;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -69,16 +69,16 @@ public abstract class AbstractLicensesConsumerPluginIntegrationTestCase extends
|
|||
logger.info("using {} consumer plugin", consumerPlugin.getClass().getName());
|
||||
logger.info(" --> trial license generated");
|
||||
// managerService should report feature to be enabled on all data nodes
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
// consumer plugin service should return enabled on all data nodes
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.ENABLED, 2);
|
||||
|
||||
logger.info(" --> check trial license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired trial license)
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.GRACE_PERIOD, trialLicenseDurationInSeconds * 2);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.DISABLED, trialLicenseDurationInSeconds * 2);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
|
||||
logger.info(" --> put signed license");
|
||||
putLicense(TimeValue.timeValueSeconds(trialLicenseDurationInSeconds));
|
||||
|
@ -86,35 +86,35 @@ public abstract class AbstractLicensesConsumerPluginIntegrationTestCase extends
|
|||
logger.info(" --> check signed license enabled notification");
|
||||
// consumer plugin should notify onEnabled on all data nodes (signed license)
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.ENABLED, 1);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
|
||||
logger.info(" --> check signed license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired signed license)
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.GRACE_PERIOD, trialLicenseDurationInSeconds * 2);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.DISABLED, trialLicenseDurationInSeconds * 2);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
}
|
||||
|
||||
public void testTrialLicenseNotification() throws Exception {
|
||||
logger.info(" --> check onEnabled for trial license");
|
||||
// managerService should report feature to be enabled on all data nodes
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
// consumer plugin service should return enabled on all data nodes
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.ENABLED, 1);
|
||||
|
||||
logger.info(" --> check trial license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired signed license)
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.GRACE_PERIOD, trialLicenseDurationInSeconds);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.DISABLED, trialLicenseDurationInSeconds);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
}
|
||||
|
||||
public void testOverlappingTrialAndSignedLicenseNotification() throws Exception {
|
||||
logger.info(" --> check onEnabled for trial license");
|
||||
// managerService should report feature to be enabled on all data nodes
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
// consumer plugin service should return enabled on all data nodes
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.ENABLED, 1);
|
||||
|
||||
|
@ -124,7 +124,7 @@ public abstract class AbstractLicensesConsumerPluginIntegrationTestCase extends
|
|||
logger.info(" --> check signed license enabled notification");
|
||||
// consumer plugin should notify onEnabled on all data nodes (signed license)
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.ENABLED, 1);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
|
||||
logger.info(" --> sleep for rest of trailLicense duration");
|
||||
Thread.sleep(trialLicenseDurationInSeconds * 1000L);
|
||||
|
@ -132,14 +132,14 @@ public abstract class AbstractLicensesConsumerPluginIntegrationTestCase extends
|
|||
logger.info(" --> check consumer is still enabled [signed license]");
|
||||
// consumer plugin should notify onEnabled on all data nodes (signed license)
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.ENABLED, 1);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
|
||||
logger.info(" --> check signed license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired signed license)
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.GRACE_PERIOD, trialLicenseDurationInSeconds * 2 * 2);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertConsumerPluginNotification(consumerPluginServices(), LicenseState.DISABLED, trialLicenseDurationInSeconds * 2 * 2);
|
||||
assertLicenseeState(consumerPlugin.id(), LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
}
|
||||
|
||||
private List<TestPluginServiceBase> consumerPluginServices() {
|
||||
|
|
|
@ -103,11 +103,11 @@ public abstract class AbstractLicensesIntegrationTestCase extends ESIntegTestCas
|
|||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
}
|
||||
|
||||
protected void assertLicenseeState(final String id, final LicenseState state) throws InterruptedException {
|
||||
assertTrue("LicensesManagerService for licensee " + id + " should have status " + state.name(), awaitBusy(() -> {
|
||||
protected void assertLicenseeState(final LicenseState state) throws InterruptedException {
|
||||
assertTrue("license should have status " + state.name(), awaitBusy(() -> {
|
||||
final InternalTestCluster clients = internalCluster();
|
||||
for (LicensesManagerService managerService : clients.getDataNodeInstances(LicensesManagerService.class)) {
|
||||
if (!managerService.licenseesWithState(state).contains(id)) {
|
||||
if (managerService.licenseState() != state) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,16 +65,16 @@ public class LicensesPluginIntegrationTests extends AbstractLicensesIntegrationT
|
|||
logger.info("using {} consumer plugin", useEagerLicenseRegistrationPlugin ? "eager" : "lazy");
|
||||
logger.info(" --> trial license generated");
|
||||
// managerService should report feature to be enabled on all data nodes
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
// consumer plugin service should return enabled on all data nodes
|
||||
assertConsumerPluginEnabledNotification(2);
|
||||
|
||||
logger.info(" --> check trial license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired trial license)
|
||||
assertConsumerPluginDisabledNotification(trialLicenseDurationInSeconds * 2);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
|
||||
logger.info(" --> put signed license");
|
||||
putLicense(TimeValue.timeValueSeconds(trialLicenseDurationInSeconds));
|
||||
|
@ -82,33 +82,33 @@ public class LicensesPluginIntegrationTests extends AbstractLicensesIntegrationT
|
|||
logger.info(" --> check signed license enabled notification");
|
||||
// consumer plugin should notify onEnabled on all data nodes (signed license)
|
||||
assertConsumerPluginEnabledNotification(1);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
|
||||
logger.info(" --> check signed license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired signed license)
|
||||
assertConsumerPluginDisabledNotification(trialLicenseDurationInSeconds * 2);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
}
|
||||
|
||||
public void testTrialLicenseNotification() throws Exception {
|
||||
logger.info(" --> check onEnabled for trial license");
|
||||
// managerService should report feature to be enabled on all data nodes
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
// consumer plugin service should return enabled on all data nodes
|
||||
assertConsumerPluginEnabledNotification(1);
|
||||
|
||||
logger.info(" --> check trial license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired signed license)
|
||||
assertConsumerPluginDisabledNotification(trialLicenseDurationInSeconds * 2);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
}
|
||||
|
||||
public void testOverlappingTrialAndSignedLicenseNotification() throws Exception {
|
||||
logger.info(" --> check onEnabled for trial license");
|
||||
// managerService should report feature to be enabled on all data nodes
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
// consumer plugin service should return enabled on all data nodes
|
||||
assertConsumerPluginEnabledNotification(1);
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class LicensesPluginIntegrationTests extends AbstractLicensesIntegrationT
|
|||
logger.info(" --> check signed license enabled notification");
|
||||
// consumer plugin should notify onEnabled on all data nodes (signed license)
|
||||
assertConsumerPluginEnabledNotification(1);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
|
||||
logger.info(" --> sleep for rest of trailLicense duration");
|
||||
Thread.sleep(trialLicenseDurationInSeconds * 1000L);
|
||||
|
@ -126,13 +126,13 @@ public class LicensesPluginIntegrationTests extends AbstractLicensesIntegrationT
|
|||
logger.info(" --> check consumer is still enabled [signed license]");
|
||||
// consumer plugin should notify onEnabled on all data nodes (signed license)
|
||||
assertConsumerPluginEnabledNotification(1);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
|
||||
logger.info(" --> check signed license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired signed license)
|
||||
assertConsumerPluginDisabledNotification(trialLicenseDurationInSeconds * 2 * 2);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(getCurrentFeatureName(), LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
}
|
||||
|
||||
private String getCurrentFeatureName() {
|
||||
|
|
|
@ -70,8 +70,8 @@ public class LicensesPluginsIntegrationTests extends AbstractLicensesIntegration
|
|||
|
||||
logger.info(" --> trial license generated");
|
||||
// managerService should report feature to be enabled on all data nodes
|
||||
assertLicenseeState(ID_1, LicenseState.ENABLED);
|
||||
assertLicenseeState(ID_2, LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
// consumer plugin service should return enabled on all data nodes
|
||||
assertEagerConsumerPluginNotification(LicenseState.ENABLED, 1);
|
||||
assertLazyConsumerPluginNotification(LicenseState.ENABLED, 1);
|
||||
|
@ -80,10 +80,10 @@ public class LicensesPluginsIntegrationTests extends AbstractLicensesIntegration
|
|||
// consumer plugin should notify onDisabled on all data nodes (expired trial license)
|
||||
assertEagerConsumerPluginNotification(LicenseState.GRACE_PERIOD, trialLicenseDurationInSec * 2);
|
||||
assertLazyConsumerPluginNotification(LicenseState.GRACE_PERIOD, trialLicenseDurationInSec * 2);
|
||||
assertLicenseeState(ID_1, LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(ID_2, LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(ID_1, LicenseState.DISABLED);
|
||||
assertLicenseeState(ID_2, LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
|
||||
logger.info(" --> put signed license");
|
||||
putLicense(TimeValue.timeValueSeconds(signedLicenseDuration));
|
||||
|
@ -92,20 +92,20 @@ public class LicensesPluginsIntegrationTests extends AbstractLicensesIntegration
|
|||
// consumer plugin should notify onEnabled on all data nodes (signed license)
|
||||
assertEagerConsumerPluginNotification(LicenseState.ENABLED, 1);
|
||||
assertLazyConsumerPluginNotification(LicenseState.ENABLED, 1);
|
||||
assertLicenseeState(ID_1, LicenseState.ENABLED);
|
||||
assertLicenseeState(ID_2, LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
|
||||
logger.info(" --> check signed license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired signed license)
|
||||
assertEagerConsumerPluginNotification(LicenseState.GRACE_PERIOD, signedLicenseDuration * 2);
|
||||
assertLazyConsumerPluginNotification(LicenseState.GRACE_PERIOD, signedLicenseDuration * 2);
|
||||
assertLicenseeState(ID_1, LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(ID_2, LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
|
||||
assertEagerConsumerPluginNotification(LicenseState.DISABLED, 10 * 2);
|
||||
assertLazyConsumerPluginNotification(LicenseState.DISABLED, 10 * 2);
|
||||
assertLicenseeState(ID_1, LicenseState.DISABLED);
|
||||
assertLicenseeState(ID_2, LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
}
|
||||
|
||||
public void testRandomFeatureLicensesActions() throws Exception {
|
||||
|
@ -116,19 +116,19 @@ public class LicensesPluginsIntegrationTests extends AbstractLicensesIntegration
|
|||
logger.info(" --> check license enabled notification");
|
||||
assertEagerConsumerPluginNotification(LicenseState.ENABLED, 1);
|
||||
assertLazyConsumerPluginNotification(LicenseState.ENABLED, 1);
|
||||
assertLicenseeState(ID_1, LicenseState.ENABLED);
|
||||
assertLicenseeState(ID_2, LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
|
||||
logger.info(" --> check license expiry notification");
|
||||
// consumer plugin should notify onDisabled on all data nodes (expired signed license)
|
||||
assertEagerConsumerPluginNotification(LicenseState.GRACE_PERIOD, 10 * 2);
|
||||
assertLazyConsumerPluginNotification(LicenseState.GRACE_PERIOD, 10 * 2);
|
||||
assertLicenseeState(ID_1, LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(ID_2, LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertLicenseeState(LicenseState.GRACE_PERIOD);
|
||||
assertEagerConsumerPluginNotification(LicenseState.DISABLED, 10 * 2);
|
||||
assertLazyConsumerPluginNotification(LicenseState.DISABLED, 10 * 2);
|
||||
assertLicenseeState(ID_1, LicenseState.DISABLED);
|
||||
assertLicenseeState(ID_2, LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
assertLicenseeState(LicenseState.DISABLED);
|
||||
}
|
||||
|
||||
private void startNodesWithConsumerPlugins(int nNodes, int trialLicenseDuration) {
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.license.plugin.consumer.LazyLicenseRegistrationPluginSe
|
|||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.LicensesMetaData;
|
||||
import org.elasticsearch.license.plugin.core.LicensesStatus;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
|
@ -219,7 +218,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
|
|||
|
||||
private void assertLicenseesStateEnabled() throws Exception {
|
||||
for (String id : PLUGINS) {
|
||||
assertLicenseeState(id, LicenseState.ENABLED);
|
||||
assertLicenseeState(LicenseState.ENABLED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -247,7 +247,7 @@ public abstract class AbstractCollectorTestCase extends MarvelIntegTestCase {
|
|||
private volatile License license;
|
||||
|
||||
@Override
|
||||
public List<String> licenseesWithState(LicenseState state) {
|
||||
public LicenseState licenseState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -146,12 +146,8 @@ public class LicenseIntegrationTests extends MarvelIntegTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<String> licenseesWithState(LicenseState state) {
|
||||
List<String> licenseesWithState = new ArrayList<>();
|
||||
for (Licensee licensee : licensees) {
|
||||
licenseesWithState.add(licensee.id());
|
||||
}
|
||||
return licenseesWithState;
|
||||
public LicenseState licenseState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue