X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fclient%2Freq%2Fsdc%2FSdcCatalogServices.java;h=e3bd17852e643f4574c15d15142cf8a0478658dd;hb=8205bcbd6d83f1f7f910dbe01bf0d95dff62b76e;hp=6684f1a1eae2faba1ee068b533bc993512357a5b;hpb=d2cb8a156597c082e50953a255a58fcb868ab1e0;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java index 6684f1a1..e3bd1785 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java +++ b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.clamp.clds.client.req.sdc; @@ -58,41 +58,44 @@ import org.apache.commons.csv.CSVRecord; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpHeaders; -import org.onap.clamp.clds.exception.SdcCommunicationException; +import org.onap.clamp.clds.config.ClampProperties; +import org.onap.clamp.clds.exception.sdc.SdcCommunicationException; 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.Global; -import org.onap.clamp.clds.model.prop.ModelProperties; -import org.onap.clamp.clds.model.refprop.RefProp; +import org.onap.clamp.clds.model.properties.Global; +import org.onap.clamp.clds.model.properties.ModelProperties; +import org.onap.clamp.clds.model.sdc.SdcArtifact; +import org.onap.clamp.clds.model.sdc.SdcResource; +import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo; +import org.onap.clamp.clds.model.sdc.SdcServiceDetail; +import org.onap.clamp.clds.model.sdc.SdcServiceInfo; +import org.onap.clamp.clds.service.CldsService; import org.onap.clamp.clds.util.CryptoUtils; +import org.onap.clamp.clds.util.JacksonUtils; import org.onap.clamp.clds.util.LoggingUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +@Component public class SdcCatalogServices { private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class); private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); - private static final String RESOURCE_VF_TYPE = "VF"; - private static final String RESOURCE_VFC_TYPE = "VFC"; - private static final String RESOURCE_CVFC_TYPE = "CVFC"; + private static final String RESOURCE_VF_TYPE = "VF"; + private static final String RESOURCE_VFC_TYPE = "VFC"; + private static final String RESOURCE_CVFC_TYPE = "CVFC"; private static final String SDC_REQUESTID_PROPERTY_NAME = "sdc.header.requestId"; - private static final String SDC_METADATA_URL_PREFIX = "/metadata"; - private static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID"; - private static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url"; - private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl"; - private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool"; - private static final String RESOURCE_URL_PREFIX = "resources"; + private static final String SDC_METADATA_URL_PREFIX = "/metadata"; + private static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID"; + private static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url"; + private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl"; + private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool"; + private static final String RESOURCE_URL_PREFIX = "resources"; @Autowired - private RefProp refProp; + private ClampProperties refProp; /** * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic @@ -131,7 +134,7 @@ public class SdcCatalogServices { LoggingUtils.setTargetContext("SDC", "getSdcServicesInformation"); try { String url = baseUrl; - if (uuid != null) { + if (uuid != null && !uuid.isEmpty()) { url = baseUrl + "/" + uuid + SDC_METADATA_URL_PREFIX; } URL urlObj = new URL(url); @@ -142,7 +145,7 @@ public class SdcCatalogServices { conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId()); conn.setRequestMethod("GET"); String resp = getResponse(conn); - logger.info(resp); + logger.debug("Services list received from SDC:" + resp); // metrics log LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName()); return resp; @@ -164,8 +167,8 @@ public class SdcCatalogServices { * A list of CldsSdcServiceInfo * @return A list of CldsSdcServiceInfo without duplicate service UUID */ - public List removeDuplicateServices(List rawCldsSdcServiceList) { - List cldsSdcServiceInfoList = null; + public List removeDuplicateServices(List rawCldsSdcServiceList) { + List cldsSdcServiceInfoList = null; if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) { // sort list Collections.sort(rawCldsSdcServiceList); @@ -175,7 +178,7 @@ public class SdcCatalogServices { 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); + SdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1); if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) { cldsSdcServiceInfoList.add(prev); } @@ -192,8 +195,8 @@ public class SdcCatalogServices { * @param rawCldsSdcResourceList * @return List of CldsSdcResource */ - public List removeDuplicateSdcResourceInstances(List rawCldsSdcResourceList) { - List cldsSdcResourceList = null; + public List removeDuplicateSdcResourceInstances(List rawCldsSdcResourceList) { + List cldsSdcResourceList = null; if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) { // sort list Collections.sort(rawCldsSdcResourceList); @@ -203,7 +206,7 @@ public class SdcCatalogServices { 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); + SdcResource prev = rawCldsSdcResourceList.get(i - 1); if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) { cldsSdcResourceList.add(prev); } @@ -220,9 +223,9 @@ public class SdcCatalogServices { * @param rawCldsSdcResourceListBasicList * @return List of CldsSdcResourceBasicInfo */ - public List removeDuplicateSdcResourceBasicInfo( - List rawCldsSdcResourceListBasicList) { - List cldsSdcResourceBasicInfoList = null; + public List removeDuplicateSdcResourceBasicInfo( + List rawCldsSdcResourceListBasicList) { + List cldsSdcResourceBasicInfoList = null; if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) { // sort list Collections.sort(rawCldsSdcResourceListBasicList); @@ -232,7 +235,7 @@ public class SdcCatalogServices { 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); + SdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1); if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) { cldsSdcResourceBasicInfoList.add(prev); } @@ -259,10 +262,10 @@ public class SdcCatalogServices { throws GeneralSecurityException, DecoderException { String serviceUuid = ""; String responseStr = getSdcServicesInformation(null); - List rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr); - List cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList); + List rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr); + List cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList); if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) { - for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) { + for (SdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) { if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) { serviceUuid = currCldsSdcServiceInfo.getUuid(); @@ -281,14 +284,13 @@ public class SdcCatalogServices { * @return The list of CldsSdcServiceInfo, if there is a failure it return * an empty list */ - private List getCldsSdcServicesListFromJson(String jsonStr) { - ObjectMapper objectMapper = new ObjectMapper(); + private List getCldsSdcServicesListFromJson(String jsonStr) { if (StringUtils.isBlank(jsonStr)) { return new ArrayList<>(); } try { - return objectMapper.readValue(jsonStr, - objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class)); + return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance() + .getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class)); } catch (IOException e) { logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e); return new ArrayList<>(); @@ -303,14 +305,13 @@ public class SdcCatalogServices { * @return The list of CldsSdcResourceBasicInfo, an empty list in case of * issues */ - private List getAllSdcResourcesListFromJson(String jsonStr) { - ObjectMapper objectMapper = new ObjectMapper(); + private List getAllSdcResourcesListFromJson(String jsonStr) { if (StringUtils.isBlank(jsonStr)) { return new ArrayList<>(); } try { - return objectMapper.readValue(jsonStr, - objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class)); + return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance() + .getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class)); } catch (IOException e) { logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e); return new ArrayList<>(); @@ -323,17 +324,15 @@ public class SdcCatalogServices { * @param jsonStr * @return */ - public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) { - ObjectMapper objectMapper = new ObjectMapper(); + public SdcServiceDetail decodeCldsSdcServiceDetailFromJson(String jsonStr) { try { - return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class); + return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, SdcServiceDetail.class); } catch (IOException e) { logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e); return null; } } - // upload artifact to sdc based on serviceUUID and resource name on url private String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formattedSdcReq) { // Verify whether it is triggered by Validation Test button from UI @@ -422,23 +421,11 @@ public class SdcCatalogServices { } } - public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData) { - try { - CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache(); - cldsDbServiceCache.setCldsDataInstream(cldsServiceData); - cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID()); - cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID()); - return cldsDbServiceCache; - } catch (IOException e) { - logger.error("Exception when getting service in cache", e); - throw new SdcCommunicationException("Exception when getting service in cache", e); - } - } - /** * Check if the SDC Info in cache has expired. * * @param cldsServiceData + * The object representing the service data * @return boolean flag * @throws GeneralSecurityException * In case of issues with the decryting the encrypted password @@ -447,23 +434,25 @@ public class SdcCatalogServices { */ public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) throws GeneralSecurityException, DecoderException { - 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; + String configuredMaxAge = refProp.getStringValue("clds.service.cache.invalidate.after.seconds"); + if (configuredMaxAge == null) { + logger.warn( + "clds.service.cache.invalidate.after.seconds NOT set in clds-reference.properties file, taking 60s as default"); + configuredMaxAge = "60"; } + return (!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null + && cldsServiceData.getAgeOfRecord() > Long.parseLong(configuredMaxAge)); } else { - expired = true; + return true; } - return expired; } /** - * Get the Service Data with Alarm Conditions for a given invariantServiceUuid. + * Get the Service Data with Alarm Conditions for a given + * invariantServiceUuid. * * @param invariantServiceUuid * @return The CldsServiceData @@ -479,12 +468,12 @@ public class SdcCatalogServices { String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid); String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX; String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl); - ObjectMapper objectMapper = new ObjectMapper(); CldsServiceData cldsServiceData = new CldsServiceData(); if (responseStr != null) { - CldsSdcServiceDetail cldsSdcServiceDetail; + SdcServiceDetail cldsSdcServiceDetail; try { - cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class); + cldsSdcServiceDetail = JacksonUtils.getObjectMapperInstance().readValue(responseStr, + SdcServiceDetail.class); } catch (IOException e) { logger.error("Exception when decoding the CldsServiceData JSON from SDC", e); throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e); @@ -494,11 +483,11 @@ public class SdcCatalogServices { if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) { cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid()); cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID()); - List cldsSdcResourceList = removeDuplicateSdcResourceInstances( + List cldsSdcResourceList = removeDuplicateSdcResourceInstances( cldsSdcServiceDetail.getResources()); if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) { List cldsVfDataList = new ArrayList<>(); - for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) { + for (SdcResource currCldsSdcResource : cldsSdcResourceList) { if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) { CldsVfData currCldsVfData = new CldsVfData(); @@ -510,8 +499,7 @@ public class SdcCatalogServices { 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()); + logger.info("Invariant Service ID of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID()); } } } @@ -522,9 +510,8 @@ public class SdcCatalogServices { throws GeneralSecurityException { // todo : refact this.. if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) { - List allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType( - RESOURCE_VF_TYPE); - List allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType( + List allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_VF_TYPE); + List allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType( RESOURCE_VFC_TYPE); allVfcResources.addAll(getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_CVFC_TYPE)); for (CldsVfData currCldsVfData : cldsVfDataList) { @@ -579,11 +566,10 @@ public class SdcCatalogServices { } } - private List getVfcDataListFromVfResponse(String vfResponse) throws GeneralSecurityException { - ObjectMapper mapper = new ObjectMapper(); + private List getVfcDataListFromVfResponse(String vfResponse) { ObjectNode vfResponseNode; try { - vfResponseNode = (ObjectNode) mapper.readTree(vfResponse); + vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse); } catch (IOException e) { logger.error("Exception when decoding the JSON list of CldsVfcData", e); return new ArrayList<>(); @@ -606,17 +592,17 @@ public class SdcCatalogServices { private void handleVFCtypeNode(ObjectNode currVfcNode, List cldsVfcDataList) { CldsVfcData currCldsVfcData = new CldsVfcData(); - TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName"); - TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID"); - currCldsVfcData.setVfcName(vfcResourceName.textValue()); - currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue()); - cldsVfcDataList.add(currCldsVfcData); + TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName"); + TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID"); + currCldsVfcData.setVfcName(vfcResourceName.textValue()); + currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue()); + cldsVfcDataList.add(currCldsVfcData); } private void handleCVFCtypeNode(ObjectNode currVfcNode, List cldsVfcDataList) { handleVFCtypeNode(currVfcNode, cldsVfcDataList); - cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue())); - } + cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue())); + } private List getVFCfromCVFC(String resourceUUID) { String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME); @@ -625,8 +611,7 @@ public class SdcCatalogServices { String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX; try { String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl); - ObjectMapper mapper = new ObjectMapper(); - ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfcResponse); + ObjectNode vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse); ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources"); if (vfcArrayNode != null) { for (JsonNode vfcjsonNode : vfcArrayNode) { @@ -650,10 +635,9 @@ public class SdcCatalogServices { private List getAlarmCondtionsFromVfc(String vfcResponse) throws GeneralSecurityException { List cldsAlarmConditionList = new ArrayList<>(); - ObjectMapper mapper = new ObjectMapper(); ObjectNode vfcResponseNode; try { - vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse); + vfcResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse); } catch (IOException e) { logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e); return cldsAlarmConditionList; @@ -695,10 +679,9 @@ public class SdcCatalogServices { // Method to get the artifact for any particular VF private List getFieldPathFromVF(String vfResponse) throws GeneralSecurityException { List cldsVfKPIDataList = new ArrayList<>(); - ObjectMapper mapper = new ObjectMapper(); ObjectNode vfResponseNode; try { - vfResponseNode = (ObjectNode) mapper.readTree(vfResponse); + vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse); } catch (IOException e) { logger.error("Exception when decoding the JSON list of CldsVfKPIData", e); return cldsVfKPIDataList; @@ -786,7 +769,6 @@ public class SdcCatalogServices { cldsAlarmConditionList.add(cldsAlarmCondition); } - // Get the responses for the current artifact from the artifacts URL. private String getResponsesFromArtifactUrl(String artifactsUrl) { String hostUrl = refProp.getStringValue("sdc.hostUrl"); @@ -802,9 +784,9 @@ public class SdcCatalogServices { * Service to services/resources/artifacts from sdc.Pass alarmConditions as * true to get alarm conditons from artifact url and else it is false * - * @param url The URL to trigger + * @param url + * The URL to trigger * @return The String containing the payload - * */ public String getCldsServicesOrResourcesBasedOnURL(String url) { Date startTime = new Date(); @@ -832,12 +814,12 @@ public class SdcCatalogServices { logger.error("Exception occurred during query to SDC", e); return ""; } catch (DecoderException e) { - LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName()); + LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName()); LoggingUtils.setErrorContext("900", "Get sdc resources error"); logger.error("Exception when attempting to decode the Hex string", e); throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e); } catch (GeneralSecurityException e) { - LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName()); + LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName()); LoggingUtils.setErrorContext("900", "Get sdc resources error"); logger.error("Exception when attempting to decrypt the encrypted password", e); throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e); @@ -853,27 +835,28 @@ public class SdcCatalogServices { * @param globalProps * @param cldsServiceData * @return + * @throws IOException + * In case of issues during the parsing of the Global Properties */ - public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) { + public String createPropertiesObjectByUUID(CldsServiceData cldsServiceData) throws IOException { String totalPropsStr; - ObjectMapper mapper = new ObjectMapper(); - ObjectNode globalPropsJson; + ObjectMapper mapper = JacksonUtils.getObjectMapperInstance(); + ObjectNode globalPropsJson = (ObjectNode) refProp.getJsonTemplate(CldsService.GLOBAL_PROPERTIES_KEY); 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); + ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(cldsServiceData); byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVf); // To create byVf and vfcResourceNode with vfResourceUUID - ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs()); + ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(cldsServiceData.getCldsVfs()); byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid); // To create byKpi ObjectNode kpiObjectNode = mapper.createObjectNode(); if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) { for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) { if (currCldsVfData != null) { - createKpiObjectNodeByVfUuid(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList()); + createKpiObjectNodeByVfUuid(kpiObjectNode, currCldsVfData.getCldsKPIList()); } } } @@ -883,8 +866,7 @@ public class SdcCatalogServices { if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) { for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) { if (currCldsVfData != null) { - createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode, - currCldsVfData.getCldsVfcs()); + createAlarmCondObjectNodeByVfcUuid(vfcResourceUuidObjectNode, currCldsVfData.getCldsVfcs()); } } } @@ -892,35 +874,20 @@ public class SdcCatalogServices { // To create byAlarmCondition with alarmConditionKey List allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData, "alarmCondition"); - ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions); + ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(allAlarmConditions); byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey); // To create byAlertDescription with AlertDescription List allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData, "alertDescription"); - ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(mapper, allAlertDescriptions); + ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(allAlertDescriptions); byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert); - globalPropsJson = decodeGlobalProp(globalProps, mapper); globalPropsJson.putPOJO("shared", byIdObjectNode); - logger.info("value of objNode:" + globalPropsJson); - } else { - /** - * to create json with total properties when no serviceUUID passed - */ - globalPropsJson = decodeGlobalProp(globalProps, mapper); + logger.info("Global properties JSON created with SDC info:" + globalPropsJson); } totalPropsStr = globalPropsJson.toString(); return totalPropsStr; } - private ObjectNode decodeGlobalProp(String globalProps, ObjectMapper mapper) { - try { - return (ObjectNode) mapper.readValue(globalProps, JsonNode.class); - } catch (IOException e) { - logger.error("Exception occurred during decoding of the global props, returning an empty objectNode", e); - return mapper.createObjectNode(); - } - } - /** * Method to get alarm conditions/alert description from Service Data. * @@ -988,8 +955,8 @@ public class SdcCatalogServices { return alarmCondList; } - private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper, - List cldsAlarmCondList) { + private ObjectNode createAlarmCondObjectNodeByAlarmKey(List cldsAlarmCondList) { + ObjectMapper mapper = JacksonUtils.getObjectMapperInstance(); ObjectNode alarmCondKeyNode = mapper.createObjectNode(); if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) { for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) { @@ -1009,7 +976,8 @@ public class SdcCatalogServices { return alarmCondKeyNode; } - private ObjectNode createVfObjectNodeByServiceInvariantUuid(ObjectMapper mapper, CldsServiceData cldsServiceData) { + private ObjectNode createVfObjectNodeByServiceInvariantUuid(CldsServiceData cldsServiceData) { + ObjectMapper mapper = JacksonUtils.getObjectMapperInstance(); ObjectNode invariantUuidObjectNode = mapper.createObjectNode(); ObjectNode vfObjectNode = mapper.createObjectNode(); ObjectNode vfUuidNode = mapper.createObjectNode(); @@ -1028,8 +996,9 @@ public class SdcCatalogServices { return invariantUuidObjectNode; } - private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode, + private void createKpiObjectNodeByVfUuid(ObjectNode vfResourceUuidObjectNode, List cldsVfKpiDataList) { + ObjectMapper mapper = JacksonUtils.getObjectMapperInstance(); if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) { for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) { if (currCldsVfKpiData != null) { @@ -1047,8 +1016,9 @@ public class SdcCatalogServices { } } - private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUuidObjectNode, + private void createAlarmCondObjectNodeByVfcUuid(ObjectNode vfcResourceUuidObjectNode, List cldsVfcDataList) { + ObjectMapper mapper = JacksonUtils.getObjectMapperInstance(); ObjectNode vfcObjectNode = mapper.createObjectNode(); ObjectNode alarmCondNode = mapper.createObjectNode(); ObjectNode alertDescNode = mapper.createObjectNode(); @@ -1088,7 +1058,8 @@ public class SdcCatalogServices { * @param cldsVfDataList * @return */ - private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List cldsVfDataList) { + private ObjectNode createVfcObjectNodeByVfUuid(List cldsVfDataList) { + ObjectMapper mapper = JacksonUtils.getObjectMapperInstance(); ObjectNode vfUuidObjectNode = mapper.createObjectNode(); if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) { for (CldsVfData currCldsVfData : cldsVfDataList) { @@ -1140,18 +1111,18 @@ public class SdcCatalogServices { * The artifact name that will be searched * @return The artifact UUID found */ - public String getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail cldsSdcServiceDetail, String artifactName) { + public String getArtifactIdIfArtifactAlreadyExists(SdcServiceDetail cldsSdcServiceDetail, String artifactName) { String artifactUuid = null; boolean artifactExists = false; if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null && !cldsSdcServiceDetail.getResources().isEmpty()) { - for (CldsSdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) { + for (SdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) { if (artifactExists) { break; } if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null && !currCldsSdcResource.getArtifacts().isEmpty()) { - for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) { + for (SdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) { if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) { artifactUuid = currCldsSdcArtifact.getArtifactUUID(); @@ -1166,7 +1137,7 @@ public class SdcCatalogServices { } // To get all sdc VF/VFC Resources basic info. - private List getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) { + private List getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) { String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME); String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType; String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl); @@ -1174,10 +1145,10 @@ public class SdcCatalogServices { } private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid, - List resourceInfoList) { + List resourceInfoList) { String resourceUuid = null; if (resourceInfoList != null && !resourceInfoList.isEmpty()) { - for (CldsSdcResourceBasicInfo currResource : resourceInfoList) { + for (SdcResourceBasicInfo currResource : resourceInfoList) { if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) { resourceUuid = currResource.getUuid(); @@ -1232,7 +1203,7 @@ public class SdcCatalogServices { String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid); logger.info("ServiceUUID used before upload in url:" + originalServiceUuid); String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid); - CldsSdcServiceDetail cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation); + SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation); String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, artifactName); // Upload artifacts to sdc @@ -1245,7 +1216,7 @@ public class SdcCatalogServices { } logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUuid); sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid); - cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation); + cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation); uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, locationArtifactName); // To send location information also to sdc