aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-02-20 17:55:57 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-02-24 20:27:07 +0100
commitf8304edef63a6648ab1f05843a6be4e99af9dc71 (patch)
treec3cfec3c536d2318613fd6ae5bf8bcef93402a88
parentf874edc25c9217cd7e2ccbf3c849efb55ccfb231 (diff)
downloadsonarqube-f8304edef63a6648ab1f05843a6be4e99af9dc71.tar.gz
sonarqube-f8304edef63a6648ab1f05843a6be4e99af9dc71.zip
SONAR-7500 remove useless Monitored WARN log when web fails to start
by replacing Monitored#isUp() by Monitored#getStatus()
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java7
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java19
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/Monitored.java10
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java31
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java8
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java6
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java4
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java4
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/SearchServer.java13
-rw-r--r--server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java14
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java12
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java15
13 files changed, 87 insertions, 59 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
index 360d7409e16..1ae2b34143e 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
@@ -78,10 +78,13 @@ public class CeServer implements Monitored {
}
@Override
- public boolean isUp() {
+ public Status getStatus() {
checkState(ceMainThread != null, "isUp() can not be called before start()");
- return ceMainThread.isStarted();
+ if (ceMainThread.isStarted()) {
+ return Status.UP;
+ }
+ return Status.DOWN;
}
@Override
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java
index 4393a5c2062..0a4f46caab0 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java
@@ -32,6 +32,7 @@ import org.junit.rules.Timeout;
import org.mockito.Mockito;
import org.sonar.ce.ComputeEngine;
import org.sonar.process.MinimumViableSystem;
+import org.sonar.process.Monitored;
import static com.google.common.base.Preconditions.checkState;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -97,7 +98,7 @@ public class CeServerTest {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("isUp() can not be called before start()");
- ceServer.isUp();
+ ceServer.getStatus();
}
@Test
@@ -107,15 +108,15 @@ public class CeServerTest {
ceServer.start();
- assertThat(ceServer.isUp()).isFalse();
+ assertThat(ceServer.getStatus()).isEqualTo(Monitored.Status.DOWN);
// release ComputeEngine startup method
computeEngine.releaseStartup();
- while (!ceServer.isUp()) {
+ while (ceServer.getStatus() == Monitored.Status.DOWN) {
// wait for isReady to change to true, otherwise test will fail with timeout
}
- assertThat(ceServer.isUp()).isTrue();
+ assertThat(ceServer.getStatus()).isEqualTo(Monitored.Status.UP);
}
@Test
@@ -127,15 +128,15 @@ public class CeServerTest {
ceServer.start();
- assertThat(ceServer.isUp()).isFalse();
+ assertThat(ceServer.getStatus()).isEqualTo(Monitored.Status.DOWN);
// release ComputeEngine startup method which will throw startupException
computeEngine.releaseStartup();
- while (!ceServer.isUp()) {
+ while (ceServer.getStatus() == Monitored.Status.DOWN) {
// wait for isReady to change to true, otherwise test will fail with timeout
}
- assertThat(ceServer.isUp()).isTrue();
+ assertThat(ceServer.getStatus()).isEqualTo(Monitored.Status.UP);
}
@Test
@@ -148,7 +149,7 @@ public class CeServerTest {
ceServer.start();
ceServer.awaitStop();
- assertThat(ceServer.isUp()).isTrue();
+ assertThat(ceServer.getStatus()).isEqualTo(Monitored.Status.UP);
}
@Test
@@ -186,7 +187,7 @@ public class CeServerTest {
}
@Test
- public void awaitStop_keeps_blocking_calling_thread_even_if_calling_thread_is_interrupted_but_until_stop_is_called() throws InterruptedException, IOException {
+ public void awaitStop_keeps_blocking_calling_thread_even_if_calling_thread_is_interrupted_but_until_stop_is_called() throws Exception {
final CeServer ceServer = newCeServer();
Thread waitingThread = newWaitingThread(ceServer::awaitStop);
diff --git a/server/sonar-process/src/main/java/org/sonar/process/Monitored.java b/server/sonar-process/src/main/java/org/sonar/process/Monitored.java
index 3c59d8e7b03..837c658cf3b 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/Monitored.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/Monitored.java
@@ -27,10 +27,14 @@ public interface Monitored {
void start();
/**
- * True if the process is done starting, false otherwise.
- * An exception may be thrown if process fails to start.
+ * {@link Status#UP} if the process is done starting, {@link Status#FAILED} if the process failed to start,
+ * {@link Status#DOWN} otherwise.
*/
- boolean isUp();
+ Status getStatus();
+
+ enum Status {
+ UP, DOWN, FAILED
+ }
/**
* Blocks until the process is terminated
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
index 24bb54c6218..dffa067fd2c 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
@@ -100,26 +100,33 @@ public class ProcessEntryPoint implements Stoppable {
stopWatcher.start();
monitored.start();
- boolean up = false;
- while (!up) {
- up = monitored.isUp();
- Thread.sleep(20L);
- }
-
- // notify monitor that process is ready
- commands.setUp();
-
- if (lifecycle.tryToMoveTo(Lifecycle.State.STARTED)) {
- monitored.awaitStop();
+ Monitored.Status status = waitForNotDownStatus();
+ if (status == Monitored.Status.UP) {
+ // notify monitor that process is ready
+ commands.setUp();
+
+ if (lifecycle.tryToMoveTo(Lifecycle.State.STARTED)) {
+ monitored.awaitStop();
+ }
+ } else {
+ stop();
}
} catch (Exception e) {
logger.warn("Fail to start " + getKey(), e);
-
} finally {
stop();
}
}
+ private Monitored.Status waitForNotDownStatus() throws InterruptedException {
+ Monitored.Status status = Monitored.Status.DOWN;
+ while (status == Monitored.Status.DOWN) {
+ status = monitored.getStatus();
+ Thread.sleep(20L);
+ }
+ return status;
+ }
+
boolean isStarted() {
return lifecycle.getState() == Lifecycle.State.STARTED;
}
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
index 39934f77b04..02c07db7c66 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
@@ -173,8 +173,8 @@ public class ProcessEntryPointTest {
}
@Override
- public boolean isUp() {
- return true;
+ public Status getStatus() {
+ return Status.UP;
}
@Override
@@ -196,8 +196,8 @@ public class ProcessEntryPointTest {
}
@Override
- public boolean isUp() {
- return false;
+ public Status getStatus() {
+ return Status.DOWN;
}
@Override
diff --git a/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java b/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java
index 0e8fd31dc53..d11b173400e 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java
@@ -88,15 +88,15 @@ public class HttpProcess implements Monitored {
}
@Override
- public boolean isUp() {
+ public Status getStatus() {
if (ready) {
- return true;
+ return Status.UP;
}
if (server.isStarted()) {
ready = true;
writeTimeToFile("readyAt");
}
- return ready;
+ return ready ? Status.UP : Status.DOWN;
}
@Override
diff --git a/server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java b/server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java
index 8b9f04a7d21..47edc81a47c 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java
@@ -51,8 +51,8 @@ public class InfiniteTerminationProcess implements Monitored {
}
@Override
- public boolean isUp() {
- return state == State.STARTED;
+ public Status getStatus() {
+ return state == State.STARTED ? Status.UP : Status.DOWN;
}
@Override
diff --git a/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java b/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java
index cc76a7bf862..2c7cf0aaeff 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java
@@ -51,8 +51,8 @@ public class StandardProcess implements Monitored {
}
@Override
- public boolean isUp() {
- return state == State.STARTED;
+ public Status getStatus() {
+ return state == State.STARTED ? Status.UP : Status.DOWN;
}
@Override
diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
index 149257b38d7..b35ff952f27 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
@@ -56,12 +56,13 @@ public class SearchServer implements Monitored {
}
@Override
- public boolean isUp() {
- return node != null && node.client().admin().cluster().prepareHealth()
- .setWaitForYellowStatus()
- .setTimeout(TimeValue.timeValueSeconds(30L))
- .get()
- .getStatus() != ClusterHealthStatus.RED;
+ public Status getStatus() {
+ boolean esStatus = node != null && node.client().admin().cluster().prepareHealth()
+ .setWaitForYellowStatus()
+ .setTimeout(TimeValue.timeValueSeconds(30L))
+ .get()
+ .getStatus() != ClusterHealthStatus.RED;
+ return esStatus ? Status.UP : Status.DOWN;
}
@Override
diff --git a/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java b/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java
index c83df4ae3dc..d1ed8480767 100644
--- a/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java
+++ b/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java
@@ -34,6 +34,7 @@ import org.junit.rules.DisableOnDebug;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
+import org.sonar.process.Monitored;
import org.sonar.process.NetworkUtils;
import org.sonar.process.ProcessEntryPoint;
import org.sonar.process.ProcessProperties;
@@ -82,7 +83,7 @@ public class SearchServerTest {
underTest = new SearchServer(props);
underTest.start();
- assertThat(underTest.isUp()).isTrue();
+ assertThat(underTest.getStatus()).isEqualTo(Monitored.Status.UP);
Settings settings = Settings.builder().put("cluster.name", A_CLUSTER_NAME).build();
client = TransportClient.builder().settings(settings).build()
diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java b/server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
index 01444fa0ca6..58f355dc5d4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
@@ -65,9 +65,9 @@ class EmbeddedTomcat {
}
}
- boolean isUp() {
+ Status getStatus() {
if (webappContext == null) {
- return false;
+ return Status.DOWN;
}
switch (webappContext.getState()) {
case NEW:
@@ -75,15 +75,19 @@ class EmbeddedTomcat {
case INITIALIZED:
case STARTING_PREP:
case STARTING:
- return false;
+ return Status.DOWN;
case STARTED:
- return true;
+ return Status.UP;
default:
// problem, stopped or failed
- throw new IllegalStateException("Webapp did not start");
+ return Status.FAILED;
}
}
+ public enum Status {
+ DOWN, UP, FAILED
+ }
+
private File tomcatBasedir() {
return new File(props.value(ProcessProperties.PATH_TEMP), "tc");
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java b/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java
index fe19c547dd7..cdfdc58e168 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java
@@ -42,8 +42,16 @@ public class WebServer implements Monitored {
}
@Override
- public boolean isUp() {
- return tomcat.isUp();
+ public Status getStatus() {
+ switch (tomcat.getStatus()) {
+ case DOWN:
+ return Status.DOWN;
+ case UP:
+ return Status.UP;
+ case FAILED:
+ default:
+ return Status.FAILED;
+ }
}
@Override
diff --git a/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java b/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java
index b87f1d2d18b..480c6d9add2 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java
@@ -19,6 +19,11 @@
*/
package org.sonar.server.app;
+import java.io.File;
+import java.net.ConnectException;
+import java.net.Inet4Address;
+import java.net.URL;
+import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
@@ -26,12 +31,6 @@ import org.junit.rules.TemporaryFolder;
import org.sonar.process.NetworkUtils;
import org.sonar.process.Props;
-import java.io.File;
-import java.net.ConnectException;
-import java.net.Inet4Address;
-import java.net.URL;
-import java.util.Properties;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
@@ -60,9 +59,9 @@ public class EmbeddedTomcatTest {
props.set("sonar.web.port", String.valueOf(httpPort));
props.set("sonar.ajp.port", String.valueOf(ajpPort));
EmbeddedTomcat tomcat = new EmbeddedTomcat(props);
- assertThat(tomcat.isUp()).isFalse();
+ assertThat(tomcat.getStatus()).isEqualTo(EmbeddedTomcat.Status.DOWN);
tomcat.start();
- assertThat(tomcat.isUp()).isTrue();
+ assertThat(tomcat.getStatus()).isEqualTo(EmbeddedTomcat.Status.UP);
// check that http connector accepts requests
URL url = new URL("http://" + Inet4Address.getLocalHost().getHostAddress() + ":" + httpPort);