From d923d6792617e677da934836843d780cf44e52dc Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Thu, 10 Mar 2022 17:56:48 +0000 Subject: Fix PAP healthcheck response during failures The healthcheck response that is returned by PAP is not inline with the actual healthreport. Even when the report has healthy:false, code:503, message:not alive the response code stays 200. This is fixed, this also makes the improved readiness probe in OOM to work properly with the healthcheck calls Change-Id: Ib208e0a84bce74157aacbcad61a11dcf900c7c94 Issue-ID: POLICY-4030 Signed-off-by: a.sreekumar --- .../onap/policy/pap/main/rest/HealthCheckRestControllerV1.java | 3 ++- .../policy/pap/main/rest/TestHealthCheckRestControllerV1.java | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'main') diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java index 896f2aac..2687a302 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java @@ -53,7 +53,8 @@ public class HealthCheckRestControllerV1 extends PapRestControllerV1 { @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)}) public ResponseEntity healthcheck() { - return ResponseEntity.ok().body(provider.performHealthCheck(true)); + var report = provider.performHealthCheck(true); + return ResponseEntity.status(report.getCode()).body(report); } } diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java index bc97c634..359f9cb8 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java @@ -22,6 +22,7 @@ package org.onap.policy.pap.main.rest; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; @@ -64,7 +65,9 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer { markActivatorDead(); final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT); - final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class); + var response = invocationBuilder.get(); + var report = response.readEntity(HealthCheckReport.class); + assertThat(response.getStatus()).isEqualTo(503); validateHealthCheckReport(NAME, SELF, false, 503, NOT_ALIVE, report); } @@ -72,7 +75,9 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer { public void testHealthCheckDbConnectionFailure() throws Exception { when(policyStatusProvider.getPolicyStatus()).thenThrow(PfModelRuntimeException.class); final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT); - final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class); + var response = invocationBuilder.get(); + var report = response.readEntity(HealthCheckReport.class); + assertThat(response.getStatus()).isEqualTo(503); validateHealthCheckReport(NAME, SELF, false, 503, NOT_ALIVE, report); } -- cgit 1.2.3-korg