Fix audit, metric and error logs as per logging specification
[clamp.git] / src / main / java / org / onap / clamp / clds / service / CldsHealthcheckService.java
index c25e6e7..3fceace 100644 (file)
  * ============LICENSE_END============================================
  * ===================================================================
  */
-package org.onap.clamp.clds.service;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
+package org.onap.clamp.clds.service;
 
 import java.util.Date;
-
-import org.onap.clamp.clds.dao.CldsDao;
 import org.onap.clamp.clds.model.CldsHealthCheck;
 import org.onap.clamp.clds.util.LoggingUtils;
-import org.onap.clamp.clds.util.ONAPLogConstants;
+import org.onap.clamp.clds.util.OnapLogConstants;
+import org.onap.clamp.loop.LoopController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.slf4j.event.Level;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
 
 /**
@@ -44,44 +42,40 @@ import org.springframework.stereotype.Component;
 public class CldsHealthcheckService {
 
     @Autowired
-    private CldsDao cldsDao;
+    private LoopController loopController;
 
-    protected static final EELFLogger logger          = EELFManager.getInstance().getLogger(CldsHealthcheckService.class);
+    protected static final Logger logger = LoggerFactory.getLogger(CldsHealthcheckService.class);
 
     /**
      * REST service that retrieves clds healthcheck information.
      *
      * @return CldsHealthCheck class containing healthcheck info
      */
-    public ResponseEntity<CldsHealthCheck> gethealthcheck() {
+    public CldsHealthCheck gethealthcheck() {
         CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
         Date startTime = new Date();
         LoggingUtils util = new LoggingUtils(logger);
         LoggingUtils.setRequestContext("CldsService: GET healthcheck", "Clamp-Health-Check");
         LoggingUtils.setTimeContext(startTime, new Date());
-        boolean healthcheckFailed = false;
         try {
-            cldsDao.doHealthCheck();
+            loopController.getLoopNames();
             cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
             cldsHealthCheck.setHealthCheckStatus("UP");
             cldsHealthCheck.setDescription("OK");
-            LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName());
+            LoggingUtils.setResponseContext("0", "Get healthcheck success",
+                this.getClass().getName());
+            util.exiting(HttpStatus.OK.value(), "Healthcheck success", Level.INFO,
+                OnapLogConstants.ResponseStatus.COMPLETE);
         } catch (Exception e) {
-            healthcheckFailed = true;
             logger.error("CLAMP application Heath check failed", e);
-            LoggingUtils.setResponseContext("999", "Get healthcheck failed", this.getClass().getName());
+            LoggingUtils.setResponseContext("999", "Get healthcheck failed",
+                this.getClass().getName());
             cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
             cldsHealthCheck.setHealthCheckStatus("DOWN");
             cldsHealthCheck.setDescription("NOT-OK");
+            util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Healthcheck failed", Level.INFO,
+                OnapLogConstants.ResponseStatus.ERROR);
         }
-        // audit log
-        LoggingUtils.setTimeContext(startTime, new Date());
-        if(healthcheckFailed) {
-            util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "Healthcheck failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
-            return new ResponseEntity<>(cldsHealthCheck, HttpStatus.INTERNAL_SERVER_ERROR);
-        } else {
-            util.exiting("200", "Healthcheck failed", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
-            return new ResponseEntity<>(cldsHealthCheck, HttpStatus.OK);
-        }
+        return cldsHealthCheck;
     }
-}
\ No newline at end of file
+}