Refactor injection mechanism
Original commit: elastic/x-pack-elasticsearch@a85d5213bf
This commit is contained in:
parent
07ec8ef93f
commit
a8f5f0151d
|
@ -6,6 +6,7 @@
|
||||||
package org.elasticsearch.license.plugin;
|
package org.elasticsearch.license.plugin;
|
||||||
|
|
||||||
import org.elasticsearch.common.inject.AbstractModule;
|
import org.elasticsearch.common.inject.AbstractModule;
|
||||||
|
import org.elasticsearch.common.inject.Scopes;
|
||||||
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||||
|
|
||||||
|
@ -13,7 +14,6 @@ public class LicenseModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
//TODO: bind LicensesManagementService and LicensesValidationService to LicensesServices instead
|
//TODO: bind LicensesManagementService and LicensesValidationService to LicensesServices instead
|
||||||
bind(LicensesService.class).asEagerSingleton();
|
bind(LicensesService.class).in(Scopes.SINGLETON);
|
||||||
bind(LicensesManagerService.class).to(LicensesService.class).asEagerSingleton();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,13 @@ package org.elasticsearch.license.plugin;
|
||||||
import org.elasticsearch.action.ActionModule;
|
import org.elasticsearch.action.ActionModule;
|
||||||
import org.elasticsearch.action.admin.cluster.ClusterAction;
|
import org.elasticsearch.action.admin.cluster.ClusterAction;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.common.collect.ImmutableSet;
|
import org.elasticsearch.common.collect.ImmutableSet;
|
||||||
|
import org.elasticsearch.common.collect.Lists;
|
||||||
import org.elasticsearch.common.component.LifecycleComponent;
|
import org.elasticsearch.common.component.LifecycleComponent;
|
||||||
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.inject.Module;
|
import org.elasticsearch.common.inject.Module;
|
||||||
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
||||||
import org.elasticsearch.license.plugin.action.delete.TransportDeleteLicenseAction;
|
import org.elasticsearch.license.plugin.action.delete.TransportDeleteLicenseAction;
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
||||||
|
@ -29,10 +33,17 @@ import java.util.Collection;
|
||||||
|
|
||||||
public class LicensePlugin extends AbstractPlugin {
|
public class LicensePlugin extends AbstractPlugin {
|
||||||
|
|
||||||
|
private final boolean isClient;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
MetaData.registerFactory(LicensesMetaData.TYPE, LicensesMetaData.FACTORY);
|
MetaData.registerFactory(LicensesMetaData.TYPE, LicensesMetaData.FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public LicensePlugin(Settings settings) {
|
||||||
|
this.isClient = DiscoveryNode.clientNode(settings);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String name() {
|
public String name() {
|
||||||
return "license";
|
return "license";
|
||||||
|
@ -58,12 +69,19 @@ public class LicensePlugin extends AbstractPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Class<? extends LifecycleComponent>> services() {
|
public Collection<Class<? extends LifecycleComponent>> services() {
|
||||||
return ImmutableSet.<Class<? extends LifecycleComponent>>of(LicensesService.class);
|
Collection<Class<? extends LifecycleComponent>> services = Lists.newArrayList();
|
||||||
|
if (!isClient) {
|
||||||
|
services.add(LicensesService.class);
|
||||||
|
}
|
||||||
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Class<? extends Module>> modules() {
|
public Collection<Class<? extends Module>> modules() {
|
||||||
|
if (isClient) {
|
||||||
|
return ImmutableSet.of();
|
||||||
|
}
|
||||||
return ImmutableSet.<Class<? extends Module>>of(LicenseModule.class);
|
return ImmutableSet.<Class<? extends Module>>of(LicenseModule.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||||
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.LicensesManagerService;
|
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||||
|
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||||
|
import org.elasticsearch.node.Node;
|
||||||
|
import org.elasticsearch.node.internal.InternalNode;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
|
|
|
@ -17,22 +17,20 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||||
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.LicensesManagerService;
|
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
import org.elasticsearch.node.Node;
|
|
||||||
|
|
||||||
import static org.elasticsearch.license.plugin.core.LicensesService.PutLicenseRequestHolder;
|
import static org.elasticsearch.license.plugin.core.LicensesService.PutLicenseRequestHolder;
|
||||||
|
|
||||||
public class TransportPutLicenseAction extends TransportMasterNodeOperationAction<PutLicenseRequest, PutLicenseResponse> {
|
public class TransportPutLicenseAction extends TransportMasterNodeOperationAction<PutLicenseRequest, PutLicenseResponse> {
|
||||||
|
|
||||||
private final LicensesManagerService LicensesManagerService;
|
private final LicensesManagerService licensesManagerService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TransportPutLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
public TransportPutLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||||
LicensesManagerService LicensesManagerService, ThreadPool threadPool, ActionFilters actionFilters) {
|
LicensesManagerService licensesManagerService, ThreadPool threadPool, ActionFilters actionFilters) {
|
||||||
super(settings, PutLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
super(settings, PutLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters);
|
||||||
this.LicensesManagerService = LicensesManagerService;
|
this.licensesManagerService = licensesManagerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +57,7 @@ public class TransportPutLicenseAction extends TransportMasterNodeOperationActio
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener<PutLicenseResponse> listener) throws ElasticsearchException {
|
protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener<PutLicenseResponse> listener) throws ElasticsearchException {
|
||||||
final PutLicenseRequestHolder requestHolder = new PutLicenseRequestHolder(request, "put licenses []");
|
final PutLicenseRequestHolder requestHolder = new PutLicenseRequestHolder(request, "put licenses []");
|
||||||
LicensesManagerService.registerLicenses(requestHolder, new ActionListener<ClusterStateUpdateResponse>() {
|
licensesManagerService.registerLicenses(requestHolder, new ActionListener<ClusterStateUpdateResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
|
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
|
||||||
listener.onResponse(new PutLicenseResponse(clusterStateUpdateResponse.isAcknowledged()));
|
listener.onResponse(new PutLicenseResponse(clusterStateUpdateResponse.isAcknowledged()));
|
||||||
|
|
|
@ -7,10 +7,13 @@ package org.elasticsearch.license.plugin.core;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
||||||
|
import org.elasticsearch.common.inject.ImplementedBy;
|
||||||
|
import org.elasticsearch.common.inject.Singleton;
|
||||||
|
|
||||||
import static org.elasticsearch.license.plugin.core.LicensesService.DeleteLicenseRequestHolder;
|
import static org.elasticsearch.license.plugin.core.LicensesService.DeleteLicenseRequestHolder;
|
||||||
import static org.elasticsearch.license.plugin.core.LicensesService.PutLicenseRequestHolder;
|
import static org.elasticsearch.license.plugin.core.LicensesService.PutLicenseRequestHolder;
|
||||||
|
|
||||||
|
@ImplementedBy(LicensesService.class)
|
||||||
public interface LicensesManagerService {
|
public interface LicensesManagerService {
|
||||||
|
|
||||||
public void registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener);
|
public void registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener);
|
||||||
|
|
|
@ -7,8 +7,6 @@ package org.elasticsearch.license.plugin.core;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.ActionRequestValidationException;
|
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
|
||||||
import org.elasticsearch.cluster.*;
|
import org.elasticsearch.cluster.*;
|
||||||
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
|
@ -16,19 +14,15 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.inject.Provides;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.inject.Singleton;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.license.core.ESLicenses;
|
import org.elasticsearch.license.core.ESLicenses;
|
||||||
import org.elasticsearch.license.core.LicenseBuilders;
|
import org.elasticsearch.license.core.LicenseBuilders;
|
||||||
import org.elasticsearch.license.manager.ESLicenseManager;
|
import org.elasticsearch.license.manager.ESLicenseManager;
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
||||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
|
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
|
||||||
import org.elasticsearch.node.Node;
|
|
||||||
import org.elasticsearch.node.internal.InternalNode;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -43,20 +37,19 @@ import static org.elasticsearch.license.plugin.core.TrialLicensesBuilder.EMPTY;
|
||||||
* - implement logic in clusterChanged
|
* - implement logic in clusterChanged
|
||||||
* - interface with LicenseManager
|
* - interface with LicenseManager
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class LicensesService extends AbstractLifecycleComponent<LicensesService> implements ClusterStateListener, LicensesManagerService, LicensesValidatorService {
|
public class LicensesService extends AbstractLifecycleComponent<LicensesService> implements ClusterStateListener, LicensesManagerService, LicensesValidatorService {
|
||||||
|
|
||||||
private ESLicenseManager esLicenseManager;
|
private ESLicenseManager esLicenseManager;
|
||||||
|
|
||||||
private InternalNode node;
|
|
||||||
|
|
||||||
private ClusterService clusterService;
|
private ClusterService clusterService;
|
||||||
|
|
||||||
private volatile TrialLicenses trialLicenses = EMPTY;
|
private volatile TrialLicenses trialLicenses = EMPTY;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public LicensesService(Settings settings, Node node) {
|
public LicensesService(Settings settings, ClusterService clusterService) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.node = (InternalNode) node;
|
this.clusterService = clusterService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,10 +160,8 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws ElasticsearchException {
|
protected void doStart() throws ElasticsearchException {
|
||||||
clusterService = node.injector().getInstance(ClusterService.class);
|
|
||||||
esLicenseManager = ESLicenseManager.createClusterStateBasedInstance(clusterService);
|
esLicenseManager = ESLicenseManager.createClusterStateBasedInstance(clusterService);
|
||||||
|
if ( DiscoveryNode.dataNode(settings) || DiscoveryNode.masterNode(settings)) {
|
||||||
if (DiscoveryNode.dataNode(settings) || DiscoveryNode.masterNode(settings)) {
|
|
||||||
clusterService.add(this);
|
clusterService.add(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,9 @@ import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
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.ESLicenses;
|
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseResponse;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseResponse;
|
||||||
import org.elasticsearch.license.plugin.action.delete.TransportDeleteLicenseAction;
|
|
||||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
|
|
||||||
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
|
|
||||||
import org.elasticsearch.license.plugin.action.put.TransportPutLicenseAction;
|
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
import org.elasticsearch.rest.RestChannel;
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
|
@ -29,18 +24,13 @@ import java.util.Set;
|
||||||
|
|
||||||
import static org.elasticsearch.license.core.ESLicenses.FeatureType;
|
import static org.elasticsearch.license.core.ESLicenses.FeatureType;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
|
||||||
|
|
||||||
public class RestDeleteLicenseAction extends BaseRestHandler {
|
public class RestDeleteLicenseAction extends BaseRestHandler {
|
||||||
|
|
||||||
private final TransportDeleteLicenseAction transportDeleteLicenseAction;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestDeleteLicenseAction(Settings settings, RestController controller, Client client, TransportDeleteLicenseAction transportDeleteLicenseAction) {
|
public RestDeleteLicenseAction(Settings settings, RestController controller, Client client) {
|
||||||
super(settings, controller, client);
|
super(settings, controller, client);
|
||||||
controller.registerHandler(DELETE, "/_cluster/license/{features}", this);
|
controller.registerHandler(DELETE, "/_cluster/license/{features}", this);
|
||||||
this.transportDeleteLicenseAction = transportDeleteLicenseAction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +42,7 @@ public class RestDeleteLicenseAction extends BaseRestHandler {
|
||||||
}
|
}
|
||||||
DeleteLicenseRequest deleteLicenseRequest = new DeleteLicenseRequest(getFeaturesToDelete(features));
|
DeleteLicenseRequest deleteLicenseRequest = new DeleteLicenseRequest(getFeaturesToDelete(features));
|
||||||
deleteLicenseRequest.listenerThreaded(false);
|
deleteLicenseRequest.listenerThreaded(false);
|
||||||
transportDeleteLicenseAction.execute(deleteLicenseRequest, new AcknowledgedRestListener<DeleteLicenseResponse>(channel));
|
client.admin().cluster().execute(DeleteLicenseAction.INSTANCE, deleteLicenseRequest, new AcknowledgedRestListener<DeleteLicenseResponse>(channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] getFeaturesToDelete(String[] features) {
|
private static String[] getFeaturesToDelete(String[] features) {
|
||||||
|
|
|
@ -6,9 +6,6 @@
|
||||||
package org.elasticsearch.license.plugin.rest;
|
package org.elasticsearch.license.plugin.rest;
|
||||||
|
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.cluster.metadata.RepositoriesMetaData;
|
|
||||||
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
|
||||||
import org.elasticsearch.common.Strings;
|
|
||||||
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.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
@ -16,30 +13,24 @@ import org.elasticsearch.license.core.ESLicenses;
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseRequest;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseRequest;
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
||||||
import org.elasticsearch.license.plugin.action.get.TransportGetLicenseAction;
|
|
||||||
import org.elasticsearch.rest.*;
|
import org.elasticsearch.rest.*;
|
||||||
import org.elasticsearch.rest.action.support.AcknowledgedRestListener;
|
|
||||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||||
|
|
||||||
import static org.elasticsearch.client.Requests.getRepositoryRequest;
|
|
||||||
import static org.elasticsearch.license.plugin.action.Utils.licenseAsMap;
|
import static org.elasticsearch.license.plugin.action.Utils.licenseAsMap;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
|
|
||||||
public class RestGetLicenseAction extends BaseRestHandler {
|
public class RestGetLicenseAction extends BaseRestHandler {
|
||||||
|
|
||||||
private final TransportGetLicenseAction transportGetLicenseAction;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestGetLicenseAction(Settings settings, RestController controller, Client client, TransportGetLicenseAction transportGetLicenseAction) {
|
public RestGetLicenseAction(Settings settings, RestController controller, Client client) {
|
||||||
super(settings, controller, client);
|
super(settings, controller, client);
|
||||||
controller.registerHandler(GET, "/_cluster/license", this);
|
controller.registerHandler(GET, "/_cluster/license", this);
|
||||||
this.transportGetLicenseAction = transportGetLicenseAction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||||
transportGetLicenseAction.execute(new GetLicenseRequest(), new RestBuilderListener<GetLicenseResponse>(channel) {
|
client.admin().cluster().execute(GetLicenseAction.INSTANCE, new GetLicenseRequest(), new RestBuilderListener<GetLicenseResponse>(channel) {
|
||||||
@Override
|
@Override
|
||||||
public RestResponse buildResponse(GetLicenseResponse getLicenseResponse, XContentBuilder builder) throws Exception {
|
public RestResponse buildResponse(GetLicenseResponse getLicenseResponse, XContentBuilder builder) throws Exception {
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||||
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.action.put.TransportPutLicenseAction;
|
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
import org.elasticsearch.rest.RestChannel;
|
import org.elasticsearch.rest.RestChannel;
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
|
@ -23,14 +22,11 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||||
|
|
||||||
public class RestPutLicenseAction extends BaseRestHandler {
|
public class RestPutLicenseAction extends BaseRestHandler {
|
||||||
|
|
||||||
private final TransportPutLicenseAction transportPutLicensesAction;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RestPutLicenseAction(Settings settings, RestController controller, Client client, TransportPutLicenseAction transportPutLicenseAction) {
|
public RestPutLicenseAction(Settings settings, RestController controller, Client client) {
|
||||||
super(settings, controller, client);
|
super(settings, controller, client);
|
||||||
controller.registerHandler(PUT, "/_cluster/license", this);
|
controller.registerHandler(PUT, "/_cluster/license", this);
|
||||||
controller.registerHandler(POST, "/_cluster/license", this);
|
controller.registerHandler(POST, "/_cluster/license", this);
|
||||||
this.transportPutLicensesAction = transportPutLicenseAction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +35,6 @@ public class RestPutLicenseAction extends BaseRestHandler {
|
||||||
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
||||||
putLicenseRequest.listenerThreaded(false);
|
putLicenseRequest.listenerThreaded(false);
|
||||||
putLicenseRequest.license(request.content().toUtf8());
|
putLicenseRequest.license(request.content().toUtf8());
|
||||||
transportPutLicensesAction.execute(putLicenseRequest, new AcknowledgedRestListener<PutLicenseResponse>(channel));
|
client.admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest, new AcknowledgedRestListener<PutLicenseResponse>(channel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,25 +6,20 @@
|
||||||
package org.elasticsearch.license.plugin;
|
package org.elasticsearch.license.plugin;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionFuture;
|
import org.elasticsearch.action.ActionFuture;
|
||||||
|
import org.elasticsearch.common.collect.ImmutableSet;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.license.TestUtils;
|
import org.elasticsearch.license.TestUtils;
|
||||||
import org.elasticsearch.license.core.ESLicenses;
|
import org.elasticsearch.license.core.ESLicenses;
|
||||||
import org.elasticsearch.license.core.LicenseBuilders;
|
import org.elasticsearch.license.core.LicenseBuilders;
|
||||||
import org.elasticsearch.license.core.LicenseUtils;
|
import org.elasticsearch.license.core.LicenseUtils;
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequestBuilder;
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
|
||||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseResponse;
|
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseResponse;
|
||||||
import org.elasticsearch.license.plugin.action.delete.TransportDeleteLicenseAction;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseRequestBuilder;
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseRequest;
|
|
||||||
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
||||||
import org.elasticsearch.license.plugin.action.get.TransportGetLicenseAction;
|
import org.elasticsearch.license.plugin.action.put.PutLicenseRequestBuilder;
|
||||||
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.action.put.TransportPutLicenseAction;
|
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.elasticsearch.test.InternalTestCluster;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -36,12 +31,10 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import static org.elasticsearch.test.ElasticsearchIntegrationTest.*;
|
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
||||||
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.*;
|
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.SUITE;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
|
|
||||||
@ClusterScope(scope = SUITE, numDataNodes = 10)
|
@ClusterScope(scope = SUITE, numDataNodes = 10)
|
||||||
public class LicenseTransportTests extends ElasticsearchIntegrationTest {
|
public class LicenseTransportTests extends ElasticsearchIntegrationTest {
|
||||||
|
@ -57,6 +50,12 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Settings transportClientSettings() {
|
||||||
|
// Plugin should be loaded on the transport client as well
|
||||||
|
return nodeSettings(0);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setup() throws IOException, URISyntaxException {
|
public static void setup() throws IOException, URISyntaxException {
|
||||||
priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pri.key").toURI()).toAbsolutePath().toString();
|
priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pri.key").toURI()).toAbsolutePath().toString();
|
||||||
|
@ -72,11 +71,12 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyGetLicense() throws Exception {
|
public void testEmptyGetLicense() throws Exception {
|
||||||
final ActionFuture<DeleteLicenseResponse> deleteFuture = licenseDeleteAction().execute(new DeleteLicenseRequest("marvel", "shield"));
|
DeleteLicenseRequestBuilder deleteLicenseRequestBuilder = new DeleteLicenseRequestBuilder(client().admin().cluster()).setFeatures(ImmutableSet.of("marvel", "shield"));
|
||||||
|
final ActionFuture<DeleteLicenseResponse> deleteFuture = deleteLicenseRequestBuilder.execute();
|
||||||
final DeleteLicenseResponse deleteLicenseResponse = deleteFuture.get();
|
final DeleteLicenseResponse deleteLicenseResponse = deleteFuture.get();
|
||||||
assertTrue(deleteLicenseResponse.isAcknowledged());
|
assertTrue(deleteLicenseResponse.isAcknowledged());
|
||||||
|
|
||||||
final ActionFuture<GetLicenseResponse> getLicenseFuture = licenseGetAction().execute(new GetLicenseRequest());
|
final ActionFuture<GetLicenseResponse> getLicenseFuture = new GetLicenseRequestBuilder(client().admin().cluster()).execute();
|
||||||
|
|
||||||
final GetLicenseResponse getLicenseResponse = getLicenseFuture.get();
|
final GetLicenseResponse getLicenseResponse = getLicenseFuture.get();
|
||||||
|
|
||||||
|
@ -93,20 +93,20 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
|
||||||
String licenseString = TestUtils.generateESLicenses(map);
|
String licenseString = TestUtils.generateESLicenses(map);
|
||||||
String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath);
|
String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath);
|
||||||
|
|
||||||
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster());
|
||||||
//putLicenseRequest.license(licenseString);
|
//putLicenseRequest.license(licenseString);
|
||||||
final ESLicenses putLicenses = LicenseUtils.readLicensesFromString(licenseOutput);
|
final ESLicenses putLicenses = LicenseUtils.readLicensesFromString(licenseOutput);
|
||||||
putLicenseRequest.license(putLicenses);
|
putLicenseRequestBuilder.setLicense(putLicenses);
|
||||||
//LicenseUtils.printLicense(putLicenses);
|
//LicenseUtils.printLicense(putLicenses);
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
final ActionFuture<PutLicenseResponse> putLicenseFuture = licensePutAction().execute(putLicenseRequest);
|
final ActionFuture<PutLicenseResponse> putLicenseFuture = putLicenseRequestBuilder.execute();
|
||||||
|
|
||||||
final PutLicenseResponse putLicenseResponse = putLicenseFuture.get();
|
final PutLicenseResponse putLicenseResponse = putLicenseFuture.get();
|
||||||
|
|
||||||
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
assertThat(putLicenseResponse.isAcknowledged(), equalTo(true));
|
||||||
|
|
||||||
ActionFuture<GetLicenseResponse> getLicenseFuture = licenseGetAction().execute(new GetLicenseRequest());
|
ActionFuture<GetLicenseResponse> getLicenseFuture = new GetLicenseRequestBuilder(client().admin().cluster()).execute();
|
||||||
|
|
||||||
GetLicenseResponse getLicenseResponse = getLicenseFuture.get();
|
GetLicenseResponse getLicenseResponse = getLicenseFuture.get();
|
||||||
|
|
||||||
|
@ -116,30 +116,15 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
|
||||||
assertTrue(isSame(putLicenses, getLicenseResponse.licenses()));
|
assertTrue(isSame(putLicenses, getLicenseResponse.licenses()));
|
||||||
|
|
||||||
|
|
||||||
final ActionFuture<DeleteLicenseResponse> deleteFuture = licenseDeleteAction().execute(new DeleteLicenseRequest("marvel", "shield"));
|
final ActionFuture<DeleteLicenseResponse> deleteFuture = new DeleteLicenseRequestBuilder(client().admin().cluster())
|
||||||
|
.setFeatures(ImmutableSet.of("marvel", "shield")).execute();
|
||||||
final DeleteLicenseResponse deleteLicenseResponse = deleteFuture.get();
|
final DeleteLicenseResponse deleteLicenseResponse = deleteFuture.get();
|
||||||
assertTrue(deleteLicenseResponse.isAcknowledged());
|
assertTrue(deleteLicenseResponse.isAcknowledged());
|
||||||
|
|
||||||
getLicenseResponse = licenseGetAction().execute(new GetLicenseRequest()).get();
|
getLicenseResponse = new GetLicenseRequestBuilder(client().admin().cluster()).execute().get();
|
||||||
assertTrue(isSame(getLicenseResponse.licenses(), LicenseBuilders.licensesBuilder().build()));
|
assertTrue(isSame(getLicenseResponse.licenses(), LicenseBuilders.licensesBuilder().build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportGetLicenseAction licenseGetAction() {
|
|
||||||
final InternalTestCluster clients = internalCluster();
|
|
||||||
return clients.getInstance(TransportGetLicenseAction.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransportPutLicenseAction licensePutAction() {
|
|
||||||
final InternalTestCluster clients = internalCluster();
|
|
||||||
return clients.getInstance(TransportPutLicenseAction.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransportDeleteLicenseAction licenseDeleteAction() {
|
|
||||||
final InternalTestCluster clients = internalCluster();
|
|
||||||
return clients.getInstance(TransportDeleteLicenseAction.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: convert to asserts
|
//TODO: convert to asserts
|
||||||
public static boolean isSame(ESLicenses firstLicenses, ESLicenses secondLicenses) {
|
public static boolean isSame(ESLicenses firstLicenses, ESLicenses secondLicenses) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue