diff options
-rw-r--r-- | src/main/java/org/onap/clamp/clds/service/CldsService.java | 17 | ||||
-rw-r--r-- | src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java | 4 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index dc6ff432c..c3eb83bff 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -214,27 +214,34 @@ public class CldsService extends SecureServiceBase { @GET @Path("/healthcheck") @Produces(MediaType.APPLICATION_JSON) - public CldsHealthCheck gethealthcheck() { + public Response gethealthcheck() { CldsHealthCheck cldsHealthCheck = new CldsHealthCheck(); Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsService: GET healthcheck", getPrincipalName()); + LoggingUtils.setRequestContext("CldsService: GET healthcheck", "Clamp-Health-Check"); LoggingUtils.setTimeContext(startTime, new Date()); + boolean healthcheckFailed = false; try { cldsDao.doHealthCheck(); cldsHealthCheck.setHealthCheckComponent("CLDS-APP"); cldsHealthCheck.setHealthCheckStatus("UP"); cldsHealthCheck.setDescription("OK"); + LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName()); } catch (Exception e) { + healthcheckFailed = true; logger.error("CLAMP application DB Error", e); + LoggingUtils.setResponseContext("999", "Get healthcheck failed", this.getClass().getName()); cldsHealthCheck.setHealthCheckComponent("CLDS-APP"); cldsHealthCheck.setHealthCheckStatus("DOWN"); cldsHealthCheck.setDescription("NOT-OK"); } // audit log LoggingUtils.setTimeContext(startTime, new Date()); - LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName()); - securityLogger.info("GET healthcheck completed"); - return cldsHealthCheck; + logger.info("GET healthcheck completed"); + if (healthcheckFailed) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(cldsHealthCheck).build(); + } else { + return Response.status(Response.Status.OK).entity(cldsHealthCheck).build(); + } } /** diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java index 23df19c62..1450af902 100644 --- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java @@ -37,6 +37,7 @@ import java.security.GeneralSecurityException; import java.security.Principal; import java.util.Properties; +import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; import org.apache.commons.codec.DecoderException; @@ -127,7 +128,8 @@ public class CldsServiceItCase { @Test public void testGetHealthCheck() { - CldsHealthCheck cldsHealthCheck = cldsService.gethealthcheck(); + Response response = cldsService.gethealthcheck(); + CldsHealthCheck cldsHealthCheck = (CldsHealthCheck) response.getEntity(); assertNotNull(cldsHealthCheck); assertEquals("UP", cldsHealthCheck.getHealthCheckStatus()); assertEquals("CLDS-APP", cldsHealthCheck.getHealthCheckComponent()); |