]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5409 - Added "--debug" switch to start.jar
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 11 Jul 2014 09:00:05 +0000 (11:00 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 11 Jul 2014 09:00:16 +0000 (11:00 +0200)
server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java
sonar-start/src/main/java/org/sonar/start/StartServer.java

index d8ad63a62010008f7d820d958720d5bf48c5ea32..6dd31880e6a3210200771a678e5274ec18ac49e0 100644 (file)
@@ -34,6 +34,8 @@ public class ElasticSearch extends org.sonar.process.Process {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearch.class);
 
+
+  public static final String ES_DEBUG_PROPERTY = "esDebug";
   public static final String ES_PORT_PROPERTY = "esPort";
   public static final String ES_CLUSTER_PROPERTY = "esCluster";
   public static final String ES_HOME_PROPERTY = "esHome";
@@ -74,28 +76,30 @@ public class ElasticSearch extends org.sonar.process.Process {
       .put("index.number_of_shards", "1")
       .put("index.number_of_replicas", "0")
       .put("index.store.type", "mmapfs")
-//
       .put("indices.store.throttle.type", "merge")
       .put("indices.store.throttle.max_bytes_per_sec", "200mb")
-//
+
       .put("script.default_lang", "native")
       .put("script.native." + ListUpdate.NAME + ".type", ListUpdate.UpdateListScriptFactory.class.getName())
-//
+
       .put("cluster.name", clusterName)
-//
       .put("node.name", "sonarqube-" + System.currentTimeMillis())
       .put("node.data", true)
       .put("node.local", false)
-//
+
 //      .put("network.bind_host", "127.0.0.1")
-      .put("http.enabled", false)
-//      .put("http.port", 9200)
-//      .put("http.host", "127.0.0.1")
 
       .put("transport.tcp.port", port)
-
       .put("path.home", home);
 
+    if (props.booleanOf(ES_DEBUG_PROPERTY, false)) {
+      esSettings
+        .put("http.enabled", true)
+        .put("http.port", 9200);
+    } else {
+      esSettings.put("http.enabled", false);
+    }
+
     node = NodeBuilder.nodeBuilder()
       .settings(esSettings)
       .build().start();
@@ -103,14 +107,11 @@ public class ElasticSearch extends org.sonar.process.Process {
 
   @Override
   public void execute() {
-    while (node != null && !node.isClosed()) {
-      try {
-        Thread.sleep(1000);
-      } catch (InterruptedException e) {
-        e.printStackTrace();
-      }
+    try {
+      Thread.currentThread().join();
+    } catch (InterruptedException e) {
+      LOGGER.warn("ES Process has been interrupted");
     }
-    System.out.println("-- ES is done.");
   }
 
   public void shutdown() {
index a48745f30ded852d7927722674967924b94d3733..b45fec0e273e0b435eed4307579da9aefbe95084 100644 (file)
@@ -29,6 +29,9 @@ import java.io.File;
 import java.io.IOException;
 import java.net.DatagramSocket;
 import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
@@ -41,15 +44,25 @@ public final class StartServer {
   private final ExecutorService executor;
   private final MonitorService monitor;
   private final String esPort;
+  private final Map<String, String> properties;
 
   private ProcessWrapper elasticsearch;
   private ProcessWrapper sonarqube;
 
   public StartServer(Env env) throws IOException {
+    this(env, new String[]{});
+  }
+
+  public StartServer(Env env, String... args) throws IOException {
     this.env = env;
     this.executor = Executors.newFixedThreadPool(2);
     this.monitor = new MonitorService(systemAvailableSocket());
     this.esPort = Integer.toString(NetworkUtils.freePort());
+    this.properties = new HashMap<String, String>();
+
+    if (Arrays.binarySearch(args, "--debug") > -1) {
+      properties.put("esDebug", "true");
+    }
 
     Runtime.getRuntime().addShutdownHook(new Thread() {
       @Override
@@ -116,6 +129,7 @@ public final class StartServer {
       "org.sonar.search.ElasticSearch",
       new String[]{env.rootDir().getAbsolutePath() + "/lib/search/sonar-search-4.5-SNAPSHOT.jar"},
       ImmutableMap.of(
+        "esDebug", properties.containsKey("esDebug") ? properties.get("esDebug") : "false",
         "esPort", esPort,
         "esHome", env.rootDir().getAbsolutePath()),
       "ES", monitor.getMonitoringPort());
@@ -125,6 +139,6 @@ public final class StartServer {
 
   public static void main(String... args) throws InterruptedException, IOException, URISyntaxException {
     File home = new File(".");
-    new StartServer(new Env(home)).start();
+    new StartServer(new Env(home), args).start();
   }
 }
\ No newline at end of file