diff options
author | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-04-26 11:06:36 +0200 |
---|---|---|
committer | Determe, Sebastien (sd378r) <sd378r@intl.att.com> | 2018-04-26 11:06:36 +0200 |
commit | 90fcd198e69fca04ed57f05ef88f83662d9349bf (patch) | |
tree | 35f2a5bcfb1ce077823b3d9d08d14fe013576e83 /src/main/java/org | |
parent | 4c04ea76999004cb1fe8cb4d318a621b474c13de (diff) |
Fix HealthCheck
Change the healthcheck method to answer by http code according to the
status
Issue-ID: CLAMP-157
Change-Id: I82b11cb385e346e23e2fa3ae82f8e099d0ca10ac
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/onap/clamp/clds/service/CldsService.java | 17 |
1 files changed, 12 insertions, 5 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(); + } } /** |