listener) {
- if (licensee.isAvailable()) {
+ if (licenseState.isGraphAllowed()) {
new AsyncGraphAction(request, listener).start();
} else {
- listener.onFailure(LicenseUtils.newComplianceException(GraphLicensee.ID));
+ listener.onFailure(LicenseUtils.newComplianceException(Graph.NAME));
}
}
diff --git a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/GraphFeatureSetTests.java b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/GraphFeatureSetTests.java
index 56d3b949bbe..57e7ec8e60c 100644
--- a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/GraphFeatureSetTests.java
+++ b/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/GraphFeatureSetTests.java
@@ -7,9 +7,8 @@ package org.elasticsearch.xpack.graph;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.test.ESTestCase;
-import org.elasticsearch.xpack.graph.GraphFeatureSet;
-import org.elasticsearch.xpack.graph.GraphLicensee;
import org.junit.Before;
import static org.hamcrest.core.Is.is;
@@ -24,24 +23,24 @@ import static org.mockito.Mockito.when;
*/
public class GraphFeatureSetTests extends ESTestCase {
- private GraphLicensee licensee;
+ private XPackLicenseState licenseState;
private NamedWriteableRegistry namedWriteableRegistry;
@Before
public void init() throws Exception {
- licensee = mock(GraphLicensee.class);
+ licenseState = mock(XPackLicenseState.class);
namedWriteableRegistry = mock(NamedWriteableRegistry.class);
}
public void testWritableRegistration() throws Exception {
- new GraphFeatureSet(Settings.EMPTY, licensee, namedWriteableRegistry);
+ new GraphFeatureSet(Settings.EMPTY, licenseState, namedWriteableRegistry);
verify(namedWriteableRegistry).register(eq(GraphFeatureSet.Usage.class), eq("xpack.usage.graph"), anyObject());
}
public void testAvailable() throws Exception {
- GraphFeatureSet featureSet = new GraphFeatureSet(Settings.EMPTY, licensee, namedWriteableRegistry);
+ GraphFeatureSet featureSet = new GraphFeatureSet(Settings.EMPTY, licenseState, namedWriteableRegistry);
boolean available = randomBoolean();
- when(licensee.isAvailable()).thenReturn(available);
+ when(licenseState.isGraphAllowed()).thenReturn(available);
assertThat(featureSet.available(), is(available));
}
@@ -55,7 +54,7 @@ public class GraphFeatureSetTests extends ESTestCase {
} else {
settings.put("xpack.graph.enabled", enabled);
}
- GraphFeatureSet featureSet = new GraphFeatureSet(settings.build(), licensee, namedWriteableRegistry);
+ GraphFeatureSet featureSet = new GraphFeatureSet(settings.build(), licenseState, namedWriteableRegistry);
assertThat(featureSet.enabled(), is(enabled));
}
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
deleted file mode 100644
index 0ad59d8bc56..00000000000
--- a/elasticsearch/x-pack/graph/src/test/java/org/elasticsearch/xpack/graph/license/LicenseTests.java
+++ /dev/null
@@ -1,135 +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.license;
-
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.license.core.License.OperationMode;
-import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase;
-import org.elasticsearch.xpack.graph.GraphLicensee;
-
-import static org.hamcrest.Matchers.is;
-
-public class LicenseTests extends AbstractLicenseeTestCase {
-
- private SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry();
-
- public void testPlatinumTrialLicenseCanDoEverything() throws Exception {
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
-
- assertLicensePlatinumTrialBehaviour(graphLicensee);
- }
-
- public void testBasicLicenseIsDisabled() throws Exception {
- licenseeRegistry.setOperationMode(OperationMode.BASIC);
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
-
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
- }
-
- public void testStandardLicenseIsDisabled() throws Exception {
- licenseeRegistry.setOperationMode(OperationMode.STANDARD);
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
-
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
- }
-
- public void testNoLicenseDoesNotWork() {
- licenseeRegistry.setOperationMode(OperationMode.BASIC);
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
- licenseeRegistry.disable();
-
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
- }
-
- public void testExpiredPlatinumTrialLicenseIsRestricted() throws Exception {
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
- licenseeRegistry.disable();
-
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
- }
-
- public void testUpgradingFromBasicLicenseWorks() {
- licenseeRegistry.setOperationMode(OperationMode.BASIC);
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
-
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
-
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- assertLicensePlatinumTrialBehaviour(graphLicensee);
- }
-
- public void testDowngradingToBasicLicenseWorks() {
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
-
- assertLicensePlatinumTrialBehaviour(graphLicensee);
-
- licenseeRegistry.setOperationMode(OperationMode.BASIC);
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
- }
-
- public void testUpgradingFromStandardLicenseWorks() {
- licenseeRegistry.setOperationMode(OperationMode.STANDARD);
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
-
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
-
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- assertLicensePlatinumTrialBehaviour(graphLicensee);
- }
-
- public void testDowngradingToStandardLicenseWorks() {
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
-
- assertLicensePlatinumTrialBehaviour(graphLicensee);
-
- licenseeRegistry.setOperationMode(OperationMode.STANDARD);
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
- }
-
- public void testDowngradingToGoldLicenseWorks() {
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
-
- assertLicensePlatinumTrialBehaviour(graphLicensee);
-
- licenseeRegistry.setOperationMode(OperationMode.GOLD);
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
- }
-
- public void testUpgradingExpiredLicenseWorks() {
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
- licenseeRegistry.register(graphLicensee);
- licenseeRegistry.disable();
-
- assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
-
- licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
- assertLicensePlatinumTrialBehaviour(graphLicensee);
- }
-
- private void assertLicensePlatinumTrialBehaviour(GraphLicensee graphLicensee) {
- assertThat("Expected graph exploration to be allowed", graphLicensee.isAvailable(), is(true));
- }
-
- private void assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(GraphLicensee graphLicensee) {
- assertThat("Expected graph exploration not to be allowed", graphLicensee.isAvailable(), is(false));
- }
-}
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseAction.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseAction.java
similarity index 94%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseAction.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseAction.java
index 9bb72c3da4a..de356870fbb 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseAction.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseAction.java
@@ -3,7 +3,7 @@
* 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.action.delete;
+package org.elasticsearch.license;
import org.elasticsearch.action.Action;
import org.elasticsearch.client.ElasticsearchClient;
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseRequest.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseRequest.java
similarity index 94%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseRequest.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseRequest.java
index da52e8be014..29558cf9e42 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseRequest.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseRequest.java
@@ -3,7 +3,7 @@
* 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.action.delete;
+package org.elasticsearch.license;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseRequestBuilder.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseRequestBuilder.java
similarity index 94%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseRequestBuilder.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseRequestBuilder.java
index bbdc2574ca9..b554b005537 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseRequestBuilder.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseRequestBuilder.java
@@ -3,7 +3,7 @@
* 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.action.delete;
+package org.elasticsearch.license;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseResponse.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseResponse.java
similarity index 94%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseResponse.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseResponse.java
index 2b5d35edeae..c30890a0ff6 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/delete/DeleteLicenseResponse.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/DeleteLicenseResponse.java
@@ -3,7 +3,7 @@
* 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.action.delete;
+package org.elasticsearch.license;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.io.stream.StreamInput;
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/ExpirationCallback.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/ExpirationCallback.java
similarity index 98%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/ExpirationCallback.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/ExpirationCallback.java
index 4166ce3d423..4aab4114b01 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/ExpirationCallback.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/ExpirationCallback.java
@@ -3,7 +3,7 @@
* 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;
+package org.elasticsearch.license;
import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.unit.TimeValue;
@@ -12,7 +12,7 @@ import org.elasticsearch.xpack.scheduler.SchedulerEngine;
import java.util.UUID;
-public abstract class ExpirationCallback {
+abstract class ExpirationCallback {
static final String EXPIRATION_JOB_PREFIX = ".license_expiration_job_";
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseAction.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseAction.java
similarity index 94%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseAction.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseAction.java
index 805a45df6e6..47263410796 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseAction.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseAction.java
@@ -3,7 +3,7 @@
* 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.action.get;
+package org.elasticsearch.license;
import org.elasticsearch.action.Action;
import org.elasticsearch.client.ElasticsearchClient;
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequest.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseRequest.java
similarity index 91%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequest.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseRequest.java
index 499fdc68c2b..965308de0e4 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequest.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseRequest.java
@@ -3,7 +3,7 @@
* 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.action.get;
+package org.elasticsearch.license;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequestBuilder.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseRequestBuilder.java
similarity index 94%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequestBuilder.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseRequestBuilder.java
index 5b89c6a619c..7e92a54bce2 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequestBuilder.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseRequestBuilder.java
@@ -3,7 +3,7 @@
* 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.action.get;
+package org.elasticsearch.license;
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseResponse.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseResponse.java
similarity index 95%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseResponse.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseResponse.java
index 1d5b9a67cdf..171ccbbbdbb 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseResponse.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/GetLicenseResponse.java
@@ -3,7 +3,7 @@
* 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.action.get;
+package org.elasticsearch.license;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.io.stream.StreamInput;
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/LicenseService.java
similarity index 51%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicenseService.java
index 138f4c341a3..e1486dd119e 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/LicenseService.java
@@ -3,7 +3,7 @@
* 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;
+package org.elasticsearch.license;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
@@ -18,18 +18,18 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.component.Lifecycle;
-import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.joda.Joda;
import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.env.Environment;
import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.core.LicenseVerifier;
-import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
-import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
-import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
+import org.elasticsearch.license.core.OperationModeFileWatcher;
+import org.elasticsearch.watcher.ResourceWatcherService;
+import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.scheduler.SchedulerEngine;
import org.elasticsearch.xpack.support.clock.Clock;
@@ -40,41 +40,29 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
-import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
/**
- * 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)
+ * Service responsible for managing {@link LicensesMetaData}.
*
- * 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)}
+ * On the master node, the service handles updating the cluster state when a new license is registered.
+ * It also listens on all nodes for cluster state updates, and updates {@link XPackLicenseState} when
+ * the license changes are detected in the cluster state.
*/
-public class LicensesService extends AbstractLifecycleComponent implements ClusterStateListener, LicensesManagerService,
- LicenseeRegistry, SchedulerEngine.Listener {
+public class LicenseService extends AbstractLifecycleComponent implements ClusterStateListener, SchedulerEngine.Listener {
// pkg private for tests
static final TimeValue TRIAL_LICENSE_DURATION = TimeValue.timeValueHours(30 * 24);
+ /**
+ * Duration of grace period after a license has expired
+ */
+ static final TimeValue GRACE_PERIOD_DURATION = days(7);
+
private final ClusterService clusterService;
- /**
- * Currently active consumers to notify to
- */
- private final List registeredLicensees = new CopyOnWriteArrayList<>();
+ /** The xpack feature state to update when license changes are made. */
+ private final XPackLicenseState licenseState;
/**
* Currently active license
@@ -83,6 +71,11 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
private SchedulerEngine scheduler;
private final Clock clock;
+ /**
+ * File watcher for operation mode changes
+ */
+ private final OperationModeFileWatcher operationModeFileWatcher;
+
/**
* Callbacks to notify relative to license expiry
*/
@@ -93,125 +86,78 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
*/
private int trialLicenseMaxNodes = 1000;
- /**
- * Duration of grace period after a license has expired
- */
- public static final TimeValue GRACE_PERIOD_DURATION = days(7);
-
- private static final String LICENSE_JOB = "licenseJob";
+ public static final String LICENSE_JOB = "licenseJob";
private static final FormatDateTimeFormatter DATE_FORMATTER = Joda.forPattern("EEEE, MMMMM dd, yyyy", Locale.ROOT);
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 LicenseService(Settings settings, ClusterService clusterService, Clock clock, Environment env,
+ ResourceWatcherService resourceWatcherService, XPackLicenseState licenseState) {
super(settings);
this.clusterService = clusterService;
- populateExpirationCallbacks();
this.clock = clock;
this.scheduler = new SchedulerEngine(clock);
+ this.licenseState = licenseState;
+ this.operationModeFileWatcher = new OperationModeFileWatcher(resourceWatcherService,
+ XPackPlugin.resolveConfigFile(env, "license_mode"), logger, () -> updateLicenseState(getLicense()));
this.scheduler.register(this);
+ populateExpirationCallbacks();
+ }
+
+ private void logExpirationWarning(long expirationMillis, boolean expired) {
+ String expiredMsg = expired ? "will expire" : "expired";
+ String general = LoggerMessageFormat.format(null, "\n" +
+ "#\n" +
+ "# License [{}] on [{}]. If you have a new license, please update it.\n" +
+ "# Otherwise, please reach out to your support contact.\n" +
+ "# ", expiredMsg, DATE_FORMATTER.printer().print(expirationMillis));
+ if (expired) {
+ general = general.toUpperCase(Locale.ROOT);
+ }
+ StringBuilder builder = new StringBuilder(general);
+ builder.append(System.lineSeparator());
+ if (expired) {
+ builder.append("# COMMERCIAL PLUGINS OPERATING WITH REDUCED FUNCTIONALITY");
+ } else {
+ builder.append("# Commercial plugins operate with reduced functionality on license expiration:");
+ }
+ XPackLicenseState.EXPIRATION_MESSAGES.forEach((feature, messages) -> {
+ if (messages.length > 0) {
+ builder.append(System.lineSeparator());
+ builder.append("# - ");
+ builder.append(feature);
+ for (String message : messages) {
+ builder.append(System.lineSeparator());
+ builder.append("# - ");
+ builder.append(message);
+ }
+ }
+ });
+ logger.warn("{}", builder);
}
private void populateExpirationCallbacks() {
expirationCallbacks.add(new ExpirationCallback.Pre(days(7), days(25), days(1)) {
- @Override
- public void on(License license) {
- String general = LoggerMessageFormat.format(null, "\n" +
- "#\n" +
- "# License will expire on [{}]. If you have a new license, please update it.\n" +
- "# Otherwise, please reach out to your support contact.\n" +
- "# ", DATE_FORMATTER.printer().print(license.expiryDate()));
- if (!registeredLicensees.isEmpty()) {
- StringBuilder builder = new StringBuilder(general);
- builder.append(System.lineSeparator());
- builder.append("# Commercial plugins operate with reduced functionality on license " +
- "expiration:");
- for (InternalLicensee licensee : registeredLicensees) {
- if (licensee.expirationMessages().length > 0) {
- builder.append(System.lineSeparator());
- builder.append("# - ");
- builder.append(licensee.id());
- for (String message : licensee.expirationMessages()) {
- builder.append(System.lineSeparator());
- builder.append("# - ");
- builder.append(message);
- }
- }
- }
- logger.warn("{}", builder);
- } else {
- logger.warn("{}", general);
- }
- }
- }
- );
+ @Override
+ public void on(License license) {
+ logExpirationWarning(license.expiryDate(), false);
+ }
+ });
expirationCallbacks.add(new ExpirationCallback.Pre(days(0), days(7), TimeValue.timeValueMinutes(10)) {
- @Override
- public void on(License license) {
- String general = LoggerMessageFormat.format(null, "\n" +
- "#\n" +
- "# License will expire on [{}]. If you have a new license, please update it.\n" +
- "# Otherwise, please reach out to your support contact.\n" +
- "# ", DATE_FORMATTER.printer().print(license.expiryDate()));
- if (!registeredLicensees.isEmpty()) {
- StringBuilder builder = new StringBuilder(general);
- builder.append(System.lineSeparator());
- builder.append("# Commercial plugins operate with reduced functionality on license " +
- "expiration:");
- for (InternalLicensee licensee : registeredLicensees) {
- if (licensee.expirationMessages().length > 0) {
- builder.append(System.lineSeparator());
- builder.append("# - ");
- builder.append(licensee.id());
- for (String message : licensee.expirationMessages()) {
- builder.append(System.lineSeparator());
- builder.append("# - ");
- builder.append(message);
- }
- }
- }
- logger.warn("{}", builder.toString());
- } else {
- logger.warn("{}", general);
- }
- }
- }
- );
+ @Override
+ public void on(License license) {
+ logExpirationWarning(license.expiryDate(), false);
+ }
+ });
expirationCallbacks.add(new ExpirationCallback.Post(days(0), null, TimeValue.timeValueMinutes(10)) {
- @Override
- public void on(License license) {
- // logged when grace period begins
- String general = LoggerMessageFormat.format(null, "\n" +
- "#\n" +
- "# LICENSE EXPIRED ON [{}]. IF YOU HAVE A NEW LICENSE, PLEASE\n" +
- "# UPDATE IT. OTHERWISE, PLEASE REACH OUT TO YOUR SUPPORT CONTACT.\n" +
- "# ", DATE_FORMATTER.printer().print(license.expiryDate()));
- if (!registeredLicensees.isEmpty()) {
- StringBuilder builder = new StringBuilder(general);
- builder.append(System.lineSeparator());
- builder.append("# COMMERCIAL PLUGINS OPERATING WITH REDUCED FUNCTIONALITY");
- for (InternalLicensee licensee : registeredLicensees) {
- if (licensee.expirationMessages().length > 0) {
- builder.append(System.lineSeparator());
- builder.append("# - ");
- builder.append(licensee.id());
- for (String message : licensee.expirationMessages()) {
- builder.append(System.lineSeparator());
- builder.append("# - ");
- builder.append(message);
- }
- }
- }
- logger.warn("{}", builder.toString());
- } else {
- logger.warn("{}", general);
- }
- }
- }
- );
+ @Override
+ public void on(License license) {
+ // logged when grace period begins
+ logExpirationWarning(license.expiryDate(), true);
+ }
+ });
}
/**
@@ -227,22 +173,23 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
listener.onResponse(new PutLicenseResponse(true, LicensesStatus.EXPIRED));
} else {
if (!request.acknowledged()) {
+ // TODO: ack messages should be generated on the master, since another node's cluster state may be behind...
final License currentLicense = getLicense();
if (currentLicense != null) {
- Map acknowledgeMessages = new HashMap<>(registeredLicensees.size() + 1);
+ Map acknowledgeMessages = new HashMap<>();
if (!License.isAutoGeneratedLicense(currentLicense.signature()) // current license is not auto-generated
&& currentLicense.issueDate() > newLicense.issueDate()) { // and has a later issue date
- acknowledgeMessages.put("license",
- new String[]{"The new license is older than the currently installed license. Are you sure you want to " +
- "override the current license?"});
+ acknowledgeMessages.put("license", new String[]{
+ "The new license is older than the currently installed license. " +
+ "Are you sure you want to override the current license?"});
}
- for (InternalLicensee licensee : registeredLicensees) {
- String[] listenerAcknowledgeMessages = licensee.acknowledgmentMessages(currentLicense, newLicense);
- if (listenerAcknowledgeMessages.length > 0) {
- acknowledgeMessages.put(licensee.id(), listenerAcknowledgeMessages);
+ XPackLicenseState.ACKNOWLEDGMENT_MESSAGES.forEach((feature, ackMessages) -> {
+ String[] messages = ackMessages.apply(currentLicense.operationMode(), newLicense.operationMode());
+ if (messages.length > 0) {
+ acknowledgeMessages.put(feature, messages);
}
- }
- if (!acknowledgeMessages.isEmpty()) {
+ });
+ if (acknowledgeMessages.isEmpty() == false) {
// needs acknowledgement
listener.onResponse(new PutLicenseResponse(false, LicensesStatus.VALID, ACKNOWLEDGEMENT_HEADER,
acknowledgeMessages));
@@ -278,7 +225,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
if (licensesMetaData != null) {
final License license = licensesMetaData.getLicense();
if (event.getJobName().equals(LICENSE_JOB)) {
- notifyLicensees(license);
+ updateLicenseState(license);
} else if (event.getJobName().startsWith(ExpirationCallback.EXPIRATION_JOB_PREFIX)) {
expirationCallbacks.stream()
.filter(expirationCallback -> expirationCallback.getId().equals(event.getJobName()))
@@ -313,17 +260,6 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
});
}
- @Override
- public LicenseState licenseState() {
- if (registeredLicensees.size() > 0) {
- return registeredLicensees.get(0).currentLicenseState;
- } else {
- final License license = getLicense(clusterService.state().metaData().custom(LicensesMetaData.TYPE));
- return getLicenseState(license, clock.millis());
- }
- }
-
- @Override
public License getLicense() {
final License license = getLicense(clusterService.state().metaData().custom(LicensesMetaData.TYPE));
return license == LicensesMetaData.LICENSE_TOMBSTONE ? null : license;
@@ -377,15 +313,25 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
protected void doStart() throws ElasticsearchException {
clusterService.add(this);
scheduler.start(Collections.emptyList());
+ logger.debug("initializing license state");
+ final ClusterState clusterState = clusterService.state();
+ if (clusterService.lifecycleState() == Lifecycle.State.STARTED
+ && clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) == false
+ && clusterState.nodes().getMasterNode() != null) {
+ final LicensesMetaData currentMetaData = clusterState.metaData().custom(LicensesMetaData.TYPE);
+ if (clusterState.getNodes().isLocalNodeElectedMaster() &&
+ (currentMetaData == null || currentMetaData.getLicense() == null)) {
+ // triggers a cluster changed event
+ // eventually notifying the current licensee
+ registerTrialLicense();
+ }
+ }
}
@Override
protected void doStop() throws ElasticsearchException {
clusterService.remove(this);
scheduler.stop();
- // clear all handlers
- registeredLicensees.clear();
-
// clear current license
currentLicense.set(null);
}
@@ -430,54 +376,30 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
}
}
- private void notifyLicensees(final License license) {
+ protected void updateLicenseState(final License license) {
if (license == LicensesMetaData.LICENSE_TOMBSTONE) {
// implies license has been explicitly deleted
- // update licensee states
- registeredLicensees.forEach(InternalLicensee::onRemove);
+ licenseState.update(License.OperationMode.MISSING, false);
return;
}
if (license != null) {
- logger.debug("notifying [{}] listeners", registeredLicensees.size());
- switch (getLicenseState(license, clock.millis())) {
- case ENABLED:
- for (InternalLicensee licensee : registeredLicensees) {
- licensee.onChange(license, LicenseState.ENABLED);
- }
+ long time = clock.millis();
+ boolean active = time >= license.issueDate() &&
+ time < license.expiryDate() + GRACE_PERIOD_DURATION.getMillis();
+ licenseState.update(license.operationMode(), active);
+
+ if (active) {
+ if (time < license.expiryDate()) {
logger.debug("license [{}] - valid", license.uid());
- break;
- case GRACE_PERIOD:
- for (InternalLicensee licensee : registeredLicensees) {
- licensee.onChange(license, LicenseState.GRACE_PERIOD);
- }
+ } else {
logger.warn("license [{}] - grace", license.uid());
- break;
- case DISABLED:
- for (InternalLicensee licensee : registeredLicensees) {
- licensee.onChange(license, LicenseState.DISABLED);
- }
- logger.warn("license [{}] - expired", license.uid());
- break;
+ }
+ } else {
+ logger.warn("license [{}] - expired", license.uid());
}
}
}
- static LicenseState getLicenseState(final License license, long time) {
- if (license == null) {
- return LicenseState.DISABLED;
- }
- if (license.issueDate() > time) {
- return LicenseState.DISABLED;
- }
- if (license.expiryDate() > time) {
- return LicenseState.ENABLED;
- }
- if ((license.expiryDate() + GRACE_PERIOD_DURATION.getMillis()) > time) {
- return LicenseState.GRACE_PERIOD;
- }
- return LicenseState.DISABLED;
- }
-
/**
* Notifies registered licensees of license state change and/or new active license
* based on the license in currentLicensesMetaData
.
@@ -489,42 +411,42 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
// license can be null if the trial license is yet to be auto-generated
// in this case, it is a no-op
if (license != null) {
- notifyLicensees(license);
- if (license.equals(currentLicense.get()) == false) {
+ final License previousLicense = currentLicense.get();
+ if (license.equals(previousLicense) == false) {
currentLicense.set(license);
- scheduler.add(new SchedulerEngine.Job(LICENSE_JOB, new LicenseSchedule(license)));
+ license.setOperationModeFileWatcher(operationModeFileWatcher);
+ scheduler.add(new SchedulerEngine.Job(LICENSE_JOB, nextLicenseCheck(license)));
for (ExpirationCallback expirationCallback : expirationCallbacks) {
scheduler.add(new SchedulerEngine.Job(expirationCallback.getId(),
(startTime, now) ->
expirationCallback.nextScheduledTimeForExpiry(license.expiryDate(), startTime, now)));
}
+ if (previousLicense != null) {
+ // remove operationModeFileWatcher to gc the old license object
+ previousLicense.removeOperationModeFileWatcher();
+ }
}
+ updateLicenseState(license);
}
}
- @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");
+ // pkg private for tests
+ static SchedulerEngine.Schedule nextLicenseCheck(License license) {
+ return (startTime, time) -> {
+ if (time < license.issueDate()) {
+ // when we encounter a license with a future issue date
+ // which can happen with autogenerated license,
+ // we want to schedule a notification on the license issue date
+ // so the license is notificed once it is valid
+ // see https://github.com/elastic/x-plugins/issues/983
+ return license.issueDate();
+ } else if (time < license.expiryDate()) {
+ return license.expiryDate();
+ } else if (time < license.expiryDate() + GRACE_PERIOD_DURATION.getMillis()) {
+ return license.expiryDate() + GRACE_PERIOD_DURATION.getMillis();
}
- }
- logger.debug("registering licensee [{}]", licensee.id());
- registeredLicensees.add(new InternalLicensee(licensee));
- final ClusterState clusterState = clusterService.state();
- if (clusterService.lifecycleState() == Lifecycle.State.STARTED
- && clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) == false
- && clusterState.nodes().getMasterNode() != null) {
- final LicensesMetaData currentMetaData = clusterState.metaData().custom(LicensesMetaData.TYPE);
- if (clusterState.getNodes().isLocalNodeElectedMaster() &&
- (currentMetaData == null || currentMetaData.getLicense() == null)) {
- // triggers a cluster changed event
- // eventually notifying the current licensee
- registerTrialLicense();
- } else if (lifecycleState() == Lifecycle.State.STARTED) {
- notifyLicensees(currentMetaData.getLicense());
- }
- }
+ return -1; // license is expired, no need to check again
+ };
}
License getLicense(final LicensesMetaData metaData) {
@@ -532,7 +454,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
License license = metaData.getLicense();
if (license == LicensesMetaData.LICENSE_TOMBSTONE) {
return license;
- } else {
+ } else if (license != null) {
boolean autoGeneratedLicense = License.isAutoGeneratedLicense(license.signature());
if ((autoGeneratedLicense && TrialLicense.verify(license))
|| (!autoGeneratedLicense && LicenseVerifier.verifyLicense(license))) {
@@ -542,58 +464,4 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
}
return null;
}
-
- /**
- * Stores acknowledgement, expiration and license notification callbacks
- * for a registered listener
- */
- private class InternalLicensee {
- volatile License currentLicense = null;
- volatile LicenseState currentLicenseState = LicenseState.DISABLED;
- private final Licensee licensee;
-
- private InternalLicensee(Licensee licensee) {
- this.licensee = licensee;
- }
-
- @Override
- public String toString() {
- return "(listener: " + licensee.id() + ", state: " + currentLicenseState.name() + ")";
- }
-
- public String id() {
- return licensee.id();
- }
-
- public String[] expirationMessages() {
- return licensee.expirationMessages();
- }
-
- public String[] acknowledgmentMessages(License currentLicense, License newLicense) {
- return licensee.acknowledgmentMessages(currentLicense, newLicense);
- }
-
- public void onChange(License license, LicenseState state) {
- synchronized (this) {
- if (currentLicense == null // not yet initialized
- || !currentLicense.equals(license) // current license has changed
- || currentLicenseState != state) { // same license but state has changed
- logger.debug("licensee [{}] notified", licensee.id());
- licensee.onChange(new Licensee.Status(license.operationMode(), state));
- currentLicense = license;
- currentLicenseState = state;
- }
- }
- }
-
- public void onRemove() {
- synchronized (this) {
- if (currentLicense != null || currentLicenseState != LicenseState.DISABLED) {
- currentLicense = null;
- currentLicenseState = LicenseState.DISABLED;
- licensee.onChange(Licensee.Status.MISSING);
- }
- }
- }
- }
}
\ No newline at end of file
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicenseUtils.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicenseUtils.java
similarity index 96%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicenseUtils.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicenseUtils.java
index 2f7a3ca7470..42139471646 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicenseUtils.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicenseUtils.java
@@ -3,7 +3,7 @@
* 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;
+package org.elasticsearch.license;
import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.rest.RestStatus;
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesMetaData.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicensesMetaData.java
similarity index 98%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesMetaData.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicensesMetaData.java
index afba390049b..266d1c37aa9 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesMetaData.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicensesMetaData.java
@@ -3,7 +3,7 @@
* 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;
+package org.elasticsearch.license;
import org.apache.lucene.util.CollectionUtil;
import org.elasticsearch.Version;
@@ -32,7 +32,7 @@ import static org.elasticsearch.license.core.CryptUtils.encrypt;
/**
* Contains metadata about registered licenses
*/
-public class LicensesMetaData extends AbstractDiffable implements MetaData.Custom {
+class LicensesMetaData extends AbstractDiffable implements MetaData.Custom {
public static final String TYPE = "licenses";
diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesStatus.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicensesStatus.java
similarity index 94%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesStatus.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicensesStatus.java
index 3bd18d58770..91e0d7239cf 100644
--- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesStatus.java
+++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/LicensesStatus.java
@@ -3,7 +3,7 @@
* 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;
+package org.elasticsearch.license;
public enum LicensesStatus {
VALID((byte) 0),
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/Licensing.java
similarity index 57%
rename from elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java
rename to elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/Licensing.java
index 037c7b3b206..1e118485f2c 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/Licensing.java
@@ -3,37 +3,26 @@
* 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;
-
-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.common.inject.Module;
-import org.elasticsearch.common.settings.Setting;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
-import org.elasticsearch.license.plugin.action.delete.TransportDeleteLicenseAction;
-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;
-import org.elasticsearch.license.plugin.rest.RestGetLicenseAction;
-import org.elasticsearch.license.plugin.rest.RestPutLicenseAction;
-import org.elasticsearch.plugins.ActionPlugin;
-import org.elasticsearch.rest.RestHandler;
+package org.elasticsearch.license;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import org.elasticsearch.action.ActionRequest;
+import org.elasticsearch.action.ActionResponse;
+import org.elasticsearch.cluster.metadata.MetaData;
+import org.elasticsearch.cluster.service.ClusterService;
+import org.elasticsearch.common.inject.Module;
+import org.elasticsearch.common.settings.Setting;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.env.Environment;
+import org.elasticsearch.plugins.ActionPlugin;
+import org.elasticsearch.rest.RestHandler;
+import org.elasticsearch.watcher.ResourceWatcherService;
+import org.elasticsearch.xpack.support.clock.Clock;
+
import static java.util.Collections.emptyList;
import static org.elasticsearch.xpack.XPackPlugin.isTribeNode;
import static org.elasticsearch.xpack.XPackPlugin.transportClientMode;
@@ -42,7 +31,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 +40,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 +69,12 @@ 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 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();
+ public Collection