Browse Source

SONAR-15239 fix DCE App node not starting

tags/9.1.0.47736
Pierre Guillot 2 years ago
parent
commit
cceda2bffc

+ 13
- 5
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/LivenessCheckerImpl.java View File

@@ -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;
}


+ 16
- 11
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/LivenessCheckerImplTest.java View File

@@ -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();
}
}

+ 2
- 2
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/SafeModeLivenessCheckerImplTest.java View File

@@ -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();

Loading…
Cancel
Save