2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
\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
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END============================================
\r
20 * ===================================================================
\r
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
24 package org.onap.clamp.clds.client.req.sdc;
\r
26 import com.att.eelf.configuration.EELFLogger;
\r
27 import com.att.eelf.configuration.EELFManager;
\r
28 import com.fasterxml.jackson.databind.JsonNode;
\r
29 import com.fasterxml.jackson.databind.ObjectMapper;
\r
30 import com.fasterxml.jackson.databind.node.ArrayNode;
\r
31 import com.fasterxml.jackson.databind.node.ObjectNode;
\r
32 import com.fasterxml.jackson.databind.node.TextNode;
\r
34 import java.io.BufferedReader;
\r
35 import java.io.DataOutputStream;
\r
36 import java.io.IOException;
\r
37 import java.io.InputStream;
\r
38 import java.io.InputStreamReader;
\r
39 import java.io.Reader;
\r
40 import java.io.StringReader;
\r
41 import java.net.HttpURLConnection;
\r
42 import java.net.URL;
\r
43 import java.nio.charset.StandardCharsets;
\r
44 import java.security.GeneralSecurityException;
\r
45 import java.util.ArrayList;
\r
46 import java.util.Base64;
\r
47 import java.util.Collections;
\r
48 import java.util.Date;
\r
49 import java.util.Iterator;
\r
50 import java.util.List;
\r
52 import javax.ws.rs.BadRequestException;
\r
54 import org.apache.commons.codec.DecoderException;
\r
55 import org.apache.commons.codec.digest.DigestUtils;
\r
56 import org.apache.commons.csv.CSVFormat;
\r
57 import org.apache.commons.csv.CSVRecord;
\r
58 import org.apache.commons.io.IOUtils;
\r
59 import org.apache.commons.lang3.StringUtils;
\r
60 import org.apache.http.HttpHeaders;
\r
61 import org.onap.clamp.clds.exception.SdcCommunicationException;
\r
62 import org.onap.clamp.clds.model.CldsAlarmCondition;
\r
63 import org.onap.clamp.clds.model.CldsDBServiceCache;
\r
64 import org.onap.clamp.clds.model.CldsSdcArtifact;
\r
65 import org.onap.clamp.clds.model.CldsSdcResource;
\r
66 import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo;
\r
67 import org.onap.clamp.clds.model.CldsSdcServiceDetail;
\r
68 import org.onap.clamp.clds.model.CldsSdcServiceInfo;
\r
69 import org.onap.clamp.clds.model.CldsServiceData;
\r
70 import org.onap.clamp.clds.model.CldsVfData;
\r
71 import org.onap.clamp.clds.model.CldsVfKPIData;
\r
72 import org.onap.clamp.clds.model.CldsVfcData;
\r
73 import org.onap.clamp.clds.model.prop.Global;
\r
74 import org.onap.clamp.clds.model.prop.ModelProperties;
\r
75 import org.onap.clamp.clds.model.refprop.RefProp;
\r
76 import org.onap.clamp.clds.util.CryptoUtils;
\r
77 import org.onap.clamp.clds.util.LoggingUtils;
\r
78 import org.springframework.beans.factory.annotation.Autowired;
\r
80 public class SdcCatalogServices {
\r
82 private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class);
\r
83 private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
\r
84 private static final String RESOURCE_VF_TYPE = "VF";
\r
85 private static final String RESOURCE_VFC_TYPE = "VFC";
\r
86 private static final String RESOURCE_CVFC_TYPE = "CVFC";
\r
87 private static final String SDC_REQUESTID_PROPERTY_NAME = "sdc.header.requestId";
\r
88 private static final String SDC_METADATA_URL_PREFIX = "/metadata";
\r
89 private static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID";
\r
90 private static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url";
\r
91 private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";
\r
92 private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";
\r
93 private static final String RESOURCE_URL_PREFIX = "resources";
\r
95 private RefProp refProp;
\r
98 * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic
\r
99 * dGVzdDoxMjM0NTY=).
\r
101 * @return The String with Basic Auth and password
\r
102 * @throws GeneralSecurityException
\r
103 * In case of issue when decryting the SDC password
\r
104 * @throws DecoderException
\r
105 * In case of issues with the decoding of the HexString message
\r
107 private String getSdcBasicAuth() throws GeneralSecurityException, DecoderException {
\r
108 String sdcId = refProp.getStringValue("sdc.serviceUsername");
\r
109 String sdcPw = refProp.getStringValue("sdc.servicePassword");
\r
110 String password = CryptoUtils.decrypt(sdcPw);
\r
111 String idPw = Base64.getEncoder().encodeToString((sdcId + ":" + password).getBytes(StandardCharsets.UTF_8));
\r
112 return "Basic " + idPw;
\r
116 * This method get the SDC services Information with the corresponding
\r
121 * @return A Json String with all the service list
\r
122 * @throws GeneralSecurityException
\r
123 * In case of issue when decryting the SDC password
\r
124 * @throws DecoderException
\r
125 * In case of issues with the decoding of the Hex String
\r
127 public String getSdcServicesInformation(String uuid) throws GeneralSecurityException, DecoderException {
\r
128 Date startTime = new Date();
\r
129 String baseUrl = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);
\r
130 String basicAuth = getSdcBasicAuth();
\r
131 LoggingUtils.setTargetContext("SDC", "getSdcServicesInformation");
\r
133 String url = baseUrl;
\r
134 if (uuid != null) {
\r
135 url = baseUrl + "/" + uuid + SDC_METADATA_URL_PREFIX;
\r
137 URL urlObj = new URL(url);
\r
138 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
\r
139 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);
\r
140 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
\r
141 conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
\r
142 conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
\r
143 conn.setRequestMethod("GET");
\r
144 String resp = getResponse(conn);
\r
147 LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
\r
149 } catch (IOException e) {
\r
150 LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());
\r
151 LoggingUtils.setErrorContext("900", "Get sdc services error");
\r
152 logger.error("not able to get any service information from sdc for uuid:" + uuid, e);
\r
154 LoggingUtils.setTimeContext(startTime, new Date());
\r
155 metricsLogger.info("getSdcServicesInformation complete");
\r
161 * To remove duplicate serviceUUIDs from sdc services List.
\r
163 * @param rawCldsSdcServiceList
\r
164 * A list of CldsSdcServiceInfo
\r
165 * @return A list of CldsSdcServiceInfo without duplicate service UUID
\r
167 public List<CldsSdcServiceInfo> removeDuplicateServices(List<CldsSdcServiceInfo> rawCldsSdcServiceList) {
\r
168 List<CldsSdcServiceInfo> cldsSdcServiceInfoList = null;
\r
169 if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {
\r
171 Collections.sort(rawCldsSdcServiceList);
\r
172 // and then take only the services with the max version (last in the
\r
173 // list with the same name)
\r
174 cldsSdcServiceInfoList = new ArrayList<>();
\r
175 for (int i = 1; i < rawCldsSdcServiceList.size(); i++) {
\r
176 // compare name with previous - if not equal, then keep the
\r
177 // previous (it's the last with that name)
\r
178 CldsSdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);
\r
179 if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {
\r
180 cldsSdcServiceInfoList.add(prev);
\r
183 // add the last in the list
\r
184 cldsSdcServiceInfoList.add(rawCldsSdcServiceList.get(rawCldsSdcServiceList.size() - 1));
\r
186 return cldsSdcServiceInfoList;
\r
190 * To remove duplicate serviceUUIDs from sdc resources List.
\r
192 * @param rawCldsSdcResourceList
\r
193 * @return List of CldsSdcResource
\r
195 public List<CldsSdcResource> removeDuplicateSdcResourceInstances(List<CldsSdcResource> rawCldsSdcResourceList) {
\r
196 List<CldsSdcResource> cldsSdcResourceList = null;
\r
197 if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) {
\r
199 Collections.sort(rawCldsSdcResourceList);
\r
200 // and then take only the resources with the max version (last in
\r
201 // the list with the same name)
\r
202 cldsSdcResourceList = new ArrayList<>();
\r
203 for (int i = 1; i < rawCldsSdcResourceList.size(); i++) {
\r
204 // compare name with previous - if not equal, then keep the
\r
205 // previous (it's the last with that name)
\r
206 CldsSdcResource prev = rawCldsSdcResourceList.get(i - 1);
\r
207 if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {
\r
208 cldsSdcResourceList.add(prev);
\r
211 // add the last in the list
\r
212 cldsSdcResourceList.add(rawCldsSdcResourceList.get(rawCldsSdcResourceList.size() - 1));
\r
214 return cldsSdcResourceList;
\r
218 * To remove duplicate basic resources with same resourceUUIDs.
\r
220 * @param rawCldsSdcResourceListBasicList
\r
221 * @return List of CldsSdcResourceBasicInfo
\r
223 public List<CldsSdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(
\r
224 List<CldsSdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {
\r
225 List<CldsSdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;
\r
226 if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {
\r
228 Collections.sort(rawCldsSdcResourceListBasicList);
\r
229 // and then take only the resources with the max version (last in
\r
230 // the list with the same name)
\r
231 cldsSdcResourceBasicInfoList = new ArrayList<>();
\r
232 for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {
\r
233 // compare name with previous - if not equal, then keep the
\r
234 // previous (it's the last with that name)
\r
235 CldsSdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);
\r
236 if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {
\r
237 cldsSdcResourceBasicInfoList.add(prev);
\r
240 // add the last in the list
\r
241 cldsSdcResourceBasicInfoList
\r
242 .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));
\r
244 return cldsSdcResourceBasicInfoList;
\r
248 * To get ServiceUUID by using serviceInvariantUUID.
\r
250 * @param invariantId
\r
252 * @return The service UUID
\r
253 * @throws GeneralSecurityException
\r
254 * In case of issue when decryting the SDC password
\r
255 * @throws DecoderException
\r
256 * In case of issues with the decoding of the Hex String
\r
258 public String getServiceUuidFromServiceInvariantId(String invariantId)
\r
259 throws GeneralSecurityException, DecoderException {
\r
260 String serviceUuid = "";
\r
261 String responseStr = getSdcServicesInformation(null);
\r
262 List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);
\r
263 List<CldsSdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);
\r
264 if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {
\r
265 for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {
\r
266 if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null
\r
267 && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {
\r
268 serviceUuid = currCldsSdcServiceInfo.getUuid();
\r
273 return serviceUuid;
\r
277 * To get CldsAsdsServiceInfo class by parsing json string.
\r
280 * The Json string that must be decoded
\r
281 * @return The list of CldsSdcServiceInfo, if there is a failure it return
\r
284 private List<CldsSdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {
\r
285 ObjectMapper objectMapper = new ObjectMapper();
\r
286 if (StringUtils.isBlank(jsonStr)) {
\r
287 return new ArrayList<>();
\r
290 return objectMapper.readValue(jsonStr,
\r
291 objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));
\r
292 } catch (IOException e) {
\r
293 logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);
\r
294 return new ArrayList<>();
\r
299 * To get List of CldsSdcResourceBasicInfo class by parsing json string.
\r
302 * The JSOn string that must be decoded
\r
303 * @return The list of CldsSdcResourceBasicInfo, an empty list in case of
\r
306 private List<CldsSdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {
\r
307 ObjectMapper objectMapper = new ObjectMapper();
\r
308 if (StringUtils.isBlank(jsonStr)) {
\r
309 return new ArrayList<>();
\r
312 return objectMapper.readValue(jsonStr,
\r
313 objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcResourceBasicInfo.class));
\r
314 } catch (IOException e) {
\r
315 logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);
\r
316 return new ArrayList<>();
\r
321 * To get CldsSdcServiceDetail by parsing json string.
\r
326 public CldsSdcServiceDetail getCldsSdcServiceDetailFromJson(String jsonStr) {
\r
327 ObjectMapper objectMapper = new ObjectMapper();
\r
329 return objectMapper.readValue(jsonStr, CldsSdcServiceDetail.class);
\r
330 } catch (IOException e) {
\r
331 logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);
\r
337 // upload artifact to sdc based on serviceUUID and resource name on url
\r
338 private String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formattedSdcReq) {
\r
339 // Verify whether it is triggered by Validation Test button from UI
\r
340 if (prop.isTestOnly()) {
\r
341 return "sdc artifact upload not executed for test action";
\r
344 logger.info("userid=" + userid);
\r
345 byte[] postData = formattedSdcReq.getBytes(StandardCharsets.UTF_8);
\r
346 int postDataLength = postData.length;
\r
347 HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, formattedSdcReq);
\r
348 try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
\r
349 wr.write(postData);
\r
351 boolean requestFailed = true;
\r
352 int responseCode = conn.getResponseCode();
\r
353 logger.info("responseCode=" + responseCode);
\r
354 if (responseCode == 200) {
\r
355 requestFailed = false;
\r
357 String responseStr = getResponse(conn);
\r
358 if (responseStr != null && requestFailed) {
\r
359 logger.error("requestFailed - responseStr=" + responseStr);
\r
360 throw new BadRequestException(responseStr);
\r
362 return responseStr;
\r
363 } catch (IOException e) {
\r
364 logger.error("Exception when attempting to communicate with SDC", e);
\r
365 throw new SdcCommunicationException("Exception when attempting to communicate with SDC", e);
\r
369 private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String content) {
\r
371 logger.info("userid=" + userid);
\r
372 String basicAuth = getSdcBasicAuth();
\r
373 String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");
\r
374 URL urlObj = new URL(url);
\r
375 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
\r
376 conn.setDoOutput(true);
\r
377 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId);
\r
378 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
\r
379 conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json");
\r
380 conn.setRequestProperty(HttpHeaders.CONTENT_MD5,
\r
381 Base64.getEncoder().encodeToString(DigestUtils.md5Hex(content).getBytes("UTF-8")));
\r
382 conn.setRequestProperty("USER_ID", userid);
\r
383 conn.setRequestMethod("POST");
\r
384 conn.setRequestProperty("charset", "utf-8");
\r
385 conn.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(postDataLength));
\r
386 conn.setUseCaches(false);
\r
387 conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
\r
389 } catch (IOException e) {
\r
390 logger.error("Exception when attempting to open connection with SDC", e);
\r
391 throw new SdcCommunicationException("Exception when attempting to open connection with SDC", e);
\r
392 } catch (DecoderException e) {
\r
393 logger.error("Exception when attempting to decode the Hex string", e);
\r
394 throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);
\r
395 } catch (GeneralSecurityException e) {
\r
396 logger.error("Exception when attempting to decrypt the encrypted password", e);
\r
397 throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);
\r
401 private String getResponse(HttpURLConnection conn) {
\r
402 try (InputStream is = getInputStream(conn)) {
\r
403 try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
\r
404 return IOUtils.toString(in);
\r
406 } catch (IOException e) {
\r
407 logger.error("Exception when attempting to open SDC response", e);
\r
408 throw new SdcCommunicationException("Exception when attempting to open SDC response", e);
\r
412 private InputStream getInputStream(HttpURLConnection conn) {
\r
414 InputStream inStream = conn.getErrorStream();
\r
415 if (inStream == null) {
\r
416 inStream = conn.getInputStream();
\r
419 } catch (IOException e) {
\r
420 logger.error("Exception when attempting to open SDC error stream", e);
\r
421 throw new SdcCommunicationException("Exception when attempting to open SDC error stream", e);
\r
425 public CldsDBServiceCache getCldsDbServiceCacheUsingCldsServiceData(CldsServiceData cldsServiceData) {
\r
427 CldsDBServiceCache cldsDbServiceCache = new CldsDBServiceCache();
\r
428 cldsDbServiceCache.setCldsDataInstream(cldsServiceData);
\r
429 cldsDbServiceCache.setInvariantId(cldsServiceData.getServiceInvariantUUID());
\r
430 cldsDbServiceCache.setServiceId(cldsServiceData.getServiceUUID());
\r
431 return cldsDbServiceCache;
\r
432 } catch (IOException e) {
\r
433 logger.error("Exception when getting service in cache", e);
\r
434 throw new SdcCommunicationException("Exception when getting service in cache", e);
\r
439 * Check if the SDC Info in cache has expired.
\r
441 * @param cldsServiceData
\r
442 * @return boolean flag
\r
443 * @throws GeneralSecurityException
\r
444 * In case of issues with the decryting the encrypted password
\r
445 * @throws DecoderException
\r
446 * In case of issues with the decoding of the Hex String
\r
448 public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData)
\r
449 throws GeneralSecurityException, DecoderException {
\r
450 boolean expired = false;
\r
451 if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
\r
452 String cachedServiceUuid = cldsServiceData.getServiceUUID();
\r
453 String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID());
\r
454 String defaultRecordAge = refProp.getStringValue("CLDS_SERVICE_CACHE_MAX_SECONDS");
\r
455 if ((!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null
\r
456 && cldsServiceData.getAgeOfRecord() > Long.parseLong(defaultRecordAge))) {
\r
466 * Get the Service Data with Alarm Conditions for a given invariantServiceUuid.
\r
468 * @param invariantServiceUuid
\r
469 * @return The CldsServiceData
\r
470 * @throws GeneralSecurityException
\r
471 * In case of issues with the decryting the encrypted password
\r
472 * @throws DecoderException
\r
473 * In case of issues with the decoding of the Hex String
\r
475 public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid)
\r
476 throws GeneralSecurityException, DecoderException {
\r
477 String url = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);
\r
478 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
479 String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);
\r
480 String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX;
\r
481 String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl);
\r
482 ObjectMapper objectMapper = new ObjectMapper();
\r
483 CldsServiceData cldsServiceData = new CldsServiceData();
\r
484 if (responseStr != null) {
\r
485 CldsSdcServiceDetail cldsSdcServiceDetail;
\r
487 cldsSdcServiceDetail = objectMapper.readValue(responseStr, CldsSdcServiceDetail.class);
\r
488 } catch (IOException e) {
\r
489 logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);
\r
490 throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);
\r
492 // To remove duplicate resources from serviceDetail and add valid
\r
494 if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {
\r
495 cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());
\r
496 cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());
\r
497 List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(
\r
498 cldsSdcServiceDetail.getResources());
\r
499 if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {
\r
500 List<CldsVfData> cldsVfDataList = new ArrayList<>();
\r
501 for (CldsSdcResource currCldsSdcResource : cldsSdcResourceList) {
\r
502 if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null
\r
503 && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {
\r
504 CldsVfData currCldsVfData = new CldsVfData();
\r
505 currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());
\r
506 currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());
\r
507 cldsVfDataList.add(currCldsVfData);
\r
510 cldsServiceData.setCldsVfs(cldsVfDataList);
\r
511 // For each vf in the list , add all vfc's
\r
512 getAllVfcForVfList(cldsVfDataList, catalogUrl);
\r
513 logger.info("value of cldsServiceData:" + cldsServiceData);
\r
514 logger.info("value of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());
\r
518 return cldsServiceData;
\r
521 private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl)
\r
522 throws GeneralSecurityException {
\r
523 // todo : refact this..
\r
524 if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {
\r
525 List<CldsSdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(
\r
527 List<CldsSdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(
\r
528 RESOURCE_VFC_TYPE);
\r
529 allVfcResources.addAll(getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_CVFC_TYPE));
\r
530 for (CldsVfData currCldsVfData : cldsVfDataList) {
\r
531 if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) {
\r
532 String resourceUuid = getResourceUuidFromResourceInvariantUuid(
\r
533 currCldsVfData.getVfInvariantResourceUUID(), allVfResources);
\r
534 if (resourceUuid != null) {
\r
535 String vfResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUuid
\r
536 + SDC_METADATA_URL_PREFIX;
\r
537 String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl);
\r
538 if (vfResponse != null) {
\r
539 // Below 2 line are to get the KPI(field path) data
\r
540 // associated with the VF's
\r
541 List<CldsVfKPIData> cldsVfKPIDataList = getFieldPathFromVF(vfResponse);
\r
542 currCldsVfData.setCldsKPIList(cldsVfKPIDataList);
\r
543 List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);
\r
544 if (vfcDataListFromVfResponse != null) {
\r
545 currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);
\r
546 if (!vfcDataListFromVfResponse.isEmpty()) {
\r
547 // To get artifacts for every VFC and get
\r
548 // alarm conditions from artifact
\r
549 for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {
\r
550 if (currCldsVfcData != null
\r
551 && currCldsVfcData.getVfcInvariantResourceUUID() != null) {
\r
552 String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(
\r
553 currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);
\r
554 if (resourceVfcUuid != null) {
\r
555 String vfcResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/"
\r
556 + resourceVfcUuid + SDC_METADATA_URL_PREFIX;
\r
557 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(
\r
558 vfcResourceUuidUrl);
\r
559 if (vfcResponse != null) {
\r
560 List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(
\r
562 currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc);
\r
565 logger.info("No resourceVFC UUID found for given invariantID:"
\r
566 + currCldsVfcData.getVfcInvariantResourceUUID());
\r
574 logger.info("No resourceUUID found for given invariantREsourceUUID:"
\r
575 + currCldsVfData.getVfInvariantResourceUUID());
\r
582 private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws GeneralSecurityException {
\r
583 ObjectMapper mapper = new ObjectMapper();
\r
584 ObjectNode vfResponseNode;
\r
586 vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
\r
587 } catch (IOException e) {
\r
588 logger.error("Exception when decoding the JSON list of CldsVfcData", e);
\r
589 return new ArrayList<>();
\r
591 ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
\r
592 List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
\r
593 if (vfcArrayNode != null) {
\r
594 for (JsonNode vfcjsonNode : vfcArrayNode) {
\r
595 ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;
\r
596 TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");
\r
597 if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
\r
598 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
599 } else if (resourceTypeNode != null && "CVFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
\r
600 handleCVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
604 return cldsVfcDataList;
\r
607 private void handleVFCtypeNode(ObjectNode currVfcNode, List<CldsVfcData> cldsVfcDataList) {
\r
608 CldsVfcData currCldsVfcData = new CldsVfcData();
\r
609 TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");
\r
610 TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID");
\r
611 currCldsVfcData.setVfcName(vfcResourceName.textValue());
\r
612 currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue());
\r
613 cldsVfcDataList.add(currCldsVfcData);
\r
616 private void handleCVFCtypeNode(ObjectNode currVfcNode, List<CldsVfcData> cldsVfcDataList) {
\r
617 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
618 cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue()));
\r
621 private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {
\r
622 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
623 List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
\r
624 if (resourceUUID != null) {
\r
625 String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX;
\r
627 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl);
\r
628 ObjectMapper mapper = new ObjectMapper();
\r
629 ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
\r
630 ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
\r
631 if (vfcArrayNode != null) {
\r
632 for (JsonNode vfcjsonNode : vfcArrayNode) {
\r
633 ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;
\r
634 TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");
\r
635 if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
\r
636 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
640 } catch (IOException e) {
\r
641 logger.error("Exception during JSON analyzis", e);
\r
644 return cldsVfcDataList;
\r
647 private String removeUnwantedBracesFromString(String id) {
\r
648 return (id != null) ? id.replaceAll("\"", "") : "";
\r
651 private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws GeneralSecurityException {
\r
652 List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
\r
653 ObjectMapper mapper = new ObjectMapper();
\r
654 ObjectNode vfcResponseNode;
\r
656 vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
\r
657 } catch (IOException e) {
\r
658 logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);
\r
659 return cldsAlarmConditionList;
\r
661 ArrayNode artifactsArrayNode = (ArrayNode) vfcResponseNode.get("artifacts");
\r
662 if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
\r
663 for (int index = 0; index < artifactsArrayNode.size(); index++) {
\r
664 ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);
\r
665 TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");
\r
666 if (artifactUrlNode != null) {
\r
667 String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());
\r
668 cldsAlarmConditionList.addAll(parseCsvToGetAlarmConditions(responsesFromArtifactUrl));
\r
669 logger.info(responsesFromArtifactUrl);
\r
673 return cldsAlarmConditionList;
\r
676 private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) {
\r
678 List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
\r
679 Reader alarmReader = new StringReader(allAlarmCondsValues);
\r
680 Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
\r
681 if (records != null) {
\r
682 Iterator<CSVRecord> it = records.iterator();
\r
683 if (it.hasNext()) {
\r
686 it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));
\r
688 return cldsAlarmConditionList;
\r
689 } catch (IOException e) {
\r
690 logger.error("Exception when attempting to parse the CSV containing the alarm", e);
\r
691 return new ArrayList<>();
\r
695 // Method to get the artifact for any particular VF
\r
696 private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws GeneralSecurityException {
\r
697 List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
\r
698 ObjectMapper mapper = new ObjectMapper();
\r
699 ObjectNode vfResponseNode;
\r
701 vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
\r
702 } catch (IOException e) {
\r
703 logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);
\r
704 return cldsVfKPIDataList;
\r
706 ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");
\r
707 if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
\r
708 for (int index = 0; index < artifactsArrayNode.size(); index++) {
\r
709 ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);
\r
710 TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");
\r
711 TextNode artifactNameNode = (TextNode) currArtifactNode.get("artifactName");
\r
712 String artifactName = "";
\r
713 if (artifactNameNode != null) {
\r
714 artifactName = artifactNameNode.textValue();
\r
715 artifactName = artifactName.substring(artifactName.lastIndexOf('.') + 1);
\r
717 if (artifactUrlNode != null && "csv".equalsIgnoreCase(artifactName)) {
\r
718 String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());
\r
719 cldsVfKPIDataList.addAll(parseCsvToGetFieldPath(responsesFromArtifactUrl));
\r
720 logger.info(responsesFromArtifactUrl);
\r
724 return cldsVfKPIDataList;
\r
727 private CldsVfKPIData convertCsvRecordToKpiData(CSVRecord record) {
\r
728 if (record.size() < 6) {
\r
729 logger.debug("invalid csv field path Record,total columns less than 6: " + record);
\r
732 if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
\r
733 || StringUtils.isBlank(record.get(5))) {
\r
734 logger.debug("Invalid csv field path Record,one of column is having blank value : " + record);
\r
737 CldsVfKPIData cldsVfKPIData = new CldsVfKPIData();
\r
738 cldsVfKPIData.setNfNamingCode(record.get(0).trim());
\r
739 cldsVfKPIData.setNfNamingValue(record.get(1).trim());
\r
740 cldsVfKPIData.setFieldPath(record.get(2).trim());
\r
741 cldsVfKPIData.setFieldPathValue(record.get(3).trim());
\r
742 cldsVfKPIData.setThresholdName(record.get(4).trim());
\r
743 cldsVfKPIData.setThresholdValue(record.get(5).trim());
\r
744 return cldsVfKPIData;
\r
747 // Method to get the artifactURL Data and set the CldsVfKPIData node
\r
748 private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) {
\r
750 List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
\r
751 Reader alarmReader = new StringReader(allFieldPathValues);
\r
752 Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
\r
753 if (records != null) {
\r
754 for (CSVRecord record : records) {
\r
755 CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);
\r
756 if (kpiData != null) {
\r
757 cldsVfKPIDataList.add(kpiData);
\r
761 return cldsVfKPIDataList;
\r
762 } catch (IOException e) {
\r
763 logger.error("Exception when attempting to parse the CSV containing the alarm kpi data", e);
\r
764 return new ArrayList<>();
\r
768 private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {
\r
769 if (record == null) {
\r
772 if (record.size() < 5) {
\r
773 logger.debug("invalid csv alarm Record,total columns less than 5: " + record);
\r
776 if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
\r
777 || StringUtils.isBlank(record.get(4))) {
\r
778 logger.debug("invalid csv alarm Record,one of column is having blank value : " + record);
\r
781 CldsAlarmCondition cldsAlarmCondition = new CldsAlarmCondition();
\r
782 cldsAlarmCondition.setEventSourceType(record.get(1));
\r
783 cldsAlarmCondition.setEventName(record.get(2));
\r
784 cldsAlarmCondition.setAlarmConditionKey(record.get(3));
\r
785 cldsAlarmCondition.setSeverity(record.get(4));
\r
786 cldsAlarmConditionList.add(cldsAlarmCondition);
\r
790 // Get the responses for the current artifact from the artifacts URL.
\r
791 private String getResponsesFromArtifactUrl(String artifactsUrl) {
\r
792 String hostUrl = refProp.getStringValue("sdc.hostUrl");
\r
793 String artifactsUrlReworked = artifactsUrl.replaceAll("\"", "");
\r
794 String artifactUrl = hostUrl + artifactsUrlReworked;
\r
795 logger.info("value of artifactURl:" + artifactUrl);
\r
796 String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl);
\r
797 logger.info("value of artifactResponse:" + currArtifactResponse);
\r
798 return currArtifactResponse;
\r
802 * Service to services/resources/artifacts from sdc.Pass alarmConditions as
\r
803 * true to get alarm conditons from artifact url and else it is false
\r
805 * @param url The URL to trigger
\r
806 * @return The String containing the payload
\r
809 public String getCldsServicesOrResourcesBasedOnURL(String url) {
\r
810 Date startTime = new Date();
\r
812 LoggingUtils.setTargetContext("SDC", "getCldsServicesOrResourcesBasedOnURL");
\r
813 String urlReworked = removeUnwantedBracesFromString(url);
\r
814 URL urlObj = new URL(urlReworked);
\r
815 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
\r
816 String basicAuth = getSdcBasicAuth();
\r
817 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);
\r
818 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
\r
819 conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
\r
820 conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
\r
821 conn.setRequestMethod("GET");
\r
822 int responseCode = conn.getResponseCode();
\r
823 logger.info("Sdc resource url - " + urlReworked + " , responseCode=" + responseCode);
\r
824 try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
\r
825 String response = IOUtils.toString(in);
\r
826 LoggingUtils.setResponseContext("0", "Get sdc resources success", this.getClass().getName());
\r
829 } catch (IOException e) {
\r
830 LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());
\r
831 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
832 logger.error("Exception occurred during query to SDC", e);
\r
834 } catch (DecoderException e) {
\r
835 LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());
\r
836 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
837 logger.error("Exception when attempting to decode the Hex string", e);
\r
838 throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);
\r
839 } catch (GeneralSecurityException e) {
\r
840 LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());
\r
841 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
842 logger.error("Exception when attempting to decrypt the encrypted password", e);
\r
843 throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);
\r
845 LoggingUtils.setTimeContext(startTime, new Date());
\r
846 metricsLogger.info("getCldsServicesOrResourcesBasedOnURL completed");
\r
851 * To create properties object by using cldsServicedata.
\r
853 * @param globalProps
\r
854 * @param cldsServiceData
\r
857 public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) {
\r
858 String totalPropsStr;
\r
859 ObjectMapper mapper = new ObjectMapper();
\r
860 ObjectNode globalPropsJson;
\r
861 if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
\r
862 // Objectnode to save all byservice, byvf , byvfc and byalarm nodes
\r
863 ObjectNode byIdObjectNode = mapper.createObjectNode();
\r
864 // To create vf ResourceUUID node with serviceInvariantUUID
\r
865 ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(mapper,
\r
867 byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVf);
\r
868 // To create byVf and vfcResourceNode with vfResourceUUID
\r
869 ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs());
\r
870 byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);
\r
872 ObjectNode kpiObjectNode = mapper.createObjectNode();
\r
873 if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
874 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
875 if (currCldsVfData != null) {
\r
876 createKpiObjectNodeByVfUuid(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());
\r
880 byIdObjectNode.putPOJO("byKpi", kpiObjectNode);
\r
881 // To create byVfc and alarmCondition with vfcResourceUUID
\r
882 ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode();
\r
883 if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
884 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
885 if (currCldsVfData != null) {
\r
886 createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,
\r
887 currCldsVfData.getCldsVfcs());
\r
891 byIdObjectNode.putPOJO("byVfc", vfcResourceUuidObjectNode);
\r
892 // To create byAlarmCondition with alarmConditionKey
\r
893 List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
\r
895 ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions);
\r
896 byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);
\r
897 // To create byAlertDescription with AlertDescription
\r
898 List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
\r
899 "alertDescription");
\r
900 ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(mapper, allAlertDescriptions);
\r
901 byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);
\r
902 globalPropsJson = decodeGlobalProp(globalProps, mapper);
\r
903 globalPropsJson.putPOJO("shared", byIdObjectNode);
\r
904 logger.info("value of objNode:" + globalPropsJson);
\r
907 * to create json with total properties when no serviceUUID passed
\r
909 globalPropsJson = decodeGlobalProp(globalProps, mapper);
\r
911 totalPropsStr = globalPropsJson.toString();
\r
912 return totalPropsStr;
\r
915 private ObjectNode decodeGlobalProp(String globalProps, ObjectMapper mapper) {
\r
917 return (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
\r
918 } catch (IOException e) {
\r
919 logger.error("Exception occurred during decoding of the global props, returning an empty objectNode", e);
\r
920 return mapper.createObjectNode();
\r
925 * Method to get alarm conditions/alert description from Service Data.
\r
927 * @param cldsServiceData
\r
928 * CldsServiceData the Service Data to analyze
\r
930 * The String event name that will be used to filter the alarm
\r
932 * @return The list of CldsAlarmCondition for the event name specified
\r
934 public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData,
\r
935 String eventName) {
\r
936 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
937 if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null
\r
938 && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
939 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
940 alarmCondList.addAll(getAllAlarmConditionsFromCldsVfData(currCldsVfData, eventName));
\r
943 return alarmCondList;
\r
947 * Method to get alarm conditions/alert description from VF Data.
\r
949 * @param currCldsVfData
\r
950 * The Vf Data to analyze
\r
952 * The String event name that will be used to filter the alarm
\r
954 * @return The list of CldsAlarmCondition for the event name specified
\r
956 private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfData(CldsVfData currCldsVfData, String eventName) {
\r
957 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
958 if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {
\r
959 for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
\r
960 alarmCondList.addAll(getAllAlarmConditionsFromCldsVfcData(currCldsVfcData, eventName));
\r
963 return alarmCondList;
\r
967 * Method to get alarm conditions/alert description from VFC Data.
\r
969 * @param currCldsVfcData
\r
970 * The VfC Data to analyze
\r
972 * The String event name that will be used to filter the alarm
\r
974 * @return The list of CldsAlarmCondition for the event name specified
\r
976 private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfcData(CldsVfcData currCldsVfcData,
\r
977 String eventName) {
\r
978 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
979 if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null
\r
980 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
981 for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
\r
982 if (currCldsAlarmCondition != null
\r
983 && currCldsAlarmCondition.getEventName().equalsIgnoreCase(eventName)) {
\r
984 alarmCondList.add(currCldsAlarmCondition);
\r
988 return alarmCondList;
\r
991 private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper,
\r
992 List<CldsAlarmCondition> cldsAlarmCondList) {
\r
993 ObjectNode alarmCondKeyNode = mapper.createObjectNode();
\r
994 if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {
\r
995 for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {
\r
996 if (currCldsAlarmCondition != null) {
\r
997 ObjectNode alarmCondNode = mapper.createObjectNode();
\r
998 alarmCondNode.put("eventSourceType", currCldsAlarmCondition.getEventSourceType());
\r
999 alarmCondNode.put("eventSeverity", currCldsAlarmCondition.getSeverity());
\r
1000 alarmCondKeyNode.putPOJO(currCldsAlarmCondition.getAlarmConditionKey(), alarmCondNode);
\r
1004 ObjectNode alarmCondNode = mapper.createObjectNode();
\r
1005 alarmCondNode.put("eventSourceType", "");
\r
1006 alarmCondNode.put("eventSeverity", "");
\r
1007 alarmCondKeyNode.putPOJO("", alarmCondNode);
\r
1009 return alarmCondKeyNode;
\r
1012 private ObjectNode createVfObjectNodeByServiceInvariantUuid(ObjectMapper mapper, CldsServiceData cldsServiceData) {
\r
1013 ObjectNode invariantUuidObjectNode = mapper.createObjectNode();
\r
1014 ObjectNode vfObjectNode = mapper.createObjectNode();
\r
1015 ObjectNode vfUuidNode = mapper.createObjectNode();
\r
1016 List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();
\r
1017 if (cldsVfsList != null && !cldsVfsList.isEmpty()) {
\r
1018 for (CldsVfData currCldsVfData : cldsVfsList) {
\r
1019 if (currCldsVfData != null) {
\r
1020 vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());
\r
1024 vfUuidNode.put("", "");
\r
1026 vfObjectNode.putPOJO("vf", vfUuidNode);
\r
1027 invariantUuidObjectNode.putPOJO(cldsServiceData.getServiceInvariantUUID(), vfObjectNode);
\r
1028 return invariantUuidObjectNode;
\r
1031 private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode,
\r
1032 List<CldsVfKPIData> cldsVfKpiDataList) {
\r
1033 if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {
\r
1034 for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {
\r
1035 if (currCldsVfKpiData != null) {
\r
1036 ObjectNode thresholdNameObjectNode = mapper.createObjectNode();
\r
1037 ObjectNode fieldPathObjectNode = mapper.createObjectNode();
\r
1038 ObjectNode nfNamingCodeNode = mapper.createObjectNode();
\r
1039 fieldPathObjectNode.put(currCldsVfKpiData.getFieldPathValue(),
\r
1040 currCldsVfKpiData.getFieldPathValue());
\r
1041 nfNamingCodeNode.put(currCldsVfKpiData.getNfNamingValue(), currCldsVfKpiData.getNfNamingValue());
\r
1042 thresholdNameObjectNode.putPOJO("fieldPath", fieldPathObjectNode);
\r
1043 thresholdNameObjectNode.putPOJO("nfNamingCode", nfNamingCodeNode);
\r
1044 vfResourceUuidObjectNode.putPOJO(currCldsVfKpiData.getThresholdValue(), thresholdNameObjectNode);
\r
1050 private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUuidObjectNode,
\r
1051 List<CldsVfcData> cldsVfcDataList) {
\r
1052 ObjectNode vfcObjectNode = mapper.createObjectNode();
\r
1053 ObjectNode alarmCondNode = mapper.createObjectNode();
\r
1054 ObjectNode alertDescNode = mapper.createObjectNode();
\r
1055 if (cldsVfcDataList != null && !cldsVfcDataList.isEmpty()) {
\r
1056 for (CldsVfcData currCldsVfcData : cldsVfcDataList) {
\r
1057 if (currCldsVfcData != null) {
\r
1058 if (currCldsVfcData.getCldsAlarmConditions() != null
\r
1059 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
1060 for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
\r
1061 if ("alarmCondition".equalsIgnoreCase(currCldsAlarmCondition.getEventName())) {
\r
1062 alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),
\r
1063 currCldsAlarmCondition.getAlarmConditionKey());
\r
1065 alertDescNode.put(currCldsAlarmCondition.getAlarmConditionKey(),
\r
1066 currCldsAlarmCondition.getAlarmConditionKey());
\r
1070 vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);
\r
1071 vfcObjectNode.putPOJO("alertDescription", alertDescNode);
\r
1072 vfcResourceUuidObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), vfcObjectNode);
\r
1076 alarmCondNode.put("", "");
\r
1077 vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);
\r
1078 alertDescNode.put("", "");
\r
1079 vfcObjectNode.putPOJO("alertDescription", alarmCondNode);
\r
1080 vfcResourceUuidObjectNode.putPOJO("", vfcObjectNode);
\r
1085 * Method to create vfc and kpi nodes inside vf node
\r
1088 * @param cldsVfDataList
\r
1091 private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {
\r
1092 ObjectNode vfUuidObjectNode = mapper.createObjectNode();
\r
1093 if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {
\r
1094 for (CldsVfData currCldsVfData : cldsVfDataList) {
\r
1095 if (currCldsVfData != null) {
\r
1096 ObjectNode vfObjectNode = mapper.createObjectNode();
\r
1097 ObjectNode vfcUuidNode = mapper.createObjectNode();
\r
1098 ObjectNode kpiObjectNode = mapper.createObjectNode();
\r
1099 if (currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {
\r
1100 for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
\r
1101 if (currCldsVfcData.getCldsAlarmConditions() != null
\r
1102 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
1103 vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),
\r
1104 currCldsVfcData.getVfcName());
\r
1108 vfcUuidNode.put("", "");
\r
1110 if (currCldsVfData.getCldsKPIList() != null && !currCldsVfData.getCldsKPIList().isEmpty()) {
\r
1111 for (CldsVfKPIData currCldsVfKPIData : currCldsVfData.getCldsKPIList()) {
\r
1112 kpiObjectNode.put(currCldsVfKPIData.getThresholdValue(),
\r
1113 currCldsVfKPIData.getThresholdValue());
\r
1116 kpiObjectNode.put("", "");
\r
1118 vfObjectNode.putPOJO("vfc", vfcUuidNode);
\r
1119 vfObjectNode.putPOJO("kpi", kpiObjectNode);
\r
1120 vfUuidObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfObjectNode);
\r
1124 ObjectNode vfcUuidNode = mapper.createObjectNode();
\r
1125 vfcUuidNode.put("", "");
\r
1126 ObjectNode vfcObjectNode = mapper.createObjectNode();
\r
1127 vfcObjectNode.putPOJO("vfc", vfcUuidNode);
\r
1128 vfUuidObjectNode.putPOJO("", vfcObjectNode);
\r
1130 return vfUuidObjectNode;
\r
1134 * This method searches the equivalent artifact UUID for a specific
\r
1135 * artifactName in a SdcServiceDetail.
\r
1137 * @param cldsSdcServiceDetail
\r
1138 * The SdcServiceDetail that will be analyzed
\r
1139 * @param artifactName
\r
1140 * The artifact name that will be searched
\r
1141 * @return The artifact UUID found
\r
1143 public String getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail cldsSdcServiceDetail, String artifactName) {
\r
1144 String artifactUuid = null;
\r
1145 boolean artifactExists = false;
\r
1146 if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null
\r
1147 && !cldsSdcServiceDetail.getResources().isEmpty()) {
\r
1148 for (CldsSdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) {
\r
1149 if (artifactExists) {
\r
1152 if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null
\r
1153 && !currCldsSdcResource.getArtifacts().isEmpty()) {
\r
1154 for (CldsSdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {
\r
1155 if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null
\r
1156 && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {
\r
1157 artifactUuid = currCldsSdcArtifact.getArtifactUUID();
\r
1158 artifactExists = true;
\r
1165 return artifactUuid;
\r
1168 // To get all sdc VF/VFC Resources basic info.
\r
1169 private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {
\r
1170 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
1171 String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;
\r
1172 String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl);
\r
1173 return removeDuplicateSdcResourceBasicInfo(getAllSdcResourcesListFromJson(allSdcVfcResources));
\r
1176 private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,
\r
1177 List<CldsSdcResourceBasicInfo> resourceInfoList) {
\r
1178 String resourceUuid = null;
\r
1179 if (resourceInfoList != null && !resourceInfoList.isEmpty()) {
\r
1180 for (CldsSdcResourceBasicInfo currResource : resourceInfoList) {
\r
1181 if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null
\r
1182 && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {
\r
1183 resourceUuid = currResource.getUuid();
\r
1188 return resourceUuid;
\r
1191 // Method to get service invariant uuid from model properties.
\r
1192 private String getServiceInvariantUuidFromProps(ModelProperties props) {
\r
1193 String invariantUuid = "";
\r
1194 Global globalProps = props.getGlobal();
\r
1195 if (globalProps != null && globalProps.getService() != null) {
\r
1196 invariantUuid = globalProps.getService();
\r
1198 return invariantUuid;
\r
1202 * This method upload the BluePrint to SDC.
\r
1205 * The Clds model Properties
\r
1207 * The user id for SDC
\r
1208 * @param sdcReqUrlsList
\r
1209 * The list of SDC URL to try
\r
1210 * @param formattedSdcReq
\r
1211 * The blueprint to upload
\r
1212 * @param formattedSdcLocationReq
\r
1213 * THe location Blueprint to upload
\r
1214 * @param artifactName
\r
1215 * The artifact name from where we can get the Artifact UUID
\r
1216 * @param locationArtifactName
\r
1217 * The location artifact name from where we can get the Artifact
\r
1219 * @throws GeneralSecurityException
\r
1220 * In case of issues with the decryting the encrypted password
\r
1221 * @throws DecoderException
\r
1222 * In case of issues with the decoding of the Hex String
\r
1224 public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,
\r
1225 String formattedSdcLocationReq, String artifactName, String locationArtifactName)
\r
1226 throws GeneralSecurityException, DecoderException {
\r
1227 logger.info("userid=" + userid);
\r
1228 String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);
\r
1229 if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {
\r
1230 for (String url : sdcReqUrlsList) {
\r
1231 if (url != null) {
\r
1232 String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);
\r
1233 logger.info("ServiceUUID used before upload in url:" + originalServiceUuid);
\r
1234 String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);
\r
1235 CldsSdcServiceDetail cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation);
\r
1236 String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,
\r
1238 // Upload artifacts to sdc
\r
1239 String updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;
\r
1240 String responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcReq);
\r
1241 logger.info("value of sdc Response of uploading to sdc :" + responseStr);
\r
1242 String updatedServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);
\r
1243 if (!originalServiceUuid.equalsIgnoreCase(updatedServiceUuid)) {
\r
1244 url = url.replace(originalServiceUuid, updatedServiceUuid);
\r
1246 logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUuid);
\r
1247 sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);
\r
1248 cldsSdcServiceDetail = getCldsSdcServiceDetailFromJson(sdcServicesInformation);
\r
1249 uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,
\r
1250 locationArtifactName);
\r
1251 // To send location information also to sdc
\r
1252 updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;
\r
1253 responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcLocationReq);
\r
1254 logger.info("value of sdc Response of uploading location to sdc :" + responseStr);
\r