Add Request ID in Common Logging 91/9091/1
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Tue, 29 Aug 2017 11:40:12 +0000 (04:40 -0700)
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>
Tue, 29 Aug 2017 11:40:12 +0000 (04:40 -0700)
Add the requestId method + align the others classes using that
+ Rework the Exceptions thrown and the Javadocs

Change-Id: I15bccf1d46ced15aa85d88287f05f1c14b6017fd
Issue-Id: CLAMP-43
Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java
src/main/java/org/onap/clamp/clds/util/LoggingUtils.java

index e5144bf..3d8d5d5 100644 (file)
 \r
 package org.onap.clamp.clds.client;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
 import java.io.BufferedReader;\r
 import java.io.DataOutputStream;\r
+import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.io.InputStreamReader;\r
 import java.net.URL;\r
+import java.util.Date;\r
 import java.util.stream.Collectors;\r
 \r
 import javax.net.ssl.HttpsURLConnection;\r
+import javax.ws.rs.BadRequestException;\r
 \r
 import org.json.simple.JSONObject;\r
 import org.json.simple.parser.JSONParser;\r
+import org.onap.clamp.clds.exception.DcaeDeploymentException;\r
 import org.onap.clamp.clds.model.refprop.RefProp;\r
+import org.onap.clamp.clds.util.LoggingUtils;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
 \r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-\r
 /**\r
- *\r
+ * This class implements the communication with DCAE for the service\r
+ * deployments.\r
  *\r
  */\r
 public class DcaeDispatcherServices {\r
@@ -49,23 +55,29 @@ public class DcaeDispatcherServices {
     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();\r
 \r
     @Autowired\r
-    private RefProp                 refProp;\r
+    private RefProp                   refProp;\r
 \r
     /**\r
-     *\r
+     * Delete the deployment on DCAE.\r
+     * \r
      * @param deploymentId\r
-     * @return\r
-     * @throws Exception\r
+     *            The deployment ID\r
+     * @return Return the URL Status\r
+     * @throws IOException\r
+     *             In case of issues with the Stream\r
      */\r
-    public String deleteDeployment(String deploymentId) throws Exception {\r
+    public String deleteDeployment(String deploymentId) throws IOException {\r
 \r
         String statusUrl = null;\r
         InputStream in = null;\r
+        Date startTime = new Date();\r
+        LoggingUtils.setTargetContext("DCAE", "deleteDeployment");\r
         try {\r
             String url = refProp.getStringValue("DCAE_DISPATCHER_URL") + "/dcae-deployments/" + deploymentId;\r
             logger.info("Dcae Dispatcher url - " + url);\r
             URL obj = new URL(url);\r
             HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();\r
+            conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
             conn.setRequestMethod("DELETE");\r
             int responseCode = conn.getResponseCode();\r
 \r
@@ -94,7 +106,7 @@ public class DcaeDispatcherServices {
             if (responseStr != null) {\r
                 if (requestFailed) {\r
                     logger.error("requestFailed - responseStr=" + responseStr);\r
-                    throw new Exception(responseStr);\r
+                    throw new BadRequestException(responseStr);\r
                 }\r
             }\r
 \r
@@ -109,12 +121,14 @@ public class DcaeDispatcherServices {
             logger.debug("Status URL: " + statusUrl);\r
 \r
         } catch (Exception e) {\r
-            logger.error(e.getClass().getName() + " " + e.getMessage());\r
-            throw e;\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
             if (in != null) {\r
                 in.close();\r
             }\r
+            LoggingUtils.setTimeContext(startTime, new Date());\r
+            metricsLogger.info("deleteDeployment complete");\r
         }\r
 \r
         return statusUrl;\r
@@ -122,23 +136,30 @@ public class DcaeDispatcherServices {
     }\r
 \r
     /**\r
-     *\r
+     * Get the Operation Status from a specified URL.\r
+     * \r
      * @param statusUrl\r
-     * @return\r
-     * @throws Exception\r
+     *            The URL provided by a previous DCAE Query\r
+     * @return The status\r
+     * @throws IOException\r
+     *             In case of issues with the Stream\r
+     * \r
      */\r
-    public String getOperationStatus(String statusUrl) throws Exception {\r
+    public String getOperationStatus(String statusUrl) throws IOException {\r
 \r
-        //Assigning processing status to monitor operation status further\r
+        // Assigning processing status to monitor operation status further\r
         String opStatus = "processing";\r
         InputStream in = null;\r
+        Date startTime = new Date();\r
+        LoggingUtils.setTargetContext("DCAE", "getOperationStatus");\r
         try {\r
             URL obj = new URL(statusUrl);\r
             HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();\r
             conn.setRequestMethod("GET");\r
+            conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
             int responseCode = conn.getResponseCode();\r
             logger.debug("Deployment operation status response code - " + responseCode);\r
-            if(responseCode == 200){\r
+            if (responseCode == 200) {\r
                 in = conn.getInputStream();\r
                 String res = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));\r
                 JSONParser parser = new JSONParser();\r
@@ -150,58 +171,71 @@ public class DcaeDispatcherServices {
                 opStatus = status;\r
             }\r
         } catch (Exception e) {\r
-            logger.debug(e.getClass().getName() + " " + e.getMessage());\r
+            logger.error("Exception occurred during getOperationStatus Operation with DCAE", e);\r
             logger.debug(e.getMessage()\r
                     + " : got exception while retrieving status, trying again until we get 200 response code");\r
         } finally {\r
             if (in != null) {\r
                 in.close();\r
             }\r
+            LoggingUtils.setTimeContext(startTime, new Date());\r
+            metricsLogger.info("getOperationStatus complete");\r
         }\r
-\r
         return opStatus;\r
     }\r
 \r
     /**\r
-     *\r
-     * @throws Exception\r
+     * This method send a getDeployments operation to DCAE.\r
+     * \r
+     * @throws IOException\r
+     *             In case of issues with the Stream\r
      */\r
-    public void getDeployments() throws Exception {\r
+    public void getDeployments() throws IOException {\r
         InputStream in = null;\r
+        Date startTime = new Date();\r
+        LoggingUtils.setTargetContext("DCAE", "getDeployments");\r
         try {\r
             String url = refProp.getStringValue("DCAE_DISPATCHER_URL") + "/dcae-deployments";\r
             logger.info("Dcae Dispatcher deployments url - " + url);\r
             URL obj = new URL(url);\r
             HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();\r
             conn.setRequestMethod("GET");\r
+            conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
             int responseCode = conn.getResponseCode();\r
             logger.debug("response code " + responseCode);\r
             in = conn.getInputStream();\r
             String res = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));\r
             logger.debug("res:" + res);\r
         } catch (Exception e) {\r
-            logger.error("Exception occurred during DCAE communication", e);\r
-            throw e;\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
             if (in != null) {\r
                 in.close();\r
             }\r
+            LoggingUtils.setTimeContext(startTime, new Date());\r
+            metricsLogger.info("getDeployments complete");\r
         }\r
     }\r
 \r
     /**\r
-     * Returns status URL for deployment operation\r
+     * Returns status URL for createNewDeployment operation.\r
      *\r
      * @param deploymentId\r
+     *            The deployment ID\r
      * @param serviceTypeId\r
-     * @return\r
-     * @throws Exception\r
+     *            Service type ID\r
+     * @return The status URL\r
+     * @throws IOException\r
+     *             In case of issues with the Stream\r
      */\r
-    public String createNewDeployment(String deploymentId, String serviceTypeId) throws Exception {\r
+    public String createNewDeployment(String deploymentId, String serviceTypeId) throws IOException {\r
 \r
         String statusUrl = null;\r
         InputStream inStream = null;\r
         BufferedReader in = null;\r
+        Date startTime = new Date();\r
+        LoggingUtils.setTargetContext("DCAE", "createNewDeployment");\r
         try {\r
             String apiBodyString = "{\"serviceTypeId\": \"" + serviceTypeId + "\"}";\r
             logger.info("Dcae api Body String - " + apiBodyString);\r
@@ -210,6 +244,7 @@ public class DcaeDispatcherServices {
             URL obj = new URL(url);\r
             HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();\r
             conn.setRequestMethod("PUT");\r
+            conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
             conn.setRequestProperty("Content-Type", "application/json");\r
             conn.setDoOutput(true);\r
             try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
@@ -247,7 +282,7 @@ public class DcaeDispatcherServices {
             if (responseStr != null) {\r
                 if (requestFailed) {\r
                     logger.error("requestFailed - responseStr=" + responseStr);\r
-                    throw new Exception(responseStr);\r
+                    throw new BadRequestException(responseStr);\r
                 }\r
             }\r
 \r
@@ -259,8 +294,8 @@ public class DcaeDispatcherServices {
             statusUrl = (String) linksObj.get("status");\r
             logger.debug("Status URL: " + statusUrl);\r
         } catch (Exception e) {\r
-            logger.error("Exception occurred during the DCAE communication", e);\r
-            throw e;\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
             if (inStream != null) {\r
                 inStream.close();\r
@@ -268,21 +303,29 @@ public class DcaeDispatcherServices {
             if (in != null) {\r
                 in.close();\r
             }\r
+            LoggingUtils.setTimeContext(startTime, new Date());\r
+            metricsLogger.info("createNewDeployment complete");\r
         }\r
         return statusUrl;\r
     }\r
 \r
     /**\r
-     *\r
+     * Returns status URL for deleteExistingDeployment operation.\r
+     * \r
      * @param deploymentId\r
+     *            The deployment ID\r
      * @param serviceTypeId\r
-     * @return\r
-     * @throws Exception\r
+     *            The service Type ID\r
+     * @return The status URL\r
+     * @throws IOException\r
+     *             In case of issues with the Stream\r
      */\r
-    public String deleteExistingDeployment(String deploymentId, String serviceTypeId) throws Exception {\r
+    public String deleteExistingDeployment(String deploymentId, String serviceTypeId) throws IOException {\r
 \r
         String statusUrl = null;\r
         InputStream in = null;\r
+        Date startTime = new Date();\r
+        LoggingUtils.setTargetContext("DCAE", "deleteExistingDeployment");\r
         try {\r
             String apiBodyString = "{\"serviceTypeId\": \"" + serviceTypeId + "\"}";\r
             logger.debug(apiBodyString);\r
@@ -291,6 +334,7 @@ public class DcaeDispatcherServices {
             URL obj = new URL(url);\r
             HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();\r
             conn.setRequestMethod("DELETE");\r
+            conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
             conn.setRequestProperty("Content-Type", "application/json");\r
             conn.setDoOutput(true);\r
             DataOutputStream wr = new DataOutputStream(conn.getOutputStream());\r
@@ -309,12 +353,15 @@ public class DcaeDispatcherServices {
             statusUrl = (String) linksObj.get("status");\r
             logger.debug("Status URL: " + statusUrl);\r
         } catch (Exception e) {\r
-            logger.error("Exception occurred during DCAE communication", e);\r
-            throw e;\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
         } finally {\r
             if (in != null) {\r
                 in.close();\r
             }\r
+            LoggingUtils.setTimeContext(startTime, new Date());\r
+            metricsLogger.info("deleteExistingDeployment complete");\r
         }\r
         return statusUrl;\r
     }\r
index 3dfe9fe..c35eb0d 100644 (file)
 \r
 package org.onap.clamp.clds.client;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.core.JsonProcessingException;\r
+\r
 import java.io.BufferedReader;\r
 import java.io.IOException;\r
 import java.io.InputStreamReader;\r
 import java.net.HttpURLConnection;\r
 import java.net.URL;\r
+import java.util.Date;\r
 import java.util.List;\r
 \r
 import javax.ws.rs.BadRequestException;\r
@@ -43,29 +48,43 @@ import org.onap.clamp.clds.model.DcaeEvent;
 import org.onap.clamp.clds.model.prop.Global;\r
 import org.onap.clamp.clds.model.prop.ModelProperties;\r
 import org.onap.clamp.clds.model.refprop.RefProp;\r
+import org.onap.clamp.clds.util.LoggingUtils;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
 \r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-import com.fasterxml.jackson.core.JsonProcessingException;\r
-\r
+/**\r
+ * This class implements the communication with DCAE for the service inventory.\r
+ *\r
+ */\r
 public class DcaeInventoryServices {\r
-    protected static final EELFLogger       logger      = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);\r
-    protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();\r
+    protected static final EELFLogger logger        = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);\r
+    protected static final EELFLogger auditLogger   = EELFManager.getInstance().getAuditLogger();\r
+    protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();\r
 \r
     @Autowired\r
-    private RefProp                 refProp;\r
+    private RefProp                   refProp;\r
 \r
     @Autowired\r
-    private CldsDao                 cldsDao;\r
+    private CldsDao                   cldsDao;\r
 \r
     @Autowired\r
-    private SdcCatalogServices      sdcCatalogServices;\r
-\r
-    public void setEventInventory(CldsModel cldsModel, String userId) throws Exception {\r
+    private SdcCatalogServices        sdcCatalogServices;\r
+\r
+    /**\r
+     * Set the event inventory.\r
+     * \r
+     * @param cldsModel\r
+     *            The CldsModel\r
+     * @param userId\r
+     *            The user ID\r
+     * @throws ParseException\r
+     *             In case of issues during the parsing of DCAE answer\r
+     */\r
+    public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException {\r
         String artifactName = cldsModel.getControlName();\r
         DcaeEvent dcaeEvent = new DcaeEvent();\r
         String isDcaeInfoAvailable = null;\r
+        Date startTime = new Date();\r
+        LoggingUtils.setTargetContext("DCAE", "setEventInventory");\r
         if (artifactName != null) {\r
             artifactName = artifactName + ".yml";\r
         }\r
@@ -74,8 +93,8 @@ public class DcaeInventoryServices {
              * Below are the properties required for calling the dcae inventory\r
              * url call\r
              */\r
-            ModelProperties prop = new ModelProperties(cldsModel.getName(), cldsModel.getControlName(), null, false, "{}",\r
-                    cldsModel.getPropText());\r
+            ModelProperties prop = new ModelProperties(cldsModel.getName(), cldsModel.getControlName(), null, false,\r
+                    "{}", cldsModel.getPropText());\r
             Global global = prop.getGlobal();\r
             String invariantServiceUuid = global.getService();\r
             List<String> resourceUuidList = global.getResourceVf();\r
@@ -92,12 +111,12 @@ public class DcaeInventoryServices {
             dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);\r
 \r
         } catch (JsonProcessingException e) {\r
-            // exception\r
-            logger.error("JsonProcessingException" + e);\r
-        } catch (IOException e) {\r
-\r
-            // exception\r
-            logger.error("IOException :" + e);\r
+            logger.error("Error during JSON decoding", e);\r
+        } catch (IOException ex) {\r
+            logger.error("Error during JSON decoding", ex);\r
+        } finally {\r
+            LoggingUtils.setTimeContext(startTime, new Date());\r
+            metricsLogger.info("setEventInventory complete");\r
         }\r
         /* Null whether the DCAE has items lenght or not */\r
         if (isDcaeInfoAvailable != null) {\r
@@ -107,18 +126,18 @@ public class DcaeInventoryServices {
             Object obj0 = parser.parse(isDcaeInfoAvailable);\r
             JSONObject jsonObj = (JSONObject) obj0;\r
             String oldTypeId = cldsModel.getTypeId();\r
-                   String newTypeId = "";\r
+            String newTypeId = "";\r
             if (jsonObj.get("typeId") != null) {\r
-               newTypeId = jsonObj.get("typeId").toString();\r
+                newTypeId = jsonObj.get("typeId").toString();\r
                 cldsModel.setTypeId(jsonObj.get("typeId").toString());\r
             }\r
             // cldsModel.setTypeName(cldsModel.getControlName().toString()+".yml");\r
             if (jsonObj.get("typeName") != null) {\r
                 cldsModel.setTypeName(jsonObj.get("typeName").toString());\r
             }\r
-            if(oldTypeId == null || !oldTypeId.equalsIgnoreCase(newTypeId)){\r
-               CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(),\r
-                    CldsEvent.ACTION_STATE_RECEIVED, null);\r
+            if (oldTypeId == null || !oldTypeId.equalsIgnoreCase(newTypeId)) {\r
+                CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(),\r
+                        CldsEvent.ACTION_STATE_RECEIVED, null);\r
             }\r
             cldsModel.save(cldsDao, userId);\r
         } else {\r
@@ -126,32 +145,55 @@ public class DcaeInventoryServices {
         }\r
     }\r
 \r
-    public String getDcaeInformation(String artifactName, String serviceUUID, String resourceUUID)\r
+    /**\r
+     * DO a query to DCAE to get some Information.\r
+     * \r
+     * @param artifactName\r
+     *            The artifact Name\r
+     * @param serviceUuid\r
+     *            The service UUID\r
+     * @param resourceUuid\r
+     *            The resource UUID\r
+     * @return The DCAE inventory for the artifact\r
+     * @throws IOException\r
+     *             In case of issues with the stream\r
+     * @throws ParseException\r
+     *             In case of issues with the Json parsing\r
+     */\r
+    public String getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)\r
             throws IOException, ParseException {\r
-        String queryString = "?sdcResourceId=" + resourceUUID + "&sdcServiceId=" + serviceUUID + "&typeName="\r
+        Date startTime = new Date();\r
+        LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");\r
+        String queryString = "?sdcResourceId=" + resourceUuid + "&sdcServiceId=" + serviceUuid + "&typeName="\r
                 + artifactName;\r
         String fullUrl = refProp.getStringValue("DCAE_INVENTORY_URL") + "/dcae-service-types" + queryString;\r
+\r
         logger.info("Dcae Inventory Service full url - " + fullUrl);\r
         String daceInventoryResponse = null;\r
         URL inventoryUrl = new URL(fullUrl);\r
 \r
         HttpURLConnection conn = (HttpURLConnection) inventoryUrl.openConnection();\r
         conn.setRequestMethod("GET");\r
+        String reqid = LoggingUtils.getRequestId();\r
+        logger.info("reqid set to " + reqid);\r
+        conn.setRequestProperty("X-ECOMP-RequestID", reqid);\r
+\r
         boolean requestFailed = true;\r
         int responseCode = conn.getResponseCode();\r
         if (responseCode == 200) {\r
             requestFailed = false;\r
         }\r
 \r
-        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));\r
-        String inputLine = null;\r
-        StringBuffer response = new StringBuffer();\r
-        String responseStr = null;\r
-        while ((inputLine = in.readLine()) != null) {\r
-            response.append(inputLine);\r
+        StringBuilder response = new StringBuilder();\r
+\r
+        try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {\r
+            String inputLine = null;\r
+\r
+            while ((inputLine = in.readLine()) != null) {\r
+                response.append(inputLine);\r
+            }\r
         }\r
-        in.close();\r
-        responseStr = response.toString();\r
+        String responseStr = response.toString();\r
         if (responseStr != null) {\r
             if (requestFailed) {\r
                 logger.error("requestFailed - responseStr=" + response);\r
@@ -175,6 +217,8 @@ public class DcaeInventoryServices {
             daceInventoryResponse = dcaeServiceType0.toString();\r
             logger.info(daceInventoryResponse.toString());\r
         }\r
+        LoggingUtils.setTimeContext(startTime, new Date());\r
+        metricsLogger.info("getDcaeInformation complete: number services returned=" + numServices);\r
         return daceInventoryResponse;\r
     }\r
 \r
index ed972d4..566d11a 100644 (file)
 
 package org.onap.clamp.clds.client;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.io.IOException;
 import java.util.Map;
-import java.util.UUID;
 
 import org.camunda.bpm.engine.delegate.DelegateExecution;
 import org.camunda.bpm.engine.delegate.JavaDelegate;
@@ -33,47 +36,65 @@ import org.onap.clamp.clds.model.prop.ModelProperties;
 import org.onap.clamp.clds.model.prop.Policy;
 import org.onap.clamp.clds.model.prop.PolicyChain;
 import org.onap.clamp.clds.model.refprop.RefProp;
+import org.onap.clamp.clds.util.LoggingUtils;
 import org.onap.policy.api.AttributeType;
+import org.onap.policy.api.PolicyEngineException;
+import org.onap.policy.controlloop.policy.builder.BuilderException;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
 /**
- * Send Operational Policy info to policy api.
+ * Send Operational Policy info to policy api. It uses the policy code to define
+ * the model and communicate with it. See also the PolicyClient class.
+ * 
  */
 public class OperationalPolicyDelegate implements JavaDelegate {
     protected static final EELFLogger logger        = EELFManager.getInstance()
             .getLogger(OperationalPolicyDelegate.class);
     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
 
+    /**
+     * Automatically injected by Spring, define in CldsConfiguration as a bean.
+     */
     @Autowired
-    private PolicyClient            policyClient;
+    private PolicyClient              policyClient;
 
+    /**
+     * Automatically injected by Spring, define in CldsConfiguration as a bean.
+     */
     @Autowired
-    private RefProp                 refProp;
+    private RefProp                   refProp;
 
     /**
      * Perform activity. Send Operational Policy info to policy api.
      *
      * @param execution
+     *            The DelegateExecution
+     * @throws BuilderException
+     *             In case of issues with OperationalPolicyReq
+     * @throws IOException
+     *             In case of issues with the stream
+     * @throws PolicyEngineException
+     *             In case of issues with the PolicyEngine creation
      */
     @Override
-    public void execute(DelegateExecution execution) throws Exception {
+    public void execute(DelegateExecution execution) throws IOException, BuilderException, PolicyEngineException {
 
         // execution.setVariable("operationalPolicyRequestUuid",
         // operationalPolicyRequestUuid);
         String responseMessage = null;
         String operationalPolicyRequestUuid = null;
         ModelProperties prop = ModelProperties.create(execution);
-        for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
-            operationalPolicyRequestUuid = UUID.randomUUID().toString();
-            Map<AttributeType, Map<String, String>> attributes = OperationalPolicyReq.formatAttributes(refProp, prop,
-                    prop.getType(Policy.class).getId(), policyChain);
-            responseMessage = policyClient.sendBrms(attributes, prop, operationalPolicyRequestUuid);
-        }
-        if (responseMessage != null) {
-            execution.setVariable("operationalPolicyResponseMessage", responseMessage.getBytes());
+        Policy policy = prop.getType(Policy.class);
+        if (policy.isFound()) {
+            for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
+                operationalPolicyRequestUuid = LoggingUtils.getRequestId();
+                Map<AttributeType, Map<String, String>> attributes = OperationalPolicyReq.formatAttributes(refProp,
+                        prop, prop.getType(Policy.class).getId(), policyChain);
+                responseMessage = policyClient.sendBrms(attributes, prop, operationalPolicyRequestUuid);
+            }
+            if (responseMessage != null) {
+                execution.setVariable("operationalPolicyResponseMessage", responseMessage.getBytes());
+            }
         }
     }
 
index df86977..a4e332a 100644 (file)
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- *                             reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END============================================
- * ===================================================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-
-package org.onap.clamp.clds.client;
-
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.commons.csv.CSVFormat;
-import org.apache.commons.csv.CSVRecord;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.clamp.clds.client.req.SdcReq;
-import org.onap.clamp.clds.model.CldsAlarmCondition;
-import org.onap.clamp.clds.model.CldsDBServiceCache;
-import org.onap.clamp.clds.model.CldsSdcArtifact;
-import org.onap.clamp.clds.model.CldsSdcResource;
-import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo;
-import org.onap.clamp.clds.model.CldsSdcServiceDetail;
-import org.onap.clamp.clds.model.CldsSdcServiceInfo;
-import org.onap.clamp.clds.model.CldsServiceData;
-import org.onap.clamp.clds.model.CldsVfData;
-import org.onap.clamp.clds.model.CldsVfKPIData;
-import org.onap.clamp.clds.model.CldsVfcData;
-import org.onap.clamp.clds.model.prop.ModelProperties;
-import org.onap.clamp.clds.model.refprop.RefProp;
-import org.onap.clamp.clds.util.LoggingUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.fasterxml.jackson.databind.node.TextNode;
-
-public class SdcCatalogServices {
-    protected static final EELFLogger logger            = EELFManager.getInstance().getLogger(SdcCatalogServices.class);
-    protected static final EELFLogger metricsLogger     = EELFManager.getInstance().getMetricsLogger();
-
-    private static final String       RESOURCE_VF_TYPE  = "VF";
-    private static final String       RESOURCE_VFC_TYPE = "VFC";
-
-    @Autowired
-    private RefProp                   refProp;
-
-    public String getSdcServicesInformation(String uuid) throws Exception {
-        Date startTime = new Date();
-        String baseUrl = refProp.getStringValue("sdc.serviceUrl");
-        String basicAuth = SdcReq.getSdcBasicAuth(refProp);
-        try {
-            String url = baseUrl;
-            if (uuid != null) {
-                url = baseUrl + "/" + uuid + "/metadata";
-            }
-            URL urlObj = new URL(url);
-
-            HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
-
-            conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
-            conn.setRequestProperty("Authorization", basicAuth);
-            conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
-            conn.setRequestMethod("GET");
-
-            String resp = getResponse(conn);
-            if (resp != null) {
-                logger.info(resp.toString());
-                return resp;
-            }
-            // metrics log
-            LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
-
-        } catch (Exception e) {
-            LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());
-            LoggingUtils.setErrorContext("900", "Get sdc services error");
-            logger.error("not able to get any service information from sdc for uuid:" + uuid + " , exception is - " + e.getMessage());
-        }
-        LoggingUtils.setTimeContext(startTime, new Date());
-        LoggingUtils.setTargetContext("SDC", "Get Services");
-        metricsLogger.info("Get sdc services information");
-
-        return "";
-    }
-
-    /**
-     * To remove duplicate serviceUUIDs from sdc services List
-     *
-     * @param rawCldsSdcServiceList
-     * @return
-     */
-    public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {
-        List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;
-        if (rawCldsSdcServiceList != null && rawCldsSdcServiceList.size() > 0) {
-            // sort list
-            Collections.sort(rawCldsSdcServiceList);
-            // and then take only the services with the max version (last in the
-            // list with the same name)
-            cldsSdcServiceInfoList = new ArrayList<>();
-            for (int i = 1; i < rawCldsSdcServiceList.size(); i++) {
-                // compare name with previous - if not equal, then keep the
-                // previous (it's the last with that name)
-                CldsSdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);
-                if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {
-                    cldsSdcServiceInfoList.add(prev);
-                }
-            }
-            // add the last in the list
-            cldsSdcServiceInfoList.add(rawCldsSdcServiceList.get(rawCldsSdcServiceList.size() - 1));
-        }
-        return cldsSdcServiceInfoList;
-    }
-
-    /**
-     * To remove duplicate serviceUUIDs from sdc resources List
-     *
-     * @param rawCldsSdcResourceList
-     * @return
-     */
-    public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {
-        List<CldsSdcResource> cldsSdcResourceList = null;
-        if (rawCldsSdcResourceList != null && rawCldsSdcResourceList.size() > 0) {
-            // sort list
-            Collections.sort(rawCldsSdcResourceList);
-            // and then take only the resources with the max version (last in
-            // the list with the same name)
-            cldsSdcResourceList = new ArrayList<>();
-            for (int i = 1; i < rawCldsSdcResourceList.size(); i++) {
-                // compare name with previous - if not equal, then keep the
-                // previous (it's the last with that name)
-                CldsSdcResource prev = rawCldsSdcResourceList.get(i - 1);
-                if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {
-                    cldsSdcResourceList.add(prev);
-                }
-            }
-            // add the last in the list
-            cldsSdcResourceList.add(rawCldsSdcResourceList.get(rawCldsSdcResourceList.size() - 1));
-        }
-        return cldsSdcResourceList;
-    }
-
-    /**
-     * To remove duplicate basic resources with same resourceUUIDs
-     *
-     * @param rawCldsSdcResourceListBasicList
-     * @return
-     */
-    public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(
-            List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {
-        List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;
-        if (rawCldsSdcResourceListBasicList != null && rawCldsSdcResourceListBasicList.size() > 0) {
-            // sort list
-            Collections.sort(rawCldsSdcResourceListBasicList);
-            // and then take only the resources with the max version (last in
-            // the list with the same name)
-            cldsSdcResourceBasicInfoList = new ArrayList<>();
-            for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {
-                // compare name with previous - if not equal, then keep the
-                // previous (it's the last with that name)
-                CldsSdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);
-                if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {
-                    cldsSdcResourceBasicInfoList.add(prev);
-                }
-            }
-            // add the last in the list
-            cldsSdcResourceBasicInfoList
-                    .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));
-        }
-        return cldsSdcResourceBasicInfoList;
-    }
-
-    /**
-     * To get ServiceUUID by using serviceInvariantUUID
-     *
-     * @param invariantId
-     * @return
-     * @throws Exception
-     */
-    public String getServiceUuidFromServiceInvariantId(String invariantId) throws Exception {
-        String serviceUuid = "";
-        String responseStr = getSdcServicesInformation(null);
-        List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);
-        List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);
-        if (cldsSdcServicesList != null && cldsSdcServicesList.size() > 0) {
-            for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {
-                if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null
-                        && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {
-                    serviceUuid = currCldsSdcServiceInfo.getUuid();
-                    break;
-                }
-            }
-        }
-        return serviceUuid;
-    }
-
-    /**
-     * To get CldsAsdsServiceInfo class by parsing json string
-     *
-     * @param jsonStr
-     * @return
-     * @throws JsonParseException
-     * @throws JsonMappingException
-     * @throws IOException
-     */
-    public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) throws IOException {
-        ObjectMapper objectMapper = new ObjectMapper();
-        if (StringUtils.isBlank(jsonStr)) {
-            return null;
-        }
-        return objectMapper.readValue(jsonStr,
-                objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));
-    }
-
-    /**
-     * To get List<CldsSdcResourceBasicInfo> class by parsing json string
-     *
-     * @param jsonStr
-     * @return
-     * @throws JsonParseException
-     * @throws JsonMappingException
-     * @throws IOException
-     */
-    public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) throws IOException {
-        ObjectMapper objectMapper = new ObjectMapper();
-        if (StringUtils.isBlank(jsonStr)) {
-            return null;
-        }
-        return objectMapper.readValue(jsonStr,
-                objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));
-    }
-
-    /**
-     * To get CldsAsdsResource class by parsing json string
-     *
-     * @param jsonStr
-     * @return
-     * @throws JsonParseException
-     * @throws JsonMappingException
-     * @throws IOException
-     */
-    public CldsSdcResource getCldsSdcResourceFromJson(String jsonStr) throws IOException {
-        ObjectMapper objectMapper = new ObjectMapper();
-        return objectMapper.readValue(jsonStr, CldsSdcResource.class);
-    }
-
-    /**
-     * To get CldsSdcServiceDetail by parsing json string
-     *
-     * @param jsonStr
-     * @return
-     * @throws JsonParseException
-     * @throws JsonMappingException
-     * @throws IOException
-     */
-    public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) throws IOException {
-        ObjectMapper objectMapper = new ObjectMapper();
-        return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);
-    }
-
-    /**
-     * To upload artifact to sdc based on serviceUUID and resourcename on url
-     *
-     * @param prop
-     * @param userid
-     * @param url
-     * @param formatttedSdcReq
-     * @return
-     * @throws Exception
-     */
-    public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq)
-            throws Exception {
-        // Verify whether it is triggered by Validation Test button from UI
-        if (prop.isTest()) {
-            return "sdc artifact upload not executed for test action";
-        }
-        logger.info("userid=" + userid);
-        String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq);
-        byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);
-        int postDataLength = postData.length;
-        HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);
-        try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
-            wr.write(postData);
-        }
-        boolean requestFailed = true;
-        int responseCode = conn.getResponseCode();
-        logger.info("responseCode=" + responseCode);
-        if (responseCode == 200) {
-            requestFailed = false;
-        }
-
-        String responseStr = getResponse(conn);
-        if (responseStr != null) {
-            if (requestFailed) {
-                logger.error("requestFailed - responseStr=" + responseStr);
-                throw new Exception(responseStr);
-            }
-        }
-        return responseStr;
-    }
-
-    private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text)
-            throws IOException {
-        logger.info("userid=" + userid);
-        String basicAuth = SdcReq.getSdcBasicAuth(refProp);
-        String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");
-        URL urlObj = new URL(url);
-        HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
-        conn.setDoOutput(true);
-        conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);
-        conn.setRequestProperty("Authorization", basicAuth);
-        conn.setRequestProperty("Content-Type", "application/json");
-        conn.setRequestProperty("Content-MD5", md5Text);
-        conn.setRequestProperty("USER_ID", userid);
-        conn.setRequestMethod("POST");
-        conn.setRequestProperty("charset", "utf-8");
-        conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
-        conn.setUseCaches(false);
-        return conn;
-    }
-
-    private String getResponse(HttpURLConnection conn) throws IOException {
-        try (InputStream is = getInputStream(conn)) {
-            if (is != null) {
-                try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
-                    StringBuffer response = new StringBuffer();
-                    String inputLine;
-                    while ((inputLine = in.readLine()) != null) {
-                        response.append(inputLine);
-                    }
-                    return response.toString();
-                }
-            }
-        }
-        return null;
-    }
-
-    private InputStream getInputStream(HttpURLConnection conn) throws IOException {
-        InputStream inStream = conn.getErrorStream();
-        if (inStream == null) {
-            inStream = conn.getInputStream();
-        }
-        return inStream;
-    }
-
-    public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData)
-            throws IOException {
-        CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();
-        cldsDbServiceCache.setCldsDataInstream(cldsServiceData);
-        cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());
-        cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());
-        return cldsDbServiceCache;
-    }
-
-    public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) throws Exception {
-        boolean expired = false;
-        if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
-            String cachedServiceUuid = cldsServiceData.getServiceUUID();
-            String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID());
-            String defaultRecordAge = refProp.getStringValue("CLDS_SERVICE_CACHE_MAX_SECONDS");
-            if ((!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null
-                    && cldsServiceData.getAgeOfRecord() > Long.parseLong(defaultRecordAge))) {
-                expired = true;
-            }
-        } else {
-            expired = true;
-        }
-        return expired;
-    }
-
-    public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) throws Exception {
-        String url = refProp.getStringValue("sdc.serviceUrl");
-        String catalogUrl = refProp.getStringValue("sdc.catalog.url");
-        String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);
-        String serviceDetailUrl = url + "/" + serviceUuid + "/metadata";
-        String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl, false);
-        ObjectMapper objectMapper = new ObjectMapper();
-        CldsServiceData cldsServiceData = new CldsServiceData();
-        if (responseStr != null) {
-            CldsSdcServiceDetail cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);
-            cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());
-            cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());
-
-            // To remove duplicate resources from serviceDetail and add valid
-            // vfs to service
-            if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {
-                List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(
-                        cldsSdcServiceDetail.getResources());
-                if (cldsSdcResourceList != null && cldsSdcResourceList.size() > 0) {
-                    List<CldsVfData> cldsVfDataList = new ArrayList<>();
-                    for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {
-                        if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null
-                                && currCldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) {
-                            CldsVfData currCldsVfData = new CldsVfData();
-                            currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());
-                            currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());
-                            cldsVfDataList.add(currCldsVfData);
-                        }
-                    }
-                    cldsServiceData.setCldsVfs(cldsVfDataList);
-                    // For each vf in the list , add all vfc's
-                    getAllVfcForVfList(cldsVfDataList, catalogUrl);
-                    logger.info("value of cldsServiceData:" + cldsServiceData);
-                    logger.info("value of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());
-                }
-            }
-        }
-        return cldsServiceData;
-    }
-
-    /**
-     * @param cldsVfDataList
-     * @throws IOException
-     */
-    private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) throws IOException {
-        // todo : refact this..
-        if (cldsVfDataList != null && cldsVfDataList.size() > 0) {
-            List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVFCResourcesBasedOnResourceType(
-                    RESOURCE_VF_TYPE);
-            List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVFCResourcesBasedOnResourceType(
-                    RESOURCE_VFC_TYPE);
-            for (CldsVfData currCldsVfData : cldsVfDataList) {
-                if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) {
-                    String resourceUuid = getResourceUuidFromResourceInvariantUuid(
-                            currCldsVfData.getVfInvariantResourceUUID(), allVfResources);
-                    if (resourceUuid != null) {
-                        String vfResourceUuidUrl = catalogUrl + "resources" + "/" + resourceUuid + "/metadata";
-                        String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl, false);
-                        if (vfResponse != null) {
-                            // Below 2 line are to get the KPI(field path) data
-                            // associated with the VF's
-                            List<CldsVfKPIData> cldsVfKPIDataList = getFieldPathFromVF(vfResponse);
-                            currCldsVfData.setCldsKPIList(cldsVfKPIDataList);
-
-                            List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);
-                            if (vfcDataListFromVfResponse != null) {
-                                currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);
-                                if (vfcDataListFromVfResponse.size() > 0) {
-                                    // To get artifacts for every VFC and get
-                                    // alarm conditions from artifact
-                                    for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {
-                                        if (currCldsVfcData != null
-                                                && currCldsVfcData.getVfcInvariantResourceUUID() != null) {
-                                            String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(
-                                                    currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);
-                                            if (resourceVfcUuid != null) {
-                                                String vfcResourceUuidUrl = catalogUrl + "resources" + "/"
-                                                        + resourceVfcUuid + "/metadata";
-                                                String vfcResponse = getCldsServicesOrResourcesBasedOnURL(
-                                                        vfcResourceUuidUrl, false);
-                                                if (vfcResponse != null) {
-                                                    List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(
-                                                            vfcResponse);
-                                                    currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc);
-                                                }
-                                            } else {
-                                                logger.info("No resourceVFC UUID found for given invariantID:"
-                                                        + currCldsVfcData.getVfcInvariantResourceUUID());
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    } else {
-                        logger.info("No resourceUUID found for given invariantREsourceUUID:"
-                                + currCldsVfData.getVfInvariantResourceUUID());
-                    }
-                }
-            }
-        }
-    }
-
-    private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws IOException {
-        ObjectMapper mapper = new ObjectMapper();
-        ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
-        ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
-        List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
-        if (vfcArrayNode != null && vfcArrayNode.size() > 0) {
-            for (int index = 0; index < vfcArrayNode.size(); index++) {
-                CldsVfcData currCldsVfcData = new CldsVfcData();
-                ObjectNode currVfcNode = (ObjectNode) vfcArrayNode.get(index);
-                TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");
-                if (resourceTypeNode != null && resourceTypeNode.textValue().equalsIgnoreCase("VFC")) {
-                    TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");
-                    TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID");
-                    currCldsVfcData.setVfcName(vfcResourceName.textValue());
-                    currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue());
-                    cldsVfcDataList.add(currCldsVfcData);
-                }
-            }
-        }
-        return cldsVfcDataList;
-    }
-
-    private String removeUnwantedBracesFromString(String id) {
-        if (id != null && id.contains("\"")) {
-            id = id.replaceAll("\"", "");
-        }
-        return id;
-    }
-
-    private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws IOException {
-        List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
-        ObjectMapper mapper = new ObjectMapper();
-        ObjectNode vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
-        ArrayNode artifactsArrayNode = (ArrayNode) vfcResponseNode.get("artifacts");
-
-        if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
-            for (int index = 0; index < artifactsArrayNode.size(); index++) {
-                ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);
-                TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");
-                if (artifactUrlNode != null) {
-                    String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());
-                    cldsAlarmConditionList.addAll(parseCsvToGetAlarmConditions(responsesFromArtifactUrl));
-                    logger.info(responsesFromArtifactUrl);
-                }
-            }
-        }
-        return cldsAlarmConditionList;
-    }
-
-    private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) throws IOException {
-        List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
-        Reader alarmReader = new StringReader(allAlarmCondsValues);
-        Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
-        if (records != null) {
-            Iterator<CSVRecord> it = records.iterator();
-            if (it.hasNext()) {
-                it.next();
-            }
-            it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));
-        }
-        return cldsAlarmConditionList;
-    }
-
-    // Method to get the artifact for any particular VF
-    private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws JsonProcessingException, IOException {
-        List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();
-        ObjectMapper mapper = new ObjectMapper();
-        ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
-        ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");
-
-        if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
-            for (int index = 0; index < artifactsArrayNode.size(); index++) {
-                ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);
-                TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");
-                TextNode artifactNameNode = (TextNode) currArtifactNode.get("artifactName");
-                String artifactName = "";
-                if (artifactNameNode != null) {
-                    artifactName = artifactNameNode.textValue();
-                    artifactName = artifactName.substring(artifactName.lastIndexOf(".") + 1);
-                }
-                if (artifactUrlNode != null && artifactName != null && !artifactName.isEmpty()
-                        && artifactName.equalsIgnoreCase("csv")) {
-                    String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());
-                    cldsVfKPIDataList.addAll(parseCsvToGetFieldPath(responsesFromArtifactUrl));
-                    logger.info(responsesFromArtifactUrl);
-                }
-            }
-        }
-        return cldsVfKPIDataList;
-    }
-
-    private CldsVfKPIData convertCsvRecordToKpiData(CSVRecord record) {
-        if (record.size() < 6) {
-            logger.debug("invalid csv field path Record,total columns less than 6: " + record);
-            return null;
-        }
-
-        if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
-                || StringUtils.isBlank(record.get(5))) {
-            logger.debug("Invalid csv field path Record,one of column is having blank value : " + record);
-            return null;
-        }
-
-        CldsVfKPIData cldsVfKPIData = new CldsVfKPIData();
-        cldsVfKPIData.setNfNamingCode(record.get(0).trim());
-        cldsVfKPIData.setNfNamingValue(record.get(1).trim());
-
-        cldsVfKPIData.setFieldPath(record.get(2).trim());
-        cldsVfKPIData.setFieldPathValue(record.get(3).trim());
-
-        cldsVfKPIData.setThresholdName(record.get(4).trim());
-        cldsVfKPIData.setThresholdValue(record.get(5).trim());
-        return cldsVfKPIData;
-
-    }
-
-    // Method to get the artifactURL Data and set the CldsVfKPIData node
-    private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) throws IOException {
-        List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();
-        Reader alarmReader = new StringReader(allFieldPathValues);
-        Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
-        if (records != null) {
-            for (CSVRecord record : records) {
-                CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);
-                if (kpiData != null) {
-                    cldsVfKPIDataList.add(kpiData);
-                }
-            }
-        }
-        return cldsVfKPIDataList;
-    }
-
-    private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {
-        if (record == null) {
-            return;
-        }
-        if (record.size() < 5) {
-            logger.debug("invalid csv alarm Record,total columns less than 5: " + record);
-            return;
-        }
-        if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
-                || StringUtils.isBlank(record.get(4))) {
-            logger.debug("invalid csv alarm Record,one of column is having blank value : " + record);
-            return;
-        }
-        CldsAlarmCondition cldsAlarmCondition = new CldsAlarmCondition();
-        cldsAlarmCondition.setEventSourceType(record.get(1));
-        cldsAlarmCondition.setAlarmConditionKey(record.get(3));
-        cldsAlarmCondition.setSeverity(record.get(4));
-        cldsAlarmConditionList.add(cldsAlarmCondition);
-    }
-
-    public String getResponsesFromArtifactUrl(String artifactsUrl) throws IOException {
-        String hostUrl = refProp.getStringValue("sdc.hostUrl");
-        artifactsUrl = artifactsUrl.replaceAll("\"", "");
-        String artifactUrl = hostUrl + artifactsUrl;
-        logger.info("value of artifactURl:" + artifactUrl);
-        String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl, true);
-        logger.info("value of artifactResponse:" + currArtifactResponse);
-        return currArtifactResponse;
-    }
-
-    /**
-     * Service to services/resources/artifacts from sdc.Pass alarmConditions as
-     * true to get alarmconditons from artifact url and else it is false
-     *
-     * @param url
-     * @param alarmConditions
-     * @return
-     * @throws IOException
-     */
-    public String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) {
-        String responseStr;
-        try {
-            url = removeUnwantedBracesFromString(url);
-            URL urlObj = new URL(url);
-
-            HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
-            String basicAuth = SdcReq.getSdcBasicAuth(refProp);
-            conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
-            conn.setRequestProperty("Authorization", basicAuth);
-            conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
-            conn.setRequestMethod("GET");
-
-            int responseCode = conn.getResponseCode();
-            logger.info("responseCode=" + responseCode);
-
-            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
-            StringBuffer response = new StringBuffer();
-            String inputLine;
-            while ((inputLine = in.readLine()) != null) {
-                response.append(inputLine);
-                if (alarmConditions) {
-                    response.append("\n");
-                }
-            }
-            responseStr = response.toString();
-            in.close();
-            return responseStr;
-        } catch (Exception e) {
-            logger.error("Exception occurred :", e);
-            return "";
-        }
-
-    }
-
-    /**
-     * To create properties object by using cldsServicedata
-     *
-     * @param globalProps
-     * @param cldsServiceData
-     * @return
-     * @throws IOException
-     */
-    public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) throws IOException {
-        String totalPropsStr;
-        ObjectMapper mapper = new ObjectMapper();
-        ObjectNode globalPropsJson;
-        if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
-
-            // Objectnode to save all byservice, byvf , byvfc and byalarm nodes
-            ObjectNode byIdObjectNode = mapper.createObjectNode();
-
-            // To create vf ResourceUUID node with serviceInvariantUUID
-            ObjectNode invariantUuidObjectNodeWithVF = createVFObjectNodeByServiceInvariantUUID(mapper,
-                    cldsServiceData);
-            byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVF);
-
-            // To create byVf and vfcResourceNode with vfResourceUUID
-            ObjectNode vfcObjectNodeByVfUuid = createVFCObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs());
-            byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);
-
-            // To create byKpi
-            ObjectNode kpiObjectNode = mapper.createObjectNode();
-            if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {
-                for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
-                    if (currCldsVfData != null) {
-                        createKPIObjectNodeByVfUUID(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());
-                    }
-                }
-            }
-            byIdObjectNode.putPOJO("byKpi", kpiObjectNode);
-
-            // To create byVfc and alarmCondition with vfcResourceUUID
-            ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode();
-            if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {
-                for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
-                    if (currCldsVfData != null) {
-                        createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,
-                                currCldsVfData.getCldsVfcs());
-                    }
-                }
-            }
-            byIdObjectNode.putPOJO("byVfc", vfcResourceUuidObjectNode);
-
-            // To create byAlarmCondition with alarmConditionKey
-            List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData);
-            ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions);
-
-            byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);
-
-            globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
-
-            globalPropsJson.putPOJO("shared", byIdObjectNode);
-            logger.info("valuie of objNode:" + globalPropsJson);
-        } else {
-            /**
-             * to create json with total properties when no serviceUUID passed
-             */
-            globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
-        }
-        totalPropsStr = globalPropsJson.toString();
-        return totalPropsStr;
-    }
-
-    public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData) {
-        List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
-        if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null
-                && cldsServiceData.getCldsVfs().size() > 0) {
-            for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
-                if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null
-                        && currCldsVfData.getCldsVfcs().size() > 0) {
-                    for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
-                        if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null
-                                && currCldsVfcData.getCldsAlarmConditions().size() > 0) {
-                            for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
-                                if (currCldsAlarmCondition != null) {
-                                    alarmCondList.add(currCldsAlarmCondition);
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return alarmCondList;
-    }
-
-    private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper,
-            List<CldsAlarmCondition> cldsAlarmCondList) {
-        ObjectNode alarmCondKeyNode = mapper.createObjectNode();
-
-        if (cldsAlarmCondList != null && cldsAlarmCondList.size() > 0) {
-            for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {
-                if (currCldsAlarmCondition != null) {
-                    ObjectNode alarmCondNode = mapper.createObjectNode();
-                    alarmCondNode.put("eventSourceType", currCldsAlarmCondition.getEventSourceType());
-                    alarmCondNode.put("eventSeverity", currCldsAlarmCondition.getSeverity());
-                    alarmCondKeyNode.putPOJO(currCldsAlarmCondition.getAlarmConditionKey(), alarmCondNode);
-                }
-            }
-        } else {
-            ObjectNode alarmCondNode = mapper.createObjectNode();
-            alarmCondNode.put("eventSourceType", "");
-            alarmCondNode.put("eventSeverity", "");
-            alarmCondKeyNode.putPOJO("", alarmCondNode);
-        }
-        return alarmCondKeyNode;
-    }
-
-    private ObjectNode createVFObjectNodeByServiceInvariantUUID(ObjectMapper mapper, CldsServiceData cldsServiceData) {
-        ObjectNode invariantUuidObjectNode = mapper.createObjectNode();
-        ObjectNode vfObjectNode = mapper.createObjectNode();
-        ObjectNode vfUuidNode = mapper.createObjectNode();
-        List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();
-        if (cldsVfsList != null && cldsVfsList.size() > 0) {
-            for (CldsVfData currCldsVfData : cldsVfsList) {
-                if (currCldsVfData != null) {
-                    vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());
-                }
-            }
-        } else {
-            vfUuidNode.put("", "");
-        }
-        vfObjectNode.putPOJO("vf", vfUuidNode);
-        invariantUuidObjectNode.putPOJO(cldsServiceData.getServiceInvariantUUID(), vfObjectNode);
-        return invariantUuidObjectNode;
-    }
-
-    private void createKPIObjectNodeByVfUUID(ObjectMapper mapper, ObjectNode vfResourceUUIDObjectNode,
-            List<CldsVfKPIData> cldsVfKPIDataList) {
-        if (cldsVfKPIDataList != null && cldsVfKPIDataList.size() > 0) {
-            for (CldsVfKPIData currCldsVfKPIData : cldsVfKPIDataList) {
-                if (currCldsVfKPIData != null) {
-                    ObjectNode thresholdNameObjectNode = mapper.createObjectNode();
-
-                    ObjectNode fieldPathObjectNode = mapper.createObjectNode();
-                    ObjectNode nfNamingCodeNode = mapper.createObjectNode();
-
-                    fieldPathObjectNode.put(currCldsVfKPIData.getFieldPathValue(),
-                            currCldsVfKPIData.getFieldPathValue());
-                    nfNamingCodeNode.put(currCldsVfKPIData.getNfNamingValue(), currCldsVfKPIData.getNfNamingValue());
-
-                    thresholdNameObjectNode.putPOJO("fieldPath", fieldPathObjectNode);
-                    thresholdNameObjectNode.putPOJO("nfNamingCode", nfNamingCodeNode);
-
-                    vfResourceUUIDObjectNode.putPOJO(currCldsVfKPIData.getThresholdValue(), thresholdNameObjectNode);
-                }
-            }
-        }
-    }
-
-    private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUUIDObjectNode,
-            List<CldsVfcData> cldsVfcDataList) {
-        ObjectNode alarmCondContsObjectNode = mapper.createObjectNode();
-        ObjectNode alarmCondNode = mapper.createObjectNode();
-        // alarmCondNode.put("", "");
-        if (cldsVfcDataList != null && cldsVfcDataList.size() > 0) {
-            for (CldsVfcData currCldsVfcData : cldsVfcDataList) {
-                if (currCldsVfcData != null) {
-                    if (currCldsVfcData.getCldsAlarmConditions() != null
-                            && currCldsVfcData.getCldsAlarmConditions().size() > 0) {
-                        for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
-                            alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),
-                                    currCldsAlarmCondition.getAlarmConditionKey());
-                        }
-                        alarmCondContsObjectNode.putPOJO("alarmCondition", alarmCondNode);
-                    }
-                    alarmCondContsObjectNode.putPOJO("alarmCondition", alarmCondNode);
-                    vfcResourceUUIDObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(),
-                            alarmCondContsObjectNode);
-                }
-            }
-        } else {
-            alarmCondNode.put("", "");
-            alarmCondContsObjectNode.putPOJO("alarmCondition", alarmCondNode);
-            vfcResourceUUIDObjectNode.putPOJO("", alarmCondContsObjectNode);
-        }
-    }
-
-    private ObjectNode createVFCObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {
-        ObjectNode vfUUIDObjectNode = mapper.createObjectNode();
-
-        if (cldsVfDataList != null && cldsVfDataList.size() > 0) {
-            for (CldsVfData currCldsVfData : cldsVfDataList) {
-                if (currCldsVfData != null) {
-                    ObjectNode vfcObjectNode = mapper.createObjectNode();
-                    ObjectNode vfcUuidNode = mapper.createObjectNode();
-                    if (currCldsVfData.getCldsVfcs() != null && currCldsVfData.getCldsVfcs().size() > 0) {
-                        for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
-                            vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),
-                                    currCldsVfcData.getVfcName());
-                        }
-                    } else {
-                        vfcUuidNode.put("", "");
-                    }
-                    vfcObjectNode.putPOJO("vfc", vfcUuidNode);
-                    vfUUIDObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfcObjectNode);
-                }
-            }
-        } else {
-            ObjectNode vfcUuidNode = mapper.createObjectNode();
-            vfcUuidNode.put("", "");
-            ObjectNode vfcObjectNode = mapper.createObjectNode();
-            vfcObjectNode.putPOJO("vfc", vfcUuidNode);
-            vfUUIDObjectNode.putPOJO("", vfcObjectNode);
-        }
-        return vfUUIDObjectNode;
-    }
-
-    public String getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail CldsSdcServiceDetail, String artifactName) {
-        String artifactUuid = null;
-        boolean artifactxists = false;
-        if (CldsSdcServiceDetail != null && CldsSdcServiceDetail.getResources() != null
-                && CldsSdcServiceDetail.getResources().size() > 0) {
-            for (CldsSdcResource currCldsSdcResource : CldsSdcServiceDetail.getResources()) {
-                if (artifactxists) {
-                    break;
-                }
-                if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null
-                        && currCldsSdcResource.getArtifacts().size() > 0) {
-                    for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {
-                        if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null) {
-                            if (currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {
-                                artifactUuid = currCldsSdcArtifact.getArtifactUUID();
-                                artifactxists = true;
-                                break;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return artifactUuid;
-    }
-
-    public String updateControlLoopStatusToDcae(String dcaeUrl, String invariantResourceUuid,
-            String invariantServiceUuid, String artifactName) {
-        String baseUrl = refProp.getStringValue("sdc.serviceUrl");
-        String basicAuth = SdcReq.getSdcBasicAuth(refProp);
-        String postStatusData = "{ \n" + "\"event\" : \"" + "Created" + "\",\n" + "\"serviceUUID\" : \""
-                + invariantServiceUuid + "\",\n" + "\"resourceUUID\" :\"" + invariantResourceUuid + "\",\n"
-                + "\"artifactName\" : \"" + artifactName + "\",\n" + "} \n";
-        try {
-            String url = baseUrl;
-            if (invariantServiceUuid != null) {
-                url = dcaeUrl + "/closed-loops";
-            }
-            URL urlObj = new URL(url);
-
-            HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
-            conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
-            conn.setRequestProperty("Authorization", basicAuth);
-            conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
-            conn.setRequestMethod("POST");
-
-            byte[] postData = SdcReq.stringToByteArray(postStatusData);
-            try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
-                wr.write(postData);
-            }
-
-            int responseCode = conn.getResponseCode();
-            logger.info("responseCode=" + responseCode);
-
-            String resp = getResponse(conn);
-            if (resp != null) {
-                return resp;
-            }
-        } catch (Exception e) {
-            logger.error("not able to ger any service information from sdc for uuid:" + invariantServiceUuid);
-        }
-        return "";
-    }
-
-    /**
-     * To get all sdc VF/VFC Resources basic info
-     *
-     * @return
-     * @throws IOException
-     */
-    private List<CldsSdcResourceBasicInfo> getAllSdcVForVFCResourcesBasedOnResourceType(String resourceType)
-            throws IOException {
-        List<CldsSdcResourceBasicInfo> allSdcResourceVFCBasicInfo = new ArrayList<CldsSdcResourceBasicInfo>();
-        String catalogUrl = refProp.getStringValue("sdc.catalog.url");
-        String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;
-        String allSdcVFCResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false);
-
-        allSdcResourceVFCBasicInfo = getAllSdcResourcesListFromJson(allSdcVFCResources);
-        return removeDuplicateSdcResourceBasicInfo(allSdcResourceVFCBasicInfo);
-    }
-
-    private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUUID,
-            List<CldsSdcResourceBasicInfo> resourceInfoList) throws IOException {
-        String resourceUuid = null;
-        if (resourceInfoList != null && resourceInfoList.size() > 0) {
-            for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {
-                if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null
-                        && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUUID)) {
-                    resourceUuid = currResource.getUuid();
-                    break;
-                }
-            }
-        }
-        return resourceUuid;
-    }
-}
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP CLAMP\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights\r
+ *                             reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END============================================\r
+ * ===================================================================\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+\r
+package org.onap.clamp.clds.client;\r
+\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.core.JsonProcessingException;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.fasterxml.jackson.databind.node.ArrayNode;\r
+import com.fasterxml.jackson.databind.node.ObjectNode;\r
+import com.fasterxml.jackson.databind.node.TextNode;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.DataOutputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.Reader;\r
+import java.io.StringReader;\r
+import java.net.HttpURLConnection;\r
+import java.net.URL;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Date;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import javax.ws.rs.BadRequestException;\r
+\r
+import org.apache.commons.csv.CSVFormat;\r
+import org.apache.commons.csv.CSVRecord;\r
+import org.apache.commons.lang3.StringUtils;\r
+import org.onap.clamp.clds.client.req.SdcReq;\r
+import org.onap.clamp.clds.model.CldsAlarmCondition;\r
+import org.onap.clamp.clds.model.CldsDBServiceCache;\r
+import org.onap.clamp.clds.model.CldsSdcArtifact;\r
+import org.onap.clamp.clds.model.CldsSdcResource;\r
+import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo;\r
+import org.onap.clamp.clds.model.CldsSdcServiceDetail;\r
+import org.onap.clamp.clds.model.CldsSdcServiceInfo;\r
+import org.onap.clamp.clds.model.CldsServiceData;\r
+import org.onap.clamp.clds.model.CldsVfData;\r
+import org.onap.clamp.clds.model.CldsVfKPIData;\r
+import org.onap.clamp.clds.model.CldsVfcData;\r
+import org.onap.clamp.clds.model.prop.Global;\r
+import org.onap.clamp.clds.model.prop.ModelProperties;\r
+import org.onap.clamp.clds.model.refprop.RefProp;\r
+import org.onap.clamp.clds.util.LoggingUtils;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+\r
+public class SdcCatalogServices {\r
+    protected static final EELFLogger logger            = EELFManager.getInstance().getLogger(SdcCatalogServices.class);\r
+    protected static final EELFLogger metricsLogger     = EELFManager.getInstance().getMetricsLogger();\r
+\r
+    private static final String       RESOURCE_VF_TYPE  = "VF";\r
+    private static final String       RESOURCE_VFC_TYPE = "VFC";\r
+\r
+    @Autowired\r
+    private RefProp                   refProp;\r
+\r
+    /**\r
+     * This method get the SDC services Information with the corresponding\r
+     * Service UUID.\r
+     * \r
+     * @param uuid\r
+     *            The service UUID\r
+     * @return A Json String with all the service list\r
+     */\r
+    public String getSdcServicesInformation(String uuid) {\r
+        Date startTime = new Date();\r
+        String baseUrl = refProp.getStringValue("sdc.serviceUrl");\r
+        String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
+        LoggingUtils.setTargetContext("SDC", "getSdcServicesInformation");\r
+\r
+        try {\r
+            String url = baseUrl;\r
+            if (uuid != null) {\r
+                url = baseUrl + "/" + uuid + "/metadata";\r
+            }\r
+            URL urlObj = new URL(url);\r
+\r
+            HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+\r
+            conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");\r
+            conn.setRequestProperty("Authorization", basicAuth);\r
+            conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");\r
+            conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
+            conn.setRequestMethod("GET");\r
+\r
+            String resp = getResponse(conn);\r
+            if (resp != null) {\r
+                logger.info(resp.toString());\r
+                // metrics log\r
+                LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());\r
+                return resp;\r
+            }\r
+        } catch (IOException e) {\r
+            LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());\r
+            LoggingUtils.setErrorContext("900", "Get sdc services error");\r
+            logger.error("not able to get any service information from sdc for uuid:" + uuid, e);\r
+        } finally {\r
+            LoggingUtils.setTimeContext(startTime, new Date());\r
+            metricsLogger.info("getSdcServicesInformation complete");\r
+        }\r
+\r
+        return "";\r
+    }\r
+\r
+    /**\r
+     * To remove duplicate serviceUUIDs from sdc services List.\r
+     *\r
+     * @param rawCldsSdcServiceList\r
+     *            A list of CldsSdcServiceInfo\r
+     * @return A list of CldsSdcServiceInfo without duplicate service UUID\r
+     */\r
+    public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {\r
+        List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;\r
+        if (rawCldsSdcServiceList != null && rawCldsSdcServiceList.size() > 0) {\r
+            // sort list\r
+            Collections.sort(rawCldsSdcServiceList);\r
+            // and then take only the services with the max version (last in the\r
+            // list with the same name)\r
+            cldsSdcServiceInfoList = new ArrayList<>();\r
+            for (int i = 1; i < rawCldsSdcServiceList.size(); i++) {\r
+                // compare name with previous - if not equal, then keep the\r
+                // previous (it's the last with that name)\r
+                CldsSdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);\r
+                if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {\r
+                    cldsSdcServiceInfoList.add(prev);\r
+                }\r
+            }\r
+            // add the last in the list\r
+            cldsSdcServiceInfoList.add(rawCldsSdcServiceList.get(rawCldsSdcServiceList.size() - 1));\r
+        }\r
+        return cldsSdcServiceInfoList;\r
+    }\r
+\r
+    /**\r
+     * To remove duplicate serviceUUIDs from sdc resources List.\r
+     *\r
+     * @param rawCldsSdcResourceList\r
+     * @return\r
+     */\r
+    public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {\r
+        List<CldsSdcResource> cldsSdcResourceList = null;\r
+        if (rawCldsSdcResourceList != null && rawCldsSdcResourceList.size() > 0) {\r
+            // sort list\r
+            Collections.sort(rawCldsSdcResourceList);\r
+            // and then take only the resources with the max version (last in\r
+            // the list with the same name)\r
+            cldsSdcResourceList = new ArrayList<>();\r
+            for (int i = 1; i < rawCldsSdcResourceList.size(); i++) {\r
+                // compare name with previous - if not equal, then keep the\r
+                // previous (it's the last with that name)\r
+                CldsSdcResource prev = rawCldsSdcResourceList.get(i - 1);\r
+                if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {\r
+                    cldsSdcResourceList.add(prev);\r
+                }\r
+            }\r
+            // add the last in the list\r
+            cldsSdcResourceList.add(rawCldsSdcResourceList.get(rawCldsSdcResourceList.size() - 1));\r
+        }\r
+        return cldsSdcResourceList;\r
+    }\r
+\r
+    /**\r
+     * To remove duplicate basic resources with same resourceUUIDs.\r
+     *\r
+     * @param rawCldsSdcResourceListBasicList\r
+     * @return\r
+     */\r
+    public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
+            List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
+        List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
+        if (rawCldsSdcResourceListBasicList != null && rawCldsSdcResourceListBasicList.size() > 0) {\r
+            // sort list\r
+            Collections.sort(rawCldsSdcResourceListBasicList);\r
+            // and then take only the resources with the max version (last in\r
+            // the list with the same name)\r
+            cldsSdcResourceBasicInfoList = new ArrayList<>();\r
+            for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {\r
+                // compare name with previous - if not equal, then keep the\r
+                // previous (it's the last with that name)\r
+                CldsSdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);\r
+                if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {\r
+                    cldsSdcResourceBasicInfoList.add(prev);\r
+                }\r
+            }\r
+            // add the last in the list\r
+            cldsSdcResourceBasicInfoList\r
+                    .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));\r
+        }\r
+        return cldsSdcResourceBasicInfoList;\r
+    }\r
+\r
+    /**\r
+     * To get ServiceUUID by using serviceInvariantUUID.\r
+     *\r
+     * @param invariantId\r
+     *            The invariant ID\r
+     * @return The service UUID\r
+     * @throws IOException\r
+     *             In case of issues with the JSON decoder\r
+     */\r
+    public String getServiceUuidFromServiceInvariantId(String invariantId) throws IOException {\r
+        String serviceUuid = "";\r
+        String responseStr = getSdcServicesInformation(null);\r
+        List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);\r
+        List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);\r
+        if (cldsSdcServicesList != null && cldsSdcServicesList.size() > 0) {\r
+            for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
+                if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null\r
+                        && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {\r
+                    serviceUuid = currCldsSdcServiceInfo.getUuid();\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+        return serviceUuid;\r
+    }\r
+\r
+    /**\r
+     * To get CldsAsdsServiceInfo class by parsing json string.\r
+     *\r
+     * @param jsonStr\r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) throws IOException {\r
+        ObjectMapper objectMapper = new ObjectMapper();\r
+        if (StringUtils.isBlank(jsonStr)) {\r
+            return null;\r
+        }\r
+        return objectMapper.readValue(jsonStr,\r
+                objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));\r
+    }\r
+\r
+    /**\r
+     * To get List of CldsSdcResourceBasicInfo class by parsing json string.\r
+     *\r
+     * @param jsonStr\r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) throws IOException {\r
+        ObjectMapper objectMapper = new ObjectMapper();\r
+        if (StringUtils.isBlank(jsonStr)) {\r
+            return null;\r
+        }\r
+        return objectMapper.readValue(jsonStr,\r
+                objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));\r
+    }\r
+\r
+    /**\r
+     * To get CldsAsdsResource class by parsing json string.\r
+     *\r
+     * @param jsonStr\r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public CldsSdcResource getCldsSdcResourceFromJson(String jsonStr) throws IOException {\r
+        ObjectMapper objectMapper = new ObjectMapper();\r
+        return objectMapper.readValue(jsonStr, CldsSdcResource.class);\r
+    }\r
+\r
+    /**\r
+     * To get CldsSdcServiceDetail by parsing json string.\r
+     *\r
+     * @param jsonStr\r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) throws IOException {\r
+        ObjectMapper objectMapper = new ObjectMapper();\r
+        return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);\r
+    }\r
+\r
+    /**\r
+     * To upload artifact to sdc based on serviceUUID and resourcename on url.\r
+     *\r
+     * @param prop\r
+     * @param userid\r
+     * @param url\r
+     * @param formatttedSdcReq\r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq)\r
+            throws IOException {\r
+        // Verify whether it is triggered by Validation Test button from UI\r
+        if (prop.isTest()) {\r
+            return "sdc artifact upload not executed for test action";\r
+        }\r
+        logger.info("userid=" + userid);\r
+        String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq);\r
+        byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);\r
+        int postDataLength = postData.length;\r
+        HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);\r
+        try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
+            wr.write(postData);\r
+        }\r
+        boolean requestFailed = true;\r
+        int responseCode = conn.getResponseCode();\r
+        logger.info("responseCode=" + responseCode);\r
+        if (responseCode == 200) {\r
+            requestFailed = false;\r
+        }\r
+\r
+        String responseStr = getResponse(conn);\r
+        if (responseStr != null) {\r
+            if (requestFailed) {\r
+                logger.error("requestFailed - responseStr=" + responseStr);\r
+                throw new BadRequestException(responseStr);\r
+            }\r
+        }\r
+        return responseStr;\r
+    }\r
+\r
+    private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text)\r
+            throws IOException {\r
+        logger.info("userid=" + userid);\r
+        String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
+        String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
+        URL urlObj = new URL(url);\r
+        HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+        conn.setDoOutput(true);\r
+        conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);\r
+        conn.setRequestProperty("Authorization", basicAuth);\r
+        conn.setRequestProperty("Content-Type", "application/json");\r
+        conn.setRequestProperty("Content-MD5", md5Text);\r
+        conn.setRequestProperty("USER_ID", userid);\r
+        conn.setRequestMethod("POST");\r
+        conn.setRequestProperty("charset", "utf-8");\r
+        conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));\r
+        conn.setUseCaches(false);\r
+        conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
+        return conn;\r
+    }\r
+\r
+    private String getResponse(HttpURLConnection conn) throws IOException {\r
+        try (InputStream is = getInputStream(conn)) {\r
+            if (is != null) {\r
+                try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {\r
+                    StringBuilder response = new StringBuilder();\r
+                    String inputLine;\r
+                    while ((inputLine = in.readLine()) != null) {\r
+                        response.append(inputLine);\r
+                    }\r
+                    return response.toString();\r
+                }\r
+            }\r
+        }\r
+        return null;\r
+    }\r
+\r
+    private InputStream getInputStream(HttpURLConnection conn) throws IOException {\r
+        InputStream inStream = conn.getErrorStream();\r
+        if (inStream == null) {\r
+            inStream = conn.getInputStream();\r
+        }\r
+        return inStream;\r
+    }\r
+\r
+    public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData)\r
+            throws IOException {\r
+        CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();\r
+        cldsDbServiceCache.setCldsDataInstream(cldsServiceData);\r
+        cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());\r
+        cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());\r
+        return cldsDbServiceCache;\r
+    }\r
+\r
+    public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) throws IOException {\r
+        boolean expired = false;\r
+        if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
+            String cachedServiceUuid = cldsServiceData.getServiceUUID();\r
+            String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID());\r
+            String defaultRecordAge = refProp.getStringValue("CLDS_SERVICE_CACHE_MAX_SECONDS");\r
+            if ((!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null\r
+                    && cldsServiceData.getAgeOfRecord() > Long.parseLong(defaultRecordAge))) {\r
+                expired = true;\r
+            }\r
+        } else {\r
+            expired = true;\r
+        }\r
+        return expired;\r
+    }\r
+\r
+    public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) throws IOException {\r
+        String url = refProp.getStringValue("sdc.serviceUrl");\r
+        String catalogUrl = refProp.getStringValue("sdc.catalog.url");\r
+        String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);\r
+        String serviceDetailUrl = url + "/" + serviceUuid + "/metadata";\r
+        String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl, false);\r
+        ObjectMapper objectMapper = new ObjectMapper();\r
+        CldsServiceData cldsServiceData = new CldsServiceData();\r
+        if (responseStr != null) {\r
+            CldsSdcServiceDetail cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);\r
+            cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());\r
+            cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());\r
+\r
+            // To remove duplicate resources from serviceDetail and add valid\r
+            // vfs to service\r
+            if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {\r
+                List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
+                        cldsSdcServiceDetail.getResources());\r
+                if (cldsSdcResourceList != null && cldsSdcResourceList.size() > 0) {\r
+                    List<CldsVfData> cldsVfDataList = new ArrayList<>();\r
+                    for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {\r
+                        if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null\r
+                                && currCldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) {\r
+                            CldsVfData currCldsVfData = new CldsVfData();\r
+                            currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());\r
+                            currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());\r
+                            cldsVfDataList.add(currCldsVfData);\r
+                        }\r
+                    }\r
+                    cldsServiceData.setCldsVfs(cldsVfDataList);\r
+                    // For each vf in the list , add all vfc's\r
+                    getAllVfcForVfList(cldsVfDataList, catalogUrl);\r
+                    logger.info("value of cldsServiceData:" + cldsServiceData);\r
+                    logger.info("value of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());\r
+                }\r
+            }\r
+        }\r
+        return cldsServiceData;\r
+    }\r
+\r
+    /**\r
+     * @param cldsVfDataList\r
+     * @throws IOException\r
+     */\r
+    private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) throws IOException {\r
+        // todo : refact this..\r
+        if (cldsVfDataList != null && cldsVfDataList.size() > 0) {\r
+            List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
+                    RESOURCE_VF_TYPE);\r
+            List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
+                    RESOURCE_VFC_TYPE);\r
+            for (CldsVfData currCldsVfData : cldsVfDataList) {\r
+                if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) {\r
+                    String resourceUuid = getResourceUuidFromResourceInvariantUuid(\r
+                            currCldsVfData.getVfInvariantResourceUUID(), allVfResources);\r
+                    if (resourceUuid != null) {\r
+                        String vfResourceUuidUrl = catalogUrl + "resources" + "/" + resourceUuid + "/metadata";\r
+                        String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl, false);\r
+                        if (vfResponse != null) {\r
+                            // Below 2 line are to get the KPI(field path) data\r
+                            // associated with the VF's\r
+                            List<CldsVfKPIData> cldsVfKPIDataList = getFieldPathFromVF(vfResponse);\r
+                            currCldsVfData.setCldsKPIList(cldsVfKPIDataList);\r
+\r
+                            List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);\r
+                            if (vfcDataListFromVfResponse != null) {\r
+                                currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);\r
+                                if (vfcDataListFromVfResponse.size() > 0) {\r
+                                    // To get artifacts for every VFC and get\r
+                                    // alarm conditions from artifact\r
+                                    for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {\r
+                                        if (currCldsVfcData != null\r
+                                                && currCldsVfcData.getVfcInvariantResourceUUID() != null) {\r
+                                            String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(\r
+                                                    currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);\r
+                                            if (resourceVfcUuid != null) {\r
+                                                String vfcResourceUuidUrl = catalogUrl + "resources" + "/"\r
+                                                        + resourceVfcUuid + "/metadata";\r
+                                                String vfcResponse = getCldsServicesOrResourcesBasedOnURL(\r
+                                                        vfcResourceUuidUrl, false);\r
+                                                if (vfcResponse != null) {\r
+                                                    List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(\r
+                                                            vfcResponse);\r
+                                                    currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc);\r
+                                                }\r
+                                            } else {\r
+                                                logger.info("No resourceVFC UUID found for given invariantID:"\r
+                                                        + currCldsVfcData.getVfcInvariantResourceUUID());\r
+                                            }\r
+                                        }\r
+                                    }\r
+                                }\r
+                            }\r
+                        }\r
+                    } else {\r
+                        logger.info("No resourceUUID found for given invariantREsourceUUID:"\r
+                                + currCldsVfData.getVfInvariantResourceUUID());\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws IOException {\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+        ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");\r
+        List<CldsVfcData> cldsVfcDataList = new ArrayList<>();\r
+        if (vfcArrayNode != null) {\r
+            for (JsonNode vfcjsonNode : vfcArrayNode) {\r
+                CldsVfcData currCldsVfcData = new CldsVfcData();\r
+                ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;\r
+                TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");\r
+                if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {\r
+                    TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");\r
+                    TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID");\r
+                    currCldsVfcData.setVfcName(vfcResourceName.textValue());\r
+                    currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue());\r
+                    cldsVfcDataList.add(currCldsVfcData);\r
+                } else if (resourceTypeNode != null && "CVFC".equalsIgnoreCase(resourceTypeNode.textValue())) {\r
+                    cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue()));\r
+                }\r
+            }\r
+        }\r
+        return cldsVfcDataList;\r
+    }\r
+\r
+    private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {\r
+        String catalogUrl = refProp.getStringValue("sdc.catalog.url");\r
+        List<CldsVfcData> cldsVfcDataList = new ArrayList<CldsVfcData>();\r
+\r
+        if (resourceUUID != null) {\r
+            String vfcResourceUUIDUrl = catalogUrl + "resources" + "/" + resourceUUID + "/metadata";\r
+            try {\r
+                String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl, false);\r
+                ObjectMapper mapper = new ObjectMapper();\r
+                ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+                ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");\r
+\r
+                if (vfcArrayNode != null) {\r
+                    for (JsonNode vfcjsonNode : vfcArrayNode) {\r
+                        CldsVfcData currCldsVfcData = new CldsVfcData();\r
+                        ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;\r
+                        TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");\r
+                        if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {\r
+                            TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");\r
+                            TextNode vfcInvariantResourceUUID = (TextNode) currVfcNode.get("resourceInvariantUUID");\r
+                            currCldsVfcData.setVfcName(vfcResourceName.textValue());\r
+                            currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUUID.textValue());\r
+                            cldsVfcDataList.add(currCldsVfcData);\r
+                        }\r
+                    }\r
+                }\r
+            } catch (IOException e) {\r
+                logger.error("Exception during JSON analyzis", e);\r
+            }\r
+        }\r
+        return cldsVfcDataList;\r
+    }\r
+\r
+    private String removeUnwantedBracesFromString(String id) {\r
+        if (id != null && id.contains("\"")) {\r
+            id = id.replaceAll("\"", "");\r
+        }\r
+        return id;\r
+    }\r
+\r
+    private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws IOException {\r
+        List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        ObjectNode vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+        ArrayNode artifactsArrayNode = (ArrayNode) vfcResponseNode.get("artifacts");\r
+\r
+        if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {\r
+            for (int index = 0; index < artifactsArrayNode.size(); index++) {\r
+                ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);\r
+                TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");\r
+                if (artifactUrlNode != null) {\r
+                    String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());\r
+                    cldsAlarmConditionList.addAll(parseCsvToGetAlarmConditions(responsesFromArtifactUrl));\r
+                    logger.info(responsesFromArtifactUrl);\r
+                }\r
+            }\r
+        }\r
+        return cldsAlarmConditionList;\r
+    }\r
+\r
+    private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) throws IOException {\r
+        List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
+        Reader alarmReader = new StringReader(allAlarmCondsValues);\r
+        Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
+        if (records != null) {\r
+            Iterator<CSVRecord> it = records.iterator();\r
+            if (it.hasNext()) {\r
+                it.next();\r
+            }\r
+            it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));\r
+        }\r
+        return cldsAlarmConditionList;\r
+    }\r
+\r
+    // Method to get the artifact for any particular VF\r
+    private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws JsonProcessingException, IOException {\r
+        List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+        ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");\r
+\r
+        if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {\r
+            for (int index = 0; index < artifactsArrayNode.size(); index++) {\r
+                ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);\r
+                TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");\r
+                TextNode artifactNameNode = (TextNode) currArtifactNode.get("artifactName");\r
+                String artifactName = "";\r
+                if (artifactNameNode != null) {\r
+                    artifactName = artifactNameNode.textValue();\r
+                    artifactName = artifactName.substring(artifactName.lastIndexOf(".") + 1);\r
+                }\r
+                if (artifactUrlNode != null && artifactName != null && !artifactName.isEmpty()\r
+                        && artifactName.equalsIgnoreCase("csv")) {\r
+                    String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());\r
+                    cldsVfKPIDataList.addAll(parseCsvToGetFieldPath(responsesFromArtifactUrl));\r
+                    logger.info(responsesFromArtifactUrl);\r
+                }\r
+            }\r
+        }\r
+        return cldsVfKPIDataList;\r
+    }\r
+\r
+    private CldsVfKPIData convertCsvRecordToKpiData(CSVRecord record) {\r
+        if (record.size() < 6) {\r
+            logger.debug("invalid csv field path Record,total columns less than 6: " + record);\r
+            return null;\r
+        }\r
+\r
+        if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))\r
+                || StringUtils.isBlank(record.get(5))) {\r
+            logger.debug("Invalid csv field path Record,one of column is having blank value : " + record);\r
+            return null;\r
+        }\r
+\r
+        CldsVfKPIData cldsVfKPIData = new CldsVfKPIData();\r
+        cldsVfKPIData.setNfNamingCode(record.get(0).trim());\r
+        cldsVfKPIData.setNfNamingValue(record.get(1).trim());\r
+\r
+        cldsVfKPIData.setFieldPath(record.get(2).trim());\r
+        cldsVfKPIData.setFieldPathValue(record.get(3).trim());\r
+\r
+        cldsVfKPIData.setThresholdName(record.get(4).trim());\r
+        cldsVfKPIData.setThresholdValue(record.get(5).trim());\r
+        return cldsVfKPIData;\r
+\r
+    }\r
+\r
+    // Method to get the artifactURL Data and set the CldsVfKPIData node\r
+    private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) throws IOException {\r
+        List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();\r
+        Reader alarmReader = new StringReader(allFieldPathValues);\r
+        Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
+        if (records != null) {\r
+            for (CSVRecord record : records) {\r
+                CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);\r
+                if (kpiData != null) {\r
+                    cldsVfKPIDataList.add(kpiData);\r
+                }\r
+            }\r
+        }\r
+        return cldsVfKPIDataList;\r
+    }\r
+\r
+    private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {\r
+        if (record == null) {\r
+            return;\r
+        }\r
+        if (record.size() < 5) {\r
+            logger.debug("invalid csv alarm Record,total columns less than 5: " + record);\r
+            return;\r
+        }\r
+        if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))\r
+                || StringUtils.isBlank(record.get(4))) {\r
+            logger.debug("invalid csv alarm Record,one of column is having blank value : " + record);\r
+            return;\r
+        }\r
+        CldsAlarmCondition cldsAlarmCondition = new CldsAlarmCondition();\r
+        cldsAlarmCondition.setEventSourceType(record.get(1));\r
+        cldsAlarmCondition.setEventName(record.get(2));\r
+        cldsAlarmCondition.setAlarmConditionKey(record.get(3));\r
+        cldsAlarmCondition.setSeverity(record.get(4));\r
+        cldsAlarmConditionList.add(cldsAlarmCondition);\r
+    }\r
+\r
+    public String getResponsesFromArtifactUrl(String artifactsUrl) {\r
+        String hostUrl = refProp.getStringValue("sdc.hostUrl");\r
+        artifactsUrl = artifactsUrl.replaceAll("\"", "");\r
+        String artifactUrl = hostUrl + artifactsUrl;\r
+        logger.info("value of artifactURl:" + artifactUrl);\r
+        String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl, true);\r
+        logger.info("value of artifactResponse:" + currArtifactResponse);\r
+        return currArtifactResponse;\r
+    }\r
+\r
+    /**\r
+     * Service to services/resources/artifacts from sdc.Pass alarmConditions as\r
+     * true to get alarmconditons from artifact url and else it is false\r
+     *\r
+     * @param url\r
+     * @param alarmConditions\r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) {\r
+        try {\r
+            url = removeUnwantedBracesFromString(url);\r
+            URL urlObj = new URL(url);\r
+\r
+            HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+            String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
+            conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");\r
+            conn.setRequestProperty("Authorization", basicAuth);\r
+            conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");\r
+            conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
+            conn.setRequestMethod("GET");\r
+\r
+            int responseCode = conn.getResponseCode();\r
+            logger.info("responseCode=" + responseCode);\r
+            StringBuilder response;\r
+            try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {\r
+                response = new StringBuilder();\r
+                String inputLine;\r
+                while ((inputLine = in.readLine()) != null) {\r
+                    response.append(inputLine);\r
+                    if (alarmConditions) {\r
+                        response.append("\n");\r
+                    }\r
+                }\r
+            }\r
+            return response.toString();\r
+        } catch (IOException e) {\r
+            logger.error("Exception occurred during query to SDC", e);\r
+            return "";\r
+        }\r
+\r
+    }\r
+\r
+    /**\r
+     * To create properties object by using cldsServicedata.\r
+     *\r
+     * @param globalProps\r
+     * @param cldsServiceData\r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) throws IOException {\r
+        String totalPropsStr;\r
+        ObjectMapper mapper = new ObjectMapper();\r
+        ObjectNode globalPropsJson;\r
+        if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
+\r
+            // Objectnode to save all byservice, byvf , byvfc and byalarm nodes\r
+            ObjectNode byIdObjectNode = mapper.createObjectNode();\r
+\r
+            // To create vf ResourceUUID node with serviceInvariantUUID\r
+            ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(mapper,\r
+                    cldsServiceData);\r
+            byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVf);\r
+\r
+            // To create byVf and vfcResourceNode with vfResourceUUID\r
+            ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs());\r
+            byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);\r
+\r
+            // To create byKpi\r
+            ObjectNode kpiObjectNode = mapper.createObjectNode();\r
+            if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {\r
+                for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
+                    if (currCldsVfData != null) {\r
+                        createKpiObjectNodeByVfUuid(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());\r
+                    }\r
+                }\r
+            }\r
+            byIdObjectNode.putPOJO("byKpi", kpiObjectNode);\r
+\r
+            // To create byVfc and alarmCondition with vfcResourceUUID\r
+            ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode();\r
+            if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {\r
+                for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
+                    if (currCldsVfData != null) {\r
+                        createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,\r
+                                currCldsVfData.getCldsVfcs());\r
+                    }\r
+                }\r
+            }\r
+            byIdObjectNode.putPOJO("byVfc", vfcResourceUuidObjectNode);\r
+\r
+            // To create byAlarmCondition with alarmConditionKey\r
+            List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
+                    "alarmCondition");\r
+            ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions);\r
+\r
+            byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);\r
+\r
+            // To create byAlertDescription with AlertDescription\r
+            List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
+                    "alertDescription");\r
+            ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(mapper, allAlertDescriptions);\r
+\r
+            byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
+\r
+            globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);\r
+\r
+            globalPropsJson.putPOJO("shared", byIdObjectNode);\r
+            logger.info("valuie of objNode:" + globalPropsJson);\r
+        } else {\r
+            /**\r
+             * to create json with total properties when no serviceUUID passed\r
+             */\r
+            globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);\r
+        }\r
+        totalPropsStr = globalPropsJson.toString();\r
+        return totalPropsStr;\r
+    }\r
+\r
+    /**\r
+     * Method to get alarm conditions/alert description from Service Data.\r
+     * \r
+     * @param cldsServiceData\r
+     *            CldsServiceData the Service Data to analyze\r
+     * @param eventName\r
+     *            The String event name that will be used to filter the alarm\r
+     *            list\r
+     * @return The list of CldsAlarmCondition for the event name specified\r
+     */\r
+    public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData,\r
+            String eventName) {\r
+        List<CldsAlarmCondition> alarmCondList = new ArrayList<>();\r
+        if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null\r
+                && !cldsServiceData.getCldsVfs().isEmpty()) {\r
+            for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
+                alarmCondList.addAll(getAllAlarmConditionsFromCldsVfData(currCldsVfData, eventName));\r
+            }\r
+        }\r
+        return alarmCondList;\r
+    }\r
+\r
+    /**\r
+     * Method to get alarm conditions/alert description from VF Data.\r
+     * \r
+     * @param currCldsVfData\r
+     *            The Vf Data to analyze\r
+     * @param eventName\r
+     *            The String event name that will be used to filter the alarm\r
+     *            list\r
+     * @return The list of CldsAlarmCondition for the event name specified\r
+     */\r
+    private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfData(CldsVfData currCldsVfData, String eventName) {\r
+        List<CldsAlarmCondition> alarmCondList = new ArrayList<>();\r
+\r
+        if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {\r
+            for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {\r
+                alarmCondList.addAll(getAllAlarmConditionsFromCldsVfcData(currCldsVfcData, eventName));\r
+            }\r
+        }\r
+        return alarmCondList;\r
+    }\r
+\r
+    /**\r
+     * Method to get alarm conditions/alert description from VFC Data.\r
+     * \r
+     * @param currCldsVfcData\r
+     *            The VfC Data to analyze\r
+     * @param eventName\r
+     *            The String event name that will be used to filter the alarm\r
+     *            list\r
+     * @return The list of CldsAlarmCondition for the event name specified\r
+     */\r
+    private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfcData(CldsVfcData currCldsVfcData,\r
+            String eventName) {\r
+        List<CldsAlarmCondition> alarmCondList = new ArrayList<>();\r
+\r
+        if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null\r
+                && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
+            for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {\r
+                if (currCldsAlarmCondition != null\r
+                        && currCldsAlarmCondition.getEventName().equalsIgnoreCase(eventName)) {\r
+                    alarmCondList.add(currCldsAlarmCondition);\r
+                }\r
+            }\r
+        }\r
+        return alarmCondList;\r
+    }\r
+\r
+    private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper,\r
+            List<CldsAlarmCondition> cldsAlarmCondList) {\r
+        ObjectNode alarmCondKeyNode = mapper.createObjectNode();\r
+\r
+        if (cldsAlarmCondList != null && cldsAlarmCondList.size() > 0) {\r
+            for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {\r
+                if (currCldsAlarmCondition != null) {\r
+                    ObjectNode alarmCondNode = mapper.createObjectNode();\r
+                    alarmCondNode.put("eventSourceType", currCldsAlarmCondition.getEventSourceType());\r
+                    alarmCondNode.put("eventSeverity", currCldsAlarmCondition.getSeverity());\r
+                    alarmCondKeyNode.putPOJO(currCldsAlarmCondition.getAlarmConditionKey(), alarmCondNode);\r
+                }\r
+            }\r
+        } else {\r
+            ObjectNode alarmCondNode = mapper.createObjectNode();\r
+            alarmCondNode.put("eventSourceType", "");\r
+            alarmCondNode.put("eventSeverity", "");\r
+            alarmCondKeyNode.putPOJO("", alarmCondNode);\r
+        }\r
+        return alarmCondKeyNode;\r
+    }\r
+\r
+    private ObjectNode createVfObjectNodeByServiceInvariantUuid(ObjectMapper mapper, CldsServiceData cldsServiceData) {\r
+        ObjectNode invariantUuidObjectNode = mapper.createObjectNode();\r
+        ObjectNode vfObjectNode = mapper.createObjectNode();\r
+        ObjectNode vfUuidNode = mapper.createObjectNode();\r
+        List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();\r
+        if (cldsVfsList != null && cldsVfsList.size() > 0) {\r
+            for (CldsVfData currCldsVfData : cldsVfsList) {\r
+                if (currCldsVfData != null) {\r
+                    vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());\r
+                }\r
+            }\r
+        } else {\r
+            vfUuidNode.put("", "");\r
+        }\r
+        vfObjectNode.putPOJO("vf", vfUuidNode);\r
+        invariantUuidObjectNode.putPOJO(cldsServiceData.getServiceInvariantUUID(), vfObjectNode);\r
+        return invariantUuidObjectNode;\r
+    }\r
+\r
+    private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode,\r
+            List<CldsVfKPIData> cldsVfKpiDataList) {\r
+        if (cldsVfKpiDataList != null && cldsVfKpiDataList.size() > 0) {\r
+            for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {\r
+                if (currCldsVfKpiData != null) {\r
+                    ObjectNode thresholdNameObjectNode = mapper.createObjectNode();\r
+\r
+                    ObjectNode fieldPathObjectNode = mapper.createObjectNode();\r
+                    ObjectNode nfNamingCodeNode = mapper.createObjectNode();\r
+\r
+                    fieldPathObjectNode.put(currCldsVfKpiData.getFieldPathValue(),\r
+                            currCldsVfKpiData.getFieldPathValue());\r
+                    nfNamingCodeNode.put(currCldsVfKpiData.getNfNamingValue(), currCldsVfKpiData.getNfNamingValue());\r
+\r
+                    thresholdNameObjectNode.putPOJO("fieldPath", fieldPathObjectNode);\r
+                    thresholdNameObjectNode.putPOJO("nfNamingCode", nfNamingCodeNode);\r
+\r
+                    vfResourceUuidObjectNode.putPOJO(currCldsVfKpiData.getThresholdValue(), thresholdNameObjectNode);\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUuidObjectNode,\r
+            List<CldsVfcData> cldsVfcDataList) {\r
+        ObjectNode vfcObjectNode = mapper.createObjectNode();\r
+        ObjectNode alarmCondNode = mapper.createObjectNode();\r
+        ObjectNode alertDescNode = mapper.createObjectNode();\r
+        if (cldsVfcDataList != null && cldsVfcDataList.size() > 0) {\r
+            for (CldsVfcData currCldsVfcData : cldsVfcDataList) {\r
+                if (currCldsVfcData != null) {\r
+                    if (currCldsVfcData.getCldsAlarmConditions() != null\r
+                            && currCldsVfcData.getCldsAlarmConditions().size() > 0) {\r
+                        for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {\r
+                            alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
+                                    currCldsAlarmCondition.getAlarmConditionKey());\r
+                            if (currCldsAlarmCondition.getEventName().equalsIgnoreCase("alarmCondition")) {\r
+                                alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
+                                        currCldsAlarmCondition.getAlarmConditionKey());\r
+                            } else {\r
+                                alertDescNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
+                                        currCldsAlarmCondition.getAlarmConditionKey());\r
+                            }\r
+                        }\r
+                    }\r
+                    vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);\r
+                    vfcObjectNode.putPOJO("alertDescription", alertDescNode);\r
+                    vfcResourceUuidObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), vfcObjectNode);\r
+                }\r
+            }\r
+        } else {\r
+            alarmCondNode.put("", "");\r
+            vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);\r
+            alertDescNode.put("", "");\r
+            vfcObjectNode.putPOJO("alertDescription", alarmCondNode);\r
+            vfcResourceUuidObjectNode.putPOJO("", vfcObjectNode);\r
+        }\r
+    }\r
+\r
+    private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {\r
+        ObjectNode vfUuidObjectNode = mapper.createObjectNode();\r
+\r
+        if (cldsVfDataList != null && cldsVfDataList.size() > 0) {\r
+            for (CldsVfData currCldsVfData : cldsVfDataList) {\r
+                if (currCldsVfData != null) {\r
+                    ObjectNode vfcObjectNode = mapper.createObjectNode();\r
+                    ObjectNode vfcUuidNode = mapper.createObjectNode();\r
+                    if (currCldsVfData.getCldsVfcs() != null && currCldsVfData.getCldsVfcs().size() > 0) {\r
+                        for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {\r
+                            vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),\r
+                                    currCldsVfcData.getVfcName());\r
+                        }\r
+                    } else {\r
+                        vfcUuidNode.put("", "");\r
+                    }\r
+                    vfcObjectNode.putPOJO("vfc", vfcUuidNode);\r
+                    vfUuidObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfcObjectNode);\r
+                }\r
+            }\r
+        } else {\r
+            ObjectNode vfcUuidNode = mapper.createObjectNode();\r
+            vfcUuidNode.put("", "");\r
+            ObjectNode vfcObjectNode = mapper.createObjectNode();\r
+            vfcObjectNode.putPOJO("vfc", vfcUuidNode);\r
+            vfUuidObjectNode.putPOJO("", vfcObjectNode);\r
+        }\r
+        return vfUuidObjectNode;\r
+    }\r
+\r
+    /**\r
+     * This method searches the equivalent artifact UUID for a specific\r
+     * artifactName in a SdcServiceDetail.\r
+     * \r
+     * @param cldsSdcServiceDetail\r
+     *            The SdcServiceDetail that will be analyzed\r
+     * @param artifactName\r
+     *            The artifact name that will be searched\r
+     * @return The artifact UUID found\r
+     */\r
+    public String getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail cldsSdcServiceDetail, String artifactName) {\r
+        String artifactUuid = null;\r
+        boolean artifactExists = false;\r
+        if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null\r
+                && !cldsSdcServiceDetail.getResources().isEmpty()) {\r
+            for (CldsSdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) {\r
+                if (artifactExists) {\r
+                    break;\r
+                }\r
+                if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null\r
+                        && !currCldsSdcResource.getArtifacts().isEmpty()) {\r
+                    for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {\r
+                        if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null) {\r
+                            if (currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
+                                artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
+                                artifactExists = true;\r
+                                break;\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        return artifactUuid;\r
+    }\r
+\r
+    public String updateControlLoopStatusToDcae(String dcaeUrl, String invariantResourceUuid,\r
+            String invariantServiceUuid, String artifactName) {\r
+        String baseUrl = refProp.getStringValue("sdc.serviceUrl");\r
+        String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
+        String postStatusData = "{ \n" + "\"event\" : \"" + "Created" + "\",\n" + "\"serviceUUID\" : \""\r
+                + invariantServiceUuid + "\",\n" + "\"resourceUUID\" :\"" + invariantResourceUuid + "\",\n"\r
+                + "\"artifactName\" : \"" + artifactName + "\",\n" + "} \n";\r
+        try {\r
+            String url = baseUrl;\r
+            if (invariantServiceUuid != null) {\r
+                url = dcaeUrl + "/closed-loops";\r
+            }\r
+            URL urlObj = new URL(url);\r
+\r
+            HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+            conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");\r
+            conn.setRequestProperty("Authorization", basicAuth);\r
+            conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");\r
+            conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
+            conn.setRequestMethod("POST");\r
+\r
+            byte[] postData = SdcReq.stringToByteArray(postStatusData);\r
+            try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
+                wr.write(postData);\r
+            }\r
+\r
+            int responseCode = conn.getResponseCode();\r
+            logger.info("responseCode=" + responseCode);\r
+\r
+            String resp = getResponse(conn);\r
+            if (resp != null) {\r
+                return resp;\r
+            }\r
+        } catch (IOException e) {\r
+            logger.error("Not able to get any service information from sdc for uuid:" + invariantServiceUuid, e);\r
+        }\r
+        return "";\r
+    }\r
+\r
+    /**\r
+     * To get all sdc VF/VFC Resources basic info.\r
+     * \r
+     * @param resourceType\r
+     *            The resourceType\r
+     * @return The list of CldsSdcResourceBasicInfo\r
+     * @throws IOException\r
+     *             In case of issues with the Streams\r
+     */\r
+    private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType)\r
+            throws IOException {\r
+        List<CldsSdcResourceBasicInfo> allSdcResourceVfcBasicInfo = new ArrayList<CldsSdcResourceBasicInfo>();\r
+        String catalogUrl = refProp.getStringValue("sdc.catalog.url");\r
+        String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;\r
+        String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false);\r
+\r
+        allSdcResourceVfcBasicInfo = getAllSdcResourcesListFromJson(allSdcVfcResources);\r
+        return removeDuplicateSdcResourceBasicInfo(allSdcResourceVfcBasicInfo);\r
+    }\r
+\r
+    private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,\r
+            List<CldsSdcResourceBasicInfo> resourceInfoList) throws IOException {\r
+        String resourceUuid = null;\r
+        if (resourceInfoList != null && resourceInfoList.size() > 0) {\r
+            for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {\r
+                if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null\r
+                        && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {\r
+                    resourceUuid = currResource.getUuid();\r
+                    break;\r
+                }\r
+            }\r
+        }\r
+        return resourceUuid;\r
+    }\r
+\r
+    /**\r
+     * Method to get service invariant uuid from model properties.\r
+     * \r
+     * @param props\r
+     *            The Clds model properties\r
+     * @return The Service Id\r
+     */\r
+    private String getServiceInvariantUuidFromProps(ModelProperties props) {\r
+        String invariantUuid = "";\r
+        Global globalProps = props.getGlobal();\r
+        if (globalProps != null && globalProps.getService() != null) {\r
+            invariantUuid = globalProps.getService();\r
+        }\r
+        return invariantUuid;\r
+    }\r
+\r
+    /**\r
+     * This method upload the BluePrint to SDC.\r
+     * \r
+     * @param prop\r
+     *            The Clds model Properties\r
+     * @param userid\r
+     *            The user id for SDC\r
+     * @param sdcReqUrlsList\r
+     *            The list of SDC URL to try\r
+     * @param formattedSdcReq\r
+     *            The blueprint to upload\r
+     * @param formattedSdcLocationReq\r
+     *            THe location Blueprint to upload\r
+     * @param artifactName\r
+     *            The artifact name from where we can get the Artifact UUID\r
+     * @param locationArtifactName\r
+     *            The location artifact name from where we can get the Artifact\r
+     *            UUID\r
+     * @throws IOException\r
+     *             In case of issues with the streams\r
+     * \r
+     */\r
+    public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,\r
+            String formattedSdcLocationReq, String artifactName, String locationArtifactName) throws IOException {\r
+        logger.info("userid=" + userid);\r
+        String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);\r
+        if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {\r
+            for (String url : sdcReqUrlsList) {\r
+                if (url != null) {\r
+                    String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
+                    logger.info("ServiceUUID used before upload in url:" + originalServiceUuid);\r
+                    String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);\r
+                    CldsSdcServiceDetail cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
+                    String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
+                            artifactName);\r
+                    // Upload artifacts to sdc\r
+                    String updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;\r
+                    String responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcReq);\r
+                    logger.info("value of sdc Response of uploading to sdc :" + responseStr);\r
+                    String updatedServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
+                    if (!originalServiceUuid.equalsIgnoreCase(updatedServiceUuid)) {\r
+                        url = url.replace(originalServiceUuid, updatedServiceUuid);\r
+                    }\r
+                    logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUuid);\r
+                    sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);\r
+                    cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
+                    uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
+                            locationArtifactName);\r
+                    // To send location information also to sdc\r
+                    updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;\r
+                    responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcLocationReq);\r
+                    logger.info("value of sdc Response of uploading location to sdc :" + responseStr);\r
+                }\r
+            }\r
+        }\r
+    }\r
+}\r
index 8ceaa3d..b501b2d 100644 (file)
@@ -29,27 +29,32 @@ import java.util.Date;
 import java.util.TimeZone;\r
 import java.util.UUID;\r
 \r
-import org.jboss.logging.MDC;\r
+import org.apache.log4j.MDC;\r
 \r
+/**\r
+ * This class handles the special info that appear in the log, like RequestID,\r
+ * time context, ...\r
+ *\r
+ */\r
 public class LoggingUtils {\r
 \r
     /**\r
      * Set request related logging variables in thread local data via MDC\r
-     *\r
+     * \r
      * @param service\r
      *            Service Name of API (ex. "PUT template")\r
      * @param partner\r
      *            Partner name (client or user invoking API)\r
      */\r
     public static void setRequestContext(String service, String partner) {\r
-        MDC.put("RequestId",  UUID.randomUUID().toString());\r
+        MDC.put("RequestId", UUID.randomUUID().toString());\r
         MDC.put("ServiceName", service);\r
         MDC.put("PartnerName", partner);\r
     }\r
 \r
     /**\r
-     * Set time related logging variables in thread local data via MDC\r
-     *\r
+     * Set time related logging variables in thread local data via MDC.\r
+     * \r
      * @param beginTimeStamp\r
      *            Start time\r
      * @param endTimeStamp\r
@@ -72,7 +77,7 @@ public class LoggingUtils {
     }\r
 \r
     /**\r
-     * Set response related logging variables in thread local data via MDC\r
+     * Set response related logging variables in thread local data via MDC.\r
      * \r
      * @param code\r
      *            Response code ("0" indicates success)\r
@@ -102,7 +107,7 @@ public class LoggingUtils {
     }\r
 \r
     /**\r
-     * Set error related logging variables in thread local data via MDC\r
+     * Set error related logging variables in thread local data via MDC.\r
      * \r
      * @param code\r
      *            Error code\r
@@ -121,4 +126,22 @@ public class LoggingUtils {
         return df.format(timeStamp);\r
     }\r
 \r
+    /**\r
+     * Get a previously stored RequestID for the thread local data via MDC. If\r
+     * one was not previously stored, generate one, store it, and return that\r
+     * one.\r
+     * \r
+     * @return A string with the request ID\r
+     */\r
+    public static String getRequestId() {\r
+        String reqid;\r
+\r
+        reqid = (String) MDC.get("RequestID");\r
+        if (reqid == null || reqid.isEmpty()) {\r
+            reqid = UUID.randomUUID().toString();\r
+            MDC.put("RequestId", reqid);\r
+        }\r
+        return reqid;\r
+    }\r
+\r
 }\r