Merge "Code improvement"
[clamp.git] / src / main / java / org / onap / clamp / clds / client / SdcCatalogServices.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.client;
25
26 import java.io.BufferedReader;
27 import java.io.DataOutputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import java.io.Reader;
32 import java.io.StringReader;
33 import java.net.HttpURLConnection;
34 import java.net.URL;
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.Date;
38 import java.util.Iterator;
39 import java.util.List;
40
41 import org.apache.commons.csv.CSVFormat;
42 import org.apache.commons.csv.CSVRecord;
43 import org.apache.commons.lang3.StringUtils;
44 import org.onap.clamp.clds.client.req.SdcReq;
45 import org.onap.clamp.clds.model.CldsAlarmCondition;
46 import org.onap.clamp.clds.model.CldsDBServiceCache;
47 import org.onap.clamp.clds.model.CldsSdcArtifact;
48 import org.onap.clamp.clds.model.CldsSdcResource;
49 import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo;
50 import org.onap.clamp.clds.model.CldsSdcServiceDetail;
51 import org.onap.clamp.clds.model.CldsSdcServiceInfo;
52 import org.onap.clamp.clds.model.CldsServiceData;
53 import org.onap.clamp.clds.model.CldsVfData;
54 import org.onap.clamp.clds.model.CldsVfKPIData;
55 import org.onap.clamp.clds.model.CldsVfcData;
56 import org.onap.clamp.clds.model.prop.ModelProperties;
57 import org.onap.clamp.clds.model.refprop.RefProp;
58 import org.onap.clamp.clds.util.LoggingUtils;
59 import org.springframework.beans.factory.annotation.Autowired;
60
61 import com.att.eelf.configuration.EELFLogger;
62 import com.att.eelf.configuration.EELFManager;
63 import com.fasterxml.jackson.core.JsonParseException;
64 import com.fasterxml.jackson.core.JsonProcessingException;
65 import com.fasterxml.jackson.databind.JsonMappingException;
66 import com.fasterxml.jackson.databind.JsonNode;
67 import com.fasterxml.jackson.databind.ObjectMapper;
68 import com.fasterxml.jackson.databind.node.ArrayNode;
69 import com.fasterxml.jackson.databind.node.ObjectNode;
70 import com.fasterxml.jackson.databind.node.TextNode;
71
72 public class SdcCatalogServices {
73     protected static final EELFLogger logger            = EELFManager.getInstance().getLogger(SdcCatalogServices.class);
74     protected static final EELFLogger metricsLogger     = EELFManager.getInstance().getMetricsLogger();
75
76     private static final String       RESOURCE_VF_TYPE  = "VF";
77     private static final String       RESOURCE_VFC_TYPE = "VFC";
78
79     @Autowired
80     private RefProp                   refProp;
81
82     public String getSdcServicesInformation(String uuid) throws Exception {
83         Date startTime = new Date();
84         String baseUrl = refProp.getStringValue("sdc.serviceUrl");
85         String basicAuth = SdcReq.getSdcBasicAuth(refProp);
86         try {
87             String url = baseUrl;
88             if (uuid != null) {
89                 url = baseUrl + "/" + uuid + "/metadata";
90             }
91             URL urlObj = new URL(url);
92
93             HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
94
95             conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
96             conn.setRequestProperty("Authorization", basicAuth);
97             conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
98             conn.setRequestMethod("GET");
99
100             String resp = getResponse(conn);
101             if (resp != null) {
102                 logger.info(resp.toString());
103                 return resp;
104             }
105             // metrics log
106             LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
107
108         } catch (Exception e) {
109             LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());
110             LoggingUtils.setErrorContext("900", "Get sdc services error");
111             logger.error("not able to get any service information from sdc for uuid:" + uuid + " , exception is - " + e.getMessage());
112         }
113         LoggingUtils.setTimeContext(startTime, new Date());
114         LoggingUtils.setTargetContext("SDC", "Get Services");
115         metricsLogger.info("Get sdc services information");
116
117         return "";
118     }
119
120     /**
121      * To remove duplicate serviceUUIDs from sdc services List
122      *
123      * @param rawCldsSdcServiceList
124      * @return
125      */
126     public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {
127         List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;
128         if (rawCldsSdcServiceList != null && rawCldsSdcServiceList.size() > 0) {
129             // sort list
130             Collections.sort(rawCldsSdcServiceList);
131             // and then take only the services with the max version (last in the
132             // list with the same name)
133             cldsSdcServiceInfoList = new ArrayList<>();
134             for (int i = 1; i < rawCldsSdcServiceList.size(); i++) {
135                 // compare name with previous - if not equal, then keep the
136                 // previous (it's the last with that name)
137                 CldsSdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);
138                 if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {
139                     cldsSdcServiceInfoList.add(prev);
140                 }
141             }
142             // add the last in the list
143             cldsSdcServiceInfoList.add(rawCldsSdcServiceList.get(rawCldsSdcServiceList.size() - 1));
144         }
145         return cldsSdcServiceInfoList;
146     }
147
148     /**
149      * To remove duplicate serviceUUIDs from sdc resources List
150      *
151      * @param rawCldsSdcResourceList
152      * @return
153      */
154     public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {
155         List<CldsSdcResource> cldsSdcResourceList = null;
156         if (rawCldsSdcResourceList != null && rawCldsSdcResourceList.size() > 0) {
157             // sort list
158             Collections.sort(rawCldsSdcResourceList);
159             // and then take only the resources with the max version (last in
160             // the list with the same name)
161             cldsSdcResourceList = new ArrayList<>();
162             for (int i = 1; i < rawCldsSdcResourceList.size(); i++) {
163                 // compare name with previous - if not equal, then keep the
164                 // previous (it's the last with that name)
165                 CldsSdcResource prev = rawCldsSdcResourceList.get(i - 1);
166                 if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {
167                     cldsSdcResourceList.add(prev);
168                 }
169             }
170             // add the last in the list
171             cldsSdcResourceList.add(rawCldsSdcResourceList.get(rawCldsSdcResourceList.size() - 1));
172         }
173         return cldsSdcResourceList;
174     }
175
176     /**
177      * To remove duplicate basic resources with same resourceUUIDs
178      *
179      * @param rawCldsSdcResourceListBasicList
180      * @return
181      */
182     public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(
183             List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {
184         List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;
185         if (rawCldsSdcResourceListBasicList != null && rawCldsSdcResourceListBasicList.size() > 0) {
186             // sort list
187             Collections.sort(rawCldsSdcResourceListBasicList);
188             // and then take only the resources with the max version (last in
189             // the list with the same name)
190             cldsSdcResourceBasicInfoList = new ArrayList<>();
191             for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {
192                 // compare name with previous - if not equal, then keep the
193                 // previous (it's the last with that name)
194                 CldsSdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);
195                 if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {
196                     cldsSdcResourceBasicInfoList.add(prev);
197                 }
198             }
199             // add the last in the list
200             cldsSdcResourceBasicInfoList
201                     .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));
202         }
203         return cldsSdcResourceBasicInfoList;
204     }
205
206     /**
207      * To get ServiceUUID by using serviceInvariantUUID
208      *
209      * @param invariantId
210      * @return
211      * @throws Exception
212      */
213     public String getServiceUuidFromServiceInvariantId(String invariantId) throws Exception {
214         String serviceUuid = "";
215         String responseStr = getSdcServicesInformation(null);
216         List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);
217         List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);
218         if (cldsSdcServicesList != null && cldsSdcServicesList.size() > 0) {
219             for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {
220                 if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null
221                         && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {
222                     serviceUuid = currCldsSdcServiceInfo.getUuid();
223                     break;
224                 }
225             }
226         }
227         return serviceUuid;
228     }
229
230     /**
231      * To get CldsAsdsServiceInfo class by parsing json string
232      *
233      * @param jsonStr
234      * @return
235      * @throws JsonParseException
236      * @throws JsonMappingException
237      * @throws IOException
238      */
239     public List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) throws IOException {
240         ObjectMapper objectMapper = new ObjectMapper();
241         if (StringUtils.isBlank(jsonStr)) {
242             return null;
243         }
244         return objectMapper.readValue(jsonStr,
245                 objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));
246     }
247
248     /**
249      * To get List<CldsSdcResourceBasicInfo> class by parsing json string
250      *
251      * @param jsonStr
252      * @return
253      * @throws JsonParseException
254      * @throws JsonMappingException
255      * @throws IOException
256      */
257     public List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) throws IOException {
258         ObjectMapper objectMapper = new ObjectMapper();
259         if (StringUtils.isBlank(jsonStr)) {
260             return null;
261         }
262         return objectMapper.readValue(jsonStr,
263                 objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));
264     }
265
266     /**
267      * To get CldsAsdsResource class by parsing json string
268      *
269      * @param jsonStr
270      * @return
271      * @throws JsonParseException
272      * @throws JsonMappingException
273      * @throws IOException
274      */
275     public CldsSdcResource getCldsSdcResourceFromJson(String jsonStr) throws IOException {
276         ObjectMapper objectMapper = new ObjectMapper();
277         return objectMapper.readValue(jsonStr, CldsSdcResource.class);
278     }
279
280     /**
281      * To get CldsSdcServiceDetail by parsing json string
282      *
283      * @param jsonStr
284      * @return
285      * @throws JsonParseException
286      * @throws JsonMappingException
287      * @throws IOException
288      */
289     public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) throws IOException {
290         ObjectMapper objectMapper = new ObjectMapper();
291         return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);
292     }
293
294     /**
295      * To upload artifact to sdc based on serviceUUID and resourcename on url
296      *
297      * @param prop
298      * @param userid
299      * @param url
300      * @param formatttedSdcReq
301      * @return
302      * @throws Exception
303      */
304     public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formatttedSdcReq)
305             throws Exception {
306         // Verify whether it is triggered by Validation Test button from UI
307         if (prop.isTest()) {
308             return "sdc artifact upload not executed for test action";
309         }
310         logger.info("userid=" + userid);
311         String md5Text = SdcReq.calculateMD5ByString(formatttedSdcReq);
312         byte[] postData = SdcReq.stringToByteArray(formatttedSdcReq);
313         int postDataLength = postData.length;
314         HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);
315         try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
316             wr.write(postData);
317         }
318         boolean requestFailed = true;
319         int responseCode = conn.getResponseCode();
320         logger.info("responseCode=" + responseCode);
321         if (responseCode == 200) {
322             requestFailed = false;
323         }
324
325         String responseStr = getResponse(conn);
326         if (responseStr != null) {
327             if (requestFailed) {
328                 logger.error("requestFailed - responseStr=" + responseStr);
329                 throw new Exception(responseStr);
330             }
331         }
332         return responseStr;
333     }
334
335     private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text)
336             throws IOException {
337         logger.info("userid=" + userid);
338         String basicAuth = SdcReq.getSdcBasicAuth(refProp);
339         String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");
340         URL urlObj = new URL(url);
341         HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
342         conn.setDoOutput(true);
343         conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);
344         conn.setRequestProperty("Authorization", basicAuth);
345         conn.setRequestProperty("Content-Type", "application/json");
346         conn.setRequestProperty("Content-MD5", md5Text);
347         conn.setRequestProperty("USER_ID", userid);
348         conn.setRequestMethod("POST");
349         conn.setRequestProperty("charset", "utf-8");
350         conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
351         conn.setUseCaches(false);
352         return conn;
353     }
354
355     private String getResponse(HttpURLConnection conn) throws IOException {
356         try (InputStream is = getInputStream(conn)) {
357             if (is != null) {
358                 try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
359                     StringBuffer response = new StringBuffer();
360                     String inputLine;
361                     while ((inputLine = in.readLine()) != null) {
362                         response.append(inputLine);
363                     }
364                     return response.toString();
365                 }
366             }
367         }
368         return null;
369     }
370
371     private InputStream getInputStream(HttpURLConnection conn) throws IOException {
372         InputStream inStream = conn.getErrorStream();
373         if (inStream == null) {
374             inStream = conn.getInputStream();
375         }
376         return inStream;
377     }
378
379     public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData)
380             throws IOException {
381         CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();
382         cldsDbServiceCache.setCldsDataInstream(cldsServiceData);
383         cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());
384         cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());
385         return cldsDbServiceCache;
386     }
387
388     public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) throws Exception {
389         boolean expired = false;
390         if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
391             String cachedServiceUuid = cldsServiceData.getServiceUUID();
392             String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID());
393             String defaultRecordAge = refProp.getStringValue("CLDS_SERVICE_CACHE_MAX_SECONDS");
394             if ((!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null
395                     && cldsServiceData.getAgeOfRecord() > Long.parseLong(defaultRecordAge))) {
396                 expired = true;
397             }
398         } else {
399             expired = true;
400         }
401         return expired;
402     }
403
404     public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid) throws Exception {
405         String url = refProp.getStringValue("sdc.serviceUrl");
406         String catalogUrl = refProp.getStringValue("sdc.catalog.url");
407         String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);
408         String serviceDetailUrl = url + "/" + serviceUuid + "/metadata";
409         String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl, false);
410         ObjectMapper objectMapper = new ObjectMapper();
411         CldsServiceData cldsServiceData = new CldsServiceData();
412         if (responseStr != null) {
413             CldsSdcServiceDetail cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);
414             cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());
415             cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());
416
417             // To remove duplicate resources from serviceDetail and add valid
418             // vfs to service
419             if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {
420                 List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(
421                         cldsSdcServiceDetail.getResources());
422                 if (cldsSdcResourceList != null && cldsSdcResourceList.size() > 0) {
423                     List<CldsVfData> cldsVfDataList = new ArrayList<>();
424                     for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {
425                         if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null
426                                 && currCldsSdcResource.getResoucreType().equalsIgnoreCase("VF")) {
427                             CldsVfData currCldsVfData = new CldsVfData();
428                             currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());
429                             currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());
430                             cldsVfDataList.add(currCldsVfData);
431                         }
432                     }
433                     cldsServiceData.setCldsVfs(cldsVfDataList);
434                     // For each vf in the list , add all vfc's
435                     getAllVfcForVfList(cldsVfDataList, catalogUrl);
436                     logger.info("value of cldsServiceData:" + cldsServiceData);
437                     logger.info("value of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());
438                 }
439             }
440         }
441         return cldsServiceData;
442     }
443
444     /**
445      * @param cldsVfDataList
446      * @throws IOException
447      */
448     private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl) throws IOException {
449         // todo : refact this..
450         if (cldsVfDataList != null && cldsVfDataList.size() > 0) {
451             List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVFCResourcesBasedOnResourceType(
452                     RESOURCE_VF_TYPE);
453             List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVFCResourcesBasedOnResourceType(
454                     RESOURCE_VFC_TYPE);
455             for (CldsVfData currCldsVfData : cldsVfDataList) {
456                 if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) {
457                     String resourceUuid = getResourceUuidFromResourceInvariantUuid(
458                             currCldsVfData.getVfInvariantResourceUUID(), allVfResources);
459                     if (resourceUuid != null) {
460                         String vfResourceUuidUrl = catalogUrl + "resources" + "/" + resourceUuid + "/metadata";
461                         String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl, false);
462                         if (vfResponse != null) {
463                             // Below 2 line are to get the KPI(field path) data
464                             // associated with the VF's
465                             List<CldsVfKPIData> cldsVfKPIDataList = getFieldPathFromVF(vfResponse);
466                             currCldsVfData.setCldsKPIList(cldsVfKPIDataList);
467
468                             List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);
469                             if (vfcDataListFromVfResponse != null) {
470                                 currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);
471                                 if (vfcDataListFromVfResponse.size() > 0) {
472                                     // To get artifacts for every VFC and get
473                                     // alarm conditions from artifact
474                                     for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {
475                                         if (currCldsVfcData != null
476                                                 && currCldsVfcData.getVfcInvariantResourceUUID() != null) {
477                                             String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(
478                                                     currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);
479                                             if (resourceVfcUuid != null) {
480                                                 String vfcResourceUuidUrl = catalogUrl + "resources" + "/"
481                                                         + resourceVfcUuid + "/metadata";
482                                                 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(
483                                                         vfcResourceUuidUrl, false);
484                                                 if (vfcResponse != null) {
485                                                     List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(
486                                                             vfcResponse);
487                                                     currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc);
488                                                 }
489                                             } else {
490                                                 logger.info("No resourceVFC UUID found for given invariantID:"
491                                                         + currCldsVfcData.getVfcInvariantResourceUUID());
492                                             }
493                                         }
494                                     }
495                                 }
496                             }
497                         }
498                     } else {
499                         logger.info("No resourceUUID found for given invariantREsourceUUID:"
500                                 + currCldsVfData.getVfInvariantResourceUUID());
501                     }
502                 }
503             }
504         }
505     }
506
507     private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws IOException {
508         ObjectMapper mapper = new ObjectMapper();
509         ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
510         ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
511         List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
512         if (vfcArrayNode != null && vfcArrayNode.size() > 0) {
513             for (int index = 0; index < vfcArrayNode.size(); index++) {
514                 CldsVfcData currCldsVfcData = new CldsVfcData();
515                 ObjectNode currVfcNode = (ObjectNode) vfcArrayNode.get(index);
516                 TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");
517                 if (resourceTypeNode != null && resourceTypeNode.textValue().equalsIgnoreCase("VFC")) {
518                     TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");
519                     TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID");
520                     currCldsVfcData.setVfcName(vfcResourceName.textValue());
521                     currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue());
522                     cldsVfcDataList.add(currCldsVfcData);
523                 }
524             }
525         }
526         return cldsVfcDataList;
527     }
528
529     private String removeUnwantedBracesFromString(String id) {
530         if (id != null && id.contains("\"")) {
531             id = id.replaceAll("\"", "");
532         }
533         return id;
534     }
535
536     private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws IOException {
537         List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
538         ObjectMapper mapper = new ObjectMapper();
539         ObjectNode vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
540         ArrayNode artifactsArrayNode = (ArrayNode) vfcResponseNode.get("artifacts");
541
542         if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
543             for (int index = 0; index < artifactsArrayNode.size(); index++) {
544                 ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);
545                 TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");
546                 if (artifactUrlNode != null) {
547                     String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());
548                     cldsAlarmConditionList.addAll(parseCsvToGetAlarmConditions(responsesFromArtifactUrl));
549                     logger.info(responsesFromArtifactUrl);
550                 }
551             }
552         }
553         return cldsAlarmConditionList;
554     }
555
556     private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) throws IOException {
557         List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
558         Reader alarmReader = new StringReader(allAlarmCondsValues);
559         Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
560         if (records != null) {
561             Iterator<CSVRecord> it = records.iterator();
562             if (it.hasNext()) {
563                 it.next();
564             }
565             it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));
566         }
567         return cldsAlarmConditionList;
568     }
569
570     // Method to get the artifact for any particular VF
571     private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws JsonProcessingException, IOException {
572         List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();
573         ObjectMapper mapper = new ObjectMapper();
574         ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
575         ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");
576
577         if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
578             for (int index = 0; index < artifactsArrayNode.size(); index++) {
579                 ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);
580                 TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");
581                 TextNode artifactNameNode = (TextNode) currArtifactNode.get("artifactName");
582                 String artifactName = "";
583                 if (artifactNameNode != null) {
584                     artifactName = artifactNameNode.textValue();
585                     artifactName = artifactName.substring(artifactName.lastIndexOf(".") + 1);
586                 }
587                 if (artifactUrlNode != null && artifactName != null && !artifactName.isEmpty()
588                         && artifactName.equalsIgnoreCase("csv")) {
589                     String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());
590                     cldsVfKPIDataList.addAll(parseCsvToGetFieldPath(responsesFromArtifactUrl));
591                     logger.info(responsesFromArtifactUrl);
592                 }
593             }
594         }
595         return cldsVfKPIDataList;
596     }
597
598     private CldsVfKPIData convertCsvRecordToKpiData(CSVRecord record) {
599         if (record.size() < 6) {
600             logger.debug("invalid csv field path Record,total columns less than 6: " + record);
601             return null;
602         }
603
604         if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
605                 || StringUtils.isBlank(record.get(5))) {
606             logger.debug("Invalid csv field path Record,one of column is having blank value : " + record);
607             return null;
608         }
609
610         CldsVfKPIData cldsVfKPIData = new CldsVfKPIData();
611         cldsVfKPIData.setNfNamingCode(record.get(0).trim());
612         cldsVfKPIData.setNfNamingValue(record.get(1).trim());
613
614         cldsVfKPIData.setFieldPath(record.get(2).trim());
615         cldsVfKPIData.setFieldPathValue(record.get(3).trim());
616
617         cldsVfKPIData.setThresholdName(record.get(4).trim());
618         cldsVfKPIData.setThresholdValue(record.get(5).trim());
619         return cldsVfKPIData;
620
621     }
622
623     // Method to get the artifactURL Data and set the CldsVfKPIData node
624     private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) throws IOException {
625         List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<CldsVfKPIData>();
626         Reader alarmReader = new StringReader(allFieldPathValues);
627         Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
628         if (records != null) {
629             for (CSVRecord record : records) {
630                 CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);
631                 if (kpiData != null) {
632                     cldsVfKPIDataList.add(kpiData);
633                 }
634             }
635         }
636         return cldsVfKPIDataList;
637     }
638
639     private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {
640         if (record == null) {
641             return;
642         }
643         if (record.size() < 5) {
644             logger.debug("invalid csv alarm Record,total columns less than 5: " + record);
645             return;
646         }
647         if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
648                 || StringUtils.isBlank(record.get(4))) {
649             logger.debug("invalid csv alarm Record,one of column is having blank value : " + record);
650             return;
651         }
652         CldsAlarmCondition cldsAlarmCondition = new CldsAlarmCondition();
653         cldsAlarmCondition.setEventSourceType(record.get(1));
654         cldsAlarmCondition.setAlarmConditionKey(record.get(3));
655         cldsAlarmCondition.setSeverity(record.get(4));
656         cldsAlarmConditionList.add(cldsAlarmCondition);
657     }
658
659     public String getResponsesFromArtifactUrl(String artifactsUrl) throws IOException {
660         String hostUrl = refProp.getStringValue("sdc.hostUrl");
661         artifactsUrl = artifactsUrl.replaceAll("\"", "");
662         String artifactUrl = hostUrl + artifactsUrl;
663         logger.info("value of artifactURl:" + artifactUrl);
664         String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl, true);
665         logger.info("value of artifactResponse:" + currArtifactResponse);
666         return currArtifactResponse;
667     }
668
669     /**
670      * Service to services/resources/artifacts from sdc.Pass alarmConditions as
671      * true to get alarmconditons from artifact url and else it is false
672      *
673      * @param url
674      * @param alarmConditions
675      * @return
676      * @throws IOException
677      */
678     public String getCldsServicesOrResourcesBasedOnURL(String url, boolean alarmConditions) {
679         String responseStr;
680         try {
681             url = removeUnwantedBracesFromString(url);
682             URL urlObj = new URL(url);
683
684             HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
685             String basicAuth = SdcReq.getSdcBasicAuth(refProp);
686             conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
687             conn.setRequestProperty("Authorization", basicAuth);
688             conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
689             conn.setRequestMethod("GET");
690
691             int responseCode = conn.getResponseCode();
692             logger.info("responseCode=" + responseCode);
693
694             BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
695             StringBuffer response = new StringBuffer();
696             String inputLine;
697             while ((inputLine = in.readLine()) != null) {
698                 response.append(inputLine);
699                 if (alarmConditions) {
700                     response.append("\n");
701                 }
702             }
703             responseStr = response.toString();
704             in.close();
705             return responseStr;
706         } catch (Exception e) {
707             logger.error("Exception occurred :", e);
708             return "";
709         }
710
711     }
712
713     /**
714      * To create properties object by using cldsServicedata
715      *
716      * @param globalProps
717      * @param cldsServiceData
718      * @return
719      * @throws IOException
720      */
721     public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) throws IOException {
722         String totalPropsStr;
723         ObjectMapper mapper = new ObjectMapper();
724         ObjectNode globalPropsJson;
725         if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
726
727             // Objectnode to save all byservice, byvf , byvfc and byalarm nodes
728             ObjectNode byIdObjectNode = mapper.createObjectNode();
729
730             // To create vf ResourceUUID node with serviceInvariantUUID
731             ObjectNode invariantUuidObjectNodeWithVF = createVFObjectNodeByServiceInvariantUUID(mapper,
732                     cldsServiceData);
733             byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVF);
734
735             // To create byVf and vfcResourceNode with vfResourceUUID
736             ObjectNode vfcObjectNodeByVfUuid = createVFCObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs());
737             byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);
738
739             // To create byKpi
740             ObjectNode kpiObjectNode = mapper.createObjectNode();
741             if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {
742                 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
743                     if (currCldsVfData != null) {
744                         createKPIObjectNodeByVfUUID(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());
745                     }
746                 }
747             }
748             byIdObjectNode.putPOJO("byKpi", kpiObjectNode);
749
750             // To create byVfc and alarmCondition with vfcResourceUUID
751             ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode();
752             if (cldsServiceData.getCldsVfs() != null && cldsServiceData.getCldsVfs().size() > 0) {
753                 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
754                     if (currCldsVfData != null) {
755                         createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,
756                                 currCldsVfData.getCldsVfcs());
757                     }
758                 }
759             }
760             byIdObjectNode.putPOJO("byVfc", vfcResourceUuidObjectNode);
761
762             // To create byAlarmCondition with alarmConditionKey
763             List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData);
764             ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions);
765
766             byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);
767
768             globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
769
770             globalPropsJson.putPOJO("shared", byIdObjectNode);
771             logger.info("valuie of objNode:" + globalPropsJson);
772         } else {
773             /**
774              * to create json with total properties when no serviceUUID passed
775              */
776             globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
777         }
778         totalPropsStr = globalPropsJson.toString();
779         return totalPropsStr;
780     }
781
782     public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData) {
783         List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
784         if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null
785                 && cldsServiceData.getCldsVfs().size() > 0) {
786             for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
787                 if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null
788                         && currCldsVfData.getCldsVfcs().size() > 0) {
789                     for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
790                         if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null
791                                 && currCldsVfcData.getCldsAlarmConditions().size() > 0) {
792                             for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
793                                 if (currCldsAlarmCondition != null) {
794                                     alarmCondList.add(currCldsAlarmCondition);
795                                 }
796                             }
797                         }
798                     }
799                 }
800             }
801         }
802         return alarmCondList;
803     }
804
805     private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper,
806             List<CldsAlarmCondition> cldsAlarmCondList) {
807         ObjectNode alarmCondKeyNode = mapper.createObjectNode();
808
809         if (cldsAlarmCondList != null && cldsAlarmCondList.size() > 0) {
810             for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {
811                 if (currCldsAlarmCondition != null) {
812                     ObjectNode alarmCondNode = mapper.createObjectNode();
813                     alarmCondNode.put("eventSourceType", currCldsAlarmCondition.getEventSourceType());
814                     alarmCondNode.put("eventSeverity", currCldsAlarmCondition.getSeverity());
815                     alarmCondKeyNode.putPOJO(currCldsAlarmCondition.getAlarmConditionKey(), alarmCondNode);
816                 }
817             }
818         } else {
819             ObjectNode alarmCondNode = mapper.createObjectNode();
820             alarmCondNode.put("eventSourceType", "");
821             alarmCondNode.put("eventSeverity", "");
822             alarmCondKeyNode.putPOJO("", alarmCondNode);
823         }
824         return alarmCondKeyNode;
825     }
826
827     private ObjectNode createVFObjectNodeByServiceInvariantUUID(ObjectMapper mapper, CldsServiceData cldsServiceData) {
828         ObjectNode invariantUuidObjectNode = mapper.createObjectNode();
829         ObjectNode vfObjectNode = mapper.createObjectNode();
830         ObjectNode vfUuidNode = mapper.createObjectNode();
831         List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();
832         if (cldsVfsList != null && cldsVfsList.size() > 0) {
833             for (CldsVfData currCldsVfData : cldsVfsList) {
834                 if (currCldsVfData != null) {
835                     vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());
836                 }
837             }
838         } else {
839             vfUuidNode.put("", "");
840         }
841         vfObjectNode.putPOJO("vf", vfUuidNode);
842         invariantUuidObjectNode.putPOJO(cldsServiceData.getServiceInvariantUUID(), vfObjectNode);
843         return invariantUuidObjectNode;
844     }
845
846     private void createKPIObjectNodeByVfUUID(ObjectMapper mapper, ObjectNode vfResourceUUIDObjectNode,
847             List<CldsVfKPIData> cldsVfKPIDataList) {
848         if (cldsVfKPIDataList != null && cldsVfKPIDataList.size() > 0) {
849             for (CldsVfKPIData currCldsVfKPIData : cldsVfKPIDataList) {
850                 if (currCldsVfKPIData != null) {
851                     ObjectNode thresholdNameObjectNode = mapper.createObjectNode();
852
853                     ObjectNode fieldPathObjectNode = mapper.createObjectNode();
854                     ObjectNode nfNamingCodeNode = mapper.createObjectNode();
855
856                     fieldPathObjectNode.put(currCldsVfKPIData.getFieldPathValue(),
857                             currCldsVfKPIData.getFieldPathValue());
858                     nfNamingCodeNode.put(currCldsVfKPIData.getNfNamingValue(), currCldsVfKPIData.getNfNamingValue());
859
860                     thresholdNameObjectNode.putPOJO("fieldPath", fieldPathObjectNode);
861                     thresholdNameObjectNode.putPOJO("nfNamingCode", nfNamingCodeNode);
862
863                     vfResourceUUIDObjectNode.putPOJO(currCldsVfKPIData.getThresholdValue(), thresholdNameObjectNode);
864                 }
865             }
866         }
867     }
868
869     private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUUIDObjectNode,
870             List<CldsVfcData> cldsVfcDataList) {
871         ObjectNode alarmCondContsObjectNode = mapper.createObjectNode();
872         ObjectNode alarmCondNode = mapper.createObjectNode();
873         // alarmCondNode.put("", "");
874         if (cldsVfcDataList != null && cldsVfcDataList.size() > 0) {
875             for (CldsVfcData currCldsVfcData : cldsVfcDataList) {
876                 if (currCldsVfcData != null) {
877                     if (currCldsVfcData.getCldsAlarmConditions() != null
878                             && currCldsVfcData.getCldsAlarmConditions().size() > 0) {
879                         for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
880                             alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),
881                                     currCldsAlarmCondition.getAlarmConditionKey());
882                         }
883                         alarmCondContsObjectNode.putPOJO("alarmCondition", alarmCondNode);
884                     }
885                     alarmCondContsObjectNode.putPOJO("alarmCondition", alarmCondNode);
886                     vfcResourceUUIDObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(),
887                             alarmCondContsObjectNode);
888                 }
889             }
890         } else {
891             alarmCondNode.put("", "");
892             alarmCondContsObjectNode.putPOJO("alarmCondition", alarmCondNode);
893             vfcResourceUUIDObjectNode.putPOJO("", alarmCondContsObjectNode);
894         }
895     }
896
897     private ObjectNode createVFCObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {
898         ObjectNode vfUUIDObjectNode = mapper.createObjectNode();
899
900         if (cldsVfDataList != null && cldsVfDataList.size() > 0) {
901             for (CldsVfData currCldsVfData : cldsVfDataList) {
902                 if (currCldsVfData != null) {
903                     ObjectNode vfcObjectNode = mapper.createObjectNode();
904                     ObjectNode vfcUuidNode = mapper.createObjectNode();
905                     if (currCldsVfData.getCldsVfcs() != null && currCldsVfData.getCldsVfcs().size() > 0) {
906                         for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
907                             vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),
908                                     currCldsVfcData.getVfcName());
909                         }
910                     } else {
911                         vfcUuidNode.put("", "");
912                     }
913                     vfcObjectNode.putPOJO("vfc", vfcUuidNode);
914                     vfUUIDObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfcObjectNode);
915                 }
916             }
917         } else {
918             ObjectNode vfcUuidNode = mapper.createObjectNode();
919             vfcUuidNode.put("", "");
920             ObjectNode vfcObjectNode = mapper.createObjectNode();
921             vfcObjectNode.putPOJO("vfc", vfcUuidNode);
922             vfUUIDObjectNode.putPOJO("", vfcObjectNode);
923         }
924         return vfUUIDObjectNode;
925     }
926
927     public String getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail CldsSdcServiceDetail, String artifactName) {
928         String artifactUuid = null;
929         boolean artifactxists = false;
930         if (CldsSdcServiceDetail != null && CldsSdcServiceDetail.getResources() != null
931                 && CldsSdcServiceDetail.getResources().size() > 0) {
932             for (CldsSdcResource currCldsSdcResource : CldsSdcServiceDetail.getResources()) {
933                 if (artifactxists) {
934                     break;
935                 }
936                 if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null
937                         && currCldsSdcResource.getArtifacts().size() > 0) {
938                     for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {
939                         if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null) {
940                             if (currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {
941                                 artifactUuid = currCldsSdcArtifact.getArtifactUUID();
942                                 artifactxists = true;
943                                 break;
944                             }
945                         }
946                     }
947                 }
948             }
949         }
950         return artifactUuid;
951     }
952
953     public String updateControlLoopStatusToDcae(String dcaeUrl, String invariantResourceUuid,
954             String invariantServiceUuid, String artifactName) {
955         String baseUrl = refProp.getStringValue("sdc.serviceUrl");
956         String basicAuth = SdcReq.getSdcBasicAuth(refProp);
957         String postStatusData = "{ \n" + "\"event\" : \"" + "Created" + "\",\n" + "\"serviceUUID\" : \""
958                 + invariantServiceUuid + "\",\n" + "\"resourceUUID\" :\"" + invariantResourceUuid + "\",\n"
959                 + "\"artifactName\" : \"" + artifactName + "\",\n" + "} \n";
960         try {
961             String url = baseUrl;
962             if (invariantServiceUuid != null) {
963                 url = dcaeUrl + "/closed-loops";
964             }
965             URL urlObj = new URL(url);
966
967             HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
968             conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
969             conn.setRequestProperty("Authorization", basicAuth);
970             conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
971             conn.setRequestMethod("POST");
972
973             byte[] postData = SdcReq.stringToByteArray(postStatusData);
974             try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
975                 wr.write(postData);
976             }
977
978             int responseCode = conn.getResponseCode();
979             logger.info("responseCode=" + responseCode);
980
981             String resp = getResponse(conn);
982             if (resp != null) {
983                 return resp;
984             }
985         } catch (Exception e) {
986             logger.error("not able to ger any service information from sdc for uuid:" + invariantServiceUuid);
987         }
988         return "";
989     }
990
991     /**
992      * To get all sdc VF/VFC Resources basic info
993      *
994      * @return
995      * @throws IOException
996      */
997     private List<CldsSdcResourceBasicInfo> getAllSdcVForVFCResourcesBasedOnResourceType(String resourceType)
998             throws IOException {
999         List<CldsSdcResourceBasicInfo> allSdcResourceVFCBasicInfo = new ArrayList<CldsSdcResourceBasicInfo>();
1000         String catalogUrl = refProp.getStringValue("sdc.catalog.url");
1001         String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;
1002         String allSdcVFCResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false);
1003
1004         allSdcResourceVFCBasicInfo = getAllSdcResourcesListFromJson(allSdcVFCResources);
1005         return removeDuplicateSdcResourceBasicInfo(allSdcResourceVFCBasicInfo);
1006     }
1007
1008     private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUUID,
1009             List<CldsSdcResourceBasicInfo> resourceInfoList) throws IOException {
1010         String resourceUuid = null;
1011         if (resourceInfoList != null && resourceInfoList.size() > 0) {
1012             for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {
1013                 if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null
1014                         && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUUID)) {
1015                     resourceUuid = currResource.getUuid();
1016                     break;
1017                 }
1018             }
1019         }
1020         return resourceUuid;
1021     }
1022 }