Use NetworkModule for transport/http related extensions

This is the xplugins side of elastic/elasticsearch#15434.

Original commit: elastic/x-pack-elasticsearch@728d8b728a
This commit is contained in:
Ryan Ernst 2015-12-14 20:10:57 -08:00
parent fbc8da8c4d
commit 1a9a79caa4
9 changed files with 75 additions and 71 deletions

View File

@ -12,6 +12,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.component.LifecycleComponent;
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.license.plugin.action.delete.DeleteLicenseAction;
import org.elasticsearch.license.plugin.action.delete.TransportDeleteLicenseAction;
@ -25,7 +26,6 @@ import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction;
import org.elasticsearch.license.plugin.rest.RestGetLicenseAction;
import org.elasticsearch.license.plugin.rest.RestPutLicenseAction;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestModule;
import java.util.ArrayList;
import java.util.Collection;
@ -60,11 +60,10 @@ public class LicensePlugin extends Plugin {
return "Internal Elasticsearch Licensing Plugin";
}
public void onModule(RestModule module) {
// Register REST endpoint
module.addRestAction(RestPutLicenseAction.class);
module.addRestAction(RestGetLicenseAction.class);
module.addRestAction(RestDeleteLicenseAction.class);
public void onModule(NetworkModule module) {
module.registerRestHandler(RestPutLicenseAction.class);
module.registerRestHandler(RestGetLicenseAction.class);
module.registerRestHandler(RestDeleteLicenseAction.class);
}
public void onModule(ActionModule module) {

View File

@ -14,6 +14,7 @@ import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.AbstractModule;
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;
@ -28,13 +29,16 @@ import org.elasticsearch.marvel.shield.SecuredClient;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.xpack.XPackPlugin;
import org.junit.Before;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
@ -201,7 +205,7 @@ public class AbstractCollectorTestCase extends MarvelIntegTestCase {
}
@Override
public void onModule(RestModule module) {
public void onModule(NetworkModule module) {
}
@Override

View File

@ -11,21 +11,18 @@ import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.AbstractModule;
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.index.IndexModule;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.LicensePlugin;
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.rest.RestModule;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.xpack.XPackPlugin;
import java.util.ArrayList;
import java.util.Arrays;
@ -100,7 +97,7 @@ public class LicenseIntegrationTests extends MarvelIntegTestCase {
}
@Override
public void onModule(RestModule module) {
public void onModule(NetworkModule module) {
}
@Override

View File

@ -12,12 +12,11 @@ import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.settings.Validator;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.http.HttpServerModule;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.shield.action.ShieldActionFilter;
import org.elasticsearch.shield.action.ShieldActionModule;
import org.elasticsearch.shield.action.authc.cache.ClearRealmCacheAction;
@ -48,11 +47,15 @@ import org.elasticsearch.shield.transport.ShieldTransportModule;
import org.elasticsearch.shield.transport.filter.IPFilter;
import org.elasticsearch.shield.transport.netty.ShieldNettyHttpServerTransport;
import org.elasticsearch.shield.transport.netty.ShieldNettyTransport;
import org.elasticsearch.transport.TransportModule;
import org.elasticsearch.xpack.XPackPlugin;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
*
@ -141,6 +144,9 @@ public class ShieldPlugin extends Plugin {
}
Settings.Builder settingsBuilder = Settings.settingsBuilder();
settingsBuilder.put(NetworkModule.TRANSPORT_TYPE_KEY, ShieldPlugin.NAME);
settingsBuilder.put(NetworkModule.TRANSPORT_SERVICE_TYPE_KEY, ShieldPlugin.NAME);
settingsBuilder.put(NetworkModule.HTTP_TYPE_KEY, ShieldPlugin.NAME);
addUserSettings(settingsBuilder);
addTribeSettings(settingsBuilder);
addQueryCacheSettings(settingsBuilder);
@ -185,32 +191,27 @@ public class ShieldPlugin extends Plugin {
module.registerAction(ClearRealmCacheAction.INSTANCE, TransportClearRealmCacheAction.class);
}
public void onModule(TransportModule module) {
public void onModule(NetworkModule module) {
// we want to expose the shield rest action even when the plugin is disabled
module.registerRestHandler(RestShieldInfoAction.class);
if (enabled == false) {
return;
}
module.setTransport(ShieldNettyTransport.class, ShieldPlugin.NAME);
module.registerTransport(ShieldPlugin.NAME, ShieldNettyTransport.class);
if (clientMode) {
module.setTransportService(ShieldClientTransportService.class, ShieldPlugin.NAME);
module.registerTransportService(ShieldPlugin.NAME, ShieldClientTransportService.class);
} else {
module.setTransportService(ShieldServerTransportService.class, ShieldPlugin.NAME);
module.registerTransportService(ShieldPlugin.NAME, ShieldServerTransportService.class);
}
}
public void onModule(HttpServerModule module) {
if (enabled && clientMode == false) {
module.setHttpServerTransport(ShieldNettyHttpServerTransport.class, ShieldPlugin.NAME);
if (clientMode == false) {
module.registerRestHandler(RestClearRealmCacheAction.class);
module.registerHttpTransport(ShieldPlugin.NAME, ShieldNettyHttpServerTransport.class);
}
}
public void onModule(RestModule module) {
if (enabled && clientMode == false) {
module.addRestAction(RestClearRealmCacheAction.class);
}
// we want to expose the shield rest action even when the plugin is disabled
module.addRestAction(RestShieldInfoAction.class);
}
public void onModule(AuthorizationModule module) {
if (enabled && AuditTrailModule.auditingEnabled(settings)) {
module.registerReservedRole(IndexAuditUserHolder.ROLE);

View File

@ -22,6 +22,7 @@ import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.AbstractModule;
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.license.core.License.OperationMode;
import org.elasticsearch.license.plugin.LicensePlugin;
@ -29,7 +30,6 @@ import org.elasticsearch.license.plugin.core.LicenseState;
import org.elasticsearch.license.plugin.core.Licensee;
import org.elasticsearch.license.plugin.core.LicenseeRegistry;
import org.elasticsearch.node.Node;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.shield.ShieldPlugin;
import org.elasticsearch.shield.authc.support.UsernamePasswordToken;
@ -46,7 +46,9 @@ import java.util.List;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
/**
*
@ -253,7 +255,7 @@ public class LicensingTests extends ShieldIntegTestCase {
}
@Override
public void onModule(RestModule module) {
public void onModule(NetworkModule module) {
}
@Override

View File

@ -18,7 +18,6 @@ import org.elasticsearch.shield.audit.logfile.LoggingAuditTrail;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.threadpool.ThreadPoolModule;
import org.elasticsearch.transport.TransportModule;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
@ -56,11 +55,10 @@ public class AuditTrailModuleTests extends ESTestCase {
Injector injector = Guice.createInjector(
new SettingsModule(settings, new SettingsFilter(settings)),
new AuditTrailModule(settings),
new TransportModule(settings),
new CircuitBreakerModule(settings),
new ThreadPoolModule(pool),
new Version.Module(Version.CURRENT),
new NetworkModule(new NetworkService(settings))
new NetworkModule(new NetworkService(settings), settings, false)
);
AuditTrail auditTrail = injector.getInstance(AuditTrail.class);
assertThat(auditTrail, instanceOf(AuditTrailService.class));

View File

@ -12,6 +12,7 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.shield.action.ShieldActionMapper;
@ -24,7 +25,6 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.TransportChannel;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportModule;
import org.elasticsearch.transport.TransportRequest;
import org.elasticsearch.transport.TransportRequestHandler;
import org.elasticsearch.transport.TransportResponse;
@ -291,12 +291,12 @@ public class TransportFilterTests extends ESIntegTestCase {
public String description() {
return "a mock transport service for testing";
}
public void onModule(TransportModule transportModule) {
transportModule.addTransportService("filter-mock", InternalPluginServerTransportService.class);
public void onModule(NetworkModule module) {
module.registerTransportService("filter-mock", InternalPluginServerTransportService.class);
}
@Override
public Settings additionalSettings() {
return Settings.builder().put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, "filter-mock").build();
return Settings.builder().put(NetworkModule.TRANSPORT_SERVICE_TYPE_KEY, "filter-mock").build();
}
}

View File

@ -12,17 +12,15 @@ import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.http.HttpServerModule;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.license.plugin.LicensePlugin;
import org.elasticsearch.marvel.MarvelPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.shield.ShieldPlugin;
import org.elasticsearch.shield.authz.AuthorizationModule;
import org.elasticsearch.transport.TransportModule;
import org.elasticsearch.watcher.WatcherPlugin;
import java.security.AccessController;
@ -128,7 +126,7 @@ public class XPackPlugin extends Plugin {
marvelPlugin.onModule(module);
}
public void onModule(RestModule module) {
public void onModule(NetworkModule module) {
licensePlugin.onModule(module);
shieldPlugin.onModule(module);
watcherPlugin.onModule(module);
@ -140,14 +138,6 @@ public class XPackPlugin extends Plugin {
watcherPlugin.onModule(module);
}
public void onModule(TransportModule module) {
shieldPlugin.onModule(module);
}
public void onModule(HttpServerModule module) {
shieldPlugin.onModule(module);
}
public void onModule(AuthorizationModule module) {
shieldPlugin.onModule(module);
// FIXME clean these up

View File

@ -17,10 +17,10 @@ import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.logging.support.LoggerMessageFormat;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.shield.authz.AuthorizationModule;
import org.elasticsearch.watcher.actions.WatcherActionModule;
@ -35,7 +35,16 @@ import org.elasticsearch.watcher.history.HistoryStore;
import org.elasticsearch.watcher.input.InputModule;
import org.elasticsearch.watcher.license.LicenseModule;
import org.elasticsearch.watcher.license.WatcherLicensee;
import org.elasticsearch.watcher.rest.action.*;
import org.elasticsearch.watcher.rest.action.RestAckWatchAction;
import org.elasticsearch.watcher.rest.action.RestActivateWatchAction;
import org.elasticsearch.watcher.rest.action.RestDeleteWatchAction;
import org.elasticsearch.watcher.rest.action.RestExecuteWatchAction;
import org.elasticsearch.watcher.rest.action.RestGetWatchAction;
import org.elasticsearch.watcher.rest.action.RestHijackOperationAction;
import org.elasticsearch.watcher.rest.action.RestPutWatchAction;
import org.elasticsearch.watcher.rest.action.RestWatchServiceAction;
import org.elasticsearch.watcher.rest.action.RestWatcherInfoAction;
import org.elasticsearch.watcher.rest.action.RestWatcherStatsAction;
import org.elasticsearch.watcher.shield.InternalWatcherUser;
import org.elasticsearch.watcher.shield.ShieldIntegration;
import org.elasticsearch.watcher.shield.WatcherShieldModule;
@ -74,7 +83,11 @@ import org.elasticsearch.xpack.XPackPlugin;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
@ -177,18 +190,18 @@ public class WatcherPlugin extends Plugin {
}
}
public void onModule(RestModule module) {
public void onModule(NetworkModule module) {
if (enabled && !transportClient) {
module.addRestAction(RestPutWatchAction.class);
module.addRestAction(RestDeleteWatchAction.class);
module.addRestAction(RestWatcherStatsAction.class);
module.addRestAction(RestWatcherInfoAction.class);
module.addRestAction(RestGetWatchAction.class);
module.addRestAction(RestWatchServiceAction.class);
module.addRestAction(RestAckWatchAction.class);
module.addRestAction(RestActivateWatchAction.class);
module.addRestAction(RestExecuteWatchAction.class);
module.addRestAction(RestHijackOperationAction.class);
module.registerRestHandler(RestPutWatchAction.class);
module.registerRestHandler(RestDeleteWatchAction.class);
module.registerRestHandler(RestWatcherStatsAction.class);
module.registerRestHandler(RestWatcherInfoAction.class);
module.registerRestHandler(RestGetWatchAction.class);
module.registerRestHandler(RestWatchServiceAction.class);
module.registerRestHandler(RestAckWatchAction.class);
module.registerRestHandler(RestActivateWatchAction.class);
module.registerRestHandler(RestExecuteWatchAction.class);
module.registerRestHandler(RestHijackOperationAction.class);
}
}