Fix xplugins to suppress mock transport and transport service

This is the xplugins side of elastic/elasticsearchelastic/elasticsearch#15495

Original commit: elastic/x-pack-elasticsearch@9c29c057a5
This commit is contained in:
Ryan Ernst 2015-12-16 18:13:56 -08:00
parent 60659c39fc
commit 134cdb22bb
9 changed files with 57 additions and 11 deletions

View File

@ -35,6 +35,7 @@ public class LicensePlugin extends Plugin {
public static final String NAME = "license";
private final boolean isEnabled;
protected final boolean transportClient;
static {
MetaData.registerPrototype(LicensesMetaData.TYPE, LicensesMetaData.PROTO);
@ -48,6 +49,7 @@ public class LicensePlugin extends Plugin {
} else {
this.isEnabled = true;
}
transportClient = "transport".equals(settings.get(Client.CLIENT_TYPE_SETTING));
}
@Override
@ -61,9 +63,11 @@ public class LicensePlugin extends Plugin {
}
public void onModule(NetworkModule module) {
module.registerRestHandler(RestPutLicenseAction.class);
module.registerRestHandler(RestGetLicenseAction.class);
module.registerRestHandler(RestDeleteLicenseAction.class);
if (transportClient == false) {
module.registerRestHandler(RestPutLicenseAction.class);
module.registerRestHandler(RestGetLicenseAction.class);
module.registerRestHandler(RestDeleteLicenseAction.class);
}
}
public void onModule(ActionModule module) {

View File

@ -29,6 +29,8 @@ import org.elasticsearch.shield.authc.support.SecuredString;
import org.elasticsearch.shield.crypto.InternalCryptoService;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.TestCluster;
import org.elasticsearch.test.transport.AssertingLocalTransport;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.xpack.XPackPlugin;
import org.hamcrest.Matcher;
import org.jboss.netty.util.internal.SystemPropertyUtil;
@ -41,6 +43,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -99,6 +102,14 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
.build();
}
@Override
protected Collection<Class<? extends Plugin>> getMockPlugins() {
Set<Class<? extends Plugin>> plugins = new HashSet<>(super.getMockPlugins());
plugins.remove(MockTransportService.TestPlugin.class); // shield has its own transport service
plugins.remove(AssertingLocalTransport.TestPlugin.class); // shield has its own transport
return plugins;
}
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singletonList(XPackPlugin.class);

View File

@ -192,8 +192,10 @@ public class ShieldPlugin extends Plugin {
}
public void onModule(NetworkModule module) {
// we want to expose the shield rest action even when the plugin is disabled
module.registerRestHandler(RestShieldInfoAction.class);
if (clientMode == false) {
// we want to expose the shield rest action even when the plugin is disabled
module.registerRestHandler(RestShieldInfoAction.class);
}
if (enabled == false) {
return;

View File

@ -18,6 +18,8 @@ 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.Transport;
import org.elasticsearch.transport.local.LocalTransport;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
@ -54,11 +56,16 @@ public class AuditTrailModuleTests extends ESTestCase {
try {
Injector injector = Guice.createInjector(
new SettingsModule(settings, new SettingsFilter(settings)),
new NetworkModule(new NetworkService(settings), settings, false) {
@Override
protected void configure() {
bind(Transport.class).to(LocalTransport.class).asEagerSingleton();
}
},
new AuditTrailModule(settings),
new CircuitBreakerModule(settings),
new ThreadPoolModule(pool),
new Version.Module(Version.CURRENT),
new NetworkModule(new NetworkService(settings), settings, false)
new Version.Module(Version.CURRENT)
);
AuditTrail auditTrail = injector.getInstance(AuditTrail.class);
assertThat(auditTrail, instanceOf(AuditTrailService.class));

View File

@ -157,7 +157,7 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase {
return builder.build();
}
};
cluster2 = new InternalTestCluster("network", randomLong(), createTempDir(), numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, true);
cluster2 = new InternalTestCluster("network", randomLong(), createTempDir(), numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, getMockPlugins());
cluster2.beforeTest(getRandom(), 0.5);
remoteClient = cluster2.client();

View File

@ -106,7 +106,7 @@ public class RemoteIndexAuditTrailStartingTests extends ShieldIntegTestCase {
return builder.build();
}
};
remoteCluster = new InternalTestCluster("network", randomLong(), createTempDir(), numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, true);
remoteCluster = new InternalTestCluster("network", randomLong(), createTempDir(), numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, getMockPlugins());
remoteCluster.beforeTest(getRandom(), 0.5);
}

View File

@ -63,8 +63,8 @@ public class TransportFilterTests extends ESIntegTestCase {
}
@Override
protected boolean enableMockModules() {
return false;
protected Collection<Class<? extends Plugin>> getMockPlugins() {
return Collections.emptyList();
}
@Override

View File

@ -14,6 +14,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.shield.authc.support.SecuredString;
import org.elasticsearch.test.ESIntegTestCase.SuppressLocalMode;
import org.elasticsearch.test.transport.AssertingLocalTransport;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.xpack.XPackPlugin;
import org.junit.AfterClass;
import org.junit.Before;
@ -23,6 +25,8 @@ import org.junit.rules.ExternalResource;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
@ -145,6 +149,14 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase {
.build();
}
@Override
protected Collection<Class<? extends Plugin>> getMockPlugins() {
Set<Class<? extends Plugin>> plugins = new HashSet<>(super.getMockPlugins());
plugins.remove(MockTransportService.TestPlugin.class); // shield has its own transport service
plugins.remove(AssertingLocalTransport.TestPlugin.class); // shield has its own transport
return plugins;
}
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return customShieldSettingsSource.nodePlugins();

View File

@ -31,6 +31,8 @@ import org.elasticsearch.shield.crypto.InternalCryptoService;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.TestCluster;
import org.elasticsearch.test.transport.AssertingLocalTransport;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.watcher.WatcherLifeCycleService;
import org.elasticsearch.watcher.WatcherModule;
import org.elasticsearch.watcher.WatcherService;
@ -127,6 +129,14 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
return excludes;
}
@Override
protected Collection<Class<? extends Plugin>> getMockPlugins() {
Set<Class<? extends Plugin>> plugins = new HashSet<>(super.getMockPlugins());
plugins.remove(MockTransportService.TestPlugin.class); // shield has its own transport service
plugins.remove(AssertingLocalTransport.TestPlugin.class); // shield has its own transport
return plugins;
}
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginTypes();