- // metrics log
- LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
- return resp;
- }
- } catch (IOException 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, e);
- } finally {
- LoggingUtils.setTimeContext(startTime, new Date());
- metricsLogger.info("getSdcServicesInformation complete");
- }
-
- return "";
- }
-
- /**
- * To remove duplicate serviceUUIDs from sdc services List.
- *
- * @param rawCldsSdcServiceList
- * A list of CldsSdcServiceInfo
- * @return A list of CldsSdcServiceInfo without duplicate service UUID
- */
- public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {
- List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;
- if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {
- // 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.isEmpty()) {
- // 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.isEmpty()) {
- // 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
- * The invariant ID
- * @return The service UUID
- */
- public String getServiceUuidFromServiceInvariantId(String invariantId) {
- String serviceUuid = "";
- String responseStr = getSdcServicesInformation(null);
- List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);
- List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);
- if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {
- 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
- * The Json string that must be decoded
- * @return The list of CldsSdcServiceInfo, if there is a failure it return
- * an empty list
- */
- public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {
- ObjectMapper objectMapper = new ObjectMapper();
- if (StringUtils.isBlank(jsonStr)) {
- return new ArrayList<>();
- }
- try {
- return objectMapper.readValue(jsonStr,
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));
- } catch (IOException e) {
- logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);
- return new ArrayList<>();
- }
- }
-
- /**
- * To get List of CldsSdcResourceBasicInfo class by parsing json string.
- *
- * @param jsonStr
- * The JSOn string that must be decoded
- * @return The list of CldsSdcResourceBasicInfo, an empty list in case of
- * issues
- */
- public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {
- ObjectMapper objectMapper = new ObjectMapper();
- if (StringUtils.isBlank(jsonStr)) {
- return new ArrayList<>();
- }
-
- try {
- return objectMapper.readValue(jsonStr,
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));
- } catch (IOException e) {
- logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);
- return new ArrayList<>();
- }
- }
-
- /**
- * To get CldsAsdsResource class by parsing json string.
- *
- * @param jsonStr
- * @return
- * @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
- */
- public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) {
- ObjectMapper objectMapper = new ObjectMapper();
- try {
- return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);
- } catch (IOException e) {
- logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);
- return null;
- }
- }
-
- /**
- * To upload artifact to sdc based on serviceUUID and resource name on url.
- *
- * @param prop
- * @param userid
- * @param url
- * @param formatedSdcReq
- * @return
- */
- public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatedSdcReq) {
- // Verify whether it is triggered by Validation Test button from UI
- if (prop.isTest()) {
- return "sdc artifact upload not executed for test action";
- }
- try {
- logger.info("userid=" + userid);
- String md5Text = SdcReq.calculateMD5ByString(formatedSdcReq);
- byte[] postData = SdcReq.stringToByteArray(formatedSdcReq);
- 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 && requestFailed) {
- logger.error("requestFailed - responseStr=" + responseStr);
- throw new BadRequestException(responseStr);
- }
- return responseStr;
- } catch (IOException e) {
- logger.error("Exception when attempting to communicate with SDC", e);
- throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);
- }
-
- }
-
- private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text) {
- try {
- 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);
- conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());
- return conn;
- } catch (IOException e) {
- logger.error("Exception when attempting to open connection with SDC", e);
- throw new SdcCommunicationException("Exception when attempting to open connection with SDC", e);
- }
- }
-
- private String getResponse(HttpURLConnection conn) {
- try (InputStream is = getInputStream(conn)) {
- if (is != null) {
- try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
- StringBuilder response = new StringBuilder();
- String inputLine;
- while ((inputLine = in.readLine()) != null) {
- response.append(inputLine);
- }
- return response.toString();
- }
- } else {
- return null;
- }
- } catch (IOException e) {
- logger.error("Exception when attempting to open SDC response", e);
- throw new SdcCommunicationException("Exception when attempting to open SDC response", e);
- }
- }
-
- private InputStream getInputStream(HttpURLConnection conn) {
- try {
- InputStream inStream = conn.getErrorStream();
- if (inStream == null) {
- inStream = conn.getInputStream();
- }
- return inStream;
- } catch (IOException e) {
- logger.error("Exception when attempting to open SDC error stream", e);
- throw new SdcCommunicationException("Exception when attempting to open SDC error stream", e);
- }
- }
-
- 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);
- }
- }
-
- public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) {
- 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) {
- 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;
- try {
- cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.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);
- }
- 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.isEmpty()) {
- List<CldsVfData> cldsVfDataList = new ArrayList<>();
- for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {
- if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null
- && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {
- 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;
- }
-
- private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) {
- // todo : refact this..
- if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {
- 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.isEmpty()) {
- // 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) {
- ObjectMapper mapper = new ObjectMapper();
- ObjectNode vfResponseNode;
- try {
- vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
- } catch (IOException e) {
- logger.error("Exception when decoding the JSON list of CldsVfcData", e);
- return new ArrayList<>();
- }
- ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
- List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
- if (vfcArrayNode != null) {
- for (JsonNode vfcjsonNode : vfcArrayNode) {
- CldsVfcData currCldsVfcData = new CldsVfcData();
- ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;
- TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");
- if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
- TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");
- TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID");
- currCldsVfcData.setVfcName(vfcResourceName.textValue());
- currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue());
- cldsVfcDataList.add(currCldsVfcData);
- } else if (resourceTypeNode != null && "CVFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
- cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue()));
- }
- }
- }
- return cldsVfcDataList;
- }
-
- private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {
- String catalogUrl = refProp.getStringValue("sdc.catalog.url");
- List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
-
- if (resourceUUID != null) {
- String vfcResourceUUIDUrl = catalogUrl + "resources" + "/" + resourceUUID + "/metadata";
- try {
- String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl, false);
- ObjectMapper mapper = new ObjectMapper();
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
- ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
-
- if (vfcArrayNode != null) {
- for (JsonNode vfcjsonNode : vfcArrayNode) {
- CldsVfcData currCldsVfcData = new CldsVfcData();
- ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;
- TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");
- if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
- TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");
- TextNode vfcInvariantResourceUUID = (TextNode) currVfcNode.get("resourceInvariantUUID");
- currCldsVfcData.setVfcName(vfcResourceName.textValue());
- currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUUID.textValue());
- cldsVfcDataList.add(currCldsVfcData);
- }
- }
- }
- } catch (IOException e) {
- logger.error("Exception during JSON analyzis", e);
- }
- }
- return cldsVfcDataList;
- }
-
- private String removeUnwantedBracesFromString(String id) {
- return (id != null) ? id.replaceAll("\"", "") : "";
- }
-
- private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) {
- List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
- ObjectMapper mapper = new ObjectMapper();
- ObjectNode vfcResponseNode;
- try {
- vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
- } catch (IOException e) {
- logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);
- return cldsAlarmConditionList;
- }
- 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) {
- try {
- 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;
- } catch (IOException e) {
- logger.error("Exception when attempting to parse the CSV containing the alarm", e);
- return new ArrayList<>();
- }
- }
-
- // Method to get the artifact for any particular VF
- private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) {
- List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
- ObjectMapper mapper = new ObjectMapper();
- ObjectNode vfResponseNode;
- try {
- vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
- } catch (IOException e) {
- logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);
- return cldsVfKPIDataList;
- }
- 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);
- }
+ // 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.isEmpty()) {\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.isEmpty()) {\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.isEmpty()) {\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
+ */\r
+ public String getServiceUuidFromServiceInvariantId(String invariantId) {\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.isEmpty()) {\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
+ * 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
+ public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
+ ObjectMapper objectMapper = new ObjectMapper();\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
+ } catch (IOException e) {\r
+ logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);\r
+ return new ArrayList<>();\r
+ }\r
+ }\r
+\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
+ public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
+ ObjectMapper objectMapper = new ObjectMapper();\r
+ if (StringUtils.isBlank(jsonStr)) {\r
+ return new ArrayList<>();\r
+ }\r
+\r
+ try {\r
+ return objectMapper.readValue(jsonStr,\r
+ objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.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
+\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
+ */\r
+ public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) {\r
+ ObjectMapper objectMapper = new ObjectMapper();\r
+ try {\r
+ return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.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
+ * To upload artifact to sdc based on serviceUUID and resource name on url.\r
+ *\r
+ * @param prop\r
+ * @param userid\r
+ * @param url\r
+ * @param formattedSdcReq\r
+ * @return\r
+ */\r
+ public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formattedSdcReq) {
+ // 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
+ try {\r
+ logger.info("userid=" + userid);\r
+ String md5Text = SdcReq.calculateMD5ByString(formattedSdcReq);\r
+ byte[] postData = SdcReq.stringToByteArray(formattedSdcReq);\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 && requestFailed) {\r
+ logger.error("requestFailed - responseStr=" + responseStr);\r
+ throw new BadRequestException(responseStr);\r
+ }\r
+ return responseStr;\r
+ } catch (IOException 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
+\r
+ private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text) {\r
+ try {\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
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to open connection with SDC", e);\r
+ throw new SdcCommunicationException("Exception when attempting to open connection with SDC", e);\r
+ }\r
+ }\r
+\r
+ private String getResponse(HttpURLConnection conn) {\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
+ } else {\r
+ return null;\r
+ }\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to open SDC response", e);\r
+ throw new SdcCommunicationException("Exception when attempting to open SDC response", e);\r
+ }\r
+ }\r
+\r
+ private InputStream getInputStream(HttpURLConnection conn) {\r
+ try {\r
+ InputStream inStream = conn.getErrorStream();\r
+ if (inStream == null) {\r
+ inStream = conn.getInputStream();\r
+ }\r
+ return inStream;\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to open SDC error stream", e);\r
+ throw new SdcCommunicationException("Exception when attempting to open SDC error stream", e);\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
+ public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) {\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) {\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;\r
+ try {\r
+ cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.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
+ }\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.isEmpty()) {\r
+ List<CldsVfData> cldsVfDataList = new ArrayList<>();\r
+ for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {\r
+ if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null\r
+ && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {\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
+ private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) {\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
+ 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.isEmpty()) {\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) {\r
+ ObjectMapper mapper = new ObjectMapper();\r
+ ObjectNode vfResponseNode;\r
+ try {\r
+ vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ } catch (IOException e) {\r
+ logger.error("Exception when decoding the JSON list of CldsVfcData", e);\r
+ return new ArrayList<>();\r
+ }\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<>();\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
+ return (id != null) ? id.replaceAll("\"", "") : "";\r
+ }\r
+\r
+ private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) {\r
+ List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
+ ObjectMapper mapper = new ObjectMapper();\r
+ ObjectNode vfcResponseNode;\r
+ try {\r
+ vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+ } catch (IOException e) {\r
+ logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);\r
+ return cldsAlarmConditionList;\r
+ }\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) {\r
+ try {\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
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to parse the CSV containing the alarm", e);\r
+ return new ArrayList<>();\r
+ }\r
+ }\r
+\r
+ // Method to get the artifact for any particular VF\r
+ private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) {\r
+ List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
+ ObjectMapper mapper = new ObjectMapper();\r
+ ObjectNode vfResponseNode;\r
+ try {\r
+ vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ } catch (IOException e) {\r
+ logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);\r
+ return cldsVfKPIDataList;\r
+ }\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