*/
package org.sonar.server.platform.ws;
+import javax.servlet.http.HttpServletResponse;
+import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.common.platform.LivenessChecker;
"</p>")
.setSince("9.1")
.setInternal(true)
+ .setChangelog(new Change("10.8", "The endpoint doesn't log an error anymore when the liveness check fails. " +
+ "The failed HTTP status code changed from 500 to 503."))
.setContentType(Response.ContentType.NO_CONTENT)
.setHandler(handler);
}
if (livenessChecker.liveness()) {
response.noContent();
} else {
- throw new IllegalStateException("Liveness check failed");
+ response.stream().setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
}
}
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.SystemPasscode;
import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
import static org.assertj.core.api.Assertions.assertThat;
assertThat(definition.since()).isEqualTo("9.1");
assertThat(definition.isInternal()).isTrue();
assertThat(definition.responseExample()).isNull();
+ assertThat(definition.changelog()).isNotEmpty();
assertThat(definition.params()).isEmpty();
}
}
@Test
- public void liveness_check_failed_expect_500() {
+ public void liveness_check_failed_expect_503() {
when(systemPasscode.isValid(any())).thenReturn(true);
when(livenessChecker.liveness()).thenReturn(false);
- TestRequest request = underTest.newRequest();
- assertThatThrownBy(request::execute)
- .isInstanceOf(IllegalStateException.class)
- .hasMessage("Liveness check failed");
+ TestResponse response = underTest.newRequest().execute();
+
+ assertThat(response.getStatus()).isEqualTo(503);
}
@Test
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.user.SystemPasscode;
import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
import static org.assertj.core.api.Assertions.assertThat;
}
@Test
- public void liveness_check_failed_expect_500() {
+ public void liveness_check_failed_expect_503() {
when(systemPasscode.isValid(any())).thenReturn(true);
when(livenessChecker.liveness()).thenReturn(false);
- TestRequest request = underTest.newRequest();
- assertThatThrownBy(request::execute)
- .isInstanceOf(IllegalStateException.class)
- .hasMessage("Liveness check failed");
+ TestResponse response = underTest.newRequest().execute();
+
+ assertThat(response.getStatus()).isEqualTo(503);
}
@Test