Minor Improvement
[clamp.git] / src / main / java / org / onap / clamp / clds / client / req / sdc / SdcCatalogServices.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP CLAMP\r
4  * ================================================================================\r
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights\r
6  *                             reserved.\r
7  * ================================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  *\r
12  * http://www.apache.org/licenses/LICENSE-2.0\r
13  *\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END============================================\r
20  * ===================================================================\r
21  * \r
22  */\r
23 \r
24 package org.onap.clamp.clds.client.req.sdc;\r
25 \r
26 import com.att.eelf.configuration.EELFLogger;\r
27 import com.att.eelf.configuration.EELFManager;\r
28 import com.fasterxml.jackson.databind.JsonNode;\r
29 import com.fasterxml.jackson.databind.ObjectMapper;\r
30 import com.fasterxml.jackson.databind.node.ArrayNode;\r
31 import com.fasterxml.jackson.databind.node.ObjectNode;\r
32 import com.fasterxml.jackson.databind.node.TextNode;\r
33 \r
34 import java.io.BufferedReader;\r
35 import java.io.DataOutputStream;\r
36 import java.io.IOException;\r
37 import java.io.InputStream;\r
38 import java.io.InputStreamReader;\r
39 import java.io.Reader;\r
40 import java.io.StringReader;\r
41 import java.net.HttpURLConnection;\r
42 import java.net.URL;\r
43 import java.nio.charset.StandardCharsets;\r
44 import java.security.GeneralSecurityException;\r
45 import java.util.ArrayList;\r
46 import java.util.Base64;\r
47 import java.util.Collections;\r
48 import java.util.Date;\r
49 import java.util.Iterator;\r
50 import java.util.List;\r
51 \r
52 import javax.ws.rs.BadRequestException;\r
53 \r
54 import org.apache.commons.codec.DecoderException;\r
55 import org.apache.commons.codec.digest.DigestUtils;\r
56 import org.apache.commons.csv.CSVFormat;\r
57 import org.apache.commons.csv.CSVRecord;\r
58 import org.apache.commons.io.IOUtils;\r
59 import org.apache.commons.lang3.StringUtils;\r
60 import org.apache.http.HttpHeaders;\r
61 import org.onap.clamp.clds.config.ClampProperties;\r
62 import org.onap.clamp.clds.exception.sdc.SdcCommunicationException;\r
63 import org.onap.clamp.clds.model.CldsAlarmCondition;\r
64 import org.onap.clamp.clds.model.CldsServiceData;\r
65 import org.onap.clamp.clds.model.CldsVfData;\r
66 import org.onap.clamp.clds.model.CldsVfKPIData;\r
67 import org.onap.clamp.clds.model.CldsVfcData;\r
68 import org.onap.clamp.clds.model.properties.Global;\r
69 import org.onap.clamp.clds.model.properties.ModelProperties;\r
70 import org.onap.clamp.clds.model.sdc.SdcArtifact;\r
71 import org.onap.clamp.clds.model.sdc.SdcResource;\r
72 import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo;\r
73 import org.onap.clamp.clds.model.sdc.SdcServiceDetail;\r
74 import org.onap.clamp.clds.model.sdc.SdcServiceInfo;\r
75 import org.onap.clamp.clds.service.CldsService;\r
76 import org.onap.clamp.clds.util.CryptoUtils;\r
77 import org.onap.clamp.clds.util.JacksonUtils;\r
78 import org.onap.clamp.clds.util.LoggingUtils;\r
79 import org.springframework.beans.factory.annotation.Autowired;\r
80 import org.springframework.context.annotation.Primary;\r
81 import org.springframework.stereotype.Component;\r
82 \r
83 @Component\r
84 @Primary\r
85 public class SdcCatalogServices {\r
86 \r
87     private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class);\r
88     private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();\r
89     private static final String RESOURCE_VF_TYPE = "VF";\r
90     private static final String RESOURCE_VFC_TYPE = "VFC";\r
91     private static final String RESOURCE_CVFC_TYPE = "CVFC";\r
92     private static final String SDC_REQUESTID_PROPERTY_NAME = "sdc.header.requestId";\r
93     private static final String SDC_METADATA_URL_PREFIX = "/metadata";\r
94     private static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID";\r
95     private static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url";\r
96     private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";\r
97     private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";\r
98     private static final String RESOURCE_URL_PREFIX = "resources";\r
99     @Autowired\r
100     private ClampProperties refProp;\r
101 \r
102     /**\r
103      * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic\r
104      * dGVzdDoxMjM0NTY=).\r
105      *\r
106      * @return The String with Basic Auth and password\r
107      * @throws GeneralSecurityException\r
108      *             In case of issue when decryting the SDC password\r
109      * @throws DecoderException\r
110      *             In case of issues with the decoding of the HexString message\r
111      */\r
112     private String getSdcBasicAuth() throws GeneralSecurityException, DecoderException {\r
113         String sdcId = refProp.getStringValue("sdc.serviceUsername");\r
114         String sdcPw = refProp.getStringValue("sdc.servicePassword");\r
115         String password = CryptoUtils.decrypt(sdcPw);\r
116         String idPw = Base64.getEncoder().encodeToString((sdcId + ":" + password).getBytes(StandardCharsets.UTF_8));\r
117         return "Basic " + idPw;\r
118     }\r
119 \r
120     /**\r
121      * This method get the SDC services Information with the corresponding\r
122      * Service UUID.\r
123      * \r
124      * @param uuid\r
125      *            The service UUID\r
126      * @return A Json String with all the service list\r
127      * @throws GeneralSecurityException\r
128      *             In case of issue when decryting the SDC password\r
129      * @throws DecoderException\r
130      *             In case of issues with the decoding of the Hex String\r
131      */\r
132     public String getSdcServicesInformation(String uuid) throws GeneralSecurityException, DecoderException {\r
133         Date startTime = new Date();\r
134         String baseUrl = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);\r
135         String basicAuth = getSdcBasicAuth();\r
136         LoggingUtils.setTargetContext("SDC", "getSdcServicesInformation");\r
137         try {\r
138             String url = baseUrl;\r
139             if (uuid != null && !uuid.isEmpty()) {\r
140                 url = baseUrl + "/" + uuid + SDC_METADATA_URL_PREFIX;\r
141             }\r
142             URL urlObj = new URL(url);\r
143             HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
144             conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);\r
145             conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
146             conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");\r
147             conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());\r
148             conn.setRequestMethod("GET");\r
149             String resp = getResponse(conn);\r
150             logger.debug("Services list received from SDC:" + resp);\r
151             // metrics log\r
152             LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());\r
153             return resp;\r
154         } catch (IOException e) {\r
155             LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());\r
156             LoggingUtils.setErrorContext("900", "Get sdc services error");\r
157             logger.error("not able to get any service information from sdc for uuid:" + uuid, e);\r
158         } finally {\r
159             LoggingUtils.setTimeContext(startTime, new Date());\r
160             metricsLogger.info("getSdcServicesInformation complete");\r
161         }\r
162         return "";\r
163     }\r
164 \r
165     /**\r
166      * To remove duplicate serviceUUIDs from sdc services List.\r
167      * \r
168      * @param rawCldsSdcServiceList\r
169      *            A list of CldsSdcServiceInfo\r
170      * @return A list of CldsSdcServiceInfo without duplicate service UUID\r
171      */\r
172     public List<SdcServiceInfo> removeDuplicateServices(List<SdcServiceInfo> rawCldsSdcServiceList) {\r
173         List<SdcServiceInfo> cldsSdcServiceInfoList = null;\r
174         if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {\r
175             // sort list\r
176             Collections.sort(rawCldsSdcServiceList);\r
177             // and then take only the services with the max version (last in the\r
178             // list with the same name)\r
179             cldsSdcServiceInfoList = new ArrayList<>();\r
180             for (int i = 1; i < rawCldsSdcServiceList.size(); i++) {\r
181                 // compare name with previous - if not equal, then keep the\r
182                 // previous (it's the last with that name)\r
183                 SdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);\r
184                 if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {\r
185                     cldsSdcServiceInfoList.add(prev);\r
186                 }\r
187             }\r
188             // add the last in the list\r
189             cldsSdcServiceInfoList.add(rawCldsSdcServiceList.get(rawCldsSdcServiceList.size() - 1));\r
190         }\r
191         return cldsSdcServiceInfoList;\r
192     }\r
193 \r
194     /**\r
195      * To remove duplicate serviceUUIDs from sdc resources List.\r
196      * \r
197      * @param rawCldsSdcResourceList\r
198      * @return List of CldsSdcResource\r
199      */\r
200     public List<SdcResource> removeDuplicateSdcResourceInstances(List<SdcResource> rawCldsSdcResourceList) {\r
201         List<SdcResource> cldsSdcResourceList = null;\r
202         if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) {\r
203             // sort list\r
204             Collections.sort(rawCldsSdcResourceList);\r
205             // and then take only the resources with the max version (last in\r
206             // the list with the same name)\r
207             cldsSdcResourceList = new ArrayList<>();\r
208             for (int i = 1; i < rawCldsSdcResourceList.size(); i++) {\r
209                 // compare name with previous - if not equal, then keep the\r
210                 // previous (it's the last with that name)\r
211                 SdcResource prev = rawCldsSdcResourceList.get(i - 1);\r
212                 if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {\r
213                     cldsSdcResourceList.add(prev);\r
214                 }\r
215             }\r
216             // add the last in the list\r
217             cldsSdcResourceList.add(rawCldsSdcResourceList.get(rawCldsSdcResourceList.size() - 1));\r
218         }\r
219         return cldsSdcResourceList;\r
220     }\r
221 \r
222     /**\r
223      * To remove duplicate basic resources with same resourceUUIDs.\r
224      * \r
225      * @param rawCldsSdcResourceListBasicList\r
226      * @return List of CldsSdcResourceBasicInfo\r
227      */\r
228     public List<SdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(\r
229             List<SdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {\r
230         List<SdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;\r
231         if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {\r
232             // sort list\r
233             Collections.sort(rawCldsSdcResourceListBasicList);\r
234             // and then take only the resources with the max version (last in\r
235             // the list with the same name)\r
236             cldsSdcResourceBasicInfoList = new ArrayList<>();\r
237             for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {\r
238                 // compare name with previous - if not equal, then keep the\r
239                 // previous (it's the last with that name)\r
240                 SdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);\r
241                 if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {\r
242                     cldsSdcResourceBasicInfoList.add(prev);\r
243                 }\r
244             }\r
245             // add the last in the list\r
246             cldsSdcResourceBasicInfoList\r
247                     .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));\r
248         }\r
249         return cldsSdcResourceBasicInfoList;\r
250     }\r
251 \r
252     /**\r
253      * To get ServiceUUID by using serviceInvariantUUID.\r
254      * \r
255      * @param invariantId\r
256      *            The invariant ID\r
257      * @return The service UUID\r
258      * @throws GeneralSecurityException\r
259      *             In case of issue when decryting the SDC password\r
260      * @throws DecoderException\r
261      *             In case of issues with the decoding of the Hex String\r
262      */\r
263     public String getServiceUuidFromServiceInvariantId(String invariantId)\r
264             throws GeneralSecurityException, DecoderException {\r
265         String serviceUuid = "";\r
266         String responseStr = getSdcServicesInformation(null);\r
267         List<SdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);\r
268         List<SdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);\r
269         if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {\r
270             for (SdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {\r
271                 if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null\r
272                         && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {\r
273                     serviceUuid = currCldsSdcServiceInfo.getUuid();\r
274                     break;\r
275                 }\r
276             }\r
277         }\r
278         return serviceUuid;\r
279     }\r
280 \r
281     /**\r
282      * To get CldsAsdsServiceInfo class by parsing json string.\r
283      * \r
284      * @param jsonStr\r
285      *            The Json string that must be decoded\r
286      * @return The list of CldsSdcServiceInfo, if there is a failure it return\r
287      *         an empty list\r
288      */\r
289     private List<SdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
290         if (StringUtils.isBlank(jsonStr)) {\r
291             return new ArrayList<>();\r
292         }\r
293         try {\r
294             return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
295                     .getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
296         } catch (IOException e) {\r
297             logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);\r
298             return new ArrayList<>();\r
299         }\r
300     }\r
301 \r
302     /**\r
303      * To get List of CldsSdcResourceBasicInfo class by parsing json string.\r
304      *\r
305      * @param jsonStr\r
306      *            The JSOn string that must be decoded\r
307      * @return The list of CldsSdcResourceBasicInfo, an empty list in case of\r
308      *         issues\r
309      */\r
310     private List<SdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
311         if (StringUtils.isBlank(jsonStr)) {\r
312             return new ArrayList<>();\r
313         }\r
314         try {\r
315             return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
316                     .getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
317         } catch (IOException e) {\r
318             logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);\r
319             return new ArrayList<>();\r
320         }\r
321     }\r
322 \r
323     /**\r
324      * To get CldsSdcServiceDetail by parsing json string.\r
325      * \r
326      * @param jsonStr\r
327      * @return\r
328      */\r
329     public SdcServiceDetail decodeCldsSdcServiceDetailFromJson(String jsonStr) {\r
330         try {\r
331             return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, SdcServiceDetail.class);\r
332         } catch (IOException e) {\r
333             logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);\r
334             return null;\r
335         }\r
336     }\r
337 \r
338     // upload artifact to sdc based on serviceUUID and resource name on url\r
339     private String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formattedSdcReq) {\r
340         // Verify whether it is triggered by Validation Test button from UI\r
341         if (prop.isTestOnly()) {\r
342             return "sdc artifact upload not executed for test action";\r
343         }\r
344         try {\r
345             logger.info("userid=" + userid);\r
346             byte[] postData = formattedSdcReq.getBytes(StandardCharsets.UTF_8);\r
347             int postDataLength = postData.length;\r
348             HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, formattedSdcReq);\r
349             try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {\r
350                 wr.write(postData);\r
351             }\r
352             boolean requestFailed = true;\r
353             int responseCode = conn.getResponseCode();\r
354             logger.info("responseCode=" + responseCode);\r
355             if (responseCode == 200) {\r
356                 requestFailed = false;\r
357             }\r
358             String responseStr = getResponse(conn);\r
359             if (responseStr != null && requestFailed) {\r
360                 logger.error("requestFailed - responseStr=" + responseStr);\r
361                 throw new BadRequestException(responseStr);\r
362             }\r
363             return responseStr;\r
364         } catch (IOException e) {\r
365             logger.error("Exception when attempting to communicate with SDC", e);\r
366             throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);\r
367         }\r
368     }\r
369 \r
370     private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String content) {\r
371         try {\r
372             logger.info("userid=" + userid);\r
373             String basicAuth = getSdcBasicAuth();\r
374             String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
375             URL urlObj = new URL(url);\r
376             HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
377             conn.setDoOutput(true);\r
378             conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId);\r
379             conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
380             conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json");\r
381             conn.setRequestProperty(HttpHeaders.CONTENT_MD5,\r
382                     Base64.getEncoder().encodeToString(DigestUtils.md5Hex(content).getBytes("UTF-8")));\r
383             conn.setRequestProperty("USER_ID", userid);\r
384             conn.setRequestMethod("POST");\r
385             conn.setRequestProperty("charset", "utf-8");\r
386             conn.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(postDataLength));\r
387             conn.setUseCaches(false);\r
388             conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());\r
389             return conn;\r
390         } catch (IOException e) {\r
391             logger.error("Exception when attempting to open connection with SDC", e);\r
392             throw new SdcCommunicationException("Exception when attempting to open connection with SDC", e);\r
393         } catch (DecoderException e) {\r
394             logger.error("Exception when attempting to decode the Hex string", e);\r
395             throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);\r
396         } catch (GeneralSecurityException e) {\r
397             logger.error("Exception when attempting to decrypt the encrypted password", e);\r
398             throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);\r
399         }\r
400     }\r
401 \r
402     private String getResponse(HttpURLConnection conn) {\r
403         try (InputStream is = getInputStream(conn)) {\r
404             try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {\r
405                 return IOUtils.toString(in);\r
406             }\r
407         } catch (IOException e) {\r
408             logger.error("Exception when attempting to open SDC response", e);\r
409             throw new SdcCommunicationException("Exception when attempting to open SDC response", e);\r
410         }\r
411     }\r
412 \r
413     private InputStream getInputStream(HttpURLConnection conn) {\r
414         try {\r
415             InputStream inStream = conn.getErrorStream();\r
416             if (inStream == null) {\r
417                 inStream = conn.getInputStream();\r
418             }\r
419             return inStream;\r
420         } catch (IOException e) {\r
421             logger.error("Exception when attempting to open SDC error stream", e);\r
422             throw new SdcCommunicationException("Exception when attempting to open SDC error stream", e);\r
423         }\r
424     }\r
425 \r
426     /**\r
427      * Check if the SDC Info in cache has expired.\r
428      * \r
429      * @param cldsServiceData\r
430      *            The object representing the service data\r
431      * @return boolean flag\r
432      * @throws GeneralSecurityException\r
433      *             In case of issues with the decryting the encrypted password\r
434      * @throws DecoderException\r
435      *             In case of issues with the decoding of the Hex String\r
436      */\r
437     public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData)\r
438             throws GeneralSecurityException, DecoderException {\r
439         if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
440             String cachedServiceUuid = cldsServiceData.getServiceUUID();\r
441             String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID());\r
442             String configuredMaxAge = refProp.getStringValue("clds.service.cache.invalidate.after.seconds");\r
443             if (configuredMaxAge == null) {\r
444                 logger.warn(\r
445                         "clds.service.cache.invalidate.after.seconds NOT set in clds-reference.properties file, taking 60s as default");\r
446                 configuredMaxAge = "60";\r
447             }\r
448             return (!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null\r
449                     && cldsServiceData.getAgeOfRecord() > Long.parseLong(configuredMaxAge));\r
450         } else {\r
451             return true;\r
452         }\r
453     }\r
454 \r
455     /**\r
456      * Get the Service Data with Alarm Conditions for a given\r
457      * invariantServiceUuid.\r
458      * \r
459      * @param invariantServiceUuid\r
460      * @return The CldsServiceData\r
461      * @throws GeneralSecurityException\r
462      *             In case of issues with the decryting the encrypted password\r
463      * @throws DecoderException\r
464      *             In case of issues with the decoding of the Hex String\r
465      */\r
466     public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid)\r
467             throws GeneralSecurityException, DecoderException {\r
468         String url = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);\r
469         String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);\r
470         String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);\r
471         String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX;\r
472         String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl);\r
473         CldsServiceData cldsServiceData = new CldsServiceData();\r
474         if (responseStr != null) {\r
475             SdcServiceDetail cldsSdcServiceDetail;\r
476             try {\r
477                 cldsSdcServiceDetail = JacksonUtils.getObjectMapperInstance().readValue(responseStr,\r
478                         SdcServiceDetail.class);\r
479             } catch (IOException e) {\r
480                 logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);\r
481                 throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);\r
482             }\r
483             // To remove duplicate resources from serviceDetail and add valid\r
484             // vfs to service\r
485             if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {\r
486                 cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());\r
487                 cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());\r
488                 List<SdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(\r
489                         cldsSdcServiceDetail.getResources());\r
490                 if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {\r
491                     List<CldsVfData> cldsVfDataList = new ArrayList<>();\r
492                     for (SdcResource currCldsSdcResource : cldsSdcResourceList) {\r
493                         if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null\r
494                                 && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {\r
495                             CldsVfData currCldsVfData = new CldsVfData();\r
496                             currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());\r
497                             currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());\r
498                             cldsVfDataList.add(currCldsVfData);\r
499                         }\r
500                     }\r
501                     cldsServiceData.setCldsVfs(cldsVfDataList);\r
502                     // For each vf in the list , add all vfc's\r
503                     getAllVfcForVfList(cldsVfDataList, catalogUrl);\r
504                     logger.info("Invariant Service ID of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());\r
505                 }\r
506             }\r
507         }\r
508         return cldsServiceData;\r
509     }\r
510 \r
511     private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl)\r
512             throws GeneralSecurityException {\r
513         // todo : refact this..\r
514         if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
515             List<SdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_VF_TYPE);\r
516             List<SdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(\r
517                     RESOURCE_VFC_TYPE);\r
518             allVfcResources.addAll(getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_CVFC_TYPE));\r
519             for (CldsVfData currCldsVfData : cldsVfDataList) {\r
520                 if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) {\r
521                     String resourceUuid = getResourceUuidFromResourceInvariantUuid(\r
522                             currCldsVfData.getVfInvariantResourceUUID(), allVfResources);\r
523                     if (resourceUuid != null) {\r
524                         String vfResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUuid\r
525                                 + SDC_METADATA_URL_PREFIX;\r
526                         String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl);\r
527                         if (vfResponse != null) {\r
528                             // Below 2 line are to get the KPI(field path) data\r
529                             // associated with the VF's\r
530                             List<CldsVfKPIData> cldsVfKPIDataList = getFieldPathFromVF(vfResponse);\r
531                             currCldsVfData.setCldsKPIList(cldsVfKPIDataList);\r
532                             List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);\r
533                             if (vfcDataListFromVfResponse != null) {\r
534                                 currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);\r
535                                 if (!vfcDataListFromVfResponse.isEmpty()) {\r
536                                     // To get artifacts for every VFC and get\r
537                                     // alarm conditions from artifact\r
538                                     for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {\r
539                                         if (currCldsVfcData != null\r
540                                                 && currCldsVfcData.getVfcInvariantResourceUUID() != null) {\r
541                                             String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(\r
542                                                     currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);\r
543                                             if (resourceVfcUuid != null) {\r
544                                                 String vfcResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/"\r
545                                                         + resourceVfcUuid + SDC_METADATA_URL_PREFIX;\r
546                                                 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(\r
547                                                         vfcResourceUuidUrl);\r
548                                                 if (vfcResponse != null) {\r
549                                                     List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(\r
550                                                             vfcResponse);\r
551                                                     currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc);\r
552                                                 }\r
553                                             } else {\r
554                                                 logger.info("No resourceVFC UUID found for given invariantID:"\r
555                                                         + currCldsVfcData.getVfcInvariantResourceUUID());\r
556                                             }\r
557                                         }\r
558                                     }\r
559                                 }\r
560                             }\r
561                         }\r
562                     } else {\r
563                         logger.info("No resourceUUID found for given invariantREsourceUUID:"\r
564                                 + currCldsVfData.getVfInvariantResourceUUID());\r
565                     }\r
566                 }\r
567             }\r
568         }\r
569     }\r
570 \r
571     private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) {\r
572         ObjectNode vfResponseNode;\r
573         try {\r
574             vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse);\r
575         } catch (IOException e) {\r
576             logger.error("Exception when decoding the JSON list of CldsVfcData", e);\r
577             return new ArrayList<>();\r
578         }\r
579         ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");\r
580         List<CldsVfcData> cldsVfcDataList = new ArrayList<>();\r
581         if (vfcArrayNode != null) {\r
582             for (JsonNode vfcjsonNode : vfcArrayNode) {\r
583                 ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;\r
584                 TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");\r
585                 if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {\r
586                     handleVFCtypeNode(currVfcNode, cldsVfcDataList);\r
587                 } else if (resourceTypeNode != null && "CVFC".equalsIgnoreCase(resourceTypeNode.textValue())) {\r
588                     handleCVFCtypeNode(currVfcNode, cldsVfcDataList);\r
589                 }\r
590             }\r
591         }\r
592         return cldsVfcDataList;\r
593     }\r
594 \r
595     private void handleVFCtypeNode(ObjectNode currVfcNode, List<CldsVfcData> cldsVfcDataList) {\r
596         CldsVfcData currCldsVfcData = new CldsVfcData();\r
597         TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");\r
598         TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID");\r
599         currCldsVfcData.setVfcName(vfcResourceName.textValue());\r
600         currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue());\r
601         cldsVfcDataList.add(currCldsVfcData);\r
602     }\r
603 \r
604     private void handleCVFCtypeNode(ObjectNode currVfcNode, List<CldsVfcData> cldsVfcDataList) {\r
605         handleVFCtypeNode(currVfcNode, cldsVfcDataList);\r
606         cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue()));\r
607     }\r
608 \r
609     private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {\r
610         String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);\r
611         List<CldsVfcData> cldsVfcDataList = new ArrayList<>();\r
612         if (resourceUUID != null) {\r
613             String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX;\r
614             try {\r
615                 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl);\r
616                 ObjectNode vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse);\r
617                 ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");\r
618                 if (vfcArrayNode != null) {\r
619                     for (JsonNode vfcjsonNode : vfcArrayNode) {\r
620                         ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;\r
621                         TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");\r
622                         if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {\r
623                             handleVFCtypeNode(currVfcNode, cldsVfcDataList);\r
624                         }\r
625                     }\r
626                 }\r
627             } catch (IOException e) {\r
628                 logger.error("Exception during JSON analyzis", e);\r
629             }\r
630         }\r
631         return cldsVfcDataList;\r
632     }\r
633 \r
634     private String removeUnwantedBracesFromString(String id) {\r
635         return (id != null) ? id.replaceAll("\"", "") : "";\r
636     }\r
637 \r
638     private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws GeneralSecurityException {\r
639         List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
640         ObjectNode vfcResponseNode;\r
641         try {\r
642             vfcResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse);\r
643         } catch (IOException e) {\r
644             logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);\r
645             return cldsAlarmConditionList;\r
646         }\r
647         ArrayNode artifactsArrayNode = (ArrayNode) vfcResponseNode.get("artifacts");\r
648         if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {\r
649             for (int index = 0; index < artifactsArrayNode.size(); index++) {\r
650                 ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);\r
651                 TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");\r
652                 if (artifactUrlNode != null) {\r
653                     String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());\r
654                     cldsAlarmConditionList.addAll(parseCsvToGetAlarmConditions(responsesFromArtifactUrl));\r
655                     logger.info(responsesFromArtifactUrl);\r
656                 }\r
657             }\r
658         }\r
659         return cldsAlarmConditionList;\r
660     }\r
661 \r
662     private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) {\r
663         try {\r
664             List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
665             Reader alarmReader = new StringReader(allAlarmCondsValues);\r
666             Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
667             if (records != null) {\r
668                 Iterator<CSVRecord> it = records.iterator();\r
669                 if (it.hasNext()) {\r
670                     it.next();\r
671                 }\r
672                 it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));\r
673             }\r
674             return cldsAlarmConditionList;\r
675         } catch (IOException e) {\r
676             logger.error("Exception when attempting to parse the CSV containing the alarm", e);\r
677             return new ArrayList<>();\r
678         }\r
679     }\r
680 \r
681     // Method to get the artifact for any particular VF\r
682     private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws GeneralSecurityException {\r
683         List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
684         ObjectNode vfResponseNode;\r
685         try {\r
686             vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse);\r
687         } catch (IOException e) {\r
688             logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);\r
689             return cldsVfKPIDataList;\r
690         }\r
691         ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");\r
692         if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {\r
693             for (int index = 0; index < artifactsArrayNode.size(); index++) {\r
694                 ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);\r
695                 TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");\r
696                 TextNode artifactNameNode = (TextNode) currArtifactNode.get("artifactName");\r
697                 String artifactName = "";\r
698                 if (artifactNameNode != null) {\r
699                     artifactName = artifactNameNode.textValue();\r
700                     artifactName = artifactName.substring(artifactName.lastIndexOf('.') + 1);\r
701                 }\r
702                 if (artifactUrlNode != null && "csv".equalsIgnoreCase(artifactName)) {\r
703                     String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());\r
704                     cldsVfKPIDataList.addAll(parseCsvToGetFieldPath(responsesFromArtifactUrl));\r
705                     logger.info(responsesFromArtifactUrl);\r
706                 }\r
707             }\r
708         }\r
709         return cldsVfKPIDataList;\r
710     }\r
711 \r
712     private CldsVfKPIData convertCsvRecordToKpiData(CSVRecord record) {\r
713         if (record.size() < 6) {\r
714             logger.debug("invalid csv field path Record,total columns less than 6: " + record);\r
715             return null;\r
716         }\r
717         if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))\r
718                 || StringUtils.isBlank(record.get(5))) {\r
719             logger.debug("Invalid csv field path Record,one of column is having blank value : " + record);\r
720             return null;\r
721         }\r
722         CldsVfKPIData cldsVfKPIData = new CldsVfKPIData();\r
723         cldsVfKPIData.setNfNamingCode(record.get(0).trim());\r
724         cldsVfKPIData.setNfNamingValue(record.get(1).trim());\r
725         cldsVfKPIData.setFieldPath(record.get(2).trim());\r
726         cldsVfKPIData.setFieldPathValue(record.get(3).trim());\r
727         cldsVfKPIData.setThresholdName(record.get(4).trim());\r
728         cldsVfKPIData.setThresholdValue(record.get(5).trim());\r
729         return cldsVfKPIData;\r
730     }\r
731 \r
732     // Method to get the artifactURL Data and set the CldsVfKPIData node\r
733     private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) {\r
734         try {\r
735             List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
736             Reader alarmReader = new StringReader(allFieldPathValues);\r
737             Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);\r
738             if (records != null) {\r
739                 for (CSVRecord record : records) {\r
740                     CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);\r
741                     if (kpiData != null) {\r
742                         cldsVfKPIDataList.add(kpiData);\r
743                     }\r
744                 }\r
745             }\r
746             return cldsVfKPIDataList;\r
747         } catch (IOException e) {\r
748             logger.error("Exception when attempting to parse the CSV containing the alarm kpi data", e);\r
749             return new ArrayList<>();\r
750         }\r
751     }\r
752 \r
753     private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {\r
754         if (record == null) {\r
755             return;\r
756         }\r
757         if (record.size() < 5) {\r
758             logger.debug("invalid csv alarm Record,total columns less than 5: " + record);\r
759             return;\r
760         }\r
761         if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))\r
762                 || StringUtils.isBlank(record.get(4))) {\r
763             logger.debug("invalid csv alarm Record,one of column is having blank value : " + record);\r
764             return;\r
765         }\r
766         CldsAlarmCondition cldsAlarmCondition = new CldsAlarmCondition();\r
767         cldsAlarmCondition.setEventSourceType(record.get(1));\r
768         cldsAlarmCondition.setEventName(record.get(2));\r
769         cldsAlarmCondition.setAlarmConditionKey(record.get(3));\r
770         cldsAlarmCondition.setSeverity(record.get(4));\r
771         cldsAlarmConditionList.add(cldsAlarmCondition);\r
772     }\r
773 \r
774     // Get the responses for the current artifact from the artifacts URL.\r
775     private String getResponsesFromArtifactUrl(String artifactsUrl) {\r
776         String hostUrl = refProp.getStringValue("sdc.hostUrl");\r
777         String artifactsUrlReworked = artifactsUrl.replaceAll("\"", "");\r
778         String artifactUrl = hostUrl + artifactsUrlReworked;\r
779         logger.info("value of artifactURl:" + artifactUrl);\r
780         String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl);\r
781         logger.info("value of artifactResponse:" + currArtifactResponse);\r
782         return currArtifactResponse;\r
783     }\r
784 \r
785     /**\r
786      * Service to services/resources/artifacts from sdc.Pass alarmConditions as\r
787      * true to get alarm conditons from artifact url and else it is false\r
788      * \r
789      * @param url\r
790      *            The URL to trigger\r
791      * @return The String containing the payload\r
792      */\r
793     public String getCldsServicesOrResourcesBasedOnURL(String url) {\r
794         Date startTime = new Date();\r
795         try {\r
796             LoggingUtils.setTargetContext("SDC", "getCldsServicesOrResourcesBasedOnURL");\r
797             String urlReworked = removeUnwantedBracesFromString(url);\r
798             URL urlObj = new URL(urlReworked);\r
799             HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
800             String basicAuth = getSdcBasicAuth();\r
801             conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);\r
802             conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
803             conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");\r
804             conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());\r
805             conn.setRequestMethod("GET");\r
806             int responseCode = conn.getResponseCode();\r
807             logger.info("Sdc resource url - " + urlReworked + " , responseCode=" + responseCode);\r
808             try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {\r
809                 String response = IOUtils.toString(in);\r
810                 LoggingUtils.setResponseContext("0", "Get sdc resources success", this.getClass().getName());\r
811                 return response;\r
812             }\r
813         } catch (IOException e) {\r
814             LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
815             LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
816             logger.error("Exception occurred during query to SDC", e);\r
817             return "";\r
818         } catch (DecoderException e) {\r
819             LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
820             LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
821             logger.error("Exception when attempting to decode the Hex string", e);\r
822             throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);\r
823         } catch (GeneralSecurityException e) {\r
824             LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());\r
825             LoggingUtils.setErrorContext("900", "Get sdc resources error");\r
826             logger.error("Exception when attempting to decrypt the encrypted password", e);\r
827             throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);\r
828         } finally {\r
829             LoggingUtils.setTimeContext(startTime, new Date());\r
830             metricsLogger.info("getCldsServicesOrResourcesBasedOnURL completed");\r
831         }\r
832     }\r
833 \r
834     /**\r
835      * To create properties object by using cldsServicedata.\r
836      *\r
837      * @param globalProps\r
838      * @param cldsServiceData\r
839      * @return\r
840      * @throws IOException\r
841      *             In case of issues during the parsing of the Global Properties\r
842      */\r
843     public String createPropertiesObjectByUUID(CldsServiceData cldsServiceData) throws IOException {\r
844         String totalPropsStr;\r
845         ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
846         ObjectNode globalPropsJson = (ObjectNode) refProp.getJsonTemplate(CldsService.GLOBAL_PROPERTIES_KEY);\r
847         if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
848             // Objectnode to save all byservice, byvf , byvfc and byalarm nodes\r
849             ObjectNode byIdObjectNode = mapper.createObjectNode();\r
850             // To create vf ResourceUUID node with serviceInvariantUUID\r
851             ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(cldsServiceData);\r
852             byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVf);\r
853             // To create byVf and vfcResourceNode with vfResourceUUID\r
854             ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(cldsServiceData.getCldsVfs());\r
855             byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);\r
856             // To create byKpi\r
857             ObjectNode kpiObjectNode = mapper.createObjectNode();\r
858             if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
859                 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
860                     if (currCldsVfData != null) {\r
861                         createKpiObjectNodeByVfUuid(kpiObjectNode, currCldsVfData.getCldsKPIList());\r
862                     }\r
863                 }\r
864             }\r
865             byIdObjectNode.putPOJO("byKpi", kpiObjectNode);\r
866             // To create byVfc and alarmCondition with vfcResourceUUID\r
867             ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode();\r
868             if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
869                 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
870                     if (currCldsVfData != null) {\r
871                         createAlarmCondObjectNodeByVfcUuid(vfcResourceUuidObjectNode, currCldsVfData.getCldsVfcs());\r
872                     }\r
873                 }\r
874             }\r
875             byIdObjectNode.putPOJO("byVfc", vfcResourceUuidObjectNode);\r
876             // To create byAlarmCondition with alarmConditionKey\r
877             List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
878                     "alarmCondition");\r
879             ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(allAlarmConditions);\r
880             byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);\r
881             // To create byAlertDescription with AlertDescription\r
882             List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
883                     "alertDescription");\r
884             ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(allAlertDescriptions);\r
885             byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
886             globalPropsJson.putPOJO("shared", byIdObjectNode);\r
887             logger.info("Global properties JSON created with SDC info:" + globalPropsJson);\r
888         }\r
889         totalPropsStr = globalPropsJson.toString();\r
890         return totalPropsStr;\r
891     }\r
892 \r
893     /**\r
894      * Method to get alarm conditions/alert description from Service Data.\r
895      * \r
896      * @param cldsServiceData\r
897      *            CldsServiceData the Service Data to analyze\r
898      * @param eventName\r
899      *            The String event name that will be used to filter the alarm\r
900      *            list\r
901      * @return The list of CldsAlarmCondition for the event name specified\r
902      */\r
903     public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData,\r
904             String eventName) {\r
905         List<CldsAlarmCondition> alarmCondList = new ArrayList<>();\r
906         if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null\r
907                 && !cldsServiceData.getCldsVfs().isEmpty()) {\r
908             for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
909                 alarmCondList.addAll(getAllAlarmConditionsFromCldsVfData(currCldsVfData, eventName));\r
910             }\r
911         }\r
912         return alarmCondList;\r
913     }\r
914 \r
915     /**\r
916      * Method to get alarm conditions/alert description from VF Data.\r
917      * \r
918      * @param currCldsVfData\r
919      *            The Vf Data to analyze\r
920      * @param eventName\r
921      *            The String event name that will be used to filter the alarm\r
922      *            list\r
923      * @return The list of CldsAlarmCondition for the event name specified\r
924      */\r
925     private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfData(CldsVfData currCldsVfData, String eventName) {\r
926         List<CldsAlarmCondition> alarmCondList = new ArrayList<>();\r
927         if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {\r
928             for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {\r
929                 alarmCondList.addAll(getAllAlarmConditionsFromCldsVfcData(currCldsVfcData, eventName));\r
930             }\r
931         }\r
932         return alarmCondList;\r
933     }\r
934 \r
935     /**\r
936      * Method to get alarm conditions/alert description from VFC Data.\r
937      * \r
938      * @param currCldsVfcData\r
939      *            The VfC Data to analyze\r
940      * @param eventName\r
941      *            The String event name that will be used to filter the alarm\r
942      *            list\r
943      * @return The list of CldsAlarmCondition for the event name specified\r
944      */\r
945     private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfcData(CldsVfcData currCldsVfcData,\r
946             String eventName) {\r
947         List<CldsAlarmCondition> alarmCondList = new ArrayList<>();\r
948         if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null\r
949                 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
950             for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {\r
951                 if (currCldsAlarmCondition != null\r
952                         && currCldsAlarmCondition.getEventName().equalsIgnoreCase(eventName)) {\r
953                     alarmCondList.add(currCldsAlarmCondition);\r
954                 }\r
955             }\r
956         }\r
957         return alarmCondList;\r
958     }\r
959 \r
960     private ObjectNode createAlarmCondObjectNodeByAlarmKey(List<CldsAlarmCondition> cldsAlarmCondList) {\r
961         ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
962         ObjectNode alarmCondKeyNode = mapper.createObjectNode();\r
963         if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {\r
964             for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {\r
965                 if (currCldsAlarmCondition != null) {\r
966                     ObjectNode alarmCondNode = mapper.createObjectNode();\r
967                     alarmCondNode.put("eventSourceType", currCldsAlarmCondition.getEventSourceType());\r
968                     alarmCondNode.put("eventSeverity", currCldsAlarmCondition.getSeverity());\r
969                     alarmCondKeyNode.putPOJO(currCldsAlarmCondition.getAlarmConditionKey(), alarmCondNode);\r
970                 }\r
971             }\r
972         } else {\r
973             ObjectNode alarmCondNode = mapper.createObjectNode();\r
974             alarmCondNode.put("eventSourceType", "");\r
975             alarmCondNode.put("eventSeverity", "");\r
976             alarmCondKeyNode.putPOJO("", alarmCondNode);\r
977         }\r
978         return alarmCondKeyNode;\r
979     }\r
980 \r
981     private ObjectNode createVfObjectNodeByServiceInvariantUuid(CldsServiceData cldsServiceData) {\r
982         ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
983         ObjectNode invariantUuidObjectNode = mapper.createObjectNode();\r
984         ObjectNode vfObjectNode = mapper.createObjectNode();\r
985         ObjectNode vfUuidNode = mapper.createObjectNode();\r
986         List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();\r
987         if (cldsVfsList != null && !cldsVfsList.isEmpty()) {\r
988             for (CldsVfData currCldsVfData : cldsVfsList) {\r
989                 if (currCldsVfData != null) {\r
990                     vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());\r
991                 }\r
992             }\r
993         } else {\r
994             vfUuidNode.put("", "");\r
995         }\r
996         vfObjectNode.putPOJO("vf", vfUuidNode);\r
997         invariantUuidObjectNode.putPOJO(cldsServiceData.getServiceInvariantUUID(), vfObjectNode);\r
998         return invariantUuidObjectNode;\r
999     }\r
1000 \r
1001     private void createKpiObjectNodeByVfUuid(ObjectNode vfResourceUuidObjectNode,\r
1002             List<CldsVfKPIData> cldsVfKpiDataList) {\r
1003         ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
1004         if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {\r
1005             for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {\r
1006                 if (currCldsVfKpiData != null) {\r
1007                     ObjectNode thresholdNameObjectNode = mapper.createObjectNode();\r
1008                     ObjectNode fieldPathObjectNode = mapper.createObjectNode();\r
1009                     ObjectNode nfNamingCodeNode = mapper.createObjectNode();\r
1010                     fieldPathObjectNode.put(currCldsVfKpiData.getFieldPathValue(),\r
1011                             currCldsVfKpiData.getFieldPathValue());\r
1012                     nfNamingCodeNode.put(currCldsVfKpiData.getNfNamingValue(), currCldsVfKpiData.getNfNamingValue());\r
1013                     thresholdNameObjectNode.putPOJO("fieldPath", fieldPathObjectNode);\r
1014                     thresholdNameObjectNode.putPOJO("nfNamingCode", nfNamingCodeNode);\r
1015                     vfResourceUuidObjectNode.putPOJO(currCldsVfKpiData.getThresholdValue(), thresholdNameObjectNode);\r
1016                 }\r
1017             }\r
1018         }\r
1019     }\r
1020 \r
1021     private void createAlarmCondObjectNodeByVfcUuid(ObjectNode vfcResourceUuidObjectNode,\r
1022             List<CldsVfcData> cldsVfcDataList) {\r
1023         ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
1024         ObjectNode vfcObjectNode = mapper.createObjectNode();\r
1025         ObjectNode alarmCondNode = mapper.createObjectNode();\r
1026         ObjectNode alertDescNode = mapper.createObjectNode();\r
1027         if (cldsVfcDataList != null && !cldsVfcDataList.isEmpty()) {\r
1028             for (CldsVfcData currCldsVfcData : cldsVfcDataList) {\r
1029                 if (currCldsVfcData != null) {\r
1030                     if (currCldsVfcData.getCldsAlarmConditions() != null\r
1031                             && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
1032                         for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {\r
1033                             if ("alarmCondition".equalsIgnoreCase(currCldsAlarmCondition.getEventName())) {\r
1034                                 alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
1035                                         currCldsAlarmCondition.getAlarmConditionKey());\r
1036                             } else {\r
1037                                 alertDescNode.put(currCldsAlarmCondition.getAlarmConditionKey(),\r
1038                                         currCldsAlarmCondition.getAlarmConditionKey());\r
1039                             }\r
1040                         }\r
1041                     }\r
1042                     vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);\r
1043                     vfcObjectNode.putPOJO("alertDescription", alertDescNode);\r
1044                     vfcResourceUuidObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), vfcObjectNode);\r
1045                 }\r
1046             }\r
1047         } else {\r
1048             alarmCondNode.put("", "");\r
1049             vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);\r
1050             alertDescNode.put("", "");\r
1051             vfcObjectNode.putPOJO("alertDescription", alarmCondNode);\r
1052             vfcResourceUuidObjectNode.putPOJO("", vfcObjectNode);\r
1053         }\r
1054     }\r
1055 \r
1056     /**\r
1057      * Method to create vfc and kpi nodes inside vf node\r
1058      * \r
1059      * @param mapper\r
1060      * @param cldsVfDataList\r
1061      * @return\r
1062      */\r
1063     private ObjectNode createVfcObjectNodeByVfUuid(List<CldsVfData> cldsVfDataList) {\r
1064         ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
1065         ObjectNode vfUuidObjectNode = mapper.createObjectNode();\r
1066         if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
1067             for (CldsVfData currCldsVfData : cldsVfDataList) {\r
1068                 if (currCldsVfData != null) {\r
1069                     ObjectNode vfObjectNode = mapper.createObjectNode();\r
1070                     ObjectNode vfcUuidNode = mapper.createObjectNode();\r
1071                     ObjectNode kpiObjectNode = mapper.createObjectNode();\r
1072                     if (currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {\r
1073                         for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {\r
1074                             if (currCldsVfcData.getCldsAlarmConditions() != null\r
1075                                     && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {\r
1076                                 vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),\r
1077                                         currCldsVfcData.getVfcName());\r
1078                             }\r
1079                         }\r
1080                     } else {\r
1081                         vfcUuidNode.put("", "");\r
1082                     }\r
1083                     if (currCldsVfData.getCldsKPIList() != null && !currCldsVfData.getCldsKPIList().isEmpty()) {\r
1084                         for (CldsVfKPIData currCldsVfKPIData : currCldsVfData.getCldsKPIList()) {\r
1085                             kpiObjectNode.put(currCldsVfKPIData.getThresholdValue(),\r
1086                                     currCldsVfKPIData.getThresholdValue());\r
1087                         }\r
1088                     } else {\r
1089                         kpiObjectNode.put("", "");\r
1090                     }\r
1091                     vfObjectNode.putPOJO("vfc", vfcUuidNode);\r
1092                     vfObjectNode.putPOJO("kpi", kpiObjectNode);\r
1093                     vfUuidObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfObjectNode);\r
1094                 }\r
1095             }\r
1096         } else {\r
1097             ObjectNode vfcUuidNode = mapper.createObjectNode();\r
1098             vfcUuidNode.put("", "");\r
1099             ObjectNode vfcObjectNode = mapper.createObjectNode();\r
1100             vfcObjectNode.putPOJO("vfc", vfcUuidNode);\r
1101             vfUuidObjectNode.putPOJO("", vfcObjectNode);\r
1102         }\r
1103         return vfUuidObjectNode;\r
1104     }\r
1105 \r
1106     /**\r
1107      * This method searches the equivalent artifact UUID for a specific\r
1108      * artifactName in a SdcServiceDetail.\r
1109      * \r
1110      * @param cldsSdcServiceDetail\r
1111      *            The SdcServiceDetail that will be analyzed\r
1112      * @param artifactName\r
1113      *            The artifact name that will be searched\r
1114      * @return The artifact UUID found\r
1115      */\r
1116     public String getArtifactIdIfArtifactAlreadyExists(SdcServiceDetail cldsSdcServiceDetail, String artifactName) {\r
1117         String artifactUuid = null;\r
1118         boolean artifactExists = false;\r
1119         if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null\r
1120                 && !cldsSdcServiceDetail.getResources().isEmpty()) {\r
1121             for (SdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) {\r
1122                 if (artifactExists) {\r
1123                     break;\r
1124                 }\r
1125                 if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null\r
1126                         && !currCldsSdcResource.getArtifacts().isEmpty()) {\r
1127                     for (SdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {\r
1128                         if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null\r
1129                                 && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {\r
1130                             artifactUuid = currCldsSdcArtifact.getArtifactUUID();\r
1131                             artifactExists = true;\r
1132                             break;\r
1133                         }\r
1134                     }\r
1135                 }\r
1136             }\r
1137         }\r
1138         return artifactUuid;\r
1139     }\r
1140 \r
1141     // To get all sdc VF/VFC Resources basic info.\r
1142     private List<SdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {\r
1143         String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);\r
1144         String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;\r
1145         String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl);\r
1146         return removeDuplicateSdcResourceBasicInfo(getAllSdcResourcesListFromJson(allSdcVfcResources));\r
1147     }\r
1148 \r
1149     private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,\r
1150             List<SdcResourceBasicInfo> resourceInfoList) {\r
1151         String resourceUuid = null;\r
1152         if (resourceInfoList != null && !resourceInfoList.isEmpty()) {\r
1153             for (SdcResourceBasicInfo currResource : resourceInfoList) {\r
1154                 if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null\r
1155                         && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {\r
1156                     resourceUuid = currResource.getUuid();\r
1157                     break;\r
1158                 }\r
1159             }\r
1160         }\r
1161         return resourceUuid;\r
1162     }\r
1163 \r
1164     // Method to get service invariant uuid from model properties.\r
1165     private String getServiceInvariantUuidFromProps(ModelProperties props) {\r
1166         String invariantUuid = "";\r
1167         Global globalProps = props.getGlobal();\r
1168         if (globalProps != null && globalProps.getService() != null) {\r
1169             invariantUuid = globalProps.getService();\r
1170         }\r
1171         return invariantUuid;\r
1172     }\r
1173 \r
1174     /**\r
1175      * This method upload the BluePrint to SDC.\r
1176      * \r
1177      * @param prop\r
1178      *            The Clds model Properties\r
1179      * @param userid\r
1180      *            The user id for SDC\r
1181      * @param sdcReqUrlsList\r
1182      *            The list of SDC URL to try\r
1183      * @param formattedSdcReq\r
1184      *            The blueprint to upload\r
1185      * @param formattedSdcLocationReq\r
1186      *            THe location Blueprint to upload\r
1187      * @param artifactName\r
1188      *            The artifact name from where we can get the Artifact UUID\r
1189      * @param locationArtifactName\r
1190      *            The location artifact name from where we can get the Artifact\r
1191      *            UUID\r
1192      * @throws GeneralSecurityException\r
1193      *             In case of issues with the decryting the encrypted password\r
1194      * @throws DecoderException\r
1195      *             In case of issues with the decoding of the Hex String\r
1196      */\r
1197     public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,\r
1198             String formattedSdcLocationReq, String artifactName, String locationArtifactName)\r
1199             throws GeneralSecurityException, DecoderException {\r
1200         logger.info("userid=" + userid);\r
1201         String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);\r
1202         if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {\r
1203             for (String url : sdcReqUrlsList) {\r
1204                 if (url != null) {\r
1205                     String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
1206                     logger.info("ServiceUUID used before upload in url:" + originalServiceUuid);\r
1207                     String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);\r
1208                     SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
1209                     String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
1210                             artifactName);\r
1211                     // Upload artifacts to sdc\r
1212                     String updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;\r
1213                     String responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcReq);\r
1214                     logger.info("value of sdc Response of uploading to sdc :" + responseStr);\r
1215                     String updatedServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
1216                     if (!originalServiceUuid.equalsIgnoreCase(updatedServiceUuid)) {\r
1217                         url = url.replace(originalServiceUuid, updatedServiceUuid);\r
1218                     }\r
1219                     logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUuid);\r
1220                     sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);\r
1221                     cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
1222                     uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,\r
1223                             locationArtifactName);\r
1224                     // To send location information also to sdc\r
1225                     updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;\r
1226                     responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcLocationReq);\r
1227                     logger.info("value of sdc Response of uploading location to sdc :" + responseStr);\r
1228                 }\r
1229             }\r
1230         }\r
1231     }\r
1232 \r
1233     /**\r
1234      * Method to delete blueprint and location json artifacts from sdc\r
1235      * \r
1236      * @param prop\r
1237      * @param userid\r
1238      * @param sdcReqUrlsList\r
1239      * @param artifactName\r
1240      * @param locationArtifactName\r
1241      * @throws GeneralSecurityException\r
1242      * @throws DecoderException\r
1243      */\r
1244     public void deleteArtifactsFromSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList,\r
1245             String artifactName, String locationArtifactName) throws GeneralSecurityException, DecoderException {\r
1246         String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);\r
1247         for (String url : sdcReqUrlsList) {\r
1248             String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
1249             logger.info("ServiceUUID used before deleting in url:" + originalServiceUuid);\r
1250             String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);\r
1251             SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
1252             String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, artifactName);\r
1253             String responseStr = deleteArtifact(userid, url, uploadedArtifactUuid);\r
1254             logger.info("value of sdc Response of deleting blueprint from sdc :" + responseStr);\r
1255             String updatedServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);\r
1256             if (!originalServiceUuid.equalsIgnoreCase(updatedServiceUuid)) {\r
1257                 url = url.replace(originalServiceUuid, updatedServiceUuid);\r
1258             }\r
1259             logger.info("ServiceUUID used after delete in ulr:" + updatedServiceUuid);\r
1260             sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);\r
1261             cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);\r
1262             uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail, locationArtifactName);\r
1263             responseStr = deleteArtifact(userid, url, uploadedArtifactUuid);\r
1264             logger.info("value of sdc Response of deleting location json from sdc :" + responseStr);\r
1265         }\r
1266     }\r
1267 \r
1268     private String deleteArtifact(String userid, String url, String uploadedArtifactUuid) {\r
1269         try {\r
1270             String responseStr = "";\r
1271             if (uploadedArtifactUuid != null && !uploadedArtifactUuid.isEmpty()) {\r
1272                 logger.info("userid=" + userid);\r
1273                 String basicAuth = getSdcBasicAuth();\r
1274                 String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");\r
1275                 url = url + "/" + uploadedArtifactUuid;\r
1276                 URL urlObj = new URL(url);\r
1277                 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
1278                 conn.setDoOutput(true);\r
1279                 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId);\r
1280                 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);\r
1281                 conn.setRequestProperty("USER_ID", userid);\r
1282                 conn.setRequestMethod("DELETE");\r
1283                 conn.setRequestProperty("charset", "utf-8");\r
1284                 conn.setUseCaches(false);\r
1285                 conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME),\r
1286                         LoggingUtils.getRequestId());\r
1287                 boolean requestFailed = true;\r
1288                 int responseCode = conn.getResponseCode();\r
1289                 logger.info("responseCode=" + responseCode);\r
1290                 if (responseCode == 200) {\r
1291                     requestFailed = false;\r
1292                 }\r
1293                 responseStr = getResponse(conn);\r
1294                 if (responseStr != null && requestFailed) {\r
1295                     logger.error("requestFailed - responseStr=" + responseStr);\r
1296                     throw new BadRequestException(responseStr);\r
1297                 }\r
1298             }\r
1299             return responseStr;\r
1300         } catch (IOException | DecoderException | GeneralSecurityException e) {\r
1301             logger.error("Exception when attempting to communicate with SDC", e);\r
1302             throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);\r
1303         }\r
1304     }\r
1305 }\r