From f82fa65d7dff931725700e129123d43e60fca635 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 13 Jul 2016 14:23:23 -0700 Subject: [PATCH 1/3] Internal: Remove guice construction of most license classes This change removes some of the complexity around licensing classes in xpack. It removes the interfaces for registration and management so the remaining LicensesService class is the thing that components wanting to interact with the license should use. It also removes complexity around the Licensee interface, removing generics and the registration at construction time, as well as making the licensees no longer have a lifecycle. There is still more to be done with simplification of license classes construction, but this is a step towards a simpler world. Original commit: elastic/x-pack-elasticsearch@5307d67b5b687614c5cf95df6d49d17401db41b1 --- .../org/elasticsearch/xpack/graph/Graph.java | 16 ++-- .../xpack/graph/GraphLicensee.java | 9 +- .../xpack/graph/GraphModule.java | 35 -------- .../xpack/graph/license/LicenseTests.java | 75 +++++----------- .../license/plugin/Licensing.java | 43 ++++----- .../action/get/TransportGetLicenseAction.java | 12 +-- .../core/AbstractLicenseeComponent.java | 21 +---- .../license/plugin/core/LicenseeRegistry.java | 14 --- .../plugin/core/LicensesManagerService.java | 23 ----- .../license/plugin/core/LicensesService.java | 36 +++----- .../plugin/LicensesServiceClusterTests.java | 1 + .../license/plugin/TestUtils.java | 2 +- .../core/AbstractLicenseServiceTestCase.java | 7 +- .../plugin/core/AbstractLicenseeTestCase.java | 37 +++----- .../core/LicenseClusterChangeTests.java | 5 +- .../plugin/core/LicenseRegistrationTests.java | 11 +-- .../core/LicensesAcknowledgementTests.java | 12 ++- .../core/LicensesManagerServiceTests.java | 66 ++------------ .../core/LicensesNotificationTests.java | 11 +-- .../xpack/monitoring/Monitoring.java | 4 +- .../xpack/monitoring/MonitoringLicensee.java | 10 +-- .../xpack/monitoring/MonitoringModule.java | 3 +- .../cluster/ClusterStatsCollector.java | 10 +-- .../collector/AbstractCollectorTestCase.java | 89 +++++++++---------- .../cluster/ClusterStatsCollectorTests.java | 8 +- .../license/LicenseIntegrationTests.java | 60 ++++++------- .../license/MonitoringLicenseeTests.java | 7 +- .../xpack/security/Security.java | 16 ++-- .../xpack/security/SecurityLicensee.java | 21 +---- .../xpack/security/SecurityModule.java | 14 +-- .../integration/LicensingTests.java | 79 ++++++++-------- .../xpack/security/SecurityLicenseeTests.java | 28 +----- .../org/elasticsearch/xpack/XPackPlugin.java | 36 ++++---- .../elasticsearch/xpack/watcher/Watcher.java | 7 -- .../xpack/watcher/WatcherLicensee.java | 9 +- .../xpack/watcher/WatcherModule.java | 3 - .../xpack/watcher/license/LicenseTests.java | 20 ++--- 37 files changed, 291 insertions(+), 569 deletions(-) delete mode 100644 elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/GraphModule.java delete mode 100644 elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicenseeRegistry.java delete mode 100644 elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java index 9bc973d3219..c5c037d7653 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java @@ -9,6 +9,7 @@ import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.ActionPlugin; @@ -43,15 +44,12 @@ public class Graph extends Plugin implements ActionPlugin { } public Collection createGuiceModules() { - return Collections.singletonList(new GraphModule(enabled, transportClientMode)); - } - - @Override - public Collection> getGuiceServiceClasses() { - if (enabled == false|| transportClientMode) { - return Collections.emptyList(); - } - return Collections.singletonList(GraphLicensee.class); + return Collections.singletonList(b -> { + XPackPlugin.bindFeatureSet(b, GraphFeatureSet.class); + if (transportClientMode) { + b.bind(GraphLicensee.class).toProvider(Providers.of(null)); + } + }); } @Override diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/GraphLicensee.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/GraphLicensee.java index 01bf5f8e536..90518bc8cee 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/GraphLicensee.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/GraphLicensee.java @@ -6,21 +6,18 @@ package org.elasticsearch.xpack.graph; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; import org.elasticsearch.license.plugin.core.LicenseState; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; -public class GraphLicensee extends AbstractLicenseeComponent { +public class GraphLicensee extends AbstractLicenseeComponent { public static final String ID = Graph.NAME; - @Inject - public GraphLicensee(Settings settings, LicenseeRegistry clientService) { - super(settings, ID, clientService); + public GraphLicensee(Settings settings) { + super(settings, ID); } @Override diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/GraphModule.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/GraphModule.java deleted file mode 100644 index f4108bcd90a..00000000000 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/GraphModule.java +++ /dev/null @@ -1,35 +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.xpack.graph; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.util.Providers; -import org.elasticsearch.xpack.XPackPlugin; - -/** - * - */ -public class GraphModule extends AbstractModule { - - private final boolean enabled; - private final boolean transportClientNode; - - public GraphModule(boolean enabled, boolean transportClientNode) { - this.enabled = enabled; - this.transportClientNode = transportClientNode; - } - - @Override - protected void configure() { - XPackPlugin.bindFeatureSet(binder(), GraphFeatureSet.class); - if (enabled && transportClientNode == false) { - bind(GraphLicensee.class).asEagerSingleton(); - } else { - bind(GraphLicensee.class).toProvider(Providers.of(null)); - } - } - -} diff --git a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/license/LicenseTests.java b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/license/LicenseTests.java index 0ad59d8bc56..d68c5195402 100644 --- a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/license/LicenseTests.java +++ b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/license/LicenseTests.java @@ -14,114 +14,81 @@ import static org.hamcrest.Matchers.is; public class LicenseTests extends AbstractLicenseeTestCase { - private SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry(); + GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY); public void testPlatinumTrialLicenseCanDoEverything() throws Exception { - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); assertLicensePlatinumTrialBehaviour(graphLicensee); } public void testBasicLicenseIsDisabled() throws Exception { - licenseeRegistry.setOperationMode(OperationMode.BASIC); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - + setOperationMode(graphLicensee, OperationMode.BASIC); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); } public void testStandardLicenseIsDisabled() throws Exception { - licenseeRegistry.setOperationMode(OperationMode.STANDARD); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - + setOperationMode(graphLicensee, OperationMode.STANDARD); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); } public void testNoLicenseDoesNotWork() { - licenseeRegistry.setOperationMode(OperationMode.BASIC); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - licenseeRegistry.disable(); - + setOperationMode(graphLicensee, OperationMode.BASIC); + disable(graphLicensee); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); } public void testExpiredPlatinumTrialLicenseIsRestricted() throws Exception { - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - licenseeRegistry.disable(); - + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); + disable(graphLicensee); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); } public void testUpgradingFromBasicLicenseWorks() { - licenseeRegistry.setOperationMode(OperationMode.BASIC); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - + setOperationMode(graphLicensee, OperationMode.BASIC); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); assertLicensePlatinumTrialBehaviour(graphLicensee); } public void testDowngradingToBasicLicenseWorks() { - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); assertLicensePlatinumTrialBehaviour(graphLicensee); - licenseeRegistry.setOperationMode(OperationMode.BASIC); + setOperationMode(graphLicensee, OperationMode.BASIC); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); } public void testUpgradingFromStandardLicenseWorks() { - licenseeRegistry.setOperationMode(OperationMode.STANDARD); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - + setOperationMode(graphLicensee, OperationMode.STANDARD); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); assertLicensePlatinumTrialBehaviour(graphLicensee); } public void testDowngradingToStandardLicenseWorks() { - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); assertLicensePlatinumTrialBehaviour(graphLicensee); - licenseeRegistry.setOperationMode(OperationMode.STANDARD); + setOperationMode(graphLicensee, OperationMode.STANDARD); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); } public void testDowngradingToGoldLicenseWorks() { - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); assertLicensePlatinumTrialBehaviour(graphLicensee); - licenseeRegistry.setOperationMode(OperationMode.GOLD); + setOperationMode(graphLicensee, OperationMode.GOLD); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); } public void testUpgradingExpiredLicenseWorks() { - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); - GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(graphLicensee); - licenseeRegistry.disable(); - + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); + disable(graphLicensee); assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee); - licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode()); + setOperationMode(graphLicensee, randomTrialOrPlatinumMode()); assertLicensePlatinumTrialBehaviour(graphLicensee); } diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java index 037c7b3b206..4fcb7ee2fb1 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java @@ -8,8 +8,7 @@ package org.elasticsearch.license.plugin; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -19,8 +18,6 @@ import org.elasticsearch.license.plugin.action.get.GetLicenseAction; import org.elasticsearch.license.plugin.action.get.TransportGetLicenseAction; import org.elasticsearch.license.plugin.action.put.PutLicenseAction; import org.elasticsearch.license.plugin.action.put.TransportPutLicenseAction; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; -import org.elasticsearch.license.plugin.core.LicensesManagerService; import org.elasticsearch.license.plugin.core.LicensesMetaData; import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction; @@ -28,6 +25,12 @@ import org.elasticsearch.license.plugin.rest.RestGetLicenseAction; import org.elasticsearch.license.plugin.rest.RestPutLicenseAction; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.rest.RestHandler; +import org.elasticsearch.xpack.graph.GraphLicensee; +import org.elasticsearch.xpack.monitoring.MonitoringLicensee; +import org.elasticsearch.xpack.security.SecurityLicenseState; +import org.elasticsearch.xpack.security.SecurityLicensee; +import org.elasticsearch.xpack.support.clock.Clock; +import org.elasticsearch.xpack.watcher.WatcherLicensee; import java.util.Arrays; import java.util.Collection; @@ -42,7 +45,8 @@ import static org.elasticsearch.xpack.XPackPlugin.transportClientMode; public class Licensing implements ActionPlugin { public static final String NAME = "license"; - private final boolean isTransportClient; + protected final Settings settings; + protected final boolean isTransportClient; private final boolean isTribeNode; static { @@ -50,10 +54,15 @@ public class Licensing implements ActionPlugin { } public Licensing(Settings settings) { + this.settings = settings; isTransportClient = transportClientMode(settings); isTribeNode = isTribeNode(settings); } + public Collection nodeModules() { + return Collections.emptyList(); + } + @Override public List, ? extends ActionResponse>> getActions() { if (isTribeNode) { @@ -74,22 +83,16 @@ public class Licensing implements ActionPlugin { RestDeleteLicenseAction.class); } - public Collection> nodeServices() { - if (isTransportClient == false && isTribeNode == false) { - return Collections.>singletonList(LicensesService.class); - } - return Collections.emptyList(); - } + public Collection createComponents(ClusterService clusterService, Clock clock, + SecurityLicenseState securityLicenseState) { + SecurityLicensee securityLicensee = new SecurityLicensee(settings, securityLicenseState); + WatcherLicensee watcherLicensee = new WatcherLicensee(settings); + MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings); + GraphLicensee graphLicensee = new GraphLicensee(settings); + LicensesService licensesService = new LicensesService(settings, clusterService, clock, + Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee)); - public Collection nodeModules() { - if (isTransportClient == false && isTribeNode == false) { - return Collections.singletonList(b -> { - b.bind(LicensesService.class).asEagerSingleton(); - b.bind(LicenseeRegistry.class).to(LicensesService.class); - b.bind(LicensesManagerService.class).to(LicensesService.class); - }); - } - return Collections.emptyList(); + return Arrays.asList(licensesService, securityLicenseState, securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee); } public List> getSettings() { diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/TransportGetLicenseAction.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/TransportGetLicenseAction.java index 5028e9eb51e..dabb92ea841 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/TransportGetLicenseAction.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/TransportGetLicenseAction.java @@ -9,28 +9,28 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; -import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.license.plugin.core.LicensesManagerService; +import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; public class TransportGetLicenseAction extends TransportMasterNodeReadAction { - private final LicensesManagerService licensesManagerService; + private final LicensesService licensesService; @Inject public TransportGetLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService, - LicensesManagerService licensesManagerService, ThreadPool threadPool, ActionFilters actionFilters, + LicensesService licensesService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, GetLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, GetLicenseRequest::new); - this.licensesManagerService = licensesManagerService; + this.licensesService = licensesService; } @Override @@ -51,6 +51,6 @@ public class TransportGetLicenseAction extends TransportMasterNodeReadAction listener) throws ElasticsearchException { - listener.onResponse(new GetLicenseResponse(licensesManagerService.getLicense())); + listener.onResponse(new GetLicenseResponse(licensesService.getLicense())); } } diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/AbstractLicenseeComponent.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/AbstractLicenseeComponent.java index 73c62e780e5..5857f603ef8 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/AbstractLicenseeComponent.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/AbstractLicenseeComponent.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.license.plugin.core; +import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.settings.Settings; @@ -14,33 +15,17 @@ import java.util.concurrent.CopyOnWriteArrayList; /** * A supporting base class for injectable Licensee components. */ -public abstract class AbstractLicenseeComponent> extends AbstractLifecycleComponent - implements Licensee { +public abstract class AbstractLicenseeComponent extends AbstractComponent implements Licensee { private final String id; - private final LicenseeRegistry clientService; private final List listeners = new CopyOnWriteArrayList<>(); // we initialize the licensee state to enabled with trial operation mode protected volatile Status status = Status.ENABLED; - protected AbstractLicenseeComponent(Settings settings, String id, LicenseeRegistry clientService) { + protected AbstractLicenseeComponent(Settings settings, String id) { super(settings); this.id = id; - this.clientService = clientService; - } - - @Override - protected void doStart() { - clientService.register(this); - } - - @Override - protected void doStop() { - } - - @Override - protected void doClose() { } @Override diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicenseeRegistry.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicenseeRegistry.java deleted file mode 100644 index 53a855fa637..00000000000 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicenseeRegistry.java +++ /dev/null @@ -1,14 +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; - -public interface LicenseeRegistry { - - /** - * Registers a licensee for license notifications - */ - void register(Licensee licensee); -} diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java deleted file mode 100644 index 786f3dd970a..00000000000 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java +++ /dev/null @@ -1,23 +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 java.util.List; - -public interface LicensesManagerService { - - /** - * @return current {@link LicenseState} - */ - LicenseState licenseState(); - - /** - * @return the currently active license, or {@code null} if no license is currently installed - */ - License getLicense(); -} diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java index 138f4c341a3..2c313a5c09e 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java @@ -42,29 +42,20 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; /** * Service responsible for managing {@link LicensesMetaData} * Interfaces through which this is exposed are: - * - LicensesManagerService - responsible for managing signed and one-time-trial licenses * - LicensesClientService - responsible for listener registration of consumer plugin(s) *

- * Registration Scheme: - *

- * A consumer plugin is registered with {@link LicenseeRegistry#register(Licensee)} - * This method can be called at any time during the life-cycle of the consumer plugin. - * If the listener can not be registered immediately, it is queued up and registered on the first clusterChanged event with - * no {@link org.elasticsearch.gateway.GatewayService#STATE_NOT_RECOVERED_BLOCK} block - * Upon successful registration, the listeners are notified appropriately using the notification scheme - *

* Notification Scheme: *

* All registered listeners are notified of the current license upon registration or when a new license is installed in the cluster state. * When a new license is notified as enabled to the registered listener, a notification is scheduled at the time of license expiry. * Registered listeners are notified using {@link #onUpdate(LicensesMetaData)} */ -public class LicensesService extends AbstractLifecycleComponent implements ClusterStateListener, LicensesManagerService, - LicenseeRegistry, SchedulerEngine.Listener { +public class LicensesService extends AbstractLifecycleComponent implements ClusterStateListener, SchedulerEngine.Listener { // pkg private for tests static final TimeValue TRIAL_LICENSE_DURATION = TimeValue.timeValueHours(30 * 24); @@ -74,7 +65,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust /** * Currently active consumers to notify to */ - private final List registeredLicensees = new CopyOnWriteArrayList<>(); + private final List registeredLicensees; /** * Currently active license @@ -105,14 +96,15 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust private static final String ACKNOWLEDGEMENT_HEADER = "This license update requires acknowledgement. To acknowledge the license, " + "please read the following messages and update the license again, this time with the \"acknowledge=true\" parameter:"; - @Inject - public LicensesService(Settings settings, ClusterService clusterService, Clock clock) { + public LicensesService(Settings settings, ClusterService clusterService, Clock clock, + List registeredLicensees) { super(settings); this.clusterService = clusterService; populateExpirationCallbacks(); this.clock = clock; this.scheduler = new SchedulerEngine(clock); this.scheduler.register(this); + this.registeredLicensees = registeredLicensees.stream().map(InternalLicensee::new).collect(Collectors.toList()); } private void populateExpirationCallbacks() { @@ -313,7 +305,6 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust }); } - @Override public LicenseState licenseState() { if (registeredLicensees.size() > 0) { return registeredLicensees.get(0).currentLicenseState; @@ -323,7 +314,6 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust } } - @Override public License getLicense() { final License license = getLicense(clusterService.state().metaData().custom(LicensesMetaData.TYPE)); return license == LicensesMetaData.LICENSE_TOMBSTONE ? null : license; @@ -377,6 +367,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust protected void doStart() throws ElasticsearchException { clusterService.add(this); scheduler.start(Collections.emptyList()); + registeredLicensees.forEach(x -> initLicensee(x.licensee)); } @Override @@ -502,15 +493,8 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust } } - @Override - public void register(Licensee licensee) { - for (final InternalLicensee existingLicensee : registeredLicensees) { - if (existingLicensee.id().equals(licensee.id())) { - throw new IllegalStateException("listener: [" + licensee.id() + "] has been already registered"); - } - } - logger.debug("registering licensee [{}]", licensee.id()); - registeredLicensees.add(new InternalLicensee(licensee)); + private void initLicensee(Licensee licensee) { + logger.debug("initializing licensee [{}]", licensee.id()); final ClusterState clusterState = clusterService.state(); if (clusterService.lifecycleState() == Lifecycle.State.STARTED && clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) == false @@ -521,7 +505,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust // triggers a cluster changed event // eventually notifying the current licensee registerTrialLicense(); - } else if (lifecycleState() == Lifecycle.State.STARTED) { + } else { notifyLicensees(currentMetaData.getLicense()); } } diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTests.java index 1c2366eb8ad..f3bfeefa4b9 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTests.java @@ -176,6 +176,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest License putLicenses = generateSignedLicense(TimeValue.timeValueMinutes(1)); PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(cluster, PutLicenseAction.INSTANCE); putLicenseRequestBuilder.setLicense(putLicenses); + putLicenseRequestBuilder.setAcknowledge(true); final PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get(); assertThat(putLicenseResponse.isAcknowledged(), equalTo(true)); assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID)); diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/TestUtils.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/TestUtils.java index 31ed2b7e3b3..8904b90c086 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/TestUtils.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/TestUtils.java @@ -155,7 +155,7 @@ public class TestUtils { public static void registerAndAckSignedLicenses(final LicensesService licensesService, License license, final LicensesStatus expectedStatus) { - PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(license); + PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(license).acknowledge(true); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference status = new AtomicReference<>(); licensesService.registerLicense(putLicenseRequest, new ActionListener() { diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseServiceTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseServiceTestCase.java index 9f4c228aef6..a602aed030f 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseServiceTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseServiceTestCase.java @@ -5,6 +5,9 @@ */ package org.elasticsearch.license.plugin.core; +import java.util.Arrays; +import java.util.Collections; + import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; @@ -37,11 +40,11 @@ public abstract class AbstractLicenseServiceTestCase extends ESTestCase { public void init() throws Exception { clusterService = mock(ClusterService.class); clock = new ClockMock(); - licensesService = new LicensesService(Settings.EMPTY, clusterService, clock); discoveryNodes = mock(DiscoveryNodes.class); } - protected void setInitialState(License license) { + protected void setInitialState(License license, Licensee... licensees) { + licensesService = new LicensesService(Settings.EMPTY, clusterService, clock, Arrays.asList(licensees)); ClusterState state = mock(ClusterState.class); final ClusterBlocks noBlock = ClusterBlocks.builder().build(); when(state.blocks()).thenReturn(noBlock); diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java index b1dc8a942ae..6e7af417af6 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/AbstractLicenseeTestCase.java @@ -169,35 +169,18 @@ public abstract class AbstractLicenseeTestCase extends ESTestCase { return String.format(Locale.ROOT, "From [%s] to [%s]", fromMode, toMode); } - public static class SimpleLicenseeRegistry extends AbstractComponent implements LicenseeRegistry { - private final List licensees = new ArrayList<>(); - private OperationMode operationMode; + private OperationMode operationMode; - public SimpleLicenseeRegistry() { - super(Settings.EMPTY); - } + public void setOperationMode(Licensee licensee, OperationMode operationMode) { + this.operationMode = operationMode; + enable(licensee); + } - @Override - public void register(Licensee licensee) { - licensees.add(licensee); - enable(); - } + public void disable(Licensee licensee) { + licensee.onChange(new Licensee.Status(operationMode, LicenseState.DISABLED)); + } - public void enable() { - for (Licensee licensee : licensees) { - licensee.onChange(new Licensee.Status(operationMode, randomEnabledOrGracePeriodState())); - } - } - - public void disable() { - for (Licensee licensee : licensees) { - licensee.onChange(new Licensee.Status(operationMode, LicenseState.DISABLED)); - } - } - - public void setOperationMode(License.OperationMode operationMode) { - this.operationMode = operationMode; - enable(); - } + public void enable(Licensee licensee) { + licensee.onChange(new Licensee.Status(operationMode, randomEnabledOrGracePeriodState())); } } diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicenseClusterChangeTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicenseClusterChangeTests.java index 6a0c1168ecd..38b79988deb 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicenseClusterChangeTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicenseClusterChangeTests.java @@ -35,10 +35,9 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase { @Before public void setup() { - setInitialState(null); - licensesService.start(); licensee = new TestUtils.AssertingLicensee("LicenseClusterChangeTests", logger); - licensesService.register(licensee); + setInitialState(null, licensee); + licensesService.start(); } @After diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicenseRegistrationTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicenseRegistrationTests.java index 131bcb27269..cfe023f1b9b 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicenseRegistrationTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicenseRegistrationTests.java @@ -21,13 +21,11 @@ import static org.mockito.Mockito.when; public class LicenseRegistrationTests extends AbstractLicenseServiceTestCase { public void testTrialLicenseRequestOnEmptyLicenseState() throws Exception { - setInitialState(null); - when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true); - TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee( - "testTrialLicenseRequestOnEmptyLicenseState", logger); + "testTrialLicenseRequestOnEmptyLicenseState", logger); + setInitialState(null, licensee); + when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true); licensesService.start(); - licensesService.register(licensee); ClusterState state = ClusterState.builder(new ClusterName("a")).build(); ArgumentCaptor stateUpdater = ArgumentCaptor.forClass(ClusterStateUpdateTask.class); @@ -42,11 +40,10 @@ public class LicenseRegistrationTests extends AbstractLicenseServiceTestCase { } public void testNotificationOnRegistration() throws Exception { - setInitialState(TestUtils.generateSignedLicense(TimeValue.timeValueHours(2))); TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee( "testNotificationOnRegistration", logger); + setInitialState(TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)), licensee); licensesService.start(); - licensesService.register(licensee); assertThat(licensee.statuses.size(), equalTo(1)); final LicenseState licenseState = licensee.statuses.get(0).getLicenseState(); assertTrue(licenseState == LicenseState.ENABLED); diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesAcknowledgementTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesAcknowledgementTests.java index 68a896be279..ee951e4424d 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesAcknowledgementTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesAcknowledgementTests.java @@ -27,13 +27,13 @@ import static org.mockito.Mockito.verify; public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase { public void testAcknowledgment() throws Exception { - setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2))); - licensesService.start(); + String id = "testAcknowledgment"; String[] acknowledgeMessages = new String[] {"message"}; TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee(id, logger); + setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)), licensee); + licensesService.start(); licensee.setAcknowledgementMessages(acknowledgeMessages); - licensesService.register(licensee); // try installing a signed license License signedLicense = generateSignedLicense(TimeValue.timeValueHours(10)); PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense); @@ -57,8 +57,6 @@ public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase } public void testAcknowledgementMultipleLicensee() throws Exception { - setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2))); - licensesService.start(); String id1 = "testAcknowledgementMultipleLicensee_1"; String[] acknowledgeMessages1 = new String[] {"testAcknowledgementMultipleLicensee_1"}; String id2 = "testAcknowledgementMultipleLicensee_2"; @@ -67,8 +65,8 @@ public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase licensee1.setAcknowledgementMessages(acknowledgeMessages1); TestUtils.AssertingLicensee licensee2 = new TestUtils.AssertingLicensee(id2, logger); licensee2.setAcknowledgementMessages(acknowledgeMessages2); - licensesService.register(licensee1); - licensesService.register(licensee2); + setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)), licensee1, licensee2); + licensesService.start(); // try installing a signed license License signedLicense = generateSignedLicense(TimeValue.timeValueHours(10)); PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense); diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesManagerServiceTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesManagerServiceTests.java index b7d8f75afa2..b4195860c2c 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesManagerServiceTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesManagerServiceTests.java @@ -5,27 +5,27 @@ */ package org.elasticsearch.license.plugin.core; +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicBoolean; + import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.xpack.graph.Graph; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.TestUtils; import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest; -import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.xpack.security.Security; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.xpack.graph.Graph; +import org.elasticsearch.xpack.monitoring.Monitoring; +import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.watcher.Watcher; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicBoolean; - import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; @@ -116,9 +116,6 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase { LicensesService licensesService = getInstanceFromNode(LicensesService.class); ClusterService clusterService = getInstanceFromNode(ClusterService.class); - // generate a trial license for one feature - licensesService.register(new TestUtils.AssertingLicensee("", logger)); - // generate signed licenses License license = generateSignedLicense(TimeValue.timeValueHours(1)); TestUtils.registerAndAckSignedLicenses(licensesService, license, LicensesStatus.VALID); @@ -131,53 +128,6 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase { assertThat(licensesMetaData.getLicense(), equalTo(LicensesMetaData.LICENSE_TOMBSTONE)); } - public void testRemoveLicensesAndLicenseeNotification() throws Exception { - LicensesService licensesService = getInstanceFromNode(LicensesService.class); - licensesService.start(); - ClusterService clusterService = getInstanceFromNode(ClusterService.class); - - // generate a trial license for one feature - TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee("", logger); - licensesService.register(licensee); - - // we should get a trial license to begin with - assertBusy(new Runnable() { - @Override - public void run() { - assertThat(licensee.statuses, hasSize(1)); - assertThat(licensee.statuses.get(0).getMode(), is(License.OperationMode.TRIAL)); - assertThat(licensee.statuses.get(0).getLicenseState(), is(LicenseState.ENABLED)); - } - }); - - - // generate signed licenses - License license = generateSignedLicense("gold", TimeValue.timeValueHours(1)); - TestUtils.registerAndAckSignedLicenses(licensesService, license, LicensesStatus.VALID); - assertBusy(new Runnable() { - @Override - public void run() { - assertThat(licensee.statuses, hasSize(2)); - assertThat(licensee.statuses.get(1).getMode(), not(License.OperationMode.TRIAL)); - assertThat(licensee.statuses.get(1).getLicenseState(), is(LicenseState.ENABLED)); - } - }); - - // remove signed licenses - removeAndAckSignedLicenses(licensesService); - assertBusy(new Runnable() { - @Override - public void run() { - assertThat(licensee.statuses, hasSize(3)); - } - }); - LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); - assertThat(licensesMetaData.getLicense(), is(LicensesMetaData.LICENSE_TOMBSTONE)); - assertThat(licensee.statuses, hasSize(3)); - assertThat(licensee.statuses.get(2).getLicenseState(), is(LicenseState.DISABLED)); - assertThat(licensee.statuses.get(2).getMode(), is(License.OperationMode.MISSING)); - } - private void removeAndAckSignedLicenses(final LicensesService licensesService) { final CountDownLatch latch = new CountDownLatch(1); final AtomicBoolean success = new AtomicBoolean(false); diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesNotificationTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesNotificationTests.java index a6824ad5867..524059fafdf 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesNotificationTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesNotificationTests.java @@ -5,6 +5,8 @@ */ package org.elasticsearch.license.plugin.core; +import java.util.List; + import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.TestUtils; @@ -12,21 +14,20 @@ import org.elasticsearch.license.plugin.TestUtils.AssertingLicensee; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import java.util.List; - import static org.hamcrest.Matchers.equalTo; public class LicensesNotificationTests extends AbstractLicenseServiceTestCase { public void testLicenseNotification() throws Exception { final License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(48)); - setInitialState(license); - licensesService.start(); int nLicensee = randomIntBetween(1, 3); AssertingLicensee[] assertingLicensees = new AssertingLicensee[nLicensee]; for (int i = 0; i < assertingLicensees.length; i++) { assertingLicensees[i] = new AssertingLicensee("testLicenseNotification" + i, logger); - licensesService.register(assertingLicensees[i]); + } + setInitialState(license, assertingLicensees); + licensesService.start(); + for (int i = 0; i < assertingLicensees.length; i++) { assertLicenseStates(assertingLicensees[i], LicenseState.ENABLED); } clock.fastForward(TimeValue.timeValueMillis(license.expiryDate() - clock.millis())); diff --git a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java index e32e347ad11..bb359f5453c 100644 --- a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java +++ b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java @@ -78,9 +78,7 @@ public class Monitoring implements ActionPlugin { if (enabled == false || transportClientMode || tribeNode) { return Collections.emptyList(); } - return Arrays.>asList(MonitoringLicensee.class, - AgentService.class, - CleanerService.class); + return Arrays.>asList(AgentService.class, CleanerService.class); } @Override diff --git a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringLicensee.java b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringLicensee.java index 058bff4c18c..5b5ee9a59d1 100644 --- a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringLicensee.java +++ b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringLicensee.java @@ -6,15 +6,12 @@ package org.elasticsearch.xpack.monitoring; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; import org.elasticsearch.license.plugin.core.LicenseState; -import org.elasticsearch.license.plugin.core.Licensee; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; /** * {@code MonitoringLicensee} determines whether certain features of Monitoring are enabled or disabled. @@ -25,11 +22,10 @@ import org.elasticsearch.license.plugin.core.LicenseeRegistry; *

  • Cleaning up (deleting) older indices.
  • * */ -public class MonitoringLicensee extends AbstractLicenseeComponent implements Licensee { +public class MonitoringLicensee extends AbstractLicenseeComponent { - @Inject - public MonitoringLicensee(Settings settings, LicenseeRegistry clientService) { - super(settings, Monitoring.NAME, clientService); + public MonitoringLicensee(Settings settings) { + super(settings, Monitoring.NAME); } /** diff --git a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringModule.java b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringModule.java index 7234cfa8fe1..2f7162bd808 100644 --- a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringModule.java +++ b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringModule.java @@ -26,11 +26,10 @@ public class MonitoringModule extends AbstractModule { XPackPlugin.bindFeatureSet(binder(), MonitoringFeatureSet.class); if (enabled && transportClientMode == false) { - bind(MonitoringLicensee.class).asEagerSingleton(); bind(MonitoringSettings.class).asEagerSingleton(); bind(AgentService.class).asEagerSingleton(); bind(CleanerService.class).asEagerSingleton(); - } else { + } else if (transportClientMode) { bind(MonitoringLicensee.class).toProvider(Providers.of(null)); } } diff --git a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/agent/collector/cluster/ClusterStatsCollector.java b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/agent/collector/cluster/ClusterStatsCollector.java index efcdf64b0bb..a24cf9e5d7e 100644 --- a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/agent/collector/cluster/ClusterStatsCollector.java +++ b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/agent/collector/cluster/ClusterStatsCollector.java @@ -14,7 +14,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.plugin.core.LicenseUtils; -import org.elasticsearch.license.plugin.core.LicensesManagerService; +import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.xpack.monitoring.MonitoringLicensee; import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector; @@ -40,16 +40,16 @@ public class ClusterStatsCollector extends AbstractCollector { public static final String NAME = "cluster-stats-collector"; - private final LicensesManagerService licensesManagerService; + private final LicensesService licensesService; private final Client client; @Inject public ClusterStatsCollector(Settings settings, ClusterService clusterService, MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client, - LicensesManagerService licensesManagerService) { + LicensesService licensesService) { super(settings, NAME, clusterService, monitoringSettings, licensee); this.client = client; - this.licensesManagerService = licensesManagerService; + this.licensesService = licensesService; } @Override @@ -85,7 +85,7 @@ public class ClusterStatsCollector extends AbstractCollector { clusterInfoDoc.setSourceNode(sourceNode); clusterInfoDoc.setClusterName(clusterService.getClusterName().value()); clusterInfoDoc.setVersion(Version.CURRENT.toString()); - clusterInfoDoc.setLicense(licensesManagerService.getLicense()); + clusterInfoDoc.setLicense(licensesService.getLicense()); clusterInfoDoc.setClusterStats(clusterStats); results.add(clusterInfoDoc); diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/AbstractCollectorTestCase.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/AbstractCollectorTestCase.java index 4e140cce814..339d071c0e7 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/AbstractCollectorTestCase.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/AbstractCollectorTestCase.java @@ -5,43 +5,43 @@ */ package org.elasticsearch.xpack.monitoring.agent.collector; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; + import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.SysGlobals; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.block.ClusterBlocks; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.Licensing; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; -import org.elasticsearch.license.plugin.core.LicensesManagerService; +import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestHandler; -import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.xpack.graph.GraphLicensee; +import org.elasticsearch.xpack.monitoring.MonitoringLicensee; import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase; +import org.elasticsearch.xpack.security.InternalClient; +import org.elasticsearch.xpack.security.SecurityLicenseState; +import org.elasticsearch.xpack.support.clock.Clock; +import org.elasticsearch.xpack.watcher.WatcherLicensee; import org.junit.Before; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; - import static java.util.Collections.emptyList; import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes; @@ -110,7 +110,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) { service.onChange(license.operationMode(), LicenseState.ENABLED); } - for (LicensesManagerServiceForCollectors service : internalCluster().getInstances(LicensesManagerServiceForCollectors.class)) { + for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) { service.update(license); } } @@ -123,7 +123,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) { service.onChange(license.operationMode(), LicenseState.GRACE_PERIOD); } - for (LicensesManagerServiceForCollectors service : internalCluster().getInstances(LicensesManagerServiceForCollectors.class)) { + for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) { service.update(license); } } @@ -136,7 +136,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) { service.onChange(license.operationMode(), LicenseState.DISABLED); } - for (LicensesManagerServiceForCollectors service : internalCluster().getInstances(LicensesManagerServiceForCollectors.class)) { + for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) { service.update(license); } } @@ -149,7 +149,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) { service.onChange(license.operationMode(), LicenseState.DISABLED); } - for (LicensesManagerServiceForCollectors service : internalCluster().getInstances(LicensesManagerServiceForCollectors.class)) { + for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) { service.update(license); } } @@ -190,16 +190,18 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase @Override public Collection nodeModules() { - return Collections.singletonList(new AbstractModule() { + return Collections.singletonList(b -> b.bind(LicensesService.class).to(LicenseServiceForCollectors.class)); + } - @Override - protected void configure() { - bind(LicenseServiceForCollectors.class).asEagerSingleton(); - bind(LicenseeRegistry.class).to(LicenseServiceForCollectors.class); - bind(LicensesManagerServiceForCollectors.class).asEagerSingleton(); - bind(LicensesManagerService.class).to(LicensesManagerServiceForCollectors.class); - } - }); + @Override + public Collection createComponents(ClusterService clusterService, Clock clock, + SecurityLicenseState securityLicenseState) { + WatcherLicensee watcherLicensee = new WatcherLicensee(settings); + MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings); + GraphLicensee graphLicensee = new GraphLicensee(settings); + LicensesService licensesService = new LicenseServiceForCollectors(settings, + Arrays.asList(watcherLicensee, monitoringLicensee, graphLicensee)); + return Arrays.asList(licensesService, watcherLicensee, monitoringLicensee, graphLicensee); } @Override @@ -211,11 +213,6 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase public List> getRestHandlers() { return emptyList(); } - - @Override - public Collection> nodeServices() { - return Collections.emptyList(); - } } public static class InternalXPackPlugin extends XPackPlugin { @@ -226,18 +223,15 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase } } - public static class LicenseServiceForCollectors extends AbstractComponent implements LicenseeRegistry { + public static class LicenseServiceForCollectors extends LicensesService { - private final List licensees = new ArrayList<>(); + private final List licensees; + private volatile License license; @Inject - public LicenseServiceForCollectors(Settings settings) { - super(settings); - } - - @Override - public void register(Licensee licensee) { - licensees.add(licensee); + public LicenseServiceForCollectors(Settings settings, List licensees) { + super(settings, null, null, licensees); + this.licensees = licensees; } public void onChange(License.OperationMode operationMode, LicenseState state) { @@ -245,11 +239,6 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase licensee.onChange(new Licensee.Status(operationMode, state)); } } - } - - public static class LicensesManagerServiceForCollectors implements LicensesManagerService { - - private volatile License license; @Override public LicenseState licenseState() { @@ -264,5 +253,11 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase public synchronized void update(License license) { this.license = license; } + + @Override + protected void doStart() {} + + @Override + protected void doStop() {} } } diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/cluster/ClusterStatsCollectorTests.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/cluster/ClusterStatsCollectorTests.java index a54443e98e2..6bc24d3d12c 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/cluster/ClusterStatsCollectorTests.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/cluster/ClusterStatsCollectorTests.java @@ -5,11 +5,13 @@ */ package org.elasticsearch.xpack.monitoring.agent.collector.cluster; +import java.util.Collection; + import org.apache.lucene.util.LuceneTestCase.BadApple; import org.elasticsearch.Version; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.license.plugin.core.LicensesManagerService; +import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.xpack.monitoring.MonitoredSystem; import org.elasticsearch.xpack.monitoring.MonitoringLicensee; import org.elasticsearch.xpack.monitoring.MonitoringSettings; @@ -17,8 +19,6 @@ import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector; import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollectorTestCase; import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc; -import java.util.Collection; - import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasSize; @@ -133,7 +133,7 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase { internalCluster().getInstance(MonitoringSettings.class, nodeId), internalCluster().getInstance(MonitoringLicensee.class, nodeId), securedClient(nodeId), - internalCluster().getInstance(LicensesManagerService.class, nodeId)); + internalCluster().getInstance(LicensesService.class, nodeId)); } private void assertCanCollect(AbstractCollector collector, Class... classes) { diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/LicenseIntegrationTests.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/LicenseIntegrationTests.java index 6d2b17d60d7..745c664a1bf 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/LicenseIntegrationTests.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/LicenseIntegrationTests.java @@ -7,9 +7,7 @@ package org.elasticsearch.xpack.monitoring.license; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; @@ -17,14 +15,17 @@ import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.Licensing; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; -import org.elasticsearch.license.plugin.core.LicensesManagerService; +import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.xpack.graph.GraphLicensee; import org.elasticsearch.xpack.monitoring.MonitoringLicensee; import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase; +import org.elasticsearch.xpack.security.SecurityLicenseState; +import org.elasticsearch.xpack.support.clock.Clock; +import org.elasticsearch.xpack.watcher.WatcherLicensee; import java.io.IOException; import java.util.ArrayList; @@ -92,7 +93,18 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase { @Override public Collection nodeModules() { - return Collections.singletonList(new InternalLicenseModule()); + return Collections.singletonList(b -> b.bind(LicensesService.class).to(MockLicenseService.class)); + } + + @Override + public Collection createComponents(ClusterService clusterService, Clock clock, + SecurityLicenseState securityLicenseState) { + WatcherLicensee watcherLicensee = new WatcherLicensee(settings); + MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings); + GraphLicensee graphLicensee = new GraphLicensee(settings); + LicensesService licensesService = new MockLicenseService(settings, + Arrays.asList(watcherLicensee, monitoringLicensee, graphLicensee)); + return Arrays.asList(licensesService, watcherLicensee, monitoringLicensee, graphLicensee); } @Override @@ -104,36 +116,16 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase { public List> getRestHandlers() { return emptyList(); } - - @Override - public Collection> nodeServices() { - return Collections.emptyList(); - } - } - public static class InternalLicenseModule extends AbstractModule { - @Override - protected void configure() { - bind(MockLicenseService.class).asEagerSingleton(); - bind(LicenseeRegistry.class).to(MockLicenseService.class); - bind(LicensesManagerService.class).to(MockLicenseService.class); - } - } + public static class MockLicenseService extends LicensesService { - public static class MockLicenseService extends AbstractComponent implements LicenseeRegistry, LicensesManagerService { - - private final List licensees = new ArrayList<>(); + private final List licensees; @Inject - public MockLicenseService(Settings settings) { - super(settings); - enable(); - } - - @Override - public void register(Licensee licensee) { - licensees.add(licensee); + public MockLicenseService(Settings settings, List licensees) { + super(settings, null, null, licensees); + this.licensees = licensees; enable(); } @@ -159,6 +151,12 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase { public License getLicense() { return null; } + + @Override + protected void doStart() {} + + @Override + protected void doStop() {} } public static class InternalXPackPlugin extends XPackPlugin { diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/MonitoringLicenseeTests.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/MonitoringLicenseeTests.java index 837816ad1e4..b41353af1a9 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/MonitoringLicenseeTests.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/MonitoringLicenseeTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.license.core.License.OperationMode; 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.LicenseeRegistry; import org.elasticsearch.xpack.monitoring.MonitoringLicensee; import java.util.function.Predicate; @@ -18,7 +17,6 @@ import java.util.function.Predicate; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; /** @@ -27,8 +25,7 @@ import static org.mockito.Mockito.when; * If you change the behavior of these tests, then it means that licensing changes for Monitoring! */ public class MonitoringLicenseeTests extends AbstractLicenseeTestCase { - private final LicenseeRegistry registry = mock(LicenseeRegistry.class); - private final MonitoringLicensee licensee = new MonitoringLicensee(Settings.EMPTY, registry); + private final MonitoringLicensee licensee = new MonitoringLicensee(Settings.EMPTY); public void testAcknowledgementMessagesToAnyFromFreeIsNoOp() { assertEmptyAck(OperationMode.BASIC, randomMode(), licensee); @@ -93,7 +90,6 @@ public class MonitoringLicenseeTests extends AbstractLicenseeTestCase { assertThat(predicate.test(licensee), equalTo(expected)); verify(status).getLicenseState(); - verifyNoMoreInteractions(registry); } /** @@ -112,6 +108,5 @@ public class MonitoringLicenseeTests extends AbstractLicenseeTestCase { assertThat(predicate.test(licensee), equalTo(expected)); verify(status).getMode(); - verifyNoMoreInteractions(registry); } } diff --git a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java index 21d29bb730f..75a045081b6 100644 --- a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -118,7 +118,7 @@ public class Security implements ActionPlugin { private final Settings settings; private final boolean enabled; private final boolean transportClientMode; - private SecurityLicenseState securityLicenseState; + private final SecurityLicenseState securityLicenseState; private final CryptoService cryptoService; public Security(Settings settings, Environment env) throws IOException { @@ -131,12 +131,17 @@ public class Security implements ActionPlugin { } else { cryptoService = null; } + securityLicenseState = new SecurityLicenseState(); } public CryptoService getCryptoService() { return cryptoService; } + public SecurityLicenseState getSecurityLicenseState() { + return securityLicenseState; + } + public Collection nodeModules() { List modules = new ArrayList<>(); @@ -144,7 +149,7 @@ public class Security implements ActionPlugin { if (enabled == false) { return modules; } - modules.add(new SecurityModule(settings, securityLicenseState)); + modules.add(new SecurityModule(settings)); modules.add(new SecurityTransportModule(settings)); modules.add(new SSLModule(settings)); return modules; @@ -154,7 +159,7 @@ public class Security implements ActionPlugin { modules.add(new AuthorizationModule(settings)); if (enabled == false) { modules.add(b -> b.bind(CryptoService.class).toProvider(Providers.of(null))); - modules.add(new SecurityModule(settings, securityLicenseState)); + modules.add(new SecurityModule(settings)); modules.add(new AuditTrailModule(settings)); modules.add(new SecurityTransportModule(settings)); return modules; @@ -163,9 +168,9 @@ public class Security implements ActionPlugin { // we can't load that at construction time since the license plugin might not have been loaded at that point // which might not be the case during Plugin class instantiation. Once nodeModules are pulled // everything should have been loaded - securityLicenseState = new SecurityLicenseState(); + modules.add(b -> b.bind(CryptoService.class).toInstance(cryptoService)); - modules.add(new SecurityModule(settings, securityLicenseState)); + modules.add(new SecurityModule(settings)); modules.add(new AuditTrailModule(settings)); modules.add(new SecurityRestModule(settings)); modules.add(new SecurityActionModule(settings)); @@ -184,7 +189,6 @@ public class Security implements ActionPlugin { if (AuditTrailModule.fileAuditLoggingEnabled(settings) == true) { list.add(LoggingAuditTrail.class); } - list.add(SecurityLicensee.class); list.add(FileRolesStore.class); list.add(Realms.class); return list; diff --git a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/SecurityLicensee.java b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/SecurityLicensee.java index 95d9d8e5864..07cf91e5b78 100644 --- a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/SecurityLicensee.java +++ b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/SecurityLicensee.java @@ -5,26 +5,21 @@ */ package org.elasticsearch.xpack.security; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; -import org.elasticsearch.license.plugin.core.Licensee; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; /** * */ -public class SecurityLicensee extends AbstractLicenseeComponent implements Licensee { +public class SecurityLicensee extends AbstractLicenseeComponent { private final boolean isTribeNode; private final SecurityLicenseState securityLicenseState; - @Inject - public SecurityLicensee(Settings settings, LicenseeRegistry clientService, SecurityLicenseState securityLicenseState) { - super(settings, Security.NAME, clientService); + public SecurityLicensee(Settings settings, SecurityLicenseState securityLicenseState) { + super(settings, Security.NAME); this.securityLicenseState = securityLicenseState; this.isTribeNode = settings.getGroups("tribe", true).isEmpty() == false; } @@ -96,14 +91,4 @@ public class SecurityLicensee extends AbstractLicenseeComponentof(null)); - } - XPackPlugin.bindFeatureSet(binder(), SecurityFeatureSet.class); if (securityEnabled) { diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java index e3aa3ea06e8..1442faadabc 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java @@ -5,6 +5,13 @@ */ package org.elasticsearch.integration; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; @@ -19,10 +26,7 @@ import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; @@ -31,7 +35,7 @@ import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.Licensing; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; +import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestStatus; @@ -40,16 +44,16 @@ import org.elasticsearch.test.SecuritySettingsSource; import org.elasticsearch.transport.Transport; import org.elasticsearch.xpack.MockNettyPlugin; import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.xpack.graph.GraphLicensee; +import org.elasticsearch.xpack.monitoring.MonitoringLicensee; import org.elasticsearch.xpack.security.Security; +import org.elasticsearch.xpack.security.SecurityLicenseState; +import org.elasticsearch.xpack.security.SecurityLicensee; import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken; +import org.elasticsearch.xpack.support.clock.Clock; +import org.elasticsearch.xpack.watcher.WatcherLicensee; import org.junit.After; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - import static java.util.Collections.emptyList; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; @@ -231,7 +235,7 @@ public class LicensingTests extends SecurityIntegTestCase { } public static void disableLicensing(OperationMode operationMode) { - for (InternalLicenseeRegistry service : internalCluster().getInstances(InternalLicenseeRegistry.class)) { + for (TestLicensesService service : internalCluster().getInstances(TestLicensesService.class)) { service.disable(operationMode); } } @@ -241,7 +245,7 @@ public class LicensingTests extends SecurityIntegTestCase { } public static void enableLicensing(OperationMode operationMode) { - for (InternalLicenseeRegistry service : internalCluster().getInstances(InternalLicenseeRegistry.class)) { + for (TestLicensesService service : internalCluster().getInstances(TestLicensesService.class)) { service.enable(operationMode); } } @@ -250,7 +254,19 @@ public class LicensingTests extends SecurityIntegTestCase { @Override public Collection nodeModules() { - return Collections.singletonList(new InternalLicenseModule()); + return Collections.singletonList(b -> b.bind(LicensesService.class).to(TestLicensesService.class)); + } + + @Override + public Collection createComponents(ClusterService clusterService, Clock clock, + SecurityLicenseState securityLicenseState) { + SecurityLicensee securityLicensee = new SecurityLicensee(settings, securityLicenseState); + WatcherLicensee watcherLicensee = new WatcherLicensee(settings); + MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings); + GraphLicensee graphLicensee = new GraphLicensee(settings); + TestLicensesService licensesService = new TestLicensesService(settings, + Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee)); + return Arrays.asList(securityLicensee, licensesService, watcherLicensee, monitoringLicensee, graphLicensee, securityLicenseState); } public InternalLicensing() { @@ -266,11 +282,6 @@ public class LicensingTests extends SecurityIntegTestCase { public List> getRestHandlers() { return emptyList(); } - - @Override - public Collection> nodeServices() { - return Collections.emptyList(); - } } public static class InternalXPackPlugin extends XPackPlugin { @@ -281,27 +292,13 @@ public class LicensingTests extends SecurityIntegTestCase { } } - public static class InternalLicenseModule extends AbstractModule { - @Override - protected void configure() { - bind(InternalLicenseeRegistry.class).asEagerSingleton(); - bind(LicenseeRegistry.class).to(InternalLicenseeRegistry.class); - } - } + public static class TestLicensesService extends LicensesService { - public static class InternalLicenseeRegistry extends AbstractComponent implements LicenseeRegistry { + private final List licensees; - private final List licensees = new ArrayList<>(); - - @Inject - public InternalLicenseeRegistry(Settings settings) { - super(settings); - enable(OperationMode.BASIC); - } - - @Override - public void register(Licensee licensee) { - licensees.add(licensee); + public TestLicensesService(Settings settings, List licensees) { + super(settings, null, null, Collections.emptyList()); + this.licensees = licensees; enable(OperationMode.BASIC); } @@ -316,5 +313,11 @@ public class LicensingTests extends SecurityIntegTestCase { licensee.onChange(new Licensee.Status(operationMode, LicenseState.DISABLED)); } } + + @Override + protected void doStart() {} + + @Override + protected void doStop() {} } } diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/SecurityLicenseeTests.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/SecurityLicenseeTests.java index c221c7be83a..34b399548f3 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/SecurityLicenseeTests.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/SecurityLicenseeTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase; import org.elasticsearch.license.plugin.core.Licensee.Status; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; @@ -23,39 +22,18 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; */ public class SecurityLicenseeTests extends AbstractLicenseeTestCase { private final SecurityLicenseState securityLicenseState = mock(SecurityLicenseState.class); - private final LicenseeRegistry registry = mock(LicenseeRegistry.class); - - public void testStartsWithoutTribeNode() { - SecurityLicensee licensee = new SecurityLicensee(Settings.EMPTY, registry, securityLicenseState); - - // starting the Licensee start trigger it being registered - licensee.start(); - - verify(registry).register(licensee); - verifyNoMoreInteractions(registry, securityLicenseState); - } - - public void testDoesNotStartWithTribeNode() { - Settings settings = Settings.builder().put("tribe.fake.cluster.name", "notchecked").build(); - SecurityLicensee licensee = new SecurityLicensee(settings, registry, securityLicenseState); - - // starting the Licensee as a tribe node should not trigger it being registered - licensee.start(); - - verifyNoMoreInteractions(registry, securityLicenseState); - } public void testOnChangeModifiesSecurityLicenseState() { Status status = mock(Status.class); - SecurityLicensee licensee = new SecurityLicensee(Settings.EMPTY, registry, securityLicenseState); + SecurityLicensee licensee = new SecurityLicensee(Settings.EMPTY, securityLicenseState); licensee.onChange(status); assertSame(status, licensee.getStatus()); verify(securityLicenseState).updateStatus(status); - verifyNoMoreInteractions(registry, securityLicenseState); + verifyNoMoreInteractions(securityLicenseState); } public void testAcknowledgementMessagesFromBasicToAnyNotGoldOrStandardIsNoOp() { @@ -97,6 +75,6 @@ public class SecurityLicenseeTests extends AbstractLicenseeTestCase { } private SecurityLicensee buildLicensee() { - return new SecurityLicensee(Settings.EMPTY, registry, securityLicenseState); + return new SecurityLicensee(Settings.EMPTY, securityLicenseState); } } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 167cbfed764..b3e09c64c32 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -33,6 +33,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.IndexModule; import org.elasticsearch.license.plugin.Licensing; +import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; @@ -155,7 +156,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { ArrayList modules = new ArrayList<>(); modules.add(b -> b.bind(Clock.class).toInstance(getClock())); modules.addAll(notification.nodeModules()); - modules.addAll(licensing.nodeModules()); modules.addAll(security.nodeModules()); modules.addAll(watcher.nodeModules()); modules.addAll(monitoring.nodeModules()); @@ -163,6 +163,8 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { if (transportClientMode == false) { modules.add(new TextTemplateModule()); + // Note: this only exists so LicensesService subclasses can be bound in mock tests + modules.addAll(licensing.nodeModules()); } return modules; } @@ -171,28 +173,30 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { public Collection> getGuiceServiceClasses() { ArrayList> services = new ArrayList<>(); services.addAll(notification.nodeServices()); - services.addAll(licensing.nodeServices()); services.addAll(security.nodeServices()); - services.addAll(watcher.nodeServices()); services.addAll(monitoring.nodeServices()); - services.addAll(graph.getGuiceServiceClasses()); return services; } @Override public Collection createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, - ResourceWatcherService resourceWatcherService) { - List components = new ArrayList<>(); - if (transportClientMode == false) { - // watcher http stuff - Map httpAuthFactories = new HashMap<>(); - httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService())); - // TODO: add more auth types, or remove this indirection - HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories); - components.add(new HttpRequestTemplate.Parser(httpAuthRegistry)); - components.add(new HttpClient(settings, httpAuthRegistry, env)); + ResourceWatcherService resourceWatcherService) { + + if (transportClientMode) { + return Collections.emptyList(); } + List components = new ArrayList<>(); + components.addAll(licensing.createComponents(clusterService, getClock(), security.getSecurityLicenseState())); + + // watcher http stuff + Map httpAuthFactories = new HashMap<>(); + httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService())); + // TODO: add more auth types, or remove this indirection + HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories); + components.add(new HttpRequestTemplate.Parser(httpAuthRegistry)); + components.add(new HttpClient(settings, httpAuthRegistry, env)); + return components; } @@ -201,7 +205,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { Settings.Builder builder = Settings.builder(); builder.put(security.additionalSettings()); builder.put(watcher.additionalSettings()); - builder.put(graph.additionalSettings()); return builder.build(); } @@ -236,7 +239,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { filters.addAll(notification.getSettingsFilter()); filters.addAll(security.getSettingsFilter()); filters.addAll(MonitoringSettings.getSettingsFilter()); - filters.addAll(graph.getSettingsFilter()); return filters; } @@ -269,7 +271,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { filters.addAll(monitoring.getActionFilters()); filters.addAll(security.getActionFilters()); filters.addAll(watcher.getActionFilters()); - filters.addAll(graph.getActionFilters()); return filters; } @@ -294,7 +295,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { public void onIndexModule(IndexModule module) { security.onIndexModule(module); - graph.onIndexModule(module); } public static void bindFeatureSet(Binder binder, Class featureSet) { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 30e9654f19b..f2935bae084 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -126,13 +126,6 @@ public class Watcher implements ActionPlugin { return modules; } - public Collection> nodeServices() { - if (enabled == false|| transportClient) { - return Collections.emptyList(); - } - return Collections.singletonList(WatcherLicensee.class); - } - public Settings additionalSettings() { return Settings.EMPTY; } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLicensee.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLicensee.java index fe199d0241c..3c1c6f10a7a 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLicensee.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherLicensee.java @@ -6,21 +6,18 @@ package org.elasticsearch.xpack.watcher; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; import org.elasticsearch.license.plugin.core.LicenseState; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; -public class WatcherLicensee extends AbstractLicenseeComponent { +public class WatcherLicensee extends AbstractLicenseeComponent { public static final String ID = Watcher.NAME; - @Inject - public WatcherLicensee(Settings settings, LicenseeRegistry clientService) { - super(settings, ID, clientService); + public WatcherLicensee(Settings settings) { + super(settings, ID); } @Override diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherModule.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherModule.java index c656acfb661..f59bed1e194 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherModule.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherModule.java @@ -25,16 +25,13 @@ public class WatcherModule extends AbstractModule { @Override protected void configure() { if (transportClientMode) { - bind(WatcherLicensee.class).toProvider(Providers.of(null)); return; } if (enabled == false) { - bind(WatcherLicensee.class).toProvider(Providers.of(null)); // watcher service must be null, so that the watcher feature set can be instantiated even if watcher is not enabled bind(WatcherService.class).toProvider(Providers.of(null)); } else { - bind(WatcherLicensee.class).asEagerSingleton(); bind(WatcherLifeCycleService.class).asEagerSingleton(); bind(WatcherIndexTemplateRegistry.class).asEagerSingleton(); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/license/LicenseTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/license/LicenseTests.java index 4a34a5ab986..36caea8b0a3 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/license/LicenseTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/license/LicenseTests.java @@ -8,6 +8,8 @@ package org.elasticsearch.xpack.watcher.license; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License; 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 static org.elasticsearch.license.core.License.OperationMode.BASIC; @@ -19,7 +21,6 @@ import static org.hamcrest.Matchers.is; public class LicenseTests extends AbstractLicenseeTestCase { - private final SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry(); private WatcherLicensee watcherLicensee; public void testPlatinumGoldTrialLicenseCanDoEverything() throws Exception { @@ -34,14 +35,14 @@ public class LicenseTests extends AbstractLicenseeTestCase { public void testNoLicenseDisablesWatcher() { initLicense(BASIC, STANDARD); - licenseeRegistry.disable(); + disable(watcherLicensee); assertWatcherActionsNotAllowed(watcherLicensee); } public void testExpiredPlatinumGoldTrialLicenseDisablesWatcher() throws Exception { initLicense(TRIAL, GOLD, PLATINUM); - licenseeRegistry.disable(); + disable(watcherLicensee); assertWatcherActionsNotAllowed(watcherLicensee); } @@ -50,7 +51,7 @@ public class LicenseTests extends AbstractLicenseeTestCase { initLicense(BASIC, STANDARD); assertWatcherActionsNotAllowed(watcherLicensee); - licenseeRegistry.setOperationMode(randomFrom(TRIAL, GOLD, PLATINUM)); + setOperationMode(watcherLicensee, randomFrom(TRIAL, GOLD, PLATINUM)); assertWatcherActionsAllowed(watcherLicensee); } @@ -58,17 +59,17 @@ public class LicenseTests extends AbstractLicenseeTestCase { initLicense(TRIAL, GOLD, PLATINUM); assertWatcherActionsAllowed(watcherLicensee); - licenseeRegistry.setOperationMode(randomFrom(BASIC, STANDARD)); + setOperationMode(watcherLicensee, randomFrom(BASIC, STANDARD)); assertWatcherActionsNotAllowed(watcherLicensee); } public void testUpgradingExpiredLicenseWorks() { initLicense(TRIAL, GOLD, PLATINUM); - licenseeRegistry.disable(); + disable(watcherLicensee); assertWatcherActionsNotAllowed(watcherLicensee); - licenseeRegistry.setOperationMode(randomFrom(TRIAL, GOLD, PLATINUM)); + setOperationMode(watcherLicensee, randomFrom(TRIAL, GOLD, PLATINUM)); assertWatcherActionsAllowed(watcherLicensee); } @@ -87,8 +88,7 @@ public class LicenseTests extends AbstractLicenseeTestCase { } private void initLicense(License.OperationMode ... allowedLicenses) { - licenseeRegistry.setOperationMode(randomFrom(allowedLicenses)); - watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry); - licenseeRegistry.register(watcherLicensee); + watcherLicensee = new WatcherLicensee(Settings.EMPTY); + setOperationMode(watcherLicensee, randomFrom(allowedLicenses)); } } From 7f6788af1a10688662034b33569b4bca89222605 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 13 Jul 2016 17:05:32 -0700 Subject: [PATCH 2/3] Fix line length Original commit: elastic/x-pack-elasticsearch@50e9ef0667108f4225922e62126a39bcb7b714de --- .../java/org/elasticsearch/integration/LicensingTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java index 1442faadabc..4e906e35aca 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java @@ -266,7 +266,8 @@ public class LicensingTests extends SecurityIntegTestCase { GraphLicensee graphLicensee = new GraphLicensee(settings); TestLicensesService licensesService = new TestLicensesService(settings, Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee)); - return Arrays.asList(securityLicensee, licensesService, watcherLicensee, monitoringLicensee, graphLicensee, securityLicenseState); + return Arrays.asList(securityLicensee, licensesService, watcherLicensee, monitoringLicensee, + graphLicensee, securityLicenseState); } public InternalLicensing() { From 394a4fc0c1f9b65d2f7edc739654fa3b8916e36e Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 14 Jul 2016 19:55:10 -0700 Subject: [PATCH 3/3] Remove unused var Original commit: elastic/x-pack-elasticsearch@a0dd4600c279bc64195d7f1faee2c99a0c986cd9 --- .../java/org/elasticsearch/xpack/security/SecurityLicensee.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/SecurityLicensee.java b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/SecurityLicensee.java index 07cf91e5b78..dc25b44c09f 100644 --- a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/SecurityLicensee.java +++ b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/SecurityLicensee.java @@ -15,13 +15,11 @@ import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; */ public class SecurityLicensee extends AbstractLicenseeComponent { - private final boolean isTribeNode; private final SecurityLicenseState securityLicenseState; public SecurityLicensee(Settings settings, SecurityLicenseState securityLicenseState) { super(settings, Security.NAME); this.securityLicenseState = securityLicenseState; - this.isTribeNode = settings.getGroups("tribe", true).isEmpty() == false; } @Override