]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9587 exclude non used ES modules from distribution zip
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 7 Sep 2017 13:23:27 +0000 (15:23 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 13 Sep 2017 13:50:55 +0000 (15:50 +0200)
pom.xml
server/sonar-server/src/main/java/org/sonar/server/es/EsClientProvider.java
sonar-application/assembly.xml
sonar-application/pom.xml
tests/src/test/java/org/sonarqube/tests/performance/server/ServerPerfTest.java

diff --git a/pom.xml b/pom.xml
index 176d71ab43e3de7763763a5f1359fabe5117d470..daa804740d7b05bfe9f095061c719154e17aeefb 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <groupId>org.elasticsearch.client</groupId>
         <artifactId>transport</artifactId>
         <version>${elasticsearch.version}</version>
+        <exclusions>
+          <exclusion>
+            <groupId>org.elasticsearch.plugin</groupId>
+            <artifactId>lang-mustache-client</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.elasticsearch.plugin</groupId>
+            <artifactId>transport-netty3-client</artifactId>
+          </exclusion>
+        </exclusions>
       </dependency>
       <dependency>
         <groupId>com.github.tlrx</groupId>
index 110ae95f6fa19c077d80c1bde10d373b288c167f..1dbd2eb5f8fe07de4ee644491b166ee84e2ed83b 100644 (file)
 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();
+        }
+      }
+    }
+  }
 }
index 16e91b4d6907b76b9cc6c51bdefa63cf0fa9c612..a2122e2ebff9ee226c06e966e3b3e5e612343020 100644 (file)
         <exclude>**/*.sh</exclude>
         <exclude>**/ant</exclude>
         <exclude>**/antRun</exclude>
+        <!--exclude ES modules by default in the distribution that we don't use-->
+        <exclude>elasticsearch/modules/lang-expression/</exclude>
+        <exclude>elasticsearch/modules/lang-groovy/</exclude>
+        <exclude>elasticsearch/modules/lang-mustache/</exclude>
+        <exclude>elasticsearch/modules/lang-painless/</exclude>
+        <exclude>elasticsearch/modules/transport-netty3/</exclude>
       </excludes>
       <fileMode>0644</fileMode>
     </fileSet>
index 709e73367ad4ea8d1f2ff4571371512c6204705e..515f206f3e81ffb44c68af5933b17453a2cad296 100644 (file)
             <configuration>
               <rules>
                 <requireFilesSize>
-                  <minsize>165000000</minsize>
-                  <maxsize>180000000</maxsize>
+                  <minsize>160000000</minsize>
+                  <maxsize>175000000</maxsize>
                   <files>
                     <file>${project.build.directory}/sonarqube-${project.version}.zip</file>
                   </files>
index 58be6c8df5127a4677db6791cf95b8d69af690ae..b53cb4baad468b21ad2029359dcb4f173aee66ae 100644 (file)
@@ -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();