]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4898 - Adjusting timeouts & fix possible NPE when ES is not ready
authorStephane Gamard <stephane.gamard@searchbox.com>
Tue, 15 Jul 2014 21:03:12 +0000 (23:03 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Tue, 15 Jul 2014 21:03:12 +0000 (23:03 +0200)
server/sonar-process/src/main/java/org/sonar/process/Process.java
server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java
server/sonar-process/src/test/java/org/sonar/process/ProcessTest.java
server/sonar-search/src/main/java/org/sonar/search/ElasticSearch.java

index 35604e185b9512550a0cb76789845ba18288e9ea..cf0ef61e557f7bb12b24f6d4f02f0bf6933dda48 100644 (file)
@@ -115,7 +115,7 @@ public abstract class Process implements ProcessMXBean {
     LOGGER.info("Process[{}]::start START", name);
     if (this.port != null) {
       lastPing = System.currentTimeMillis();
-      pingTask = monitor.scheduleWithFixedDelay(breakOnMissingPing, 0, 3, TimeUnit.SECONDS);
+      pingTask = monitor.scheduleWithFixedDelay(breakOnMissingPing, 5, 5, TimeUnit.SECONDS);
     }
     this.onStart();
     LOGGER.info("Process[{}]::start END", name);
index 5f14e83b45cc682149479acbbf400ab33229b8fd..379a5ceb2fc3ce81de2f01c834d52a571e7dbe3b 100644 (file)
@@ -37,6 +37,10 @@ import java.net.InetAddress;
 import java.net.MalformedURLException;
 import java.net.UnknownHostException;
 import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
 
 public class ProcessWrapper {
 
@@ -56,6 +60,16 @@ public class ProcessWrapper {
   private StreamGobbler outputGobbler;
 
 
+  private ScheduledFuture<?> pingTask = null;
+  final ScheduledExecutorService monitor = Executors.newScheduledThreadPool(1);
+  final Runnable pinging = new Runnable() {
+    public void run() {
+      processMXBean.ping();
+    }
+  };
+
+
+
   public ProcessWrapper(String className, Map<String, String> properties, final String name, Integer port, String... classPath) {
     LOGGER.info("Creating Process for '{}' with monitoring port: {}", name, port);
     this.name = name;
@@ -105,7 +119,7 @@ public class ProcessWrapper {
       throw new IllegalStateException("Could not connect to JMX service", e);
     }
 
-    //TODO Register Scheduled timer to ping the Mbean
+    pingTask = monitor.scheduleWithFixedDelay(pinging, 0, 3, TimeUnit.SECONDS);
   }
 
   public boolean isReady() {
@@ -113,21 +127,14 @@ public class ProcessWrapper {
   }
 
   public void stop() {
+    pingTask.cancel(true);
     processMXBean.stop();
   }
 
-  public void ping() {
-    processMXBean.ping();
-  }
-
   public String getName() {
     return name;
   }
 
-  public ProcessMXBean getProcessMXBean() {
-    return processMXBean;
-  }
-
   public java.lang.Process executeProcess() {
     ProcessBuilder processBuilder =
       new ProcessBuilder("java",
index 7d300208a5cabb544501ad7a6d41b836455cdadc..10fc44187d1407543603abbad4c59a48f032eb09 100644 (file)
@@ -130,7 +130,7 @@ public class ProcessTest {
     procThread.join();
   }
 
-  @Test(timeout = 5000L)
+  @Test(timeout = 15000L)
   public void should_stop_implicit() throws Exception {
     Properties properties = new Properties();
     properties.setProperty(Process.NAME_PROPERTY, "TEST");
index 6221102ad2127e9bf5d167948b0d7f2c5e43ab99..f65655e0314e8657ba7f6cca082236c6694cb625 100644 (file)
@@ -88,9 +88,9 @@ public class ElasticSearch extends Process {
       .put("path.home", home);
 
 //    if (props.booleanOf(ES_DEBUG_PROPERTY, false)) {
-      esSettings
-        .put("http.enabled", true)
-        .put("http.port", 9200);
+    esSettings
+      .put("http.enabled", true)
+      .put("http.port", 9200);
 //    } else {
 //      esSettings.put("http.enabled", false);
 //    }
@@ -103,9 +103,13 @@ public class ElasticSearch extends Process {
 
   @Override
   public boolean isReady() {
-    ClusterHealthStatus status = node.client().admin().cluster().prepareClusterStats()
-      .get().getStatus();
-    return status != null && status == ClusterHealthStatus.GREEN;
+    try {
+      ClusterHealthStatus status = node.client().admin().cluster().prepareClusterStats()
+        .get().getStatus();
+      return status != null && status == ClusterHealthStatus.GREEN;
+    } catch (Exception e) {
+      return false;
+    }
   }
 
   @Override