From 46cea1eed83a0abe5b1fd7f50efb6f3b367ed43b Mon Sep 17 00:00:00 2001 From: Sébastien Lesaint Date: Thu, 7 Sep 2017 15:23:27 +0200 Subject: SONAR-9587 exclude non used ES modules from distribution zip --- pom.xml | 10 ++++++ .../java/org/sonar/server/es/EsClientProvider.java | 40 ++++++++++++++++++++-- sonar-application/assembly.xml | 6 ++++ sonar-application/pom.xml | 4 +-- .../tests/performance/server/ServerPerfTest.java | 2 +- 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 176d71ab43e..daa804740d7 100644 --- a/pom.xml +++ b/pom.xml @@ -715,6 +715,16 @@ org.elasticsearch.client transport ${elasticsearch.version} + + + org.elasticsearch.plugin + lang-mustache-client + + + org.elasticsearch.plugin + transport-netty3-client + + com.github.tlrx diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java b/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java index 110ae95f6fa..1dbd2eb5f8f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java +++ b/server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java @@ -20,14 +20,22 @@ package org.sonar.server.es; import com.google.common.net.HostAndPort; +import io.netty.util.ThreadDeathWatcher; +import io.netty.util.concurrent.GlobalEventExecutor; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.network.NetworkModule; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.transport.client.PreBuiltTransportClient; +import org.elasticsearch.index.reindex.ReindexPlugin; +import org.elasticsearch.join.ParentJoinPlugin; +import org.elasticsearch.percolator.PercolatorPlugin; +import org.elasticsearch.transport.Netty4Plugin; import org.picocontainer.injectors.ProviderAdapter; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.config.Configuration; @@ -37,6 +45,7 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.cluster.NodeType; import org.sonar.process.ProcessProperties; +import static java.util.Collections.unmodifiableList; import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; import static org.sonar.cluster.ClusterProperties.CLUSTER_NODE_TYPE; @@ -53,14 +62,14 @@ public class EsClientProvider extends ProviderAdapter { public EsClient provide(Configuration config) { if (cache == null) { - org.elasticsearch.common.settings.Settings.Builder esSettings = org.elasticsearch.common.settings.Settings.builder(); + Settings.Builder esSettings = Settings.builder(); // mandatory property defined by bootstrap process esSettings.put("cluster.name", config.get(CLUSTER_NAME).get()); boolean clusterEnabled = config.getBoolean(CLUSTER_ENABLED).orElse(false); boolean searchNode = !clusterEnabled || SEARCH.equals(NodeType.parse(config.get(CLUSTER_NODE_TYPE).orElse(null))); - final TransportClient nativeClient = new PreBuiltTransportClient(esSettings.build()); + final TransportClient nativeClient = new MinimalTransportClient(esSettings.build()); if (clusterEnabled && !searchNode) { esSettings.put("client.transport.sniff", true); Arrays.stream(config.getStringArray(CLUSTER_SEARCH_HOSTS)) @@ -89,4 +98,29 @@ public class EsClientProvider extends ProviderAdapter { private static String displayedAddresses(TransportClient nativeClient) { return nativeClient.transportAddresses().stream().map(TransportAddress::toString).collect(Collectors.joining(", ")); } + + static class MinimalTransportClient extends TransportClient { + + MinimalTransportClient(Settings settings) { + super(settings, unmodifiableList(Arrays.asList(Netty4Plugin.class, ReindexPlugin.class, PercolatorPlugin.class, ParentJoinPlugin.class))); + } + + @Override + public void close() { + super.close(); + if (!NetworkModule.TRANSPORT_TYPE_SETTING.exists(settings) + || NetworkModule.TRANSPORT_TYPE_SETTING.get(settings).equals(Netty4Plugin.NETTY_TRANSPORT_NAME)) { + try { + GlobalEventExecutor.INSTANCE.awaitInactivity(5, TimeUnit.SECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + try { + ThreadDeathWatcher.awaitInactivity(5, TimeUnit.SECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + } } diff --git a/sonar-application/assembly.xml b/sonar-application/assembly.xml index 16e91b4d690..a2122e2ebff 100644 --- a/sonar-application/assembly.xml +++ b/sonar-application/assembly.xml @@ -179,6 +179,12 @@ **/*.sh **/ant **/antRun + + elasticsearch/modules/lang-expression/ + elasticsearch/modules/lang-groovy/ + elasticsearch/modules/lang-mustache/ + elasticsearch/modules/lang-painless/ + elasticsearch/modules/transport-netty3/ 0644 diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index 709e73367ad..515f206f3e8 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -240,8 +240,8 @@ - 165000000 - 180000000 + 160000000 + 175000000 ${project.build.directory}/sonarqube-${project.version}.zip diff --git a/tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java b/tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java index 58be6c8df51..b53cb4baad4 100644 --- a/tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java +++ b/tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java @@ -60,7 +60,7 @@ public class ServerPerfTest extends AbstractPerfTest { // compare dates of first and last log long firstLogDate = ServerLogs.extractFirstDate(readLines(orchestrator.getServer().getAppLogs())).getTime(); long startedAtDate = extractStartedAtDate(orchestrator); - assertDurationAround(startedAtDate - firstLogDate, 34_000); + assertDurationAround(startedAtDate - firstLogDate, 32_000); ServerLogs.clear(orchestrator); orchestrator.stop(); -- cgit v1.2.3