Merge pull request elastic/elasticsearch#2810 from rjernst/deguice2
Internal: Remove guice construction of most license classes Original commit: elastic/x-pack-elasticsearch@a2b48e62e9
This commit is contained in:
commit
952ef78f98
|
@ -9,6 +9,7 @@ import org.elasticsearch.action.ActionRequest;
|
|||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.util.Providers;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.ActionPlugin;
|
||||
|
@ -43,15 +44,12 @@ public class Graph extends Plugin implements ActionPlugin {
|
|||
}
|
||||
|
||||
public Collection<Module> createGuiceModules() {
|
||||
return Collections.singletonList(new GraphModule(enabled, transportClientMode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
|
||||
if (enabled == false|| transportClientMode) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(GraphLicensee.class);
|
||||
return Collections.singletonList(b -> {
|
||||
XPackPlugin.bindFeatureSet(b, GraphFeatureSet.class);
|
||||
if (transportClientMode) {
|
||||
b.bind(GraphLicensee.class).toProvider(Providers.of(null));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,21 +6,18 @@
|
|||
package org.elasticsearch.xpack.graph;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.core.License.OperationMode;
|
||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
|
||||
public class GraphLicensee extends AbstractLicenseeComponent<GraphLicensee> {
|
||||
public class GraphLicensee extends AbstractLicenseeComponent {
|
||||
|
||||
public static final String ID = Graph.NAME;
|
||||
|
||||
@Inject
|
||||
public GraphLicensee(Settings settings, LicenseeRegistry clientService) {
|
||||
super(settings, ID, clientService);
|
||||
public GraphLicensee(Settings settings) {
|
||||
super(settings, ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.graph;
|
||||
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.util.Providers;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GraphModule extends AbstractModule {
|
||||
|
||||
private final boolean enabled;
|
||||
private final boolean transportClientNode;
|
||||
|
||||
public GraphModule(boolean enabled, boolean transportClientNode) {
|
||||
this.enabled = enabled;
|
||||
this.transportClientNode = transportClientNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
XPackPlugin.bindFeatureSet(binder(), GraphFeatureSet.class);
|
||||
if (enabled && transportClientNode == false) {
|
||||
bind(GraphLicensee.class).asEagerSingleton();
|
||||
} else {
|
||||
bind(GraphLicensee.class).toProvider(Providers.of(null));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -14,114 +14,81 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
public class LicenseTests extends AbstractLicenseeTestCase {
|
||||
|
||||
private SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry();
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY);
|
||||
|
||||
public void testPlatinumTrialLicenseCanDoEverything() throws Exception {
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
assertLicensePlatinumTrialBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testBasicLicenseIsDisabled() throws Exception {
|
||||
licenseeRegistry.setOperationMode(OperationMode.BASIC);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
|
||||
setOperationMode(graphLicensee, OperationMode.BASIC);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testStandardLicenseIsDisabled() throws Exception {
|
||||
licenseeRegistry.setOperationMode(OperationMode.STANDARD);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
|
||||
setOperationMode(graphLicensee, OperationMode.STANDARD);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testNoLicenseDoesNotWork() {
|
||||
licenseeRegistry.setOperationMode(OperationMode.BASIC);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
licenseeRegistry.disable();
|
||||
|
||||
setOperationMode(graphLicensee, OperationMode.BASIC);
|
||||
disable(graphLicensee);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testExpiredPlatinumTrialLicenseIsRestricted() throws Exception {
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
licenseeRegistry.disable();
|
||||
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
disable(graphLicensee);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testUpgradingFromBasicLicenseWorks() {
|
||||
licenseeRegistry.setOperationMode(OperationMode.BASIC);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
|
||||
setOperationMode(graphLicensee, OperationMode.BASIC);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
assertLicensePlatinumTrialBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testDowngradingToBasicLicenseWorks() {
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
assertLicensePlatinumTrialBehaviour(graphLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(OperationMode.BASIC);
|
||||
setOperationMode(graphLicensee, OperationMode.BASIC);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testUpgradingFromStandardLicenseWorks() {
|
||||
licenseeRegistry.setOperationMode(OperationMode.STANDARD);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
|
||||
setOperationMode(graphLicensee, OperationMode.STANDARD);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
assertLicensePlatinumTrialBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testDowngradingToStandardLicenseWorks() {
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
assertLicensePlatinumTrialBehaviour(graphLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(OperationMode.STANDARD);
|
||||
setOperationMode(graphLicensee, OperationMode.STANDARD);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testDowngradingToGoldLicenseWorks() {
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
assertLicensePlatinumTrialBehaviour(graphLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(OperationMode.GOLD);
|
||||
setOperationMode(graphLicensee, OperationMode.GOLD);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
public void testUpgradingExpiredLicenseWorks() {
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
GraphLicensee graphLicensee = new GraphLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(graphLicensee);
|
||||
licenseeRegistry.disable();
|
||||
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
disable(graphLicensee);
|
||||
assertLicenseBasicOrStandardGoldOrNoneOrExpiredBehaviour(graphLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(randomTrialOrPlatinumMode());
|
||||
setOperationMode(graphLicensee, randomTrialOrPlatinumMode());
|
||||
assertLicensePlatinumTrialBehaviour(graphLicensee);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,7 @@ package org.elasticsearch.license.plugin;
|
|||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -19,8 +18,6 @@ import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
|||
import org.elasticsearch.license.plugin.action.get.TransportGetLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.TransportPutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesMetaData;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction;
|
||||
|
@ -28,6 +25,12 @@ import org.elasticsearch.license.plugin.rest.RestGetLicenseAction;
|
|||
import org.elasticsearch.license.plugin.rest.RestPutLicenseAction;
|
||||
import org.elasticsearch.plugins.ActionPlugin;
|
||||
import org.elasticsearch.rest.RestHandler;
|
||||
import org.elasticsearch.xpack.graph.GraphLicensee;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
||||
import org.elasticsearch.xpack.security.SecurityLicenseState;
|
||||
import org.elasticsearch.xpack.security.SecurityLicensee;
|
||||
import org.elasticsearch.xpack.support.clock.Clock;
|
||||
import org.elasticsearch.xpack.watcher.WatcherLicensee;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -42,7 +45,8 @@ import static org.elasticsearch.xpack.XPackPlugin.transportClientMode;
|
|||
public class Licensing implements ActionPlugin {
|
||||
|
||||
public static final String NAME = "license";
|
||||
private final boolean isTransportClient;
|
||||
protected final Settings settings;
|
||||
protected final boolean isTransportClient;
|
||||
private final boolean isTribeNode;
|
||||
|
||||
static {
|
||||
|
@ -50,10 +54,15 @@ public class Licensing implements ActionPlugin {
|
|||
}
|
||||
|
||||
public Licensing(Settings settings) {
|
||||
this.settings = settings;
|
||||
isTransportClient = transportClientMode(settings);
|
||||
isTribeNode = isTribeNode(settings);
|
||||
}
|
||||
|
||||
public Collection<Module> nodeModules() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActionHandler<? extends ActionRequest<?>, ? extends ActionResponse>> getActions() {
|
||||
if (isTribeNode) {
|
||||
|
@ -74,22 +83,16 @@ public class Licensing implements ActionPlugin {
|
|||
RestDeleteLicenseAction.class);
|
||||
}
|
||||
|
||||
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
|
||||
if (isTransportClient == false && isTribeNode == false) {
|
||||
return Collections.<Class<? extends LifecycleComponent>>singletonList(LicensesService.class);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
public Collection<Object> createComponents(ClusterService clusterService, Clock clock,
|
||||
SecurityLicenseState securityLicenseState) {
|
||||
SecurityLicensee securityLicensee = new SecurityLicensee(settings, securityLicenseState);
|
||||
WatcherLicensee watcherLicensee = new WatcherLicensee(settings);
|
||||
MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(settings);
|
||||
LicensesService licensesService = new LicensesService(settings, clusterService, clock,
|
||||
Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee));
|
||||
|
||||
public Collection<Module> nodeModules() {
|
||||
if (isTransportClient == false && isTribeNode == false) {
|
||||
return Collections.singletonList(b -> {
|
||||
b.bind(LicensesService.class).asEagerSingleton();
|
||||
b.bind(LicenseeRegistry.class).to(LicensesService.class);
|
||||
b.bind(LicensesManagerService.class).to(LicensesService.class);
|
||||
});
|
||||
}
|
||||
return Collections.emptyList();
|
||||
return Arrays.asList(licensesService, securityLicenseState, securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee);
|
||||
}
|
||||
|
||||
public List<Setting<?>> getSettings() {
|
||||
|
|
|
@ -9,28 +9,28 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeReadAction;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
public class TransportGetLicenseAction extends TransportMasterNodeReadAction<GetLicenseRequest, GetLicenseResponse> {
|
||||
|
||||
private final LicensesManagerService licensesManagerService;
|
||||
private final LicensesService licensesService;
|
||||
|
||||
@Inject
|
||||
public TransportGetLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
LicensesManagerService licensesManagerService, ThreadPool threadPool, ActionFilters actionFilters,
|
||||
LicensesService licensesService, ThreadPool threadPool, ActionFilters actionFilters,
|
||||
IndexNameExpressionResolver indexNameExpressionResolver) {
|
||||
super(settings, GetLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver,
|
||||
GetLicenseRequest::new);
|
||||
this.licensesManagerService = licensesManagerService;
|
||||
this.licensesService = licensesService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +51,6 @@ public class TransportGetLicenseAction extends TransportMasterNodeReadAction<Get
|
|||
@Override
|
||||
protected void masterOperation(final GetLicenseRequest request, ClusterState state, final ActionListener<GetLicenseResponse>
|
||||
listener) throws ElasticsearchException {
|
||||
listener.onResponse(new GetLicenseResponse(licensesManagerService.getLicense()));
|
||||
listener.onResponse(new GetLicenseResponse(licensesService.getLicense()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
|
@ -14,33 +15,17 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
/**
|
||||
* A supporting base class for injectable Licensee components.
|
||||
*/
|
||||
public abstract class AbstractLicenseeComponent<T extends AbstractLicenseeComponent<T>> extends AbstractLifecycleComponent
|
||||
implements Licensee {
|
||||
public abstract class AbstractLicenseeComponent extends AbstractComponent implements Licensee {
|
||||
|
||||
private final String id;
|
||||
private final LicenseeRegistry clientService;
|
||||
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
// we initialize the licensee state to enabled with trial operation mode
|
||||
protected volatile Status status = Status.ENABLED;
|
||||
|
||||
protected AbstractLicenseeComponent(Settings settings, String id, LicenseeRegistry clientService) {
|
||||
protected AbstractLicenseeComponent(Settings settings, String id) {
|
||||
super(settings);
|
||||
this.id = id;
|
||||
this.clientService = clientService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() {
|
||||
clientService.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
public interface LicenseeRegistry {
|
||||
|
||||
/**
|
||||
* Registers a licensee for license notifications
|
||||
*/
|
||||
void register(Licensee licensee);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import org.elasticsearch.license.core.License;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface LicensesManagerService {
|
||||
|
||||
/**
|
||||
* @return current {@link LicenseState}
|
||||
*/
|
||||
LicenseState licenseState();
|
||||
|
||||
/**
|
||||
* @return the currently active license, or {@code null} if no license is currently installed
|
||||
*/
|
||||
License getLicense();
|
||||
}
|
|
@ -42,29 +42,20 @@ import java.util.Map;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Service responsible for managing {@link LicensesMetaData}
|
||||
* Interfaces through which this is exposed are:
|
||||
* - LicensesManagerService - responsible for managing signed and one-time-trial licenses
|
||||
* - LicensesClientService - responsible for listener registration of consumer plugin(s)
|
||||
* <p>
|
||||
* Registration Scheme:
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* Notification Scheme:
|
||||
* <p>
|
||||
* All registered listeners are notified of the current license upon registration or when a new license is installed in the cluster state.
|
||||
* When a new license is notified as enabled to the registered listener, a notification is scheduled at the time of license expiry.
|
||||
* Registered listeners are notified using {@link #onUpdate(LicensesMetaData)}
|
||||
*/
|
||||
public class LicensesService extends AbstractLifecycleComponent implements ClusterStateListener, LicensesManagerService,
|
||||
LicenseeRegistry, SchedulerEngine.Listener {
|
||||
public class LicensesService extends AbstractLifecycleComponent implements ClusterStateListener, SchedulerEngine.Listener {
|
||||
|
||||
// pkg private for tests
|
||||
static final TimeValue TRIAL_LICENSE_DURATION = TimeValue.timeValueHours(30 * 24);
|
||||
|
@ -74,7 +65,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
|
|||
/**
|
||||
* Currently active consumers to notify to
|
||||
*/
|
||||
private final List<InternalLicensee> registeredLicensees = new CopyOnWriteArrayList<>();
|
||||
private final List<InternalLicensee> registeredLicensees;
|
||||
|
||||
/**
|
||||
* Currently active license
|
||||
|
@ -105,14 +96,15 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
|
|||
private static final String ACKNOWLEDGEMENT_HEADER = "This license update requires acknowledgement. To acknowledge the license, " +
|
||||
"please read the following messages and update the license again, this time with the \"acknowledge=true\" parameter:";
|
||||
|
||||
@Inject
|
||||
public LicensesService(Settings settings, ClusterService clusterService, Clock clock) {
|
||||
public LicensesService(Settings settings, ClusterService clusterService, Clock clock,
|
||||
List<Licensee> registeredLicensees) {
|
||||
super(settings);
|
||||
this.clusterService = clusterService;
|
||||
populateExpirationCallbacks();
|
||||
this.clock = clock;
|
||||
this.scheduler = new SchedulerEngine(clock);
|
||||
this.scheduler.register(this);
|
||||
this.registeredLicensees = registeredLicensees.stream().map(InternalLicensee::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void populateExpirationCallbacks() {
|
||||
|
@ -313,7 +305,6 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public LicenseState licenseState() {
|
||||
if (registeredLicensees.size() > 0) {
|
||||
return registeredLicensees.get(0).currentLicenseState;
|
||||
|
@ -323,7 +314,6 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public License getLicense() {
|
||||
final License license = getLicense(clusterService.state().metaData().custom(LicensesMetaData.TYPE));
|
||||
return license == LicensesMetaData.LICENSE_TOMBSTONE ? null : license;
|
||||
|
@ -377,6 +367,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
|
|||
protected void doStart() throws ElasticsearchException {
|
||||
clusterService.add(this);
|
||||
scheduler.start(Collections.emptyList());
|
||||
registeredLicensees.forEach(x -> initLicensee(x.licensee));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -502,15 +493,8 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Licensee licensee) {
|
||||
for (final InternalLicensee existingLicensee : registeredLicensees) {
|
||||
if (existingLicensee.id().equals(licensee.id())) {
|
||||
throw new IllegalStateException("listener: [" + licensee.id() + "] has been already registered");
|
||||
}
|
||||
}
|
||||
logger.debug("registering licensee [{}]", licensee.id());
|
||||
registeredLicensees.add(new InternalLicensee(licensee));
|
||||
private void initLicensee(Licensee licensee) {
|
||||
logger.debug("initializing licensee [{}]", licensee.id());
|
||||
final ClusterState clusterState = clusterService.state();
|
||||
if (clusterService.lifecycleState() == Lifecycle.State.STARTED
|
||||
&& clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) == false
|
||||
|
@ -521,7 +505,7 @@ public class LicensesService extends AbstractLifecycleComponent implements Clust
|
|||
// triggers a cluster changed event
|
||||
// eventually notifying the current licensee
|
||||
registerTrialLicense();
|
||||
} else if (lifecycleState() == Lifecycle.State.STARTED) {
|
||||
} else {
|
||||
notifyLicensees(currentMetaData.getLicense());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,6 +176,7 @@ public class LicensesServiceClusterTests extends AbstractLicensesIntegrationTest
|
|||
License putLicenses = generateSignedLicense(TimeValue.timeValueMinutes(1));
|
||||
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(cluster, PutLicenseAction.INSTANCE);
|
||||
putLicenseRequestBuilder.setLicense(putLicenses);
|
||||
putLicenseRequestBuilder.setAcknowledge(true);
|
||||
final PutLicenseResponse putLicenseResponse = putLicenseRequestBuilder.get();
|
||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||
assertThat(putLicenseResponse.status(), equalTo(LicensesStatus.VALID));
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.ClusterName;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
|
@ -37,11 +40,11 @@ public abstract class AbstractLicenseServiceTestCase extends ESTestCase {
|
|||
public void init() throws Exception {
|
||||
clusterService = mock(ClusterService.class);
|
||||
clock = new ClockMock();
|
||||
licensesService = new LicensesService(Settings.EMPTY, clusterService, clock);
|
||||
discoveryNodes = mock(DiscoveryNodes.class);
|
||||
}
|
||||
|
||||
protected void setInitialState(License license) {
|
||||
protected void setInitialState(License license, Licensee... licensees) {
|
||||
licensesService = new LicensesService(Settings.EMPTY, clusterService, clock, Arrays.asList(licensees));
|
||||
ClusterState state = mock(ClusterState.class);
|
||||
final ClusterBlocks noBlock = ClusterBlocks.builder().build();
|
||||
when(state.blocks()).thenReturn(noBlock);
|
||||
|
|
|
@ -169,35 +169,18 @@ public abstract class AbstractLicenseeTestCase extends ESTestCase {
|
|||
return String.format(Locale.ROOT, "From [%s] to [%s]", fromMode, toMode);
|
||||
}
|
||||
|
||||
public static class SimpleLicenseeRegistry extends AbstractComponent implements LicenseeRegistry {
|
||||
private final List<Licensee> licensees = new ArrayList<>();
|
||||
private OperationMode operationMode;
|
||||
private OperationMode operationMode;
|
||||
|
||||
public SimpleLicenseeRegistry() {
|
||||
super(Settings.EMPTY);
|
||||
}
|
||||
public void setOperationMode(Licensee licensee, OperationMode operationMode) {
|
||||
this.operationMode = operationMode;
|
||||
enable(licensee);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Licensee licensee) {
|
||||
licensees.add(licensee);
|
||||
enable();
|
||||
}
|
||||
public void disable(Licensee licensee) {
|
||||
licensee.onChange(new Licensee.Status(operationMode, LicenseState.DISABLED));
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
for (Licensee licensee : licensees) {
|
||||
licensee.onChange(new Licensee.Status(operationMode, randomEnabledOrGracePeriodState()));
|
||||
}
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
for (Licensee licensee : licensees) {
|
||||
licensee.onChange(new Licensee.Status(operationMode, LicenseState.DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
public void setOperationMode(License.OperationMode operationMode) {
|
||||
this.operationMode = operationMode;
|
||||
enable();
|
||||
}
|
||||
public void enable(Licensee licensee) {
|
||||
licensee.onChange(new Licensee.Status(operationMode, randomEnabledOrGracePeriodState()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,10 +35,9 @@ public class LicenseClusterChangeTests extends AbstractLicenseServiceTestCase {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
setInitialState(null);
|
||||
licensesService.start();
|
||||
licensee = new TestUtils.AssertingLicensee("LicenseClusterChangeTests", logger);
|
||||
licensesService.register(licensee);
|
||||
setInitialState(null, licensee);
|
||||
licensesService.start();
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -21,13 +21,11 @@ import static org.mockito.Mockito.when;
|
|||
public class LicenseRegistrationTests extends AbstractLicenseServiceTestCase {
|
||||
|
||||
public void testTrialLicenseRequestOnEmptyLicenseState() throws Exception {
|
||||
setInitialState(null);
|
||||
when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true);
|
||||
|
||||
TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee(
|
||||
"testTrialLicenseRequestOnEmptyLicenseState", logger);
|
||||
"testTrialLicenseRequestOnEmptyLicenseState", logger);
|
||||
setInitialState(null, licensee);
|
||||
when(discoveryNodes.isLocalNodeElectedMaster()).thenReturn(true);
|
||||
licensesService.start();
|
||||
licensesService.register(licensee);
|
||||
|
||||
ClusterState state = ClusterState.builder(new ClusterName("a")).build();
|
||||
ArgumentCaptor<ClusterStateUpdateTask> stateUpdater = ArgumentCaptor.forClass(ClusterStateUpdateTask.class);
|
||||
|
@ -42,11 +40,10 @@ public class LicenseRegistrationTests extends AbstractLicenseServiceTestCase {
|
|||
}
|
||||
|
||||
public void testNotificationOnRegistration() throws Exception {
|
||||
setInitialState(TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)));
|
||||
TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee(
|
||||
"testNotificationOnRegistration", logger);
|
||||
setInitialState(TestUtils.generateSignedLicense(TimeValue.timeValueHours(2)), licensee);
|
||||
licensesService.start();
|
||||
licensesService.register(licensee);
|
||||
assertThat(licensee.statuses.size(), equalTo(1));
|
||||
final LicenseState licenseState = licensee.statuses.get(0).getLicenseState();
|
||||
assertTrue(licenseState == LicenseState.ENABLED);
|
||||
|
|
|
@ -27,13 +27,13 @@ import static org.mockito.Mockito.verify;
|
|||
public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase {
|
||||
|
||||
public void testAcknowledgment() throws Exception {
|
||||
setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)));
|
||||
licensesService.start();
|
||||
|
||||
String id = "testAcknowledgment";
|
||||
String[] acknowledgeMessages = new String[] {"message"};
|
||||
TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee(id, logger);
|
||||
setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)), licensee);
|
||||
licensesService.start();
|
||||
licensee.setAcknowledgementMessages(acknowledgeMessages);
|
||||
licensesService.register(licensee);
|
||||
// try installing a signed license
|
||||
License signedLicense = generateSignedLicense(TimeValue.timeValueHours(10));
|
||||
PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense);
|
||||
|
@ -57,8 +57,6 @@ public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase
|
|||
}
|
||||
|
||||
public void testAcknowledgementMultipleLicensee() throws Exception {
|
||||
setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)));
|
||||
licensesService.start();
|
||||
String id1 = "testAcknowledgementMultipleLicensee_1";
|
||||
String[] acknowledgeMessages1 = new String[] {"testAcknowledgementMultipleLicensee_1"};
|
||||
String id2 = "testAcknowledgementMultipleLicensee_2";
|
||||
|
@ -67,8 +65,8 @@ public class LicensesAcknowledgementTests extends AbstractLicenseServiceTestCase
|
|||
licensee1.setAcknowledgementMessages(acknowledgeMessages1);
|
||||
TestUtils.AssertingLicensee licensee2 = new TestUtils.AssertingLicensee(id2, logger);
|
||||
licensee2.setAcknowledgementMessages(acknowledgeMessages2);
|
||||
licensesService.register(licensee1);
|
||||
licensesService.register(licensee2);
|
||||
setInitialState(TestUtils.generateSignedLicense("trial", TimeValue.timeValueHours(2)), licensee1, licensee2);
|
||||
licensesService.start();
|
||||
// try installing a signed license
|
||||
License signedLicense = generateSignedLicense(TimeValue.timeValueHours(10));
|
||||
PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(signedLicense);
|
||||
|
|
|
@ -5,27 +5,27 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.xpack.graph.Graph;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.TestUtils;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
||||
import org.elasticsearch.xpack.monitoring.Monitoring;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.xpack.security.Security;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.graph.Graph;
|
||||
import org.elasticsearch.xpack.monitoring.Monitoring;
|
||||
import org.elasticsearch.xpack.security.Security;
|
||||
import org.elasticsearch.xpack.watcher.Watcher;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.elasticsearch.license.plugin.TestUtils.generateSignedLicense;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
|
@ -116,9 +116,6 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase {
|
|||
LicensesService licensesService = getInstanceFromNode(LicensesService.class);
|
||||
ClusterService clusterService = getInstanceFromNode(ClusterService.class);
|
||||
|
||||
// generate a trial license for one feature
|
||||
licensesService.register(new TestUtils.AssertingLicensee("", logger));
|
||||
|
||||
// generate signed licenses
|
||||
License license = generateSignedLicense(TimeValue.timeValueHours(1));
|
||||
TestUtils.registerAndAckSignedLicenses(licensesService, license, LicensesStatus.VALID);
|
||||
|
@ -131,53 +128,6 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase {
|
|||
assertThat(licensesMetaData.getLicense(), equalTo(LicensesMetaData.LICENSE_TOMBSTONE));
|
||||
}
|
||||
|
||||
public void testRemoveLicensesAndLicenseeNotification() throws Exception {
|
||||
LicensesService licensesService = getInstanceFromNode(LicensesService.class);
|
||||
licensesService.start();
|
||||
ClusterService clusterService = getInstanceFromNode(ClusterService.class);
|
||||
|
||||
// generate a trial license for one feature
|
||||
TestUtils.AssertingLicensee licensee = new TestUtils.AssertingLicensee("", logger);
|
||||
licensesService.register(licensee);
|
||||
|
||||
// we should get a trial license to begin with
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(licensee.statuses, hasSize(1));
|
||||
assertThat(licensee.statuses.get(0).getMode(), is(License.OperationMode.TRIAL));
|
||||
assertThat(licensee.statuses.get(0).getLicenseState(), is(LicenseState.ENABLED));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// generate signed licenses
|
||||
License license = generateSignedLicense("gold", TimeValue.timeValueHours(1));
|
||||
TestUtils.registerAndAckSignedLicenses(licensesService, license, LicensesStatus.VALID);
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(licensee.statuses, hasSize(2));
|
||||
assertThat(licensee.statuses.get(1).getMode(), not(License.OperationMode.TRIAL));
|
||||
assertThat(licensee.statuses.get(1).getLicenseState(), is(LicenseState.ENABLED));
|
||||
}
|
||||
});
|
||||
|
||||
// remove signed licenses
|
||||
removeAndAckSignedLicenses(licensesService);
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(licensee.statuses, hasSize(3));
|
||||
}
|
||||
});
|
||||
LicensesMetaData licensesMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
|
||||
assertThat(licensesMetaData.getLicense(), is(LicensesMetaData.LICENSE_TOMBSTONE));
|
||||
assertThat(licensee.statuses, hasSize(3));
|
||||
assertThat(licensee.statuses.get(2).getLicenseState(), is(LicenseState.DISABLED));
|
||||
assertThat(licensee.statuses.get(2).getMode(), is(License.OperationMode.MISSING));
|
||||
}
|
||||
|
||||
private void removeAndAckSignedLicenses(final LicensesService licensesService) {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final AtomicBoolean success = new AtomicBoolean(false);
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.TestUtils;
|
||||
|
@ -12,21 +14,20 @@ import org.elasticsearch.license.plugin.TestUtils.AssertingLicensee;
|
|||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class LicensesNotificationTests extends AbstractLicenseServiceTestCase {
|
||||
|
||||
public void testLicenseNotification() throws Exception {
|
||||
final License license = TestUtils.generateSignedLicense(TimeValue.timeValueHours(48));
|
||||
setInitialState(license);
|
||||
licensesService.start();
|
||||
int nLicensee = randomIntBetween(1, 3);
|
||||
AssertingLicensee[] assertingLicensees = new AssertingLicensee[nLicensee];
|
||||
for (int i = 0; i < assertingLicensees.length; i++) {
|
||||
assertingLicensees[i] = new AssertingLicensee("testLicenseNotification" + i, logger);
|
||||
licensesService.register(assertingLicensees[i]);
|
||||
}
|
||||
setInitialState(license, assertingLicensees);
|
||||
licensesService.start();
|
||||
for (int i = 0; i < assertingLicensees.length; i++) {
|
||||
assertLicenseStates(assertingLicensees[i], LicenseState.ENABLED);
|
||||
}
|
||||
clock.fastForward(TimeValue.timeValueMillis(license.expiryDate() - clock.millis()));
|
||||
|
|
|
@ -78,9 +78,7 @@ public class Monitoring implements ActionPlugin {
|
|||
if (enabled == false || transportClientMode || tribeNode) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.<Class<? extends LifecycleComponent>>asList(MonitoringLicensee.class,
|
||||
AgentService.class,
|
||||
CleanerService.class);
|
||||
return Arrays.<Class<? extends LifecycleComponent>>asList(AgentService.class, CleanerService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,15 +6,12 @@
|
|||
package org.elasticsearch.xpack.monitoring;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.logging.LoggerMessageFormat;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.core.License.OperationMode;
|
||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.Licensee;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
|
||||
/**
|
||||
* {@code MonitoringLicensee} determines whether certain features of Monitoring are enabled or disabled.
|
||||
|
@ -25,11 +22,10 @@ import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
|||
* <li>Cleaning up (deleting) older indices.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class MonitoringLicensee extends AbstractLicenseeComponent<MonitoringLicensee> implements Licensee {
|
||||
public class MonitoringLicensee extends AbstractLicenseeComponent {
|
||||
|
||||
@Inject
|
||||
public MonitoringLicensee(Settings settings, LicenseeRegistry clientService) {
|
||||
super(settings, Monitoring.NAME, clientService);
|
||||
public MonitoringLicensee(Settings settings) {
|
||||
super(settings, Monitoring.NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,11 +26,10 @@ public class MonitoringModule extends AbstractModule {
|
|||
XPackPlugin.bindFeatureSet(binder(), MonitoringFeatureSet.class);
|
||||
|
||||
if (enabled && transportClientMode == false) {
|
||||
bind(MonitoringLicensee.class).asEagerSingleton();
|
||||
bind(MonitoringSettings.class).asEagerSingleton();
|
||||
bind(AgentService.class).asEagerSingleton();
|
||||
bind(CleanerService.class).asEagerSingleton();
|
||||
} else {
|
||||
} else if (transportClientMode) {
|
||||
bind(MonitoringLicensee.class).toProvider(Providers.of(null));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.elasticsearch.cluster.service.ClusterService;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.plugin.core.LicenseUtils;
|
||||
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
||||
import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector;
|
||||
|
@ -40,16 +40,16 @@ public class ClusterStatsCollector extends AbstractCollector {
|
|||
|
||||
public static final String NAME = "cluster-stats-collector";
|
||||
|
||||
private final LicensesManagerService licensesManagerService;
|
||||
private final LicensesService licensesService;
|
||||
private final Client client;
|
||||
|
||||
@Inject
|
||||
public ClusterStatsCollector(Settings settings, ClusterService clusterService,
|
||||
MonitoringSettings monitoringSettings, MonitoringLicensee licensee, InternalClient client,
|
||||
LicensesManagerService licensesManagerService) {
|
||||
LicensesService licensesService) {
|
||||
super(settings, NAME, clusterService, monitoringSettings, licensee);
|
||||
this.client = client;
|
||||
this.licensesManagerService = licensesManagerService;
|
||||
this.licensesService = licensesService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,7 +85,7 @@ public class ClusterStatsCollector extends AbstractCollector {
|
|||
clusterInfoDoc.setSourceNode(sourceNode);
|
||||
clusterInfoDoc.setClusterName(clusterService.getClusterName().value());
|
||||
clusterInfoDoc.setVersion(Version.CURRENT.toString());
|
||||
clusterInfoDoc.setLicense(licensesManagerService.getLicense());
|
||||
clusterInfoDoc.setLicense(licensesService.getLicense());
|
||||
clusterInfoDoc.setClusterStats(clusterStats);
|
||||
results.add(clusterInfoDoc);
|
||||
|
||||
|
|
|
@ -5,43 +5,43 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.monitoring.agent.collector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.RandomizedTest;
|
||||
import com.carrotsearch.randomizedtesting.SysGlobals;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.cluster.block.ClusterBlocks;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.Licensing;
|
||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.Licensee;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestHandler;
|
||||
import org.elasticsearch.xpack.security.InternalClient;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.graph.GraphLicensee;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
||||
import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase;
|
||||
import org.elasticsearch.xpack.security.InternalClient;
|
||||
import org.elasticsearch.xpack.security.SecurityLicenseState;
|
||||
import org.elasticsearch.xpack.support.clock.Clock;
|
||||
import org.elasticsearch.xpack.watcher.WatcherLicensee;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes;
|
||||
|
||||
|
@ -110,7 +110,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||
service.onChange(license.operationMode(), LicenseState.ENABLED);
|
||||
}
|
||||
for (LicensesManagerServiceForCollectors service : internalCluster().getInstances(LicensesManagerServiceForCollectors.class)) {
|
||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||
service.update(license);
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||
service.onChange(license.operationMode(), LicenseState.GRACE_PERIOD);
|
||||
}
|
||||
for (LicensesManagerServiceForCollectors service : internalCluster().getInstances(LicensesManagerServiceForCollectors.class)) {
|
||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||
service.update(license);
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||
service.onChange(license.operationMode(), LicenseState.DISABLED);
|
||||
}
|
||||
for (LicensesManagerServiceForCollectors service : internalCluster().getInstances(LicensesManagerServiceForCollectors.class)) {
|
||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||
service.update(license);
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||
service.onChange(license.operationMode(), LicenseState.DISABLED);
|
||||
}
|
||||
for (LicensesManagerServiceForCollectors service : internalCluster().getInstances(LicensesManagerServiceForCollectors.class)) {
|
||||
for (LicenseServiceForCollectors service : internalCluster().getInstances(LicenseServiceForCollectors.class)) {
|
||||
service.update(license);
|
||||
}
|
||||
}
|
||||
|
@ -190,16 +190,18 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
|
||||
@Override
|
||||
public Collection<Module> nodeModules() {
|
||||
return Collections.<Module>singletonList(new AbstractModule() {
|
||||
return Collections.singletonList(b -> b.bind(LicensesService.class).to(LicenseServiceForCollectors.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(LicenseServiceForCollectors.class).asEagerSingleton();
|
||||
bind(LicenseeRegistry.class).to(LicenseServiceForCollectors.class);
|
||||
bind(LicensesManagerServiceForCollectors.class).asEagerSingleton();
|
||||
bind(LicensesManagerService.class).to(LicensesManagerServiceForCollectors.class);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public Collection<Object> createComponents(ClusterService clusterService, Clock clock,
|
||||
SecurityLicenseState securityLicenseState) {
|
||||
WatcherLicensee watcherLicensee = new WatcherLicensee(settings);
|
||||
MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(settings);
|
||||
LicensesService licensesService = new LicenseServiceForCollectors(settings,
|
||||
Arrays.asList(watcherLicensee, monitoringLicensee, graphLicensee));
|
||||
return Arrays.asList(licensesService, watcherLicensee, monitoringLicensee, graphLicensee);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -211,11 +213,6 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
public List<Class<? extends RestHandler>> getRestHandlers() {
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public static class InternalXPackPlugin extends XPackPlugin {
|
||||
|
@ -226,18 +223,15 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
}
|
||||
}
|
||||
|
||||
public static class LicenseServiceForCollectors extends AbstractComponent implements LicenseeRegistry {
|
||||
public static class LicenseServiceForCollectors extends LicensesService {
|
||||
|
||||
private final List<Licensee> licensees = new ArrayList<>();
|
||||
private final List<Licensee> licensees;
|
||||
private volatile License license;
|
||||
|
||||
@Inject
|
||||
public LicenseServiceForCollectors(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Licensee licensee) {
|
||||
licensees.add(licensee);
|
||||
public LicenseServiceForCollectors(Settings settings, List<Licensee> licensees) {
|
||||
super(settings, null, null, licensees);
|
||||
this.licensees = licensees;
|
||||
}
|
||||
|
||||
public void onChange(License.OperationMode operationMode, LicenseState state) {
|
||||
|
@ -245,11 +239,6 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
licensee.onChange(new Licensee.Status(operationMode, state));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LicensesManagerServiceForCollectors implements LicensesManagerService {
|
||||
|
||||
private volatile License license;
|
||||
|
||||
@Override
|
||||
public LicenseState licenseState() {
|
||||
|
@ -264,5 +253,11 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase
|
|||
public synchronized void update(License license) {
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() {}
|
||||
|
||||
@Override
|
||||
protected void doStop() {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.monitoring.agent.collector.cluster;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.BadApple;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoredSystem;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
||||
|
@ -17,8 +19,6 @@ import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector;
|
|||
import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollectorTestCase;
|
||||
import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
|
@ -133,7 +133,7 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
|
|||
internalCluster().getInstance(MonitoringSettings.class, nodeId),
|
||||
internalCluster().getInstance(MonitoringLicensee.class, nodeId),
|
||||
securedClient(nodeId),
|
||||
internalCluster().getInstance(LicensesManagerService.class, nodeId));
|
||||
internalCluster().getInstance(LicensesService.class, nodeId));
|
||||
}
|
||||
|
||||
private void assertCanCollect(AbstractCollector collector, Class<?>... classes) {
|
||||
|
|
|
@ -7,9 +7,7 @@ package org.elasticsearch.xpack.monitoring.license;
|
|||
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -17,14 +15,17 @@ import org.elasticsearch.license.core.License;
|
|||
import org.elasticsearch.license.plugin.Licensing;
|
||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.Licensee;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestHandler;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.graph.GraphLicensee;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
||||
import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase;
|
||||
import org.elasticsearch.xpack.security.SecurityLicenseState;
|
||||
import org.elasticsearch.xpack.support.clock.Clock;
|
||||
import org.elasticsearch.xpack.watcher.WatcherLicensee;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -92,7 +93,18 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase {
|
|||
|
||||
@Override
|
||||
public Collection<Module> nodeModules() {
|
||||
return Collections.<Module>singletonList(new InternalLicenseModule());
|
||||
return Collections.singletonList(b -> b.bind(LicensesService.class).to(MockLicenseService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> createComponents(ClusterService clusterService, Clock clock,
|
||||
SecurityLicenseState securityLicenseState) {
|
||||
WatcherLicensee watcherLicensee = new WatcherLicensee(settings);
|
||||
MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(settings);
|
||||
LicensesService licensesService = new MockLicenseService(settings,
|
||||
Arrays.asList(watcherLicensee, monitoringLicensee, graphLicensee));
|
||||
return Arrays.asList(licensesService, watcherLicensee, monitoringLicensee, graphLicensee);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,36 +116,16 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase {
|
|||
public List<Class<? extends RestHandler>> getRestHandlers() {
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class InternalLicenseModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(MockLicenseService.class).asEagerSingleton();
|
||||
bind(LicenseeRegistry.class).to(MockLicenseService.class);
|
||||
bind(LicensesManagerService.class).to(MockLicenseService.class);
|
||||
}
|
||||
}
|
||||
public static class MockLicenseService extends LicensesService {
|
||||
|
||||
public static class MockLicenseService extends AbstractComponent implements LicenseeRegistry, LicensesManagerService {
|
||||
|
||||
private final List<Licensee> licensees = new ArrayList<>();
|
||||
private final List<Licensee> licensees;
|
||||
|
||||
@Inject
|
||||
public MockLicenseService(Settings settings) {
|
||||
super(settings);
|
||||
enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Licensee licensee) {
|
||||
licensees.add(licensee);
|
||||
public MockLicenseService(Settings settings, List<Licensee> licensees) {
|
||||
super(settings, null, null, licensees);
|
||||
this.licensees = licensees;
|
||||
enable();
|
||||
}
|
||||
|
||||
|
@ -159,6 +151,12 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase {
|
|||
public License getLicense() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() {}
|
||||
|
||||
@Override
|
||||
protected void doStop() {}
|
||||
}
|
||||
|
||||
public static class InternalXPackPlugin extends XPackPlugin {
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.license.core.License.OperationMode;
|
|||
import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase;
|
||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.Licensee.Status;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
@ -18,7 +17,6 @@ import java.util.function.Predicate;
|
|||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
|
@ -27,8 +25,7 @@ import static org.mockito.Mockito.when;
|
|||
* If you change the behavior of these tests, then it means that licensing changes for Monitoring!
|
||||
*/
|
||||
public class MonitoringLicenseeTests extends AbstractLicenseeTestCase {
|
||||
private final LicenseeRegistry registry = mock(LicenseeRegistry.class);
|
||||
private final MonitoringLicensee licensee = new MonitoringLicensee(Settings.EMPTY, registry);
|
||||
private final MonitoringLicensee licensee = new MonitoringLicensee(Settings.EMPTY);
|
||||
|
||||
public void testAcknowledgementMessagesToAnyFromFreeIsNoOp() {
|
||||
assertEmptyAck(OperationMode.BASIC, randomMode(), licensee);
|
||||
|
@ -93,7 +90,6 @@ public class MonitoringLicenseeTests extends AbstractLicenseeTestCase {
|
|||
assertThat(predicate.test(licensee), equalTo(expected));
|
||||
|
||||
verify(status).getLicenseState();
|
||||
verifyNoMoreInteractions(registry);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,6 +108,5 @@ public class MonitoringLicenseeTests extends AbstractLicenseeTestCase {
|
|||
assertThat(predicate.test(licensee), equalTo(expected));
|
||||
|
||||
verify(status).getMode();
|
||||
verifyNoMoreInteractions(registry);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ public class Security implements ActionPlugin {
|
|||
private final Settings settings;
|
||||
private final boolean enabled;
|
||||
private final boolean transportClientMode;
|
||||
private SecurityLicenseState securityLicenseState;
|
||||
private final SecurityLicenseState securityLicenseState;
|
||||
private final CryptoService cryptoService;
|
||||
|
||||
public Security(Settings settings, Environment env) throws IOException {
|
||||
|
@ -130,12 +130,17 @@ public class Security implements ActionPlugin {
|
|||
} else {
|
||||
cryptoService = null;
|
||||
}
|
||||
securityLicenseState = new SecurityLicenseState();
|
||||
}
|
||||
|
||||
public CryptoService getCryptoService() {
|
||||
return cryptoService;
|
||||
}
|
||||
|
||||
public SecurityLicenseState getSecurityLicenseState() {
|
||||
return securityLicenseState;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
@ -147,7 +152,7 @@ public class Security implements ActionPlugin {
|
|||
if (enabled == false) {
|
||||
return modules;
|
||||
}
|
||||
modules.add(new SecurityModule(settings, securityLicenseState));
|
||||
modules.add(new SecurityModule(settings));
|
||||
modules.add(new SecurityTransportModule(settings));
|
||||
modules.add(new SSLModule(settings));
|
||||
return modules;
|
||||
|
@ -157,7 +162,7 @@ public class Security implements ActionPlugin {
|
|||
modules.add(new AuthorizationModule(settings));
|
||||
if (enabled == false) {
|
||||
modules.add(b -> b.bind(CryptoService.class).toProvider(Providers.of(null)));
|
||||
modules.add(new SecurityModule(settings, securityLicenseState));
|
||||
modules.add(new SecurityModule(settings));
|
||||
modules.add(new AuditTrailModule(settings));
|
||||
modules.add(new SecurityTransportModule(settings));
|
||||
return modules;
|
||||
|
@ -166,9 +171,9 @@ public class Security implements ActionPlugin {
|
|||
// we can't load that at construction time since the license plugin might not have been loaded at that point
|
||||
// which might not be the case during Plugin class instantiation. Once nodeModules are pulled
|
||||
// everything should have been loaded
|
||||
securityLicenseState = new SecurityLicenseState();
|
||||
|
||||
modules.add(b -> b.bind(CryptoService.class).toInstance(cryptoService));
|
||||
modules.add(new SecurityModule(settings, securityLicenseState));
|
||||
modules.add(new SecurityModule(settings));
|
||||
modules.add(new AuditTrailModule(settings));
|
||||
modules.add(new SecurityRestModule(settings));
|
||||
modules.add(new SecurityActionModule(settings));
|
||||
|
@ -182,7 +187,6 @@ public class Security implements ActionPlugin {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
List<Class<? extends LifecycleComponent>> list = new ArrayList<>();
|
||||
list.add(SecurityLicensee.class);
|
||||
list.add(FileRolesStore.class);
|
||||
list.add(Realms.class);
|
||||
return list;
|
||||
|
|
|
@ -5,28 +5,21 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.security;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
||||
import org.elasticsearch.license.plugin.core.Licensee;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SecurityLicensee extends AbstractLicenseeComponent<SecurityLicensee> implements Licensee {
|
||||
public class SecurityLicensee extends AbstractLicenseeComponent {
|
||||
|
||||
private final boolean isTribeNode;
|
||||
private final SecurityLicenseState securityLicenseState;
|
||||
|
||||
@Inject
|
||||
public SecurityLicensee(Settings settings, LicenseeRegistry clientService, SecurityLicenseState securityLicenseState) {
|
||||
super(settings, Security.NAME, clientService);
|
||||
public SecurityLicensee(Settings settings, SecurityLicenseState securityLicenseState) {
|
||||
super(settings, Security.NAME);
|
||||
this.securityLicenseState = securityLicenseState;
|
||||
this.isTribeNode = settings.getGroups("tribe", true).isEmpty() == false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,14 +89,4 @@ public class SecurityLicensee extends AbstractLicenseeComponent<SecurityLicensee
|
|||
}
|
||||
return Strings.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ElasticsearchException {
|
||||
// we rely on the initial licensee state to be enabled with trial operation mode
|
||||
// to ensure no operation is blocked due to not registering the licensee on a
|
||||
// tribe node
|
||||
if (isTribeNode == false) {
|
||||
super.doStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,21 +5,17 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.security;
|
||||
|
||||
import org.elasticsearch.common.inject.util.Providers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.xpack.security.support.AbstractSecurityModule;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.security.support.AbstractSecurityModule;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class SecurityModule extends AbstractSecurityModule {
|
||||
|
||||
private final SecurityLicenseState securityLicenseState;
|
||||
|
||||
public SecurityModule(Settings settings, SecurityLicenseState securityLicenseState) {
|
||||
public SecurityModule(Settings settings) {
|
||||
super(settings);
|
||||
this.securityLicenseState = securityLicenseState;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,12 +24,6 @@ public class SecurityModule extends AbstractSecurityModule {
|
|||
return;
|
||||
}
|
||||
|
||||
if (securityLicenseState != null) {
|
||||
bind(SecurityLicenseState.class).toInstance(securityLicenseState);
|
||||
} else {
|
||||
bind(SecurityLicenseState.class).toProvider(Providers.<SecurityLicenseState>of(null));
|
||||
}
|
||||
|
||||
XPackPlugin.bindFeatureSet(binder(), SecurityFeatureSet.class);
|
||||
|
||||
if (securityEnabled) {
|
||||
|
|
|
@ -5,6 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.integration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.ElasticsearchSecurityException;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
|
@ -19,10 +26,7 @@ import org.elasticsearch.client.Response;
|
|||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.client.transport.NoNodeAvailableException;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -31,7 +35,7 @@ import org.elasticsearch.license.core.License.OperationMode;
|
|||
import org.elasticsearch.license.plugin.Licensing;
|
||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.Licensee;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestHandler;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
@ -40,16 +44,16 @@ import org.elasticsearch.test.SecuritySettingsSource;
|
|||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.xpack.MockNetty3Plugin;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.graph.GraphLicensee;
|
||||
import org.elasticsearch.xpack.monitoring.MonitoringLicensee;
|
||||
import org.elasticsearch.xpack.security.Security;
|
||||
import org.elasticsearch.xpack.security.SecurityLicenseState;
|
||||
import org.elasticsearch.xpack.security.SecurityLicensee;
|
||||
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
|
||||
import org.elasticsearch.xpack.support.clock.Clock;
|
||||
import org.elasticsearch.xpack.watcher.WatcherLicensee;
|
||||
import org.junit.After;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
|
@ -231,7 +235,7 @@ public class LicensingTests extends SecurityIntegTestCase {
|
|||
}
|
||||
|
||||
public static void disableLicensing(OperationMode operationMode) {
|
||||
for (InternalLicenseeRegistry service : internalCluster().getInstances(InternalLicenseeRegistry.class)) {
|
||||
for (TestLicensesService service : internalCluster().getInstances(TestLicensesService.class)) {
|
||||
service.disable(operationMode);
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +245,7 @@ public class LicensingTests extends SecurityIntegTestCase {
|
|||
}
|
||||
|
||||
public static void enableLicensing(OperationMode operationMode) {
|
||||
for (InternalLicenseeRegistry service : internalCluster().getInstances(InternalLicenseeRegistry.class)) {
|
||||
for (TestLicensesService service : internalCluster().getInstances(TestLicensesService.class)) {
|
||||
service.enable(operationMode);
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +254,20 @@ public class LicensingTests extends SecurityIntegTestCase {
|
|||
|
||||
@Override
|
||||
public Collection<Module> nodeModules() {
|
||||
return Collections.<Module>singletonList(new InternalLicenseModule());
|
||||
return Collections.singletonList(b -> b.bind(LicensesService.class).to(TestLicensesService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> createComponents(ClusterService clusterService, Clock clock,
|
||||
SecurityLicenseState securityLicenseState) {
|
||||
SecurityLicensee securityLicensee = new SecurityLicensee(settings, securityLicenseState);
|
||||
WatcherLicensee watcherLicensee = new WatcherLicensee(settings);
|
||||
MonitoringLicensee monitoringLicensee = new MonitoringLicensee(settings);
|
||||
GraphLicensee graphLicensee = new GraphLicensee(settings);
|
||||
TestLicensesService licensesService = new TestLicensesService(settings,
|
||||
Arrays.asList(securityLicensee, watcherLicensee, monitoringLicensee, graphLicensee));
|
||||
return Arrays.asList(securityLicensee, licensesService, watcherLicensee, monitoringLicensee,
|
||||
graphLicensee, securityLicenseState);
|
||||
}
|
||||
|
||||
public InternalLicensing() {
|
||||
|
@ -266,11 +283,6 @@ public class LicensingTests extends SecurityIntegTestCase {
|
|||
public List<Class<? extends RestHandler>> getRestHandlers() {
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public static class InternalXPackPlugin extends XPackPlugin {
|
||||
|
@ -281,27 +293,13 @@ public class LicensingTests extends SecurityIntegTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public static class InternalLicenseModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(InternalLicenseeRegistry.class).asEagerSingleton();
|
||||
bind(LicenseeRegistry.class).to(InternalLicenseeRegistry.class);
|
||||
}
|
||||
}
|
||||
public static class TestLicensesService extends LicensesService {
|
||||
|
||||
public static class InternalLicenseeRegistry extends AbstractComponent implements LicenseeRegistry {
|
||||
private final List<Licensee> licensees;
|
||||
|
||||
private final List<Licensee> licensees = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
public InternalLicenseeRegistry(Settings settings) {
|
||||
super(settings);
|
||||
enable(OperationMode.BASIC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Licensee licensee) {
|
||||
licensees.add(licensee);
|
||||
public TestLicensesService(Settings settings, List<Licensee> licensees) {
|
||||
super(settings, null, null, Collections.emptyList());
|
||||
this.licensees = licensees;
|
||||
enable(OperationMode.BASIC);
|
||||
}
|
||||
|
||||
|
@ -316,5 +314,11 @@ public class LicensingTests extends SecurityIntegTestCase {
|
|||
licensee.onChange(new Licensee.Status(operationMode, LicenseState.DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() {}
|
||||
|
||||
@Override
|
||||
protected void doStop() {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.license.core.License.OperationMode;
|
||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase;
|
||||
import org.elasticsearch.license.plugin.core.Licensee.Status;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -23,39 +22,18 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
*/
|
||||
public class SecurityLicenseeTests extends AbstractLicenseeTestCase {
|
||||
private final SecurityLicenseState securityLicenseState = mock(SecurityLicenseState.class);
|
||||
private final LicenseeRegistry registry = mock(LicenseeRegistry.class);
|
||||
|
||||
public void testStartsWithoutTribeNode() {
|
||||
SecurityLicensee licensee = new SecurityLicensee(Settings.EMPTY, registry, securityLicenseState);
|
||||
|
||||
// starting the Licensee start trigger it being registered
|
||||
licensee.start();
|
||||
|
||||
verify(registry).register(licensee);
|
||||
verifyNoMoreInteractions(registry, securityLicenseState);
|
||||
}
|
||||
|
||||
public void testDoesNotStartWithTribeNode() {
|
||||
Settings settings = Settings.builder().put("tribe.fake.cluster.name", "notchecked").build();
|
||||
SecurityLicensee licensee = new SecurityLicensee(settings, registry, securityLicenseState);
|
||||
|
||||
// starting the Licensee as a tribe node should not trigger it being registered
|
||||
licensee.start();
|
||||
|
||||
verifyNoMoreInteractions(registry, securityLicenseState);
|
||||
}
|
||||
|
||||
public void testOnChangeModifiesSecurityLicenseState() {
|
||||
Status status = mock(Status.class);
|
||||
|
||||
SecurityLicensee licensee = new SecurityLicensee(Settings.EMPTY, registry, securityLicenseState);
|
||||
SecurityLicensee licensee = new SecurityLicensee(Settings.EMPTY, securityLicenseState);
|
||||
|
||||
licensee.onChange(status);
|
||||
|
||||
assertSame(status, licensee.getStatus());
|
||||
|
||||
verify(securityLicenseState).updateStatus(status);
|
||||
verifyNoMoreInteractions(registry, securityLicenseState);
|
||||
verifyNoMoreInteractions(securityLicenseState);
|
||||
}
|
||||
|
||||
public void testAcknowledgementMessagesFromBasicToAnyNotGoldOrStandardIsNoOp() {
|
||||
|
@ -97,6 +75,6 @@ public class SecurityLicenseeTests extends AbstractLicenseeTestCase {
|
|||
}
|
||||
|
||||
private SecurityLicensee buildLicensee() {
|
||||
return new SecurityLicensee(Settings.EMPTY, registry, securityLicenseState);
|
||||
return new SecurityLicensee(Settings.EMPTY, securityLicenseState);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.IndexModule;
|
||||
import org.elasticsearch.license.plugin.Licensing;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.plugins.ActionPlugin;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.plugins.ScriptPlugin;
|
||||
|
@ -156,7 +157,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
|
|||
ArrayList<Module> modules = new ArrayList<>();
|
||||
modules.add(b -> b.bind(Clock.class).toInstance(getClock()));
|
||||
modules.addAll(notification.nodeModules());
|
||||
modules.addAll(licensing.nodeModules());
|
||||
modules.addAll(security.nodeModules());
|
||||
modules.addAll(watcher.nodeModules());
|
||||
modules.addAll(monitoring.nodeModules());
|
||||
|
@ -164,6 +164,8 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
|
|||
|
||||
if (transportClientMode == false) {
|
||||
modules.add(new TextTemplateModule());
|
||||
// Note: this only exists so LicensesService subclasses can be bound in mock tests
|
||||
modules.addAll(licensing.nodeModules());
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
@ -172,30 +174,27 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
|
|||
public Collection<Class<? extends LifecycleComponent>> getGuiceServiceClasses() {
|
||||
ArrayList<Class<? extends LifecycleComponent>> services = new ArrayList<>();
|
||||
services.addAll(notification.nodeServices());
|
||||
services.addAll(licensing.nodeServices());
|
||||
services.addAll(security.nodeServices());
|
||||
services.addAll(watcher.nodeServices());
|
||||
services.addAll(monitoring.nodeServices());
|
||||
services.addAll(graph.getGuiceServiceClasses());
|
||||
return services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
|
||||
ResourceWatcherService resourceWatcherService) {
|
||||
ResourceWatcherService resourceWatcherService) {
|
||||
List<Object> components = new ArrayList<>();
|
||||
if (transportClientMode == false) {
|
||||
final InternalClient internalClient = new InternalClient(settings, threadPool, client, security.getCryptoService());
|
||||
components.add(internalClient);
|
||||
final InternalClient internalClient = new InternalClient(settings, threadPool, client, security.getCryptoService());
|
||||
components.add(internalClient);
|
||||
|
||||
// watcher http stuff
|
||||
Map<String, HttpAuthFactory> httpAuthFactories = new HashMap<>();
|
||||
httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService()));
|
||||
// TODO: add more auth types, or remove this indirection
|
||||
HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories);
|
||||
components.add(new HttpRequestTemplate.Parser(httpAuthRegistry));
|
||||
components.add(new HttpClient(settings, httpAuthRegistry, env));
|
||||
}
|
||||
components.addAll(licensing.createComponents(clusterService, getClock(), security.getSecurityLicenseState()));
|
||||
|
||||
// watcher http stuff
|
||||
Map<String, HttpAuthFactory> httpAuthFactories = new HashMap<>();
|
||||
httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService()));
|
||||
// TODO: add more auth types, or remove this indirection
|
||||
HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories);
|
||||
components.add(new HttpRequestTemplate.Parser(httpAuthRegistry));
|
||||
components.add(new HttpClient(settings, httpAuthRegistry, env));
|
||||
|
||||
return components;
|
||||
}
|
||||
|
@ -205,7 +204,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
|
|||
Settings.Builder builder = Settings.builder();
|
||||
builder.put(security.additionalSettings());
|
||||
builder.put(watcher.additionalSettings());
|
||||
builder.put(graph.additionalSettings());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
@ -240,7 +238,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
|
|||
filters.addAll(notification.getSettingsFilter());
|
||||
filters.addAll(security.getSettingsFilter());
|
||||
filters.addAll(MonitoringSettings.getSettingsFilter());
|
||||
filters.addAll(graph.getSettingsFilter());
|
||||
return filters;
|
||||
}
|
||||
|
||||
|
@ -273,7 +270,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
|
|||
filters.addAll(monitoring.getActionFilters());
|
||||
filters.addAll(security.getActionFilters());
|
||||
filters.addAll(watcher.getActionFilters());
|
||||
filters.addAll(graph.getActionFilters());
|
||||
return filters;
|
||||
}
|
||||
|
||||
|
@ -298,7 +294,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin {
|
|||
|
||||
public void onIndexModule(IndexModule module) {
|
||||
security.onIndexModule(module);
|
||||
graph.onIndexModule(module);
|
||||
}
|
||||
|
||||
public static void bindFeatureSet(Binder binder, Class<? extends XPackFeatureSet> featureSet) {
|
||||
|
|
|
@ -126,13 +126,6 @@ public class Watcher implements ActionPlugin {
|
|||
return modules;
|
||||
}
|
||||
|
||||
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
|
||||
if (enabled == false|| transportClient) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(WatcherLicensee.class);
|
||||
}
|
||||
|
||||
public Settings additionalSettings() {
|
||||
return Settings.EMPTY;
|
||||
}
|
||||
|
|
|
@ -6,21 +6,18 @@
|
|||
package org.elasticsearch.xpack.watcher;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.core.License.OperationMode;
|
||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeComponent;
|
||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
|
||||
|
||||
public class WatcherLicensee extends AbstractLicenseeComponent<WatcherLicensee> {
|
||||
public class WatcherLicensee extends AbstractLicenseeComponent {
|
||||
|
||||
public static final String ID = Watcher.NAME;
|
||||
|
||||
@Inject
|
||||
public WatcherLicensee(Settings settings, LicenseeRegistry clientService) {
|
||||
super(settings, ID, clientService);
|
||||
public WatcherLicensee(Settings settings) {
|
||||
super(settings, ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,16 +25,13 @@ public class WatcherModule extends AbstractModule {
|
|||
@Override
|
||||
protected void configure() {
|
||||
if (transportClientMode) {
|
||||
bind(WatcherLicensee.class).toProvider(Providers.of(null));
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled == false) {
|
||||
bind(WatcherLicensee.class).toProvider(Providers.of(null));
|
||||
// watcher service must be null, so that the watcher feature set can be instantiated even if watcher is not enabled
|
||||
bind(WatcherService.class).toProvider(Providers.of(null));
|
||||
} else {
|
||||
bind(WatcherLicensee.class).asEagerSingleton();
|
||||
bind(WatcherLifeCycleService.class).asEagerSingleton();
|
||||
bind(WatcherIndexTemplateRegistry.class).asEagerSingleton();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ package org.elasticsearch.xpack.watcher.license;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.core.License;
|
||||
import org.elasticsearch.license.plugin.core.AbstractLicenseeTestCase;
|
||||
import org.elasticsearch.license.plugin.core.LicenseState;
|
||||
import org.elasticsearch.license.plugin.core.Licensee;
|
||||
import org.elasticsearch.xpack.watcher.WatcherLicensee;
|
||||
|
||||
import static org.elasticsearch.license.core.License.OperationMode.BASIC;
|
||||
|
@ -19,7 +21,6 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
public class LicenseTests extends AbstractLicenseeTestCase {
|
||||
|
||||
private final SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry();
|
||||
private WatcherLicensee watcherLicensee;
|
||||
|
||||
public void testPlatinumGoldTrialLicenseCanDoEverything() throws Exception {
|
||||
|
@ -34,14 +35,14 @@ public class LicenseTests extends AbstractLicenseeTestCase {
|
|||
|
||||
public void testNoLicenseDisablesWatcher() {
|
||||
initLicense(BASIC, STANDARD);
|
||||
licenseeRegistry.disable();
|
||||
disable(watcherLicensee);
|
||||
|
||||
assertWatcherActionsNotAllowed(watcherLicensee);
|
||||
}
|
||||
|
||||
public void testExpiredPlatinumGoldTrialLicenseDisablesWatcher() throws Exception {
|
||||
initLicense(TRIAL, GOLD, PLATINUM);
|
||||
licenseeRegistry.disable();
|
||||
disable(watcherLicensee);
|
||||
|
||||
assertWatcherActionsNotAllowed(watcherLicensee);
|
||||
}
|
||||
|
@ -50,7 +51,7 @@ public class LicenseTests extends AbstractLicenseeTestCase {
|
|||
initLicense(BASIC, STANDARD);
|
||||
assertWatcherActionsNotAllowed(watcherLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(randomFrom(TRIAL, GOLD, PLATINUM));
|
||||
setOperationMode(watcherLicensee, randomFrom(TRIAL, GOLD, PLATINUM));
|
||||
assertWatcherActionsAllowed(watcherLicensee);
|
||||
}
|
||||
|
||||
|
@ -58,17 +59,17 @@ public class LicenseTests extends AbstractLicenseeTestCase {
|
|||
initLicense(TRIAL, GOLD, PLATINUM);
|
||||
assertWatcherActionsAllowed(watcherLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(randomFrom(BASIC, STANDARD));
|
||||
setOperationMode(watcherLicensee, randomFrom(BASIC, STANDARD));
|
||||
assertWatcherActionsNotAllowed(watcherLicensee);
|
||||
}
|
||||
|
||||
public void testUpgradingExpiredLicenseWorks() {
|
||||
initLicense(TRIAL, GOLD, PLATINUM);
|
||||
licenseeRegistry.disable();
|
||||
disable(watcherLicensee);
|
||||
|
||||
assertWatcherActionsNotAllowed(watcherLicensee);
|
||||
|
||||
licenseeRegistry.setOperationMode(randomFrom(TRIAL, GOLD, PLATINUM));
|
||||
setOperationMode(watcherLicensee, randomFrom(TRIAL, GOLD, PLATINUM));
|
||||
assertWatcherActionsAllowed(watcherLicensee);
|
||||
}
|
||||
|
||||
|
@ -87,8 +88,7 @@ public class LicenseTests extends AbstractLicenseeTestCase {
|
|||
}
|
||||
|
||||
private void initLicense(License.OperationMode ... allowedLicenses) {
|
||||
licenseeRegistry.setOperationMode(randomFrom(allowedLicenses));
|
||||
watcherLicensee = new WatcherLicensee(Settings.EMPTY, licenseeRegistry);
|
||||
licenseeRegistry.register(watcherLicensee);
|
||||
watcherLicensee = new WatcherLicensee(Settings.EMPTY);
|
||||
setOperationMode(watcherLicensee, randomFrom(allowedLicenses));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue