Improve Logs in the methods. 79/30479/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Tue, 6 Feb 2018 15:06:19 +0000 (16:06 +0100)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Tue, 6 Feb 2018 15:06:19 +0000 (16:06 +0100)
Add info to the logs inthe different methods

Issue-ID: CLAMP-85
Change-Id: Idf2aa1a8e3178b2be55d5dbcc47b1a3a8d016f38
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java

index 51e4abc..b8863e0 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================\r
  * ONAP CLAMP\r
  * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights\r
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights\r
  *                             reserved.\r
  * ================================================================================\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
@@ -42,16 +42,17 @@ import org.springframework.beans.factory.annotation.Autowired;
  *\r
  */\r
 public class DcaeDispatcherServices {\r
-    protected static final EELFLogger logger                 = EELFManager.getInstance()\r
+    protected static final EELFLogger logger                       = EELFManager.getInstance()\r
             .getLogger(DcaeDispatcherServices.class);\r
-    protected static final EELFLogger metricsLogger          = EELFManager.getInstance().getMetricsLogger();\r
+    protected static final EELFLogger metricsLogger                = EELFManager.getInstance().getMetricsLogger();\r
     @Autowired\r
     private RefProp                   refProp;\r
-    private static final String       STATUS_URL_LOG         = "Status URL extracted: ";\r
-    private static final String       DCAE_URL_PREFIX        = "/dcae-deployments/";\r
-    private static final String       DCAE_URL_PROPERTY_NAME = "DCAE_DISPATCHER_URL";\r
-    private static final String       DCAE_LINK_FIELD        = "links";\r
-    private static final String       DCAE_STATUS_FIELD      = "status";\r
+    private static final String       STATUS_URL_LOG               = "Status URL extracted: ";\r
+    private static final String       DCAE_URL_PREFIX              = "/dcae-deployments/";\r
+    private static final String       DCAE_URL_PROPERTY_NAME       = "DCAE_DISPATCHER_URL";\r
+    public static final String        DCAE_REQUESTID_PROPERTY_NAME = "dcae.header.requestId";\r
+    private static final String       DCAE_LINK_FIELD              = "links";\r
+    private static final String       DCAE_STATUS_FIELD            = "status";\r
 \r
     /**\r
      * Delete the deployment on DCAE.\r
@@ -72,8 +73,12 @@ public class DcaeDispatcherServices {
             JSONObject linksObj = (JSONObject) jsonObj.get(DCAE_LINK_FIELD);\r
             String statusUrl = (String) linksObj.get(DCAE_STATUS_FIELD);\r
             logger.info(STATUS_URL_LOG + statusUrl);\r
+            LoggingUtils.setResponseContext("0", "Delete deployments success", this.getClass().getName());\r
             return statusUrl;\r
         } catch (Exception e) {\r
+               //Log StatusCode during exception in metrics log \r
+            LoggingUtils.setResponseContext("900", "Delete deployments failed", this.getClass().getName());\r
+            LoggingUtils.setErrorContext("900", "Delete deployments error");\r
             logger.error("Exception occurred during Delete Deployment Operation with DCAE", e);\r
             throw new DcaeDeploymentException("Exception occurred during Delete Deployment Operation with DCAE", e);\r
         } finally {\r
@@ -103,8 +108,12 @@ public class DcaeDispatcherServices {
             String operationType = (String) jsonObj.get("operationType");\r
             String status = (String) jsonObj.get("status");\r
             logger.info("Operation Type - " + operationType + ", Status " + status);\r
+            LoggingUtils.setResponseContext("0", "Get operation status success", this.getClass().getName());\r
             opStatus = status;\r
         } catch (Exception e) {\r
+               //Log StatusCode during exception in metrics log \r
+            LoggingUtils.setResponseContext("900", "Get operation status failed", this.getClass().getName());\r
+            LoggingUtils.setErrorContext("900", "Get operation status error");\r
             logger.error("Exception occurred during getOperationStatus Operation with DCAE", e);\r
         } finally {\r
             LoggingUtils.setTimeContext(startTime, new Date());\r
@@ -123,7 +132,11 @@ public class DcaeDispatcherServices {
         try {\r
             String url = refProp.getStringValue(DCAE_URL_PROPERTY_NAME) + DCAE_URL_PREFIX;\r
             DcaeHttpConnectionManager.doDcaeHttpQuery(url, "GET", null, null);\r
+            LoggingUtils.setResponseContext("0", "Get deployments success", this.getClass().getName());\r
         } catch (Exception e) {\r
+               //Log StatusCode during exception in metrics log \r
+            LoggingUtils.setResponseContext("900", "Get deployments failed", this.getClass().getName());\r
+            LoggingUtils.setErrorContext("900", "Get deployments error");\r
             logger.error("Exception occurred during getDeployments Operation with DCAE", e);\r
             throw new DcaeDeploymentException("Exception occurred during getDeployments Operation with DCAE", e);\r
         } finally {\r
@@ -158,8 +171,12 @@ public class DcaeDispatcherServices {
             JSONObject linksObj = (JSONObject) jsonObj.get(DCAE_LINK_FIELD);\r
             String statusUrl = (String) linksObj.get(DCAE_STATUS_FIELD);\r
             logger.info(STATUS_URL_LOG + statusUrl);\r
+            LoggingUtils.setResponseContext("0", "Create new deployment failed", this.getClass().getName());\r
             return statusUrl;\r
         } catch (Exception e) {\r
+               //Log StatusCode during exception in metrics log \r
+            LoggingUtils.setResponseContext("900", "Create new deployment failed", this.getClass().getName());\r
+            LoggingUtils.setErrorContext("900", "Create new deployment error");\r
             logger.error("Exception occurred during createNewDeployment Operation with DCAE", e);\r
             throw new DcaeDeploymentException("Exception occurred during createNewDeployment Operation with DCAE", e);\r
         } finally {\r
@@ -192,8 +209,12 @@ public class DcaeDispatcherServices {
             JSONObject linksObj = (JSONObject) jsonObj.get(DCAE_LINK_FIELD);\r
             String statusUrl = (String) linksObj.get(DCAE_STATUS_FIELD);\r
             logger.info(STATUS_URL_LOG + statusUrl);\r
+            LoggingUtils.setResponseContext("0", "Delete existing deployment success", this.getClass().getName());\r
             return statusUrl;\r
         } catch (Exception e) {\r
+               //Log StatusCode during exception in metrics log \r
+            LoggingUtils.setResponseContext("900", "Delete existing deployment failed", this.getClass().getName());\r
+            LoggingUtils.setErrorContext("900", "Delete existing deployment error");\r
             logger.error("Exception occurred during deleteExistingDeployment Operation with DCAE", e);\r
             throw new DcaeDeploymentException("Exception occurred during deleteExistingDeployment Operation with DCAE",\r
                     e);\r