aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorPierre Guillot <50145663+pierre-guillot-sonarsource@users.noreply.github.com>2021-08-10 11:45:52 +0200
committersonartech <sonartech@sonarsource.com>2021-08-11 20:08:07 +0000
commitcceda2bffc35246d7846915a3243a495bf5decc9 (patch)
tree4e8f149384a123fabd5fa5f2184df1084d37e30d /server
parent321c84c9a711429649cb69b6fe44d2120adad0df (diff)
downloadsonarqube-cceda2bffc35246d7846915a3243a495bf5decc9.tar.gz
sonarqube-cceda2bffc35246d7846915a3243a495bf5decc9.zip
SONAR-15239 fix DCE App node not starting
Diffstat (limited to 'server')
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/LivenessCheckerImpl.java18
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/LivenessCheckerImplTest.java27
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeLivenessCheckerImplTest.java4
3 files changed, 31 insertions, 18 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/LivenessCheckerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/LivenessCheckerImpl.java
index 0be2dd55e6a..6c4fa0e1154 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/LivenessCheckerImpl.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/LivenessCheckerImpl.java
@@ -24,23 +24,31 @@ import org.sonar.server.health.DbConnectionNodeCheck;
import org.sonar.server.health.EsStatusNodeCheck;
import org.sonar.server.health.Health;
import org.sonar.server.health.WebServerStatusNodeCheck;
-import org.sonar.server.platform.WebServer;
public class LivenessCheckerImpl implements LivenessChecker {
- private final WebServer webServer;
private final DbConnectionNodeCheck dbConnectionNodeCheck;
private final CeStatusNodeCheck ceStatusNodeCheck;
private final EsStatusNodeCheck esStatusNodeCheck;
private final WebServerStatusNodeCheck webServerStatusNodeCheck;
- public LivenessCheckerImpl(WebServer webServer, DbConnectionNodeCheck dbConnectionNodeCheck,
+ public LivenessCheckerImpl(DbConnectionNodeCheck dbConnectionNodeCheck,
WebServerStatusNodeCheck webServerStatusNodeCheck, CeStatusNodeCheck ceStatusNodeCheck, EsStatusNodeCheck esStatusNodeCheck) {
- this.webServer = webServer;
this.dbConnectionNodeCheck = dbConnectionNodeCheck;
+ this.webServerStatusNodeCheck = webServerStatusNodeCheck;
this.ceStatusNodeCheck = ceStatusNodeCheck;
this.esStatusNodeCheck = esStatusNodeCheck;
+ }
+
+ /**
+ * Constructor used by Pico Container on non-standalone mode, so on a DCE App Node, where EsStatusNodeCheck is not available
+ */
+ public LivenessCheckerImpl(DbConnectionNodeCheck dbConnectionNodeCheck,
+ WebServerStatusNodeCheck webServerStatusNodeCheck, CeStatusNodeCheck ceStatusNodeCheck) {
+ this.dbConnectionNodeCheck = dbConnectionNodeCheck;
this.webServerStatusNodeCheck = webServerStatusNodeCheck;
+ this.ceStatusNodeCheck = ceStatusNodeCheck;
+ this.esStatusNodeCheck = null;
}
public boolean liveness() {
@@ -57,7 +65,7 @@ public class LivenessCheckerImpl implements LivenessChecker {
return false;
}
- if (webServer.isStandalone() && Health.Status.RED.equals(esStatusNodeCheck.check().getStatus())) {
+ if (esStatusNodeCheck != null && Health.Status.RED.equals(esStatusNodeCheck.check().getStatus())) {
return false;
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/LivenessCheckerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/LivenessCheckerImplTest.java
index 75e73cb9638..5ca61ee0699 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/LivenessCheckerImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/LivenessCheckerImplTest.java
@@ -26,7 +26,6 @@ import org.sonar.server.health.DbConnectionNodeCheck;
import org.sonar.server.health.EsStatusNodeCheck;
import org.sonar.server.health.Health;
import org.sonar.server.health.WebServerStatusNodeCheck;
-import org.sonar.server.platform.WebServer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -35,16 +34,16 @@ public class LivenessCheckerImplTest {
public static final Health RED = Health.newHealthCheckBuilder().setStatus(Health.Status.RED).build();
- private final WebServer webServer = mock(WebServer.class);
private final DbConnectionNodeCheck dbConnectionNodeCheck = mock(DbConnectionNodeCheck.class);
private final WebServerStatusNodeCheck webServerStatusNodeCheck = mock(WebServerStatusNodeCheck.class);
private final CeStatusNodeCheck ceStatusNodeCheck = mock(CeStatusNodeCheck.class);
private final EsStatusNodeCheck esStatusNodeCheck = mock(EsStatusNodeCheck.class);
- LivenessCheckerImpl underTest = new LivenessCheckerImpl(webServer, dbConnectionNodeCheck, webServerStatusNodeCheck, ceStatusNodeCheck, esStatusNodeCheck);
+ LivenessCheckerImpl underTest = new LivenessCheckerImpl(dbConnectionNodeCheck, webServerStatusNodeCheck, ceStatusNodeCheck, esStatusNodeCheck);
+ LivenessCheckerImpl underTestDCE = new LivenessCheckerImpl(dbConnectionNodeCheck, webServerStatusNodeCheck, ceStatusNodeCheck);
@Test
- public void fail_when_db_connexion_check_fail() {
+ public void fail_when_db_connection_check_fail() {
when(dbConnectionNodeCheck.check()).thenReturn(RED);
Assertions.assertThat(underTest.liveness()).isFalse();
@@ -68,25 +67,31 @@ public class LivenessCheckerImplTest {
}
@Test
- public void dont_fail_when_not_standalone_but_es_check_fail() {
+ public void fail_when_es_check_fail() {
when(dbConnectionNodeCheck.check()).thenReturn(Health.GREEN);
when(webServerStatusNodeCheck.check()).thenReturn(Health.GREEN);
when(ceStatusNodeCheck.check()).thenReturn(Health.GREEN);
- when(webServer.isStandalone()).thenReturn(false);
when(esStatusNodeCheck.check()).thenReturn(RED);
- Assertions.assertThat(underTest.liveness()).isTrue();
+ Assertions.assertThat(underTest.liveness()).isFalse();
}
@Test
- public void fail_when_not_dce_and_es_check_fail() {
+ public void success_when_db_web_ce_es_succeed() {
when(dbConnectionNodeCheck.check()).thenReturn(Health.GREEN);
when(webServerStatusNodeCheck.check()).thenReturn(Health.GREEN);
when(ceStatusNodeCheck.check()).thenReturn(Health.GREEN);
- when(webServer.isStandalone()).thenReturn(true);
- when(esStatusNodeCheck.check()).thenReturn(RED);
+ when(esStatusNodeCheck.check()).thenReturn(Health.GREEN);
- Assertions.assertThat(underTest.liveness()).isFalse();
+ Assertions.assertThat(underTest.liveness()).isTrue();
}
+ @Test
+ public void success_when_db_web_ce_succeed() {
+ when(dbConnectionNodeCheck.check()).thenReturn(Health.GREEN);
+ when(webServerStatusNodeCheck.check()).thenReturn(Health.GREEN);
+ when(ceStatusNodeCheck.check()).thenReturn(Health.GREEN);
+
+ Assertions.assertThat(underTestDCE.liveness()).isTrue();
+ }
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeLivenessCheckerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeLivenessCheckerImplTest.java
index 06cc8c7171e..3b36e247f95 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeLivenessCheckerImplTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeLivenessCheckerImplTest.java
@@ -34,14 +34,14 @@ public class SafeModeLivenessCheckerImplTest {
private final SafeModeLivenessCheckerImpl underTest = new SafeModeLivenessCheckerImpl(dbConnectionNodeCheck);
@Test
- public void fail_when_db_connexion_check_fail() {
+ public void fail_when_db_connection_check_fail() {
when(dbConnectionNodeCheck.check()).thenReturn(RED);
Assertions.assertThat(underTest.liveness()).isFalse();
}
@Test
- public void succeed_when_db_connexion_check_success() {
+ public void succeed_when_db_connection_check_success() {
when(dbConnectionNodeCheck.check()).thenReturn(Health.GREEN);
Assertions.assertThat(underTest.liveness()).isTrue();