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