Remove Camunda and replace by Camel
[clamp.git] / src / main / java / org / onap / clamp / clds / client / req / sdc / SdcCatalogServices.java
index 6684f1a..45dbf81 100644 (file)
@@ -60,7 +60,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.http.HttpHeaders;\r
 import org.onap.clamp.clds.exception.SdcCommunicationException;\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
@@ -76,23 +75,25 @@ import org.onap.clamp.clds.model.refprop.RefProp;
 import org.onap.clamp.clds.util.CryptoUtils;\r
 import org.onap.clamp.clds.util.LoggingUtils;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Component;\r
 \r
+@Component\r
 public class SdcCatalogServices {\r
 \r
     private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class);\r
     private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();\r
-    private static final String       RESOURCE_VF_TYPE              = "VF";\r
-    private static final String       RESOURCE_VFC_TYPE             = "VFC";\r
-    private static final String       RESOURCE_CVFC_TYPE            = "CVFC";\r
+    private static final String RESOURCE_VF_TYPE = "VF";\r
+    private static final String RESOURCE_VFC_TYPE = "VFC";\r
+    private static final String RESOURCE_CVFC_TYPE = "CVFC";\r
     private static final String SDC_REQUESTID_PROPERTY_NAME = "sdc.header.requestId";\r
-    private static final String       SDC_METADATA_URL_PREFIX       = "/metadata";\r
-    private static final String       SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID";\r
-    private static final String       SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url";\r
-    private static final String       SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";\r
-    private static final String       SDC_INSTANCE_ID_CLAMP         = "CLAMP-Tool";\r
-    private static final String       RESOURCE_URL_PREFIX           = "resources";\r
+    private static final String SDC_METADATA_URL_PREFIX = "/metadata";\r
+    private static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID";\r
+    private static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url";\r
+    private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";\r
+    private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";\r
+    private static final String RESOURCE_URL_PREFIX = "resources";\r
     @Autowired\r
-    private RefProp                   refProp;\r
+    private RefProp refProp;\r
 \r
     /**\r
      * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic\r
@@ -131,7 +132,7 @@ public class SdcCatalogServices {
         LoggingUtils.setTargetContext("SDC", "getSdcServicesInformation");\r
         try {\r
             String url = baseUrl;\r
-            if (uuid != null) {\r
+            if (uuid != null && !uuid.isEmpty()) {\r
                 url = baseUrl + "/" + uuid + SDC_METADATA_URL_PREFIX;\r
             }\r
             URL urlObj = new URL(url);\r
@@ -142,7 +143,7 @@ public class SdcCatalogServices {
             conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());\r
             conn.setRequestMethod("GET");\r
             String resp = getResponse(conn);\r
-            logger.info(resp);\r
+            logger.debug("Services list received from SDC:" + resp);\r
             // metrics log\r
             LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());\r
             return resp;\r
@@ -333,7 +334,6 @@ public class SdcCatalogServices {
         }\r
     }\r
 \r
-\r
     // upload artifact to sdc based on serviceUUID and resource name on url\r
     private String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formattedSdcReq) {\r
         // Verify whether it is triggered by Validation Test button from UI\r
@@ -422,23 +422,11 @@ public class SdcCatalogServices {
         }\r
     }\r
 \r
-    public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData) {\r
-        try {\r
-            CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();\r
-            cldsDbServiceCache.setCldsDataInstream(cldsServiceData);\r
-            cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());\r
-            cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());\r
-            return cldsDbServiceCache;\r
-        } catch (IOException e) {\r
-            logger.error("Exception when getting service in cache", e);\r
-            throw new SdcCommunicationException("Exception when getting service in cache", e);\r
-        }\r
-    }\r
-\r
     /**\r
      * Check if the SDC Info in cache has expired.\r
      * \r
      * @param cldsServiceData\r
+     *            The object representing the service data\r
      * @return boolean flag\r
      * @throws GeneralSecurityException\r
      *             In case of issues with the decryting the encrypted password\r
@@ -447,23 +435,25 @@ public class SdcCatalogServices {
      */\r
     public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData)\r
             throws GeneralSecurityException, DecoderException {\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
+            String configuredMaxAge = refProp.getStringValue("clds.service.cache.invalidate.after.seconds");\r
+            if (configuredMaxAge == null) {\r
+                logger.warn(\r
+                        "clds.service.cache.invalidate.after.seconds NOT set in clds-reference.properties file, taking 60s as default");\r
+                configuredMaxAge = "60";\r
             }\r
+            return (!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null\r
+                    && cldsServiceData.getAgeOfRecord() > Long.parseLong(configuredMaxAge));\r
         } else {\r
-            expired = true;\r
+            return true;\r
         }\r
-        return expired;\r
     }\r
 \r
     /**\r
-     * Get the Service Data with Alarm Conditions for a given invariantServiceUuid.\r
+     * Get the Service Data with Alarm Conditions for a given\r
+     * invariantServiceUuid.\r
      * \r
      * @param invariantServiceUuid\r
      * @return The CldsServiceData\r
@@ -510,8 +500,7 @@ public class SdcCatalogServices {
                     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
+                    logger.info("Invariant Service ID of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());\r
                 }\r
             }\r
         }\r
@@ -606,17 +595,17 @@ public class SdcCatalogServices {
 \r
     private void handleVFCtypeNode(ObjectNode currVfcNode, List<CldsVfcData> cldsVfcDataList) {\r
         CldsVfcData currCldsVfcData = new CldsVfcData();\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
+        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
     private void handleCVFCtypeNode(ObjectNode currVfcNode, List<CldsVfcData> cldsVfcDataList) {\r
         handleVFCtypeNode(currVfcNode, cldsVfcDataList);\r
-                    cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue()));\r
-                }\r
+        cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue()));\r
+    }\r
 \r
     private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {\r
         String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);\r
@@ -786,7 +775,6 @@ public class SdcCatalogServices {
         cldsAlarmConditionList.add(cldsAlarmCondition);\r
     }\r
 \r
-\r
     // Get the responses for the current artifact from the artifacts URL.\r
     private String getResponsesFromArtifactUrl(String artifactsUrl) {\r
         String hostUrl = refProp.getStringValue("sdc.hostUrl");\r
@@ -802,9 +790,9 @@ public class SdcCatalogServices {
      * Service to services/resources/artifacts from sdc.Pass alarmConditions as\r
      * true to get alarm conditons from artifact url and else it is false\r
      * \r
-     * @param url The URL to trigger\r
+     * @param url\r
+     *            The URL to trigger\r
      * @return The String containing the payload\r
-     * \r
      */\r
     public String getCldsServicesOrResourcesBasedOnURL(String url) {\r
         Date startTime = new Date();\r
@@ -832,12 +820,12 @@ public class SdcCatalogServices {
             logger.error("Exception occurred during query to SDC", e);\r
             return "";\r
         } catch (DecoderException e) {\r
-               LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
+            LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
             LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
             logger.error("Exception when attempting to decode the Hex string", e);\r
             throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);\r
         } catch (GeneralSecurityException e) {\r
-               LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
+            LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
             LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
             logger.error("Exception when attempting to decrypt the encrypted password", e);\r
             throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);\r
@@ -901,7 +889,7 @@ public class SdcCatalogServices {
             byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
             globalPropsJson = decodeGlobalProp(globalProps, mapper);\r
             globalPropsJson.putPOJO("shared", byIdObjectNode);\r
-            logger.info("value of objNode:" + globalPropsJson);\r
+            logger.info("Global properties JSON created with SDC info:" + globalPropsJson);\r
         } else {\r
             /**\r
              * to create json with total properties when no serviceUUID passed\r