* ============LICENSE_START=======================================================\r
* ONAP CLAMP\r
* ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property. All rights\r
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights\r
* reserved.\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* limitations under the License.\r
* ============LICENSE_END============================================\r
* ===================================================================\r
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * \r
*/\r
\r
package org.onap.clamp.clds.client.req.sdc;\r
import org.apache.commons.io.IOUtils;\r
import org.apache.commons.lang3.StringUtils;\r
import org.apache.http.HttpHeaders;\r
-import org.onap.clamp.clds.exception.SdcCommunicationException;\r
+import org.onap.clamp.clds.config.ClampProperties;\r
+import org.onap.clamp.clds.exception.sdc.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
-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.model.properties.Global;\r
+import org.onap.clamp.clds.model.properties.ModelProperties;\r
+import org.onap.clamp.clds.model.sdc.SdcArtifact;\r
+import org.onap.clamp.clds.model.sdc.SdcResource;\r
+import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo;\r
+import org.onap.clamp.clds.model.sdc.SdcServiceDetail;\r
+import org.onap.clamp.clds.model.sdc.SdcServiceInfo;\r
+import org.onap.clamp.clds.service.CldsService;\r
import org.onap.clamp.clds.util.CryptoUtils;\r
+import org.onap.clamp.clds.util.JacksonUtils;\r
import org.onap.clamp.clds.util.LoggingUtils;\r
import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.context.annotation.Primary;\r
+import org.springframework.stereotype.Component;\r
\r
+@Component\r
+@Primary\r
public class SdcCatalogServices {\r
\r
private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class);\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 ClampProperties refProp;\r
\r
- // returns SDC id and password as a HTTP Basic Auth string (for example: Basic dGVzdDoxMjM0NTY=)\r
+ /**\r
+ * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic\r
+ * dGVzdDoxMjM0NTY=).\r
+ *\r
+ * @return The String with Basic Auth and password\r
+ * @throws GeneralSecurityException\r
+ * In case of issue when decryting the SDC password\r
+ * @throws DecoderException\r
+ * In case of issues with the decoding of the HexString message\r
+ */\r
private String getSdcBasicAuth() throws GeneralSecurityException, DecoderException {\r
String sdcId = refProp.getStringValue("sdc.serviceUsername");\r
String sdcPw = refProp.getStringValue("sdc.servicePassword");\r
/**\r
* This method get the SDC services Information with the corresponding\r
* Service UUID.\r
- *\r
+ * \r
* @param uuid\r
* The service UUID\r
* @return A Json String with all the service list\r
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
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
\r
/**\r
* To remove duplicate serviceUUIDs from sdc services List.\r
- *\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
+ public List<SdcServiceInfo> removeDuplicateServices(List<SdcServiceInfo> rawCldsSdcServiceList) {\r
+ List<SdcServiceInfo> cldsSdcServiceInfoList = null;\r
if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {\r
// sort list\r
Collections.sort(rawCldsSdcServiceList);\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
+ SdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);\r
if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {\r
cldsSdcServiceInfoList.add(prev);\r
}\r
\r
/**\r
* To remove duplicate serviceUUIDs from sdc resources List.\r
- *\r
+ * \r
* @param rawCldsSdcResourceList\r
+ * @return List of CldsSdcResource\r
*/\r
- public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {\r
- List<CldsSdcResource> cldsSdcResourceList = null;\r
+ public List<SdcResource> removeDuplicateSdcResourceInstances(List<SdcResource> rawCldsSdcResourceList) {\r
+ List<SdcResource> cldsSdcResourceList = null;\r
if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) {\r
// sort list\r
Collections.sort(rawCldsSdcResourceList);\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
+ SdcResource prev = rawCldsSdcResourceList.get(i - 1);\r
if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {\r
cldsSdcResourceList.add(prev);\r
}\r
\r
/**\r
* To remove duplicate basic resources with same resourceUUIDs.\r
- *\r
+ * \r
* @param rawCldsSdcResourceListBasicList\r
+ * @return List of CldsSdcResourceBasicInfo\r
*/\r
- public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
- List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
- List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
+ public List<SdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
+ List<SdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
+ List<SdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {\r
// sort list\r
Collections.sort(rawCldsSdcResourceListBasicList);\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
+ SdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);\r
if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {\r
cldsSdcResourceBasicInfoList.add(prev);\r
}\r
\r
/**\r
* To get ServiceUUID by using serviceInvariantUUID.\r
- *\r
+ * \r
* @param invariantId\r
* The invariant ID\r
* @return The service UUID\r
throws GeneralSecurityException, DecoderException {\r
String serviceUuid = "";\r
String responseStr = getSdcServicesInformation(null);\r
- List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);\r
- List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);\r
+ List<SdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);\r
+ List<SdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);\r
if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {\r
- for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
+ for (SdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null\r
&& currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {\r
serviceUuid = currCldsSdcServiceInfo.getUuid();\r
return serviceUuid;\r
}\r
\r
- private List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
- ObjectMapper objectMapper = new ObjectMapper();\r
+ /**\r
+ * To get CldsAsdsServiceInfo class by parsing json string.\r
+ * \r
+ * @param jsonStr\r
+ * The Json string that must be decoded\r
+ * @return The list of CldsSdcServiceInfo, if there is a failure it return\r
+ * an empty list\r
+ */\r
+ private List<SdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
if (StringUtils.isBlank(jsonStr)) {\r
return new ArrayList<>();\r
}\r
try {\r
- return objectMapper.readValue(jsonStr,\r
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));\r
+ return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
+ .getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
} catch (IOException e) {\r
logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);\r
return new ArrayList<>();\r
}\r
}\r
\r
- private List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
- ObjectMapper objectMapper = new ObjectMapper();\r
+ /**\r
+ * To get List of CldsSdcResourceBasicInfo class by parsing json string.\r
+ *\r
+ * @param jsonStr\r
+ * The JSOn string that must be decoded\r
+ * @return The list of CldsSdcResourceBasicInfo, an empty list in case of\r
+ * issues\r
+ */\r
+ private List<SdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
if (StringUtils.isBlank(jsonStr)) {\r
return new ArrayList<>();\r
}\r
try {\r
- return objectMapper.readValue(jsonStr,\r
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));\r
+ return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
+ .getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
} catch (IOException e) {\r
logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);\r
return new ArrayList<>();\r
\r
/**\r
* To get CldsSdcServiceDetail by parsing json string.\r
- *\r
+ * \r
* @param jsonStr\r
* @return\r
*/\r
- public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) {\r
- ObjectMapper objectMapper = new ObjectMapper();\r
+ public SdcServiceDetail decodeCldsSdcServiceDetailFromJson(String jsonStr) {\r
try {\r
- return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);\r
+ return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, SdcServiceDetail.class);\r
} catch (IOException e) {\r
logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);\r
return null;\r
}\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
}\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
+ * \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
* @throws DecoderException\r
*/\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
- *\r
+ * Get the Service Data with Alarm Conditions for a given\r
+ * invariantServiceUuid.\r
+ * \r
* @param invariantServiceUuid\r
+ * @return The CldsServiceData\r
* @throws GeneralSecurityException\r
* In case of issues with the decryting the encrypted password\r
* @throws DecoderException\r
String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);\r
String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX;\r
String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl);\r
- ObjectMapper objectMapper = new ObjectMapper();\r
CldsServiceData cldsServiceData = new CldsServiceData();\r
if (responseStr != null) {\r
- CldsSdcServiceDetail cldsSdcServiceDetail;\r
+ SdcServiceDetail cldsSdcServiceDetail;\r
try {\r
- cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);\r
+ cldsSdcServiceDetail = JacksonUtils.getObjectMapperInstance().readValue(responseStr,\r
+ SdcServiceDetail.class);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);\r
throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);\r
if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {\r
cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());\r
cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());\r
- List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
+ List<SdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
cldsSdcServiceDetail.getResources());\r
if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {\r
List<CldsVfData> cldsVfDataList = new ArrayList<>();\r
- for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {\r
+ for (SdcResource currCldsSdcResource : cldsSdcResourceList) {\r
if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null\r
&& "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {\r
CldsVfData currCldsVfData = new CldsVfData();\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
+ logger.info("Invariant Service ID of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());\r
}\r
}\r
}\r
throws GeneralSecurityException {\r
// todo : refact this..\r
if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
- List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
- RESOURCE_VF_TYPE);\r
- List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
+ List<SdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_VF_TYPE);\r
+ List<SdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
RESOURCE_VFC_TYPE);\r
allVfcResources.addAll(getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_CVFC_TYPE));\r
for (CldsVfData currCldsVfData : cldsVfDataList) {\r
}\r
}\r
\r
- private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws GeneralSecurityException {\r
- ObjectMapper mapper = new ObjectMapper();\r
+ private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) {\r
ObjectNode vfResponseNode;\r
try {\r
- vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the JSON list of CldsVfcData", e);\r
return new ArrayList<>();\r
String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX;\r
try {\r
String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl);\r
- ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+ ObjectNode vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse);\r
ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");\r
if (vfcArrayNode != null) {\r
for (JsonNode vfcjsonNode : vfcArrayNode) {\r
\r
private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws GeneralSecurityException {\r
List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
- ObjectMapper mapper = new ObjectMapper();\r
ObjectNode vfcResponseNode;\r
try {\r
- vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+ vfcResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);\r
return cldsAlarmConditionList;\r
// Method to get the artifact for any particular VF\r
private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws GeneralSecurityException {\r
List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
- ObjectMapper mapper = new ObjectMapper();\r
ObjectNode vfResponseNode;\r
try {\r
- vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);\r
return cldsVfKPIDataList;\r
cldsAlarmConditionList.add(cldsAlarmCondition);\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
String artifactsUrlReworked = artifactsUrl.replaceAll("\"", "");\r
/**\r
* 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\r
+ * The URL to trigger\r
+ * @return The String containing the payload\r
*/\r
public String getCldsServicesOrResourcesBasedOnURL(String url) {\r
Date startTime = new Date();\r
logger.error("Exception occurred during query to SDC", e);\r
return "";\r
} catch (DecoderException e) {\r
+ LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
+ LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
logger.error("Exception when attempting to decode the Hex string", e);\r
throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);\r
} catch (GeneralSecurityException e) {\r
+ LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
+ LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
logger.error("Exception when attempting to decrypt the encrypted password", e);\r
throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);\r
} finally {\r
* @param globalProps\r
* @param cldsServiceData\r
* @return\r
+ * @throws IOException\r
+ * In case of issues during the parsing of the Global Properties\r
*/\r
- public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) {\r
+ public String createPropertiesObjectByUUID(CldsServiceData cldsServiceData) throws IOException {\r
String totalPropsStr;\r
- ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode globalPropsJson;\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
+ ObjectNode globalPropsJson = (ObjectNode) refProp.getJsonTemplate(CldsService.GLOBAL_PROPERTIES_KEY);\r
if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
// Objectnode to save all byservice, byvf , byvfc and byalarm nodes\r
ObjectNode byIdObjectNode = mapper.createObjectNode();\r
// To create vf ResourceUUID node with serviceInvariantUUID\r
- ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(mapper,\r
- cldsServiceData);\r
+ ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(cldsServiceData);\r
byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVf);\r
// To create byVf and vfcResourceNode with vfResourceUUID\r
- ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs());\r
+ ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(cldsServiceData.getCldsVfs());\r
byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);\r
// To create byKpi\r
ObjectNode kpiObjectNode = mapper.createObjectNode();\r
if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
if (currCldsVfData != null) {\r
- createKpiObjectNodeByVfUuid(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());\r
+ createKpiObjectNodeByVfUuid(kpiObjectNode, currCldsVfData.getCldsKPIList());\r
}\r
}\r
}\r
if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
if (currCldsVfData != null) {\r
- createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,\r
- currCldsVfData.getCldsVfcs());\r
+ createAlarmCondObjectNodeByVfcUuid(vfcResourceUuidObjectNode, currCldsVfData.getCldsVfcs());\r
}\r
}\r
}\r
// To create byAlarmCondition with alarmConditionKey\r
List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
"alarmCondition");\r
- ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions);\r
+ ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(allAlarmConditions);\r
byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);\r
// To create byAlertDescription with AlertDescription\r
List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
"alertDescription");\r
- ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(mapper, allAlertDescriptions);\r
+ ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(allAlertDescriptions);\r
byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
- globalPropsJson = decodeGlobalProp(globalProps, mapper);\r
globalPropsJson.putPOJO("shared", byIdObjectNode);\r
- logger.info("value of objNode:" + globalPropsJson);\r
- } else {\r
- /**\r
- * to create json with total properties when no serviceUUID passed\r
- */\r
- globalPropsJson = decodeGlobalProp(globalProps, mapper);\r
+ logger.info("Global properties JSON created with SDC info:" + globalPropsJson);\r
}\r
totalPropsStr = globalPropsJson.toString();\r
return totalPropsStr;\r
}\r
\r
- private ObjectNode decodeGlobalProp(String globalProps, ObjectMapper mapper) {\r
- try {\r
- return (ObjectNode) mapper.readValue(globalProps, JsonNode.class);\r
- } catch (IOException e) {\r
- logger.error("Exception occurred during decoding of the global props, returning an empty objectNode", e);\r
- return mapper.createObjectNode();\r
- }\r
- }\r
-\r
/**\r
* Method to get alarm conditions/alert description from Service Data.\r
- *\r
+ * \r
* @param cldsServiceData\r
* CldsServiceData the Service Data to analyze\r
* @param eventName\r
\r
/**\r
* Method to get alarm conditions/alert description from VF Data.\r
- *\r
+ * \r
* @param currCldsVfData\r
* The Vf Data to analyze\r
* @param eventName\r
\r
/**\r
* Method to get alarm conditions/alert description from VFC Data.\r
- *\r
+ * \r
* @param currCldsVfcData\r
* The VfC Data to analyze\r
* @param eventName\r
return alarmCondList;\r
}\r
\r
- private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper,\r
- List<CldsAlarmCondition> cldsAlarmCondList) {\r
+ private ObjectNode createAlarmCondObjectNodeByAlarmKey(List<CldsAlarmCondition> cldsAlarmCondList) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode alarmCondKeyNode = mapper.createObjectNode();\r
if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {\r
for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {\r
return alarmCondKeyNode;\r
}\r
\r
- private ObjectNode createVfObjectNodeByServiceInvariantUuid(ObjectMapper mapper, CldsServiceData cldsServiceData) {\r
+ private ObjectNode createVfObjectNodeByServiceInvariantUuid(CldsServiceData cldsServiceData) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode invariantUuidObjectNode = mapper.createObjectNode();\r
ObjectNode vfObjectNode = mapper.createObjectNode();\r
ObjectNode vfUuidNode = mapper.createObjectNode();\r
return invariantUuidObjectNode;\r
}\r
\r
- private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode,\r
+ private void createKpiObjectNodeByVfUuid(ObjectNode vfResourceUuidObjectNode,\r
List<CldsVfKPIData> cldsVfKpiDataList) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {\r
for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {\r
if (currCldsVfKpiData != null) {\r
}\r
}\r
\r
- private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUuidObjectNode,\r
+ private void createAlarmCondObjectNodeByVfcUuid(ObjectNode vfcResourceUuidObjectNode,\r
List<CldsVfcData> cldsVfcDataList) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode vfcObjectNode = mapper.createObjectNode();\r
ObjectNode alarmCondNode = mapper.createObjectNode();\r
ObjectNode alertDescNode = mapper.createObjectNode();\r
\r
/**\r
* Method to create vfc and kpi nodes inside vf node\r
- *\r
+ * \r
* @param mapper\r
* @param cldsVfDataList\r
* @return\r
*/\r
- private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {\r
+ private ObjectNode createVfcObjectNodeByVfUuid(List<CldsVfData> cldsVfDataList) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode vfUuidObjectNode = mapper.createObjectNode();\r
if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsVfDataList) {\r
/**\r
* This method searches the equivalent artifact UUID for a specific\r
* artifactName in a SdcServiceDetail.\r
- *\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
+ public String getArtifactIdIfArtifactAlreadyExists(SdcServiceDetail 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
+ for (SdcResource 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
+ for (SdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {\r
if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null\r
&& currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
return artifactUuid;\r
}\r
\r
- private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {\r
+ // To get all sdc VF/VFC Resources basic info.\r
+ private List<SdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {\r
String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);\r
String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;\r
String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl);\r
}\r
\r
private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,\r
- List<CldsSdcResourceBasicInfo> resourceInfoList) {\r
+ List<SdcResourceBasicInfo> resourceInfoList) {\r
String resourceUuid = null;\r
if (resourceInfoList != null && !resourceInfoList.isEmpty()) {\r
- for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {\r
+ for (SdcResourceBasicInfo currResource : resourceInfoList) {\r
if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null\r
&& currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {\r
resourceUuid = currResource.getUuid();\r
return resourceUuid;\r
}\r
\r
+ // Method to get service invariant uuid from model properties.\r
private String getServiceInvariantUuidFromProps(ModelProperties props) {\r
String invariantUuid = "";\r
Global globalProps = props.getGlobal();\r
\r
/**\r
* This method upload the BluePrint to SDC.\r
- *\r
+ * \r
* @param prop\r
* The Clds model Properties\r
* @param userid\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
+ SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
artifactName);\r
// Upload artifacts to sdc\r
}\r
logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUuid);\r
sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);\r
- cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
+ cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
locationArtifactName);\r
// To send location information also to sdc\r
}\r
}\r
}\r
+\r
+ /**\r
+ * Method to delete blueprint and location json artifacts from sdc\r
+ * \r
+ * @param prop\r
+ * @param userid\r
+ * @param sdcReqUrlsList\r
+ * @param artifactName\r
+ * @param locationArtifactName\r
+ * @throws GeneralSecurityException\r
+ * @throws DecoderException\r
+ */\r
+ public void deleteArtifactsFromSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList,\r
+ String artifactName, String locationArtifactName) throws GeneralSecurityException, DecoderException {\r
+ String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);\r
+ for (String url : sdcReqUrlsList) {\r
+ String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
+ logger.info("ServiceUUID used before deleting in url:" + originalServiceUuid);\r
+ String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);\r
+ SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
+ String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, artifactName);\r
+ String responseStr = deleteArtifact(userid, url, uploadedArtifactUuid);\r
+ logger.info("value of sdc Response of deleting blueprint from 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 delete in ulr:" + updatedServiceUuid);\r
+ sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);\r
+ cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
+ uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, locationArtifactName);\r
+ responseStr = deleteArtifact(userid, url, uploadedArtifactUuid);\r
+ logger.info("value of sdc Response of deleting location json from sdc :" + responseStr);\r
+ }\r
+ }\r
+\r
+ private String deleteArtifact(String userid, String url, String uploadedArtifactUuid) {\r
+ try {\r
+ String responseStr = "";\r
+ if (uploadedArtifactUuid != null && !uploadedArtifactUuid.isEmpty()) {\r
+ logger.info("userid=" + userid);\r
+ String basicAuth = getSdcBasicAuth();\r
+ String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
+ url = url + "/" + uploadedArtifactUuid;\r
+ URL urlObj = new URL(url);\r
+ HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+ conn.setDoOutput(true);\r
+ conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId);\r
+ conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
+ conn.setRequestProperty("USER_ID", userid);\r
+ conn.setRequestMethod("DELETE");\r
+ conn.setRequestProperty("charset", "utf-8");\r
+ conn.setUseCaches(false);\r
+ conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME),\r
+ LoggingUtils.getRequestId());\r
+ boolean requestFailed = true;\r
+ int responseCode = conn.getResponseCode();\r
+ logger.info("responseCode=" + responseCode);\r
+ if (responseCode == 200) {\r
+ requestFailed = false;\r
+ }\r
+ responseStr = getResponse(conn);\r
+ if (responseStr != null && requestFailed) {\r
+ logger.error("requestFailed - responseStr=" + responseStr);\r
+ throw new BadRequestException(responseStr);\r
+ }\r
+ }\r
+ return responseStr;\r
+ } catch (IOException | DecoderException | GeneralSecurityException e) {\r
+ logger.error("Exception when attempting to communicate with SDC", e);\r
+ throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);\r
+ }\r
+ }\r
}\r