Update Logging Specifications
[clamp.git] / src / main / java / org / onap / clamp / clds / client / req / sdc / SdcCatalogServices.java
index 240094e..4422c92 100644 (file)
@@ -97,6 +97,7 @@ public class SdcCatalogServices {
     private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";\r
     private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";\r
     private static final String RESOURCE_URL_PREFIX = "resources";\r
+    private static final LoggingUtils utils = new LoggingUtils (logger);\r
     @Autowired\r
     private ClampProperties refProp;\r
 \r
@@ -134,7 +135,6 @@ public class SdcCatalogServices {
         Date startTime = new Date();\r
         String baseUrl = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);\r
         String basicAuth = getSdcBasicAuth();\r
-        LoggingUtils.setTargetContext("SDC", "getSdcServicesInformation");\r
         try {\r
             String url = baseUrl;\r
             if (uuid != null && !uuid.isEmpty()) {\r
@@ -142,6 +142,7 @@ public class SdcCatalogServices {
             }\r
             URL urlObj = new URL(url);\r
             HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+            conn = utils.invoke(conn,"SDC", "getSdcServicesInformation");\r
             conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);\r
             conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
             conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");\r
@@ -149,8 +150,7 @@ public class SdcCatalogServices {
             conn.setRequestMethod("GET");\r
             String resp = getResponse(conn);\r
             logger.debug("Services list received from SDC:" + resp);\r
-            // metrics log\r
-            LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());\r
+            utils.invokeReturn();\r
             return resp;\r
         } catch (IOException e) {\r
             LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());\r
@@ -160,6 +160,7 @@ public class SdcCatalogServices {
             LoggingUtils.setTimeContext(startTime, new Date());\r
             metricsLogger.info("getSdcServicesInformation complete");\r
         }\r
+        utils.invokeReturn();\r
         return "";\r
     }\r
 \r
@@ -346,6 +347,7 @@ public class SdcCatalogServices {
             byte[] postData = formattedSdcReq.getBytes(StandardCharsets.UTF_8);\r
             int postDataLength = postData.length;\r
             HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, formattedSdcReq);\r
+            conn = utils.invoke(conn,"SDC", "uploadArtifact");\r
             try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
                 wr.write(postData);\r
             }\r
@@ -358,11 +360,14 @@ public class SdcCatalogServices {
             String responseStr = getResponse(conn);\r
             if (responseStr != null && requestFailed) {\r
                 logger.error("requestFailed - responseStr=" + responseStr);\r
+                utils.invokeReturn();\r
                 throw new BadRequestException(responseStr);\r
             }\r
+            utils.invokeReturn();\r
             return responseStr;\r
         } catch (IOException e) {\r
             logger.error("Exception when attempting to communicate with SDC", e);\r
+            utils.invokeReturn();\r
             throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);\r
         }\r
     }\r
@@ -797,6 +802,7 @@ public class SdcCatalogServices {
             String urlReworked = removeUnwantedBracesFromString(url);\r
             URL urlObj = new URL(urlReworked);\r
             HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+            conn = utils.invoke(conn,"SDC", "getSdcResources");\r
             String basicAuth = getSdcBasicAuth();\r
             conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);\r
             conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
@@ -807,27 +813,24 @@ public class SdcCatalogServices {
             logger.info("Sdc resource url - " + urlReworked + " , responseCode=" + responseCode);\r
             try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {\r
                 String response = IOUtils.toString(in);\r
-                LoggingUtils.setResponseContext("0", "Get sdc resources success", this.getClass().getName());\r
                 return response;\r
             }\r
         } catch (IOException e) {\r
-            LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
             LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
             logger.error("Exception occurred during query to SDC", e);\r
             return "";\r
         } catch (DecoderException e) {\r
-            LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
             LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
             logger.error("Exception when attempting to decode the Hex string", e);\r
             throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);\r
         } catch (GeneralSecurityException e) {\r
-            LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
             LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
             logger.error("Exception when attempting to decrypt the encrypted password", e);\r
             throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);\r
         } finally {\r
             LoggingUtils.setTimeContext(startTime, new Date());\r
             metricsLogger.info("getCldsServicesOrResourcesBasedOnURL completed");\r
+            utils.invokeReturn();\r
         }\r
     }\r
 \r
@@ -1275,6 +1278,7 @@ public class SdcCatalogServices {
                 url = url + "/" + uploadedArtifactUuid;\r
                 URL urlObj = new URL(url);\r
                 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+                conn = utils.invoke(conn,"SDC", "deleteArtifact");\r
                 conn.setDoOutput(true);\r
                 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId);\r
                 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
@@ -1293,12 +1297,15 @@ public class SdcCatalogServices {
                 responseStr = getResponse(conn);\r
                 if (responseStr != null && requestFailed) {\r
                     logger.error("requestFailed - responseStr=" + responseStr);\r
+                    utils.invokeReturn();\r
                     throw new BadRequestException(responseStr);\r
                 }\r
             }\r
+            utils.invokeReturn();\r
             return responseStr;\r
         } catch (IOException | DecoderException | GeneralSecurityException e) {\r
             logger.error("Exception when attempting to communicate with SDC", e);\r
+            utils.invokeReturn();\r
             throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);\r
         }\r
     }\r