Merge pull request elastic/elasticsearch#2891 from rjernst/license_service_name

Rename LicensesService to LicenseService

Original commit: elastic/x-pack-elasticsearch@e9c3058ca1
This commit is contained in:
Ryan Ernst 2016-07-22 08:47:06 -07:00 committed by GitHub
commit dcb9145b93
22 changed files with 107 additions and 109 deletions

View File

@ -20,7 +20,7 @@ import org.elasticsearch.license.plugin.action.get.TransportGetLicenseAction;
import org.elasticsearch.license.plugin.action.put.PutLicenseAction; import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
import org.elasticsearch.license.plugin.action.put.TransportPutLicenseAction; import org.elasticsearch.license.plugin.action.put.TransportPutLicenseAction;
import org.elasticsearch.license.plugin.core.LicensesMetaData; import org.elasticsearch.license.plugin.core.LicensesMetaData;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction; import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction;
import org.elasticsearch.license.plugin.rest.RestGetLicenseAction; import org.elasticsearch.license.plugin.rest.RestGetLicenseAction;
import org.elasticsearch.license.plugin.rest.RestPutLicenseAction; import org.elasticsearch.license.plugin.rest.RestPutLicenseAction;
@ -92,11 +92,11 @@ public class Licensing implements ActionPlugin {
WatcherLicensee watcherLicensee = new WatcherLicensee(settings); WatcherLicensee watcherLicensee = new WatcherLicensee(settings);
MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings); MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings);
GraphLicensee graphLicensee = new GraphLicensee(settings); GraphLicensee graphLicensee = new GraphLicensee(settings);
LicensesService licensesService = new LicensesService(settings, clusterService, clock, LicenseService licenseService = new LicenseService(settings, clusterService, clock,
environment, resourceWatcherService, environment, resourceWatcherService,
Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee)); Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee));
return Arrays.asList(licensesService, securityLicenseState, securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee); return Arrays.asList(licenseService, securityLicenseState, securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee);
} }
public List<Setting<?>> getSettings() { public List<Setting<?>> getSettings() {

View File

@ -17,21 +17,21 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
public class TransportDeleteLicenseAction extends TransportMasterNodeAction<DeleteLicenseRequest, DeleteLicenseResponse> { public class TransportDeleteLicenseAction extends TransportMasterNodeAction<DeleteLicenseRequest, DeleteLicenseResponse> {
private final LicensesService licensesService; private final LicenseService licenseService;
@Inject @Inject
public TransportDeleteLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportDeleteLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
LicensesService licensesService, ThreadPool threadPool, ActionFilters actionFilters, LicenseService licenseService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) { IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, DeleteLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, super(settings, DeleteLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters,
indexNameExpressionResolver, DeleteLicenseRequest::new); indexNameExpressionResolver, DeleteLicenseRequest::new);
this.licensesService = licensesService; this.licenseService = licenseService;
} }
@Override @Override
@ -52,7 +52,7 @@ public class TransportDeleteLicenseAction extends TransportMasterNodeAction<Dele
@Override @Override
protected void masterOperation(final DeleteLicenseRequest request, ClusterState state, final ActionListener<DeleteLicenseResponse> protected void masterOperation(final DeleteLicenseRequest request, ClusterState state, final ActionListener<DeleteLicenseResponse>
listener) throws ElasticsearchException { listener) throws ElasticsearchException {
licensesService.removeLicense(request, new ActionListener<ClusterStateUpdateResponse>() { licenseService.removeLicense(request, new ActionListener<ClusterStateUpdateResponse>() {
@Override @Override
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
listener.onResponse(new DeleteLicenseResponse(clusterStateUpdateResponse.isAcknowledged())); listener.onResponse(new DeleteLicenseResponse(clusterStateUpdateResponse.isAcknowledged()));

View File

@ -16,21 +16,21 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
public class TransportGetLicenseAction extends TransportMasterNodeReadAction<GetLicenseRequest, GetLicenseResponse> { public class TransportGetLicenseAction extends TransportMasterNodeReadAction<GetLicenseRequest, GetLicenseResponse> {
private final LicensesService licensesService; private final LicenseService licenseService;
@Inject @Inject
public TransportGetLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportGetLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
LicensesService licensesService, ThreadPool threadPool, ActionFilters actionFilters, LicenseService licenseService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) { IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, GetLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, super(settings, GetLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver,
GetLicenseRequest::new); GetLicenseRequest::new);
this.licensesService = licensesService; this.licenseService = licenseService;
} }
@Override @Override
@ -51,6 +51,6 @@ public class TransportGetLicenseAction extends TransportMasterNodeReadAction<Get
@Override @Override
protected void masterOperation(final GetLicenseRequest request, ClusterState state, final ActionListener<GetLicenseResponse> protected void masterOperation(final GetLicenseRequest request, ClusterState state, final ActionListener<GetLicenseResponse>
listener) throws ElasticsearchException { listener) throws ElasticsearchException {
listener.onResponse(new GetLicenseResponse(licensesService.getLicense())); listener.onResponse(new GetLicenseResponse(licenseService.getLicense()));
} }
} }

View File

@ -16,21 +16,21 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
public class TransportPutLicenseAction extends TransportMasterNodeAction<PutLicenseRequest, PutLicenseResponse> { public class TransportPutLicenseAction extends TransportMasterNodeAction<PutLicenseRequest, PutLicenseResponse> {
private final LicensesService licensesService; private final LicenseService licenseService;
@Inject @Inject
public TransportPutLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportPutLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
LicensesService licensesService, ThreadPool threadPool, ActionFilters actionFilters, LicenseService licenseService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver) { IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, PutLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, super(settings, PutLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver,
PutLicenseRequest::new); PutLicenseRequest::new);
this.licensesService = licensesService; this.licenseService = licenseService;
} }
@Override @Override
@ -51,7 +51,7 @@ public class TransportPutLicenseAction extends TransportMasterNodeAction<PutLice
@Override @Override
protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener<PutLicenseResponse> protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener<PutLicenseResponse>
listener) throws ElasticsearchException { listener) throws ElasticsearchException {
licensesService.registerLicense(request, listener); licenseService.registerLicense(request, listener);
} }
} }

View File

@ -57,7 +57,7 @@ import java.util.stream.Collectors;
* When a new license is notified as enabled to the registered listener, a notification is scheduled at the time of license expiry. * 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)} * Registered listeners are notified using {@link #onUpdate(LicensesMetaData)}
*/ */
public class LicensesService extends AbstractLifecycleComponent implements ClusterStateListener, SchedulerEngine.Listener { public class LicenseService extends AbstractLifecycleComponent implements ClusterStateListener, SchedulerEngine.Listener {
// pkg private for tests // pkg private for tests
static final TimeValue TRIAL_LICENSE_DURATION = TimeValue.timeValueHours(30 * 24); static final TimeValue TRIAL_LICENSE_DURATION = TimeValue.timeValueHours(30 * 24);
@ -98,7 +98,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
private static final String ACKNOWLEDGEMENT_HEADER = "This license update requires acknowledgement. To acknowledge the license, " + 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:"; "please read the following messages and update the license again, this time with the \"acknowledge=true\" parameter:";
public LicensesService(Settings settings, ClusterService clusterService, Clock clock, Environment env, public LicenseService(Settings settings, ClusterService clusterService, Clock clock, Environment env,
ResourceWatcherService resourceWatcherService, List<Licensee> registeredLicensees) { ResourceWatcherService resourceWatcherService, List<Licensee> registeredLicensees) {
super(settings); super(settings);
this.clusterService = clusterService; this.clusterService = clusterService;

View File

@ -8,7 +8,7 @@ package org.elasticsearch.license.plugin.core;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License;
import static org.elasticsearch.license.plugin.core.LicensesService.days; import static org.elasticsearch.license.plugin.core.LicenseService.days;
/** /**
* States of a registered licensee * States of a registered licensee

View File

@ -10,8 +10,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.xpack.MockNetty3Plugin; import org.elasticsearch.xpack.MockNetty3Plugin;
@ -170,7 +170,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
private void assertLicenseState(LicenseState state) throws InterruptedException { private void assertLicenseState(LicenseState state) throws InterruptedException {
boolean success = awaitBusy(() -> { boolean success = awaitBusy(() -> {
for (LicensesService service : internalCluster().getDataNodeInstances(LicensesService.class)) { for (LicenseService service : internalCluster().getDataNodeInstances(LicenseService.class)) {
if (service.licenseeStatus().getLicenseState() == state) { if (service.licenseeStatus().getLicenseState() == state) {
return true; return true;
} }
@ -182,7 +182,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
private void assertOperationMode(License.OperationMode operationMode) throws InterruptedException { private void assertOperationMode(License.OperationMode operationMode) throws InterruptedException {
boolean success = awaitBusy(() -> { boolean success = awaitBusy(() -> {
for (LicensesService service : internalCluster().getDataNodeInstances(LicensesService.class)) { for (LicenseService service : internalCluster().getDataNodeInstances(LicenseService.class)) {
if (service.licenseeStatus().getMode() == operationMode) { if (service.licenseeStatus().getMode() == operationMode) {
return true; return true;
} }

View File

@ -21,8 +21,8 @@ import org.elasticsearch.license.core.License;
import org.elasticsearch.license.licensor.LicenseSigner; import org.elasticsearch.license.licensor.LicenseSigner;
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest; import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse; import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.Licensee;
import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.license.plugin.core.LicensesStatus; import org.elasticsearch.license.plugin.core.LicensesStatus;
import org.junit.Assert; import org.junit.Assert;
@ -146,12 +146,12 @@ public class TestUtils {
return PathUtils.get(TestUtils.class.getResource(resource).toURI()); return PathUtils.get(TestUtils.class.getResource(resource).toURI());
} }
public static void registerAndAckSignedLicenses(final LicensesService licensesService, License license, public static void registerAndAckSignedLicenses(final LicenseService licenseService, License license,
final LicensesStatus expectedStatus) { final LicensesStatus expectedStatus) {
PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(license).acknowledge(true); PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(license).acknowledge(true);
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<LicensesStatus> status = new AtomicReference<>(); final AtomicReference<LicensesStatus> status = new AtomicReference<>();
licensesService.registerLicense(putLicenseRequest, new ActionListener<PutLicenseResponse>() { licenseService.registerLicense(putLicenseRequest, new ActionListener<PutLicenseResponse>() {
@Override @Override
public void onResponse(PutLicenseResponse licensesUpdateResponse) { public void onResponse(PutLicenseResponse licensesUpdateResponse) {
status.set(licensesUpdateResponse.status()); status.set(licensesUpdateResponse.status());

View File

@ -35,7 +35,7 @@ import static org.mockito.Mockito.when;
public abstract class AbstractLicenseServiceTestCase extends ESTestCase { public abstract class AbstractLicenseServiceTestCase extends ESTestCase {
protected LicensesService licensesService; protected LicenseService licenseService;
protected ClusterService clusterService; protected ClusterService clusterService;
protected ResourceWatcherService resourceWatcherService; protected ResourceWatcherService resourceWatcherService;
protected ClockMock clock; protected ClockMock clock;
@ -54,7 +54,7 @@ public abstract class AbstractLicenseServiceTestCase extends ESTestCase {
protected void setInitialState(License license, Licensee... licensees) { protected void setInitialState(License license, Licensee... licensees) {
Path tempDir = createTempDir(); Path tempDir = createTempDir();
when(environment.configFile()).thenReturn(tempDir); when(environment.configFile()).thenReturn(tempDir);
licensesService = new LicensesService(Settings.EMPTY, clusterService, clock, environment, licenseService = new LicenseService(Settings.EMPTY, clusterService, clock, environment,
resourceWatcherService, Arrays.asList(licensees)); resourceWatcherService, Arrays.asList(licensees));
ClusterState state = mock(ClusterState.class); ClusterState state = mock(ClusterState.class);
final ClusterBlocks noBlock = ClusterBlocks.builder().build(); final ClusterBlocks noBlock = ClusterBlocks.builder().build();
@ -74,6 +74,6 @@ public abstract class AbstractLicenseServiceTestCase extends ESTestCase {
@After @After
public void after() { public void after() {
licensesService.stop(); licenseService.stop();
} }
} }

View File

@ -37,12 +37,12 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
public void setup() { public void setup() {
licensee = new TestUtils.AssertingLicensee("LicenseClusterChangeTests", logger); licensee = new TestUtils.AssertingLicensee("LicenseClusterChangeTests", logger);
setInitialState(null, licensee); setInitialState(null, licensee);
licensesService.start(); licenseService.start();
} }
@After @After
public void teardown() { public void teardown() {
licensesService.stop(); licenseService.stop();
} }
@ -51,7 +51,7 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
final License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(24)); final License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(24));
MetaData metaData = MetaData.builder().putCustom(LicensesMetaData.TYPE, new LicensesMetaData(license)).build(); MetaData metaData = MetaData.builder().putCustom(LicensesMetaData.TYPE, new LicensesMetaData(license)).build();
ClusterState newState = ClusterState.builder(new ClusterName("a")).metaData(metaData).build(); ClusterState newState = ClusterState.builder(new ClusterName("a")).metaData(metaData).build();
licensesService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState)); licenseService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState));
assertThat(licensee.statuses.size(), equalTo(1)); assertThat(licensee.statuses.size(), equalTo(1));
assertTrue(licensee.statuses.get(0).getLicenseState() == LicenseState.ENABLED); assertTrue(licensee.statuses.get(0).getLicenseState() == LicenseState.ENABLED);
} }
@ -61,7 +61,7 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
MetaData metaData = MetaData.builder().putCustom(LicensesMetaData.TYPE, new LicensesMetaData(license)).build(); MetaData metaData = MetaData.builder().putCustom(LicensesMetaData.TYPE, new LicensesMetaData(license)).build();
ClusterState newState = ClusterState.builder(new ClusterName("a")).metaData(metaData).build(); ClusterState newState = ClusterState.builder(new ClusterName("a")).metaData(metaData).build();
ClusterState oldState = ClusterState.builder(newState).build(); ClusterState oldState = ClusterState.builder(newState).build();
licensesService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState)); licenseService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState));
assertThat(licensee.statuses.size(), equalTo(0)); assertThat(licensee.statuses.size(), equalTo(0));
} }
@ -72,13 +72,13 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true); when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true);
ClusterState newState = ClusterState.builder(oldState).nodes(discoveryNodes).build(); ClusterState newState = ClusterState.builder(oldState).nodes(discoveryNodes).build();
licensesService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState)); licenseService.clusterChanged(new ClusterChangedEvent("simulated", newState, oldState));
ArgumentCaptor<ClusterStateUpdateTask> stateUpdater = ArgumentCaptor.forClass(ClusterStateUpdateTask.class); ArgumentCaptor<ClusterStateUpdateTask> stateUpdater = ArgumentCaptor.forClass(ClusterStateUpdateTask.class);
verify(clusterService, times(1)).submitStateUpdateTask(any(), stateUpdater.capture()); verify(clusterService, times(1)).submitStateUpdateTask(any(), stateUpdater.capture());
ClusterState stateWithLicense = stateUpdater.getValue().execute(newState); ClusterState stateWithLicense = stateUpdater.getValue().execute(newState);
LicensesMetaData licenseMetaData = stateWithLicense.metaData().custom(LicensesMetaData.TYPE); LicensesMetaData licenseMetaData = stateWithLicense.metaData().custom(LicensesMetaData.TYPE);
assertNotNull(licenseMetaData); assertNotNull(licenseMetaData);
assertNotNull(licenseMetaData.getLicense()); assertNotNull(licenseMetaData.getLicense());
assertEquals(clock.millis() + LicensesService.TRIAL_LICENSE_DURATION.millis(), licenseMetaData.getLicense().expiryDate()); assertEquals(clock.millis() + LicenseService.TRIAL_LICENSE_DURATION.millis(), licenseMetaData.getLicense().expiryDate());
} }
} }

View File

@ -25,7 +25,7 @@ public class LicenseRegistrationTests extends AbstractLicenseServiceTestCase {
"testTrialLicenseRequestOnEmptyLicenseState", logger); "testTrialLicenseRequestOnEmptyLicenseState", logger);
setInitialState(null, licensee); setInitialState(null, licensee);
when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true); when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true);
licensesService.start(); licenseService.start();
ClusterState state = ClusterState.builder(new ClusterName("a")).build(); ClusterState state = ClusterState.builder(new ClusterName("a")).build();
ArgumentCaptor<ClusterStateUpdateTask> stateUpdater = ArgumentCaptor.forClass(ClusterStateUpdateTask.class); ArgumentCaptor<ClusterStateUpdateTask> stateUpdater = ArgumentCaptor.forClass(ClusterStateUpdateTask.class);
@ -34,14 +34,14 @@ public class LicenseRegistrationTests extends AbstractLicenseServiceTestCase {
LicensesMetaData licenseMetaData = stateWithLicense.metaData().custom(LicensesMetaData.TYPE); LicensesMetaData licenseMetaData = stateWithLicense.metaData().custom(LicensesMetaData.TYPE);
assertNotNull(licenseMetaData); assertNotNull(licenseMetaData);
assertNotNull(licenseMetaData.getLicense()); assertNotNull(licenseMetaData.getLicense());
assertEquals(clock.millis() + LicensesService.TRIAL_LICENSE_DURATION.millis(), licenseMetaData.getLicense().expiryDate()); assertEquals(clock.millis() + LicenseService.TRIAL_LICENSE_DURATION.millis(), licenseMetaData.getLicense().expiryDate());
} }
public void testNotificationOnRegistration() throws Exception { public void testNotificationOnRegistration() throws Exception {
TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee( TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee(
"testNotificationOnRegistration", logger); "testNotificationOnRegistration", logger);
setInitialState(TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)), licensee); setInitialState(TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)), licensee);
licensesService.start(); licenseService.start();
assertThat(licensee.statuses.size(), equalTo(1)); assertThat(licensee.statuses.size(), equalTo(1));
final LicenseState licenseState = licensee.statuses.get(0).getLicenseState(); final LicenseState licenseState = licensee.statuses.get(0).getLicenseState();
assertTrue(licenseState == LicenseState.ENABLED); assertTrue(licenseState == LicenseState.ENABLED);

View File

@ -32,23 +32,23 @@ public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase
String[] acknowledgeMessages = new String[] {"message"}; String[] acknowledgeMessages = new String[] {"message"};
TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee(id, logger); TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee(id, logger);
setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)), licensee); setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)), licensee);
licensesService.start(); licenseService.start();
licensee.setAcknowledgementMessages(acknowledgeMessages); licensee.setAcknowledgementMessages(acknowledgeMessages);
// try installing a signed license // try installing a signed license
License signedLicense = generateSignedLicense(TimeValue.timeValueHours(10)); License signedLicense = generateSignedLicense(TimeValue.timeValueHours(10));
PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense); PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense);
// ensure acknowledgement message was part of the response // ensure acknowledgement message was part of the response
licensesService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(false, LicensesStatus.VALID, licenseService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(false, LicensesStatus.VALID,
Collections.singletonMap(id, acknowledgeMessages))); Collections.singletonMap(id, acknowledgeMessages)));
assertThat(licensee.acknowledgementRequested.size(), equalTo(1)); assertThat(licensee.acknowledgementRequested.size(), equalTo(1));
assertThat(licensee.acknowledgementRequested.get(0).v2(), equalTo(signedLicense.operationMode())); assertThat(licensee.acknowledgementRequested.get(0).v2(), equalTo(signedLicense.operationMode()));
assertThat(licensesService.getLicense(), not(signedLicense)); assertThat(licenseService.getLicense(), not(signedLicense));
// try installing a signed license with acknowledgement // try installing a signed license with acknowledgement
putLicenseRequest = new PutLicenseRequest().license(signedLicense).acknowledge(true); putLicenseRequest = new PutLicenseRequest().license(signedLicense).acknowledge(true);
// ensure license was installed and no acknowledgment message was returned // ensure license was installed and no acknowledgment message was returned
licensee.setAcknowledgementMessages(new String[0]); licensee.setAcknowledgementMessages(new String[0]);
licensesService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(true, LicensesStatus.VALID, licenseService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(true, LicensesStatus.VALID,
Collections.<String, String[]>emptyMap())); Collections.<String, String[]>emptyMap()));
verify(clusterService, times(1)).submitStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class)); verify(clusterService, times(1)).submitStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class));
assertThat(licensee.acknowledgementRequested.size(), equalTo(1)); assertThat(licensee.acknowledgementRequested.size(), equalTo(1));
@ -65,7 +65,7 @@ public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase
TestUtils.AssertingLicensee licensee2 = new TestUtils.AssertingLicensee(id2, logger); TestUtils.AssertingLicensee licensee2 = new TestUtils.AssertingLicensee(id2, logger);
licensee2.setAcknowledgementMessages(acknowledgeMessages2); licensee2.setAcknowledgementMessages(acknowledgeMessages2);
setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)), licensee1, licensee2); setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)), licensee1, licensee2);
licensesService.start(); licenseService.start();
// try installing a signed license // try installing a signed license
License signedLicense = generateSignedLicense(TimeValue.timeValueHours(10)); License signedLicense = generateSignedLicense(TimeValue.timeValueHours(10));
PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense); PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense);
@ -73,21 +73,21 @@ public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase
final HashMap<String, String[]> expectedMessages = new HashMap<>(); final HashMap<String, String[]> expectedMessages = new HashMap<>();
expectedMessages.put(id1, acknowledgeMessages1); expectedMessages.put(id1, acknowledgeMessages1);
expectedMessages.put(id2, acknowledgeMessages2); expectedMessages.put(id2, acknowledgeMessages2);
licensesService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(false, LicensesStatus.VALID, licenseService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(false, LicensesStatus.VALID,
expectedMessages)); expectedMessages));
verify(clusterService, times(0)).submitStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class)); verify(clusterService, times(0)).submitStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class));
assertThat(licensee2.acknowledgementRequested.size(), equalTo(1)); assertThat(licensee2.acknowledgementRequested.size(), equalTo(1));
assertThat(licensee2.acknowledgementRequested.get(0).v2(), equalTo(signedLicense.operationMode())); assertThat(licensee2.acknowledgementRequested.get(0).v2(), equalTo(signedLicense.operationMode()));
assertThat(licensee1.acknowledgementRequested.size(), equalTo(1)); assertThat(licensee1.acknowledgementRequested.size(), equalTo(1));
assertThat(licensee1.acknowledgementRequested.get(0).v2(), equalTo(signedLicense.operationMode())); assertThat(licensee1.acknowledgementRequested.get(0).v2(), equalTo(signedLicense.operationMode()));
assertThat(licensesService.getLicense(), not(signedLicense)); assertThat(licenseService.getLicense(), not(signedLicense));
// try installing a signed license with acknowledgement // try installing a signed license with acknowledgement
putLicenseRequest = new PutLicenseRequest().license(signedLicense).acknowledge(true); putLicenseRequest = new PutLicenseRequest().license(signedLicense).acknowledge(true);
// ensure license was installed and no acknowledgment message was returned // ensure license was installed and no acknowledgment message was returned
licensee1.setAcknowledgementMessages(new String[0]); licensee1.setAcknowledgementMessages(new String[0]);
licensee2.setAcknowledgementMessages(new String[0]); licensee2.setAcknowledgementMessages(new String[0]);
licensesService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(true, LicensesStatus.VALID, licenseService.registerLicense(putLicenseRequest, new AssertingLicensesUpdateResponse(true, LicensesStatus.VALID,
Collections.<String, String[]>emptyMap())); Collections.<String, String[]>emptyMap()));
verify(clusterService, times(1)).submitStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class)); verify(clusterService, times(1)).submitStateUpdateTask(any(String.class), any(ClusterStateUpdateTask.class));
} }

View File

@ -55,46 +55,46 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase {
} }
public void testStoreAndGetLicenses() throws Exception { public void testStoreAndGetLicenses() throws Exception {
LicensesService licensesService = getInstanceFromNode(LicensesService.class); LicenseService licenseService = getInstanceFromNode(LicenseService.class);
ClusterService clusterService = getInstanceFromNode(ClusterService.class); ClusterService clusterService = getInstanceFromNode(ClusterService.class);
License goldLicense = generateSignedLicense("gold", TimeValue.timeValueHours(1)); License goldLicense = generateSignedLicense("gold", TimeValue.timeValueHours(1));
TestUtils.registerAndAckSignedLicenses(licensesService, goldLicense, LicensesStatus.VALID); TestUtils.registerAndAckSignedLicenses(licenseService, goldLicense, LicensesStatus.VALID);
License silverLicense = generateSignedLicense("silver", TimeValue.timeValueHours(2)); License silverLicense = generateSignedLicense("silver", TimeValue.timeValueHours(2));
TestUtils.registerAndAckSignedLicenses(licensesService, silverLicense, LicensesStatus.VALID); TestUtils.registerAndAckSignedLicenses(licenseService, silverLicense, LicensesStatus.VALID);
License platinumLicense = generateSignedLicense("platinum", TimeValue.timeValueHours(1)); License platinumLicense = generateSignedLicense("platinum", TimeValue.timeValueHours(1));
TestUtils.registerAndAckSignedLicenses(licensesService, platinumLicense, LicensesStatus.VALID); TestUtils.registerAndAckSignedLicenses(licenseService, platinumLicense, LicensesStatus.VALID);
License basicLicense = generateSignedLicense("basic", TimeValue.timeValueHours(3)); License basicLicense = generateSignedLicense("basic", TimeValue.timeValueHours(3));
TestUtils.registerAndAckSignedLicenses(licensesService, basicLicense, LicensesStatus.VALID); TestUtils.registerAndAckSignedLicenses(licenseService, basicLicense, LicensesStatus.VALID);
LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
assertThat(licensesMetaData.getLicense(), equalTo(basicLicense)); assertThat(licensesMetaData.getLicense(), equalTo(basicLicense));
final License getLicenses = licensesService.getLicense(); final License getLicenses = licenseService.getLicense();
assertThat(getLicenses, equalTo(basicLicense)); assertThat(getLicenses, equalTo(basicLicense));
} }
public void testEffectiveLicenses() throws Exception { public void testEffectiveLicenses() throws Exception {
final LicensesService licensesService = getInstanceFromNode(LicensesService.class); final LicenseService licenseService = getInstanceFromNode(LicenseService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class); final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
License goldLicense = generateSignedLicense("gold", TimeValue.timeValueSeconds(5)); License goldLicense = generateSignedLicense("gold", TimeValue.timeValueSeconds(5));
// put gold license // put gold license
TestUtils.registerAndAckSignedLicenses(licensesService, goldLicense, LicensesStatus.VALID); TestUtils.registerAndAckSignedLicenses(licenseService, goldLicense, LicensesStatus.VALID);
LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
assertThat(licensesService.getLicense(licensesMetaData), equalTo(goldLicense)); assertThat(licenseService.getLicense(licensesMetaData), equalTo(goldLicense));
License platinumLicense = generateSignedLicense("platinum", TimeValue.timeValueSeconds(3)); License platinumLicense = generateSignedLicense("platinum", TimeValue.timeValueSeconds(3));
// put platinum license // put platinum license
TestUtils.registerAndAckSignedLicenses(licensesService, platinumLicense, LicensesStatus.VALID); TestUtils.registerAndAckSignedLicenses(licenseService, platinumLicense, LicensesStatus.VALID);
licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
assertThat(licensesService.getLicense(licensesMetaData), equalTo(platinumLicense)); assertThat(licenseService.getLicense(licensesMetaData), equalTo(platinumLicense));
License basicLicense = generateSignedLicense("basic", TimeValue.timeValueSeconds(3)); License basicLicense = generateSignedLicense("basic", TimeValue.timeValueSeconds(3));
// put basic license // put basic license
TestUtils.registerAndAckSignedLicenses(licensesService, basicLicense, LicensesStatus.VALID); TestUtils.registerAndAckSignedLicenses(licenseService, basicLicense, LicensesStatus.VALID);
licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
assertThat(licensesService.getLicense(licensesMetaData), equalTo(basicLicense)); assertThat(licenseService.getLicense(licensesMetaData), equalTo(basicLicense));
} }
public void testInvalidLicenseStorage() throws Exception { public void testInvalidLicenseStorage() throws Exception {
LicensesService licensesService = getInstanceFromNode(LicensesService.class); LicenseService licenseService = getInstanceFromNode(LicenseService.class);
ClusterService clusterService = getInstanceFromNode(ClusterService.class); ClusterService clusterService = getInstanceFromNode(ClusterService.class);
License signedLicense = generateSignedLicense(TimeValue.timeValueMinutes(2)); License signedLicense = generateSignedLicense(TimeValue.timeValueMinutes(2));
@ -105,7 +105,7 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase {
.validate() .validate()
.build(); .build();
TestUtils.registerAndAckSignedLicenses(licensesService, tamperedLicense, LicensesStatus.INVALID); TestUtils.registerAndAckSignedLicenses(licenseService, tamperedLicense, LicensesStatus.INVALID);
// ensure that the invalid license never made it to cluster state // ensure that the invalid license never made it to cluster state
LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
@ -113,25 +113,25 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase {
} }
public void testRemoveLicenses() throws Exception { public void testRemoveLicenses() throws Exception {
LicensesService licensesService = getInstanceFromNode(LicensesService.class); LicenseService licenseService = getInstanceFromNode(LicenseService.class);
ClusterService clusterService = getInstanceFromNode(ClusterService.class); ClusterService clusterService = getInstanceFromNode(ClusterService.class);
// generate signed licenses // generate signed licenses
License license = generateSignedLicense(TimeValue.timeValueHours(1)); License license = generateSignedLicense(TimeValue.timeValueHours(1));
TestUtils.registerAndAckSignedLicenses(licensesService, license, LicensesStatus.VALID); TestUtils.registerAndAckSignedLicenses(licenseService, license, LicensesStatus.VALID);
LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
assertThat(licensesMetaData.getLicense(), not(LicensesMetaData.LICENSE_TOMBSTONE)); assertThat(licensesMetaData.getLicense(), not(LicensesMetaData.LICENSE_TOMBSTONE));
// remove signed licenses // remove signed licenses
removeAndAckSignedLicenses(licensesService); removeAndAckSignedLicenses(licenseService);
licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
assertThat(licensesMetaData.getLicense(), equalTo(LicensesMetaData.LICENSE_TOMBSTONE)); assertThat(licensesMetaData.getLicense(), equalTo(LicensesMetaData.LICENSE_TOMBSTONE));
} }
private void removeAndAckSignedLicenses(final LicensesService licensesService) { private void removeAndAckSignedLicenses(final LicenseService licenseService) {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean success = new AtomicBoolean(false); final AtomicBoolean success = new AtomicBoolean(false);
licensesService.removeLicense(new DeleteLicenseRequest(), new ActionListener<ClusterStateUpdateResponse>() { licenseService.removeLicense(new DeleteLicenseRequest(), new ActionListener<ClusterStateUpdateResponse>() {
@Override @Override
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
if (clusterStateUpdateResponse.isAcknowledged()) { if (clusterStateUpdateResponse.isAcknowledged()) {

View File

@ -26,19 +26,19 @@ public class LicensesNotificationTests extends AbstractLicenseServiceTestCase {
assertingLicensees[i] = new AssertingLicensee("testLicenseNotification" + i, logger); assertingLicensees[i] = new AssertingLicensee("testLicenseNotification" + i, logger);
} }
setInitialState(license, assertingLicensees); setInitialState(license, assertingLicensees);
licensesService.start(); licenseService.start();
for (int i = 0; i < assertingLicensees.length; i++) { for (int i = 0; i < assertingLicensees.length; i++) {
assertLicenseStates(assertingLicensees[i], LicenseState.ENABLED); assertLicenseStates(assertingLicensees[i], LicenseState.ENABLED);
} }
clock.fastForward(TimeValue.timeValueMillis(license.expiryDate() - clock.millis())); clock.fastForward(TimeValue.timeValueMillis(license.expiryDate() - clock.millis()));
final LicensesMetaData licensesMetaData = new LicensesMetaData(license); final LicensesMetaData licensesMetaData = new LicensesMetaData(license);
licensesService.onUpdate(licensesMetaData); licenseService.onUpdate(licensesMetaData);
for (AssertingLicensee assertingLicensee : assertingLicensees) { for (AssertingLicensee assertingLicensee : assertingLicensees) {
assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD); assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD);
} }
clock.fastForward(TimeValue.timeValueMillis((license.expiryDate() + clock.fastForward(TimeValue.timeValueMillis((license.expiryDate() +
LicenseState.GRACE_PERIOD_DURATION.getMillis()) - clock.millis())); LicenseState.GRACE_PERIOD_DURATION.getMillis()) - clock.millis()));
licensesService.onUpdate(licensesMetaData); licenseService.onUpdate(licensesMetaData);
for (AssertingLicensee assertingLicensee : assertingLicensees) { for (AssertingLicensee assertingLicensee : assertingLicensees) {
assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD, LicenseState.DISABLED); assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD, LicenseState.DISABLED);
} }
@ -46,7 +46,7 @@ public class LicensesNotificationTests extends AbstractLicenseServiceTestCase {
final License newLicense = TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)); final License newLicense = TestUtils.generateSignedLicense(TimeValue.timeValueHours(2));
clock.fastForward(TimeValue.timeValueHours(1)); clock.fastForward(TimeValue.timeValueHours(1));
LicensesMetaData licensesMetaData1 = new LicensesMetaData(newLicense); LicensesMetaData licensesMetaData1 = new LicensesMetaData(newLicense);
licensesService.onUpdate(licensesMetaData1); licenseService.onUpdate(licensesMetaData1);
for (AssertingLicensee assertingLicensee : assertingLicensees) { for (AssertingLicensee assertingLicensee : assertingLicensees) {
assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD, LicenseState.DISABLED, assertLicenseStates(assertingLicensee, LicenseState.ENABLED, LicenseState.GRACE_PERIOD, LicenseState.DISABLED,
LicenseState.ENABLED); LicenseState.ENABLED);

View File

@ -14,7 +14,7 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicenseUtils; import org.elasticsearch.license.plugin.core.LicenseUtils;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.xpack.monitoring.MonitoringLicensee; import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.MonitoringSettings;
import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector; 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"; public static final String NAME = "cluster-stats-collector";
private final LicensesService licensesService; private final LicenseService licenseService;
private final Client client; private final Client client;
@Inject @Inject
public ClusterStatsCollector(Settings settings, ClusterService clusterService, public ClusterStatsCollector(Settings settings, ClusterService clusterService,
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client, MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client,
LicensesService licensesService) { LicenseService licenseService) {
super(settings, NAME, clusterService, monitoringSettings, licensee); super(settings, NAME, clusterService, monitoringSettings, licensee);
this.client = client; this.client = client;
this.licensesService = licensesService; this.licenseService = licenseService;
} }
@Override @Override
@ -85,7 +85,7 @@ public class ClusterStatsCollector extends AbstractCollector {
clusterInfoDoc.setSourceNode(sourceNode); clusterInfoDoc.setSourceNode(sourceNode);
clusterInfoDoc.setClusterName(clusterService.getClusterName().value()); clusterInfoDoc.setClusterName(clusterService.getClusterName().value());
clusterInfoDoc.setVersion(Version.CURRENT.toString()); clusterInfoDoc.setVersion(Version.CURRENT.toString());
clusterInfoDoc.setLicense(licensesService.getLicense()); clusterInfoDoc.setLicense(licenseService.getLicense());
clusterInfoDoc.setClusterStats(clusterStats); clusterInfoDoc.setClusterStats(clusterStats);
results.add(clusterInfoDoc); results.add(clusterInfoDoc);

View File

@ -25,9 +25,9 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.Licensing; import org.elasticsearch.license.plugin.Licensing;
import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.Licensee;
import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
@ -192,7 +192,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
@Override @Override
public Collection<Module> nodeModules() { public Collection<Module> nodeModules() {
return Collections.singletonList(b -> b.bind(LicensesService.class).to(LicenseServiceForCollectors.class)); return Collections.singletonList(b -> b.bind(LicenseService.class).to(LicenseServiceForCollectors.class));
} }
@Override @Override
@ -202,9 +202,9 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
WatcherLicensee watcherLicensee = new WatcherLicensee(settings); WatcherLicensee watcherLicensee = new WatcherLicensee(settings);
MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings); MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings);
GraphLicensee graphLicensee = new GraphLicensee(settings); GraphLicensee graphLicensee = new GraphLicensee(settings);
LicensesService licensesService = new LicenseServiceForCollectors(settings, environment, LicenseService licenseService = new LicenseServiceForCollectors(settings, environment,
resourceWatcherService, Arrays.asList(watcherLicensee, monitoringLicensee, graphLicensee)); resourceWatcherService, Arrays.asList(watcherLicensee, monitoringLicensee, graphLicensee));
return Arrays.asList(licensesService, watcherLicensee, monitoringLicensee, graphLicensee); return Arrays.asList(licenseService, watcherLicensee, monitoringLicensee, graphLicensee);
} }
@Override @Override
@ -226,7 +226,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
} }
} }
public static class LicenseServiceForCollectors extends LicensesService { public static class LicenseServiceForCollectors extends LicenseService {
private final List<Licensee> licensees; private final List<Licensee> licensees;
private volatile License license; private volatile License license;

View File

@ -11,7 +11,7 @@ import org.apache.lucene.util.LuceneTestCase.BadApple;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.xpack.monitoring.MonitoredSystem; import org.elasticsearch.xpack.monitoring.MonitoredSystem;
import org.elasticsearch.xpack.monitoring.MonitoringLicensee; import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.MonitoringSettings;
@ -133,7 +133,7 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
internalCluster().getInstance(MonitoringSettings.class, nodeId), internalCluster().getInstance(MonitoringSettings.class, nodeId),
internalCluster().getInstance(MonitoringLicensee.class, nodeId), internalCluster().getInstance(MonitoringLicensee.class, nodeId),
securedClient(nodeId), securedClient(nodeId),
internalCluster().getInstance(LicensesService.class, nodeId)); internalCluster().getInstance(LicenseService.class, nodeId));
} }
private void assertCanCollect(AbstractCollector collector, Class<?>... classes) { private void assertCanCollect(AbstractCollector collector, Class<?>... classes) {

View File

@ -14,10 +14,9 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.Licensing; import org.elasticsearch.license.plugin.Licensing;
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.Licensee;
import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
@ -31,7 +30,6 @@ import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.WatcherLicensee; import org.elasticsearch.xpack.watcher.WatcherLicensee;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -96,7 +94,7 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase {
@Override @Override
public Collection<Module> nodeModules() { public Collection<Module> nodeModules() {
return Collections.singletonList(b -> b.bind(LicensesService.class).to(MockLicenseService.class)); return Collections.singletonList(b -> b.bind(LicenseService.class).to(MockLicenseService.class));
} }
@Override @Override
@ -106,9 +104,9 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase {
WatcherLicensee watcherLicensee = new WatcherLicensee(settings); WatcherLicensee watcherLicensee = new WatcherLicensee(settings);
MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings); MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings);
GraphLicensee graphLicensee = new GraphLicensee(settings); GraphLicensee graphLicensee = new GraphLicensee(settings);
LicensesService licensesService = new MockLicenseService(settings, environment, resourceWatcherService, LicenseService licenseService = new MockLicenseService(settings, environment, resourceWatcherService,
Arrays.asList(watcherLicensee, monitoringLicensee, graphLicensee)); Arrays.asList(watcherLicensee, monitoringLicensee, graphLicensee));
return Arrays.asList(licensesService, watcherLicensee, monitoringLicensee, graphLicensee); return Arrays.asList(licenseService, watcherLicensee, monitoringLicensee, graphLicensee);
} }
@Override @Override
@ -122,7 +120,7 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase {
} }
} }
public static class MockLicenseService extends LicensesService { public static class MockLicenseService extends LicenseService {
private final List<Licensee> licensees; private final List<Licensee> licensees;

View File

@ -34,9 +34,9 @@ import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.core.License.OperationMode;
import org.elasticsearch.license.plugin.Licensing; import org.elasticsearch.license.plugin.Licensing;
import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.Licensee;
import org.elasticsearch.license.plugin.core.LicensesService;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
@ -238,7 +238,7 @@ public class LicensingTests extends SecurityIntegTestCase {
} }
public static void disableLicensing(OperationMode operationMode) { public static void disableLicensing(OperationMode operationMode) {
for (TestLicensesService service : internalCluster().getInstances(TestLicensesService.class)) { for (TestLicenseService service : internalCluster().getInstances(TestLicenseService.class)) {
service.disable(operationMode); service.disable(operationMode);
} }
} }
@ -248,7 +248,7 @@ public class LicensingTests extends SecurityIntegTestCase {
} }
public static void enableLicensing(OperationMode operationMode) { public static void enableLicensing(OperationMode operationMode) {
for (TestLicensesService service : internalCluster().getInstances(TestLicensesService.class)) { for (TestLicenseService service : internalCluster().getInstances(TestLicenseService.class)) {
service.enable(operationMode); service.enable(operationMode);
} }
} }
@ -257,7 +257,7 @@ public class LicensingTests extends SecurityIntegTestCase {
@Override @Override
public Collection<Module> nodeModules() { public Collection<Module> nodeModules() {
return Collections.singletonList(b -> b.bind(LicensesService.class).to(TestLicensesService.class)); return Collections.singletonList(b -> b.bind(LicenseService.class).to(TestLicenseService.class));
} }
@Override @Override
@ -268,7 +268,7 @@ public class LicensingTests extends SecurityIntegTestCase {
WatcherLicensee watcherLicensee = new WatcherLicensee(settings); WatcherLicensee watcherLicensee = new WatcherLicensee(settings);
MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings); MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings);
GraphLicensee graphLicensee = new GraphLicensee(settings); GraphLicensee graphLicensee = new GraphLicensee(settings);
TestLicensesService licensesService = new TestLicensesService(settings, environment, resourceWatcherService, TestLicenseService licensesService = new TestLicenseService(settings, environment, resourceWatcherService,
Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee)); Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee));
return Arrays.asList(securityLicensee, licensesService, watcherLicensee, monitoringLicensee, return Arrays.asList(securityLicensee, licensesService, watcherLicensee, monitoringLicensee,
graphLicensee, securityLicenseState); graphLicensee, securityLicenseState);
@ -297,11 +297,11 @@ public class LicensingTests extends SecurityIntegTestCase {
} }
} }
public static class TestLicensesService extends LicensesService { public static class TestLicenseService extends LicenseService {
private final List<Licensee> licensees; private final List<Licensee> licensees;
public TestLicensesService(Settings settings, Environment env, ResourceWatcherService resourceWatcherService, public TestLicenseService(Settings settings, Environment env, ResourceWatcherService resourceWatcherService,
List<Licensee> licensees) { List<Licensee> licensees) {
super(settings, null, null, env, resourceWatcherService, Collections.emptyList()); super(settings, null, null, env, resourceWatcherService, Collections.emptyList());
this.licensees = licensees; this.licensees = licensees;

View File

@ -169,7 +169,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
if (transportClientMode == false) { if (transportClientMode == false) {
modules.add(new TextTemplateModule()); modules.add(new TextTemplateModule());
// Note: this only exists so LicensesService subclasses can be bound in mock tests // Note: this only exists so LicenseService subclasses can be bound in mock tests
modules.addAll(licensing.nodeModules()); modules.addAll(licensing.nodeModules());
} }
return modules; return modules;

View File

@ -12,7 +12,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.XPackBuild; import org.elasticsearch.xpack.XPackBuild;
@ -27,16 +27,16 @@ import java.util.stream.Collectors;
*/ */
public class TransportXPackInfoAction extends HandledTransportAction<XPackInfoRequest, XPackInfoResponse> { public class TransportXPackInfoAction extends HandledTransportAction<XPackInfoRequest, XPackInfoResponse> {
private final LicensesService licensesService; private final LicenseService licenseService;
private final Set<XPackFeatureSet> featureSets; private final Set<XPackFeatureSet> featureSets;
@Inject @Inject
public TransportXPackInfoAction(Settings settings, ThreadPool threadPool, TransportService transportService, public TransportXPackInfoAction(Settings settings, ThreadPool threadPool, TransportService transportService,
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
LicensesService licensesService, Set<XPackFeatureSet> featureSets) { LicenseService licenseService, Set<XPackFeatureSet> featureSets) {
super(settings, XPackInfoAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, super(settings, XPackInfoAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver,
XPackInfoRequest::new); XPackInfoRequest::new);
this.licensesService = licensesService; this.licenseService = licenseService;
this.featureSets = featureSets; this.featureSets = featureSets;
} }
@ -51,7 +51,7 @@ public class TransportXPackInfoAction extends HandledTransportAction<XPackInfoRe
LicenseInfo licenseInfo = null; LicenseInfo licenseInfo = null;
if (request.getCategories().contains(XPackInfoRequest.Category.LICENSE)) { if (request.getCategories().contains(XPackInfoRequest.Category.LICENSE)) {
License license = licensesService.getLicense(); License license = licenseService.getLicense();
if (license != null) { if (license != null) {
licenseInfo = new LicenseInfo(license); licenseInfo = new LicenseInfo(license);
} }

View File

@ -10,7 +10,7 @@ import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicenseService;
import org.elasticsearch.xpack.security.user.AnonymousUser; import org.elasticsearch.xpack.security.user.AnonymousUser;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
@ -57,7 +57,7 @@ public class TransportXPackInfoActionTests extends ESTestCase {
public void testDoExecute() throws Exception { public void testDoExecute() throws Exception {
LicensesService licensesService = mock(LicensesService.class); LicenseService licenseService = mock(LicenseService.class);
final Set<XPackFeatureSet> featureSets = new HashSet<>(); final Set<XPackFeatureSet> featureSets = new HashSet<>();
int featureSetCount = randomIntBetween(0, 5); int featureSetCount = randomIntBetween(0, 5);
@ -72,7 +72,7 @@ public class TransportXPackInfoActionTests extends ESTestCase {
TransportXPackInfoAction action = new TransportXPackInfoAction(Settings.EMPTY, mock(ThreadPool.class), TransportXPackInfoAction action = new TransportXPackInfoAction(Settings.EMPTY, mock(ThreadPool.class),
mock(TransportService.class), mock(ActionFilters.class), mock(IndexNameExpressionResolver.class), mock(TransportService.class), mock(ActionFilters.class), mock(IndexNameExpressionResolver.class),
licensesService, featureSets); licenseService, featureSets);
License license = mock(License.class); License license = mock(License.class);
long expiryDate = randomLong(); long expiryDate = randomLong();
@ -85,7 +85,7 @@ public class TransportXPackInfoActionTests extends ESTestCase {
when(license.operationMode()).thenReturn(mode); when(license.operationMode()).thenReturn(mode);
String uid = randomAsciiOfLength(30); String uid = randomAsciiOfLength(30);
when(license.uid()).thenReturn(uid); when(license.uid()).thenReturn(uid);
when(licensesService.getLicense()).thenReturn(license); when(licenseService.getLicense()).thenReturn(license);
XPackInfoRequest request = new XPackInfoRequest(); XPackInfoRequest request = new XPackInfoRequest();
request.setVerbose(randomBoolean()); request.setVerbose(randomBoolean());