\r
import com.att.eelf.configuration.EELFLogger;\r
import com.att.eelf.configuration.EELFManager;\r
-import com.fasterxml.jackson.core.JsonProcessingException;\r
import com.fasterxml.jackson.databind.JsonNode;\r
import com.fasterxml.jackson.databind.ObjectMapper;\r
import com.fasterxml.jackson.databind.node.ArrayNode;\r
import org.apache.commons.csv.CSVRecord;\r
import org.apache.commons.lang3.StringUtils;\r
import org.onap.clamp.clds.client.req.SdcReq;\r
+import org.onap.clamp.clds.exception.SdcCommunicationException;\r
import org.onap.clamp.clds.model.CldsAlarmCondition;\r
import org.onap.clamp.clds.model.CldsDBServiceCache;\r
import org.onap.clamp.clds.model.CldsSdcArtifact;\r
*/\r
public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {\r
List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;\r
- if (rawCldsSdcServiceList != null && rawCldsSdcServiceList.size() > 0) {\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
*/\r
public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {\r
List<CldsSdcResource> cldsSdcResourceList = null;\r
- if (rawCldsSdcResourceList != null && rawCldsSdcResourceList.size() > 0) {\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
public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
- if (rawCldsSdcResourceListBasicList != null && rawCldsSdcResourceListBasicList.size() > 0) {\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
* @param invariantId\r
* The invariant ID\r
* @return The service UUID\r
- * @throws IOException\r
- * In case of issues with the JSON decoder\r
*/\r
- public String getServiceUuidFromServiceInvariantId(String invariantId) throws IOException {\r
+ 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.size() > 0) {\r
+ if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {\r
for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null\r
&& currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {\r
* To get CldsAsdsServiceInfo class by parsing json string.\r
*\r
* @param jsonStr\r
- * @return\r
- * @throws IOException\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) throws IOException {\r
+ public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
ObjectMapper objectMapper = new ObjectMapper();\r
if (StringUtils.isBlank(jsonStr)) {\r
- return null;\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
- return objectMapper.readValue(jsonStr,\r
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));\r
}\r
\r
/**\r
* To get List of CldsSdcResourceBasicInfo class by parsing json string.\r
*\r
* @param jsonStr\r
- * @return\r
- * @throws IOException\r
+ * 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) throws IOException {\r
+ public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
ObjectMapper objectMapper = new ObjectMapper();\r
if (StringUtils.isBlank(jsonStr)) {\r
- return null;\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
- return objectMapper.readValue(jsonStr,\r
- objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));\r
}\r
\r
/**\r
*\r
* @param jsonStr\r
* @return\r
- * @throws IOException\r
*/\r
- public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) throws IOException {\r
+ public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) {\r
ObjectMapper objectMapper = new ObjectMapper();\r
- return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);\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 resourcename on url.\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 formatttedSdcReq\r
+ * @param formattedSdcReq\r
* @return\r
- * @throws IOException\r
*/\r
- public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq)\r
- throws IOException {\r
+ public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq) {\r
// Verify whether it is triggered by Validation Test button from UI\r
if (prop.isTest()) {\r
return "sdc artifact upload not executed for test action";\r
}\r
- logger.info("userid=" + userid);\r
- String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq);\r
- byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);\r
- int postDataLength = postData.length;\r
- HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);\r
- try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
- wr.write(postData);\r
- }\r
- boolean requestFailed = true;\r
- int responseCode = conn.getResponseCode();\r
- logger.info("responseCode=" + responseCode);\r
- if (responseCode == 200) {\r
- requestFailed = false;\r
- }\r
+ try {\r
+ logger.info("userid=" + userid);\r
+ String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq);\r
+ byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);\r
+ int postDataLength = postData.length;\r
+ HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);\r
+ try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
+ wr.write(postData);\r
+ }\r
+ boolean requestFailed = true;\r
+ int responseCode = conn.getResponseCode();\r
+ logger.info("responseCode=" + responseCode);\r
+ if (responseCode == 200) {\r
+ requestFailed = false;\r
+ }\r
\r
- String responseStr = getResponse(conn);\r
- if (responseStr != null) {\r
- if (requestFailed) {\r
+ 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
- return responseStr;\r
+\r
}\r
\r
- private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text)\r
- throws IOException {\r
- logger.info("userid=" + userid);\r
- String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
- String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
- URL urlObj = new URL(url);\r
- HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
- conn.setDoOutput(true);\r
- conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);\r
- conn.setRequestProperty("Authorization", basicAuth);\r
- conn.setRequestProperty("Content-Type", "application/json");\r
- conn.setRequestProperty("Content-MD5", md5Text);\r
- conn.setRequestProperty("USER_ID", userid);\r
- conn.setRequestMethod("POST");\r
- conn.setRequestProperty("charset", "utf-8");\r
- conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));\r
- conn.setUseCaches(false);\r
- conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());\r
- return conn;\r
+ 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) throws IOException {\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
}\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
- return null;\r
}\r
\r
- private InputStream getInputStream(HttpURLConnection conn) throws IOException {\r
- InputStream inStream = conn.getErrorStream();\r
- if (inStream == null) {\r
- inStream = conn.getInputStream();\r
+ 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
- return inStream;\r
}\r
\r
- public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData)\r
- throws IOException {\r
- CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();\r
- cldsDbServiceCache.setCldsDataInstream(cldsServiceData);\r
- cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());\r
- cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());\r
- return cldsDbServiceCache;\r
+ 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) throws IOException {\r
+ public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) {\r
boolean expired = false;\r
if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
String cachedServiceUuid = cldsServiceData.getServiceUUID();\r
return expired;\r
}\r
\r
- public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) throws IOException {\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
ObjectMapper objectMapper = new ObjectMapper();\r
CldsServiceData cldsServiceData = new CldsServiceData();\r
if (responseStr != null) {\r
- CldsSdcServiceDetail cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);\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
if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {\r
List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
cldsSdcServiceDetail.getResources());\r
- if (cldsSdcResourceList != null && cldsSdcResourceList.size() > 0) {\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
- && currCldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) {\r
+ && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {\r
CldsVfData currCldsVfData = new CldsVfData();\r
currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());\r
currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());\r
return cldsServiceData;\r
}\r
\r
- /**\r
- * @param cldsVfDataList\r
- * @throws IOException\r
- */\r
- private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) throws IOException {\r
+ private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) {\r
// todo : refact this..\r
- if (cldsVfDataList != null && cldsVfDataList.size() > 0) {\r
+ if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
RESOURCE_VF_TYPE);\r
List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);\r
if (vfcDataListFromVfResponse != null) {\r
currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);\r
- if (vfcDataListFromVfResponse.size() > 0) {\r
+ if (!vfcDataListFromVfResponse.isEmpty()) {\r
// To get artifacts for every VFC and get\r
// alarm conditions from artifact\r
for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {\r
}\r
}\r
\r
- private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws IOException {\r
+ private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) {\r
ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\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
\r
private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {\r
String catalogUrl = refProp.getStringValue("sdc.catalog.url");\r
- List<CldsVfcData> cldsVfcDataList = new ArrayList<CldsVfcData>();\r
+ List<CldsVfcData> cldsVfcDataList = new ArrayList<>();\r
\r
if (resourceUUID != null) {\r
String vfcResourceUUIDUrl = catalogUrl + "resources" + "/" + resourceUUID + "/metadata";\r
}\r
\r
private String removeUnwantedBracesFromString(String id) {\r
- if (id != null && id.contains("\"")) {\r
- id = id.replaceAll("\"", "");\r
- }\r
- return id;\r
+ return (id != null) ? id.replaceAll("\"", "") : "";\r
}\r
\r
- private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws IOException {\r
+ private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) {\r
List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\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
return cldsAlarmConditionList;\r
}\r
\r
- private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) throws IOException {\r
- List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
- Reader alarmReader = new StringReader(allAlarmCondsValues);\r
- Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
- if (records != null) {\r
- Iterator<CSVRecord> it = records.iterator();\r
- if (it.hasNext()) {\r
- it.next();\r
+ 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
- it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));\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
- return cldsAlarmConditionList;\r
}\r
\r
// Method to get the artifact for any particular VF\r
- private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws JsonProcessingException, IOException {\r
- List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();\r
+ private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) {\r
+ List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\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
String artifactName = "";\r
if (artifactNameNode != null) {\r
artifactName = artifactNameNode.textValue();\r
- artifactName = artifactName.substring(artifactName.lastIndexOf(".") + 1);\r
+ artifactName = artifactName.substring(artifactName.lastIndexOf('.') + 1);\r
}\r
if (artifactUrlNode != null && artifactName != null && !artifactName.isEmpty()\r
&& artifactName.equalsIgnoreCase("csv")) {\r
}\r
\r
// Method to get the artifactURL Data and set the CldsVfKPIData node\r
- private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) throws IOException {\r
- List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();\r
- Reader alarmReader = new StringReader(allFieldPathValues);\r
- Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
- if (records != null) {\r
- for (CSVRecord record : records) {\r
- CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);\r
- if (kpiData != null) {\r
- cldsVfKPIDataList.add(kpiData);\r
+ private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) {\r
+ try {\r
+ List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
+ Reader alarmReader = new StringReader(allFieldPathValues);\r
+ Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
+ if (records != null) {\r
+ for (CSVRecord record : records) {\r
+ CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);\r
+ if (kpiData != null) {\r
+ cldsVfKPIDataList.add(kpiData);\r
+ }\r
}\r
}\r
+ return cldsVfKPIDataList;\r
+ } catch (IOException e) {\r
+ logger.error("Exception when attempting to parse the CSV containing the alarm kpi data", e);\r
+ return new ArrayList<>();\r
}\r
- return cldsVfKPIDataList;\r
}\r
\r
private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {\r
\r
public String getResponsesFromArtifactUrl(String artifactsUrl) {\r
String hostUrl = refProp.getStringValue("sdc.hostUrl");\r
- artifactsUrl = artifactsUrl.replaceAll("\"", "");\r
- String artifactUrl = hostUrl + artifactsUrl;\r
+ String artifactsUrlReworked = artifactsUrl.replaceAll("\"", "");\r
+ String artifactUrl = hostUrl + artifactsUrlReworked;\r
logger.info("value of artifactURl:" + artifactUrl);\r
String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl, true);\r
logger.info("value of artifactResponse:" + currArtifactResponse);\r
* @param url\r
* @param alarmConditions\r
* @return\r
- * @throws IOException\r
*/\r
public String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) {\r
+ Date startTime = new Date();\r
try {\r
- url = removeUnwantedBracesFromString(url);\r
- URL urlObj = new URL(url);\r
+ LoggingUtils.setTargetContext("SDC", "getCldsServicesOrResourcesBasedOnURL");\r
+ String urlReworked = removeUnwantedBracesFromString(url);\r
+ URL urlObj = new URL(urlReworked);\r
\r
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
String basicAuth = SdcReq.getSdcBasicAuth(refProp);\r
conn.setRequestMethod("GET");\r
\r
int responseCode = conn.getResponseCode();\r
- logger.info("responseCode=" + responseCode);\r
+ logger.info("Sdc resource url - " + urlReworked + " , responseCode=" + responseCode);\r
StringBuilder response;\r
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {\r
response = new StringBuilder();\r
String inputLine;\r
while ((inputLine = in.readLine()) != null) {\r
- response.append(inputLine);\r
+ if (!inputLine.isEmpty()) {\r
+ response.append(inputLine);\r
+ }\r
if (alarmConditions) {\r
response.append("\n");\r
}\r
}\r
}\r
+ LoggingUtils.setResponseContext("0", "Get sdc resources success", this.getClass().getName());\r
return response.toString();\r
} catch (IOException e) {\r
+ LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
+ LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
logger.error("Exception occurred during query to SDC", e);\r
return "";\r
+ } finally {\r
+ LoggingUtils.setTimeContext(startTime, new Date());\r
+ metricsLogger.info("getCldsServicesOrResourcesBasedOnURL completed");\r
}\r
\r
}\r
* @param globalProps\r
* @param cldsServiceData\r
* @return\r
- * @throws IOException\r
*/\r
- public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) throws IOException {\r
+ public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) {\r
String totalPropsStr;\r
ObjectMapper mapper = new ObjectMapper();\r
ObjectNode globalPropsJson;\r
\r
// To create byKpi\r
ObjectNode kpiObjectNode = mapper.createObjectNode();\r
- if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {\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
\r
// To create byVfc and alarmCondition with vfcResourceUUID\r
ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode();\r
- if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {\r
+ if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
if (currCldsVfData != null) {\r
createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,\r
\r
byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
\r
- globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);\r
+ globalPropsJson = decodeGlobalProp(globalProps, mapper);\r
\r
globalPropsJson.putPOJO("shared", byIdObjectNode);\r
- logger.info("valuie of objNode:" + globalPropsJson);\r
+ logger.info("value of objNode:" + globalPropsJson);\r
} else {\r
/**\r
* to create json with total properties when no serviceUUID passed\r
*/\r
- globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);\r
+ globalPropsJson = decodeGlobalProp(globalProps, mapper);\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
List<CldsAlarmCondition> cldsAlarmCondList) {\r
ObjectNode alarmCondKeyNode = mapper.createObjectNode();\r
\r
- if (cldsAlarmCondList != null && cldsAlarmCondList.size() > 0) {\r
+ if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {\r
for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {\r
if (currCldsAlarmCondition != null) {\r
ObjectNode alarmCondNode = mapper.createObjectNode();\r
ObjectNode vfObjectNode = mapper.createObjectNode();\r
ObjectNode vfUuidNode = mapper.createObjectNode();\r
List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();\r
- if (cldsVfsList != null && cldsVfsList.size() > 0) {\r
+ if (cldsVfsList != null && !cldsVfsList.isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsVfsList) {\r
if (currCldsVfData != null) {\r
vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());\r
\r
private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode,\r
List<CldsVfKPIData> cldsVfKpiDataList) {\r
- if (cldsVfKpiDataList != null && cldsVfKpiDataList.size() > 0) {\r
+ if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {\r
for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {\r
if (currCldsVfKpiData != null) {\r
ObjectNode thresholdNameObjectNode = mapper.createObjectNode();\r
ObjectNode vfcObjectNode = mapper.createObjectNode();\r
ObjectNode alarmCondNode = mapper.createObjectNode();\r
ObjectNode alertDescNode = mapper.createObjectNode();\r
- if (cldsVfcDataList != null && cldsVfcDataList.size() > 0) {\r
+ if (cldsVfcDataList != null && !cldsVfcDataList.isEmpty()) {\r
for (CldsVfcData currCldsVfcData : cldsVfcDataList) {\r
if (currCldsVfcData != null) {\r
if (currCldsVfcData.getCldsAlarmConditions() != null\r
- && currCldsVfcData.getCldsAlarmConditions().size() > 0) {\r
+ && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {\r
alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
currCldsAlarmCondition.getAlarmConditionKey());\r
}\r
}\r
}\r
+\r
vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);\r
vfcObjectNode.putPOJO("alertDescription", alertDescNode);\r
vfcResourceUuidObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), vfcObjectNode);\r
}\r
}\r
\r
+ /**\r
+ * Method to create vfc and kpi nodes inside vf node\r
+ * \r
+ * @param mapper\r
+ * @param cldsVfDataList\r
+ * @return\r
+ */\r
private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {\r
ObjectNode vfUuidObjectNode = mapper.createObjectNode();\r
\r
- if (cldsVfDataList != null && cldsVfDataList.size() > 0) {\r
+ if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsVfDataList) {\r
if (currCldsVfData != null) {\r
- ObjectNode vfcObjectNode = mapper.createObjectNode();\r
+ ObjectNode vfObjectNode = mapper.createObjectNode();\r
ObjectNode vfcUuidNode = mapper.createObjectNode();\r
- if (currCldsVfData.getCldsVfcs() != null && currCldsVfData.getCldsVfcs().size() > 0) {\r
+ ObjectNode kpiObjectNode = mapper.createObjectNode();\r
+ if (currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {\r
for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {\r
vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),\r
currCldsVfcData.getVfcName());\r
} else {\r
vfcUuidNode.put("", "");\r
}\r
- vfcObjectNode.putPOJO("vfc", vfcUuidNode);\r
- vfUuidObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfcObjectNode);\r
+ if (currCldsVfData.getCldsKPIList() != null && !currCldsVfData.getCldsKPIList().isEmpty()) {\r
+ for (CldsVfKPIData currCldsVfKPIData : currCldsVfData.getCldsKPIList()) {\r
+ kpiObjectNode.put(currCldsVfKPIData.getThresholdValue(),\r
+ currCldsVfKPIData.getThresholdValue());\r
+ }\r
+ } else {\r
+ kpiObjectNode.put("", "");\r
+ }\r
+ vfObjectNode.putPOJO("vfc", vfcUuidNode);\r
+ vfObjectNode.putPOJO("kpi", kpiObjectNode);\r
+ vfUuidObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfObjectNode);\r
}\r
}\r
} else {\r
if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null\r
&& !currCldsSdcResource.getArtifacts().isEmpty()) {\r
for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {\r
- if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null) {\r
- if (currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
- artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
- artifactExists = true;\r
- break;\r
- }\r
+ if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null\r
+ && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
+ artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
+ artifactExists = true;\r
+ break;\r
}\r
}\r
}\r
* @param resourceType\r
* The resourceType\r
* @return The list of CldsSdcResourceBasicInfo\r
- * @throws IOException\r
- * In case of issues with the Streams\r
*/\r
- private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType)\r
- throws IOException {\r
- List<CldsSdcResourceBasicInfo> allSdcResourceVfcBasicInfo = new ArrayList<CldsSdcResourceBasicInfo>();\r
+ private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {\r
String catalogUrl = refProp.getStringValue("sdc.catalog.url");\r
String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;\r
String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false);\r
-\r
- allSdcResourceVfcBasicInfo = getAllSdcResourcesListFromJson(allSdcVfcResources);\r
- return removeDuplicateSdcResourceBasicInfo(allSdcResourceVfcBasicInfo);\r
+ return removeDuplicateSdcResourceBasicInfo(getAllSdcResourcesListFromJson(allSdcVfcResources));\r
}\r
\r
private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,\r
- List<CldsSdcResourceBasicInfo> resourceInfoList) throws IOException {\r
+ List<CldsSdcResourceBasicInfo> resourceInfoList) {\r
String resourceUuid = null;\r
- if (resourceInfoList != null && resourceInfoList.size() > 0) {\r
+ if (resourceInfoList != null && !resourceInfoList.isEmpty()) {\r
for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {\r
if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null\r
&& currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {\r
* @param locationArtifactName\r
* The location artifact name from where we can get the Artifact\r
* UUID\r
- * @throws IOException\r
- * In case of issues with the streams\r
* \r
*/\r
public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,\r
- String formattedSdcLocationReq, String artifactName, String locationArtifactName) throws IOException {\r
+ String formattedSdcLocationReq, String artifactName, String locationArtifactName) {\r
logger.info("userid=" + userid);\r
String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);\r
if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {\r