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.config.CldsReferenceProperties;
\r
62 import org.onap.clamp.clds.exception.SdcCommunicationException;
\r
63 import org.onap.clamp.clds.model.CldsAlarmCondition;
\r
64 import org.onap.clamp.clds.model.CldsServiceData;
\r
65 import org.onap.clamp.clds.model.CldsVfData;
\r
66 import org.onap.clamp.clds.model.CldsVfKPIData;
\r
67 import org.onap.clamp.clds.model.CldsVfcData;
\r
68 import org.onap.clamp.clds.model.properties.Global;
\r
69 import org.onap.clamp.clds.model.properties.ModelProperties;
\r
70 import org.onap.clamp.clds.model.sdc.SdcArtifact;
\r
71 import org.onap.clamp.clds.model.sdc.SdcResource;
\r
72 import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo;
\r
73 import org.onap.clamp.clds.model.sdc.SdcServiceDetail;
\r
74 import org.onap.clamp.clds.model.sdc.SdcServiceInfo;
\r
75 import org.onap.clamp.clds.util.CryptoUtils;
\r
76 import org.onap.clamp.clds.util.LoggingUtils;
\r
77 import org.springframework.beans.factory.annotation.Autowired;
\r
78 import org.springframework.stereotype.Component;
\r
81 public class SdcCatalogServices {
\r
83 private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcCatalogServices.class);
\r
84 private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
\r
85 private static final String RESOURCE_VF_TYPE = "VF";
\r
86 private static final String RESOURCE_VFC_TYPE = "VFC";
\r
87 private static final String RESOURCE_CVFC_TYPE = "CVFC";
\r
88 private static final String SDC_REQUESTID_PROPERTY_NAME = "sdc.header.requestId";
\r
89 private static final String SDC_METADATA_URL_PREFIX = "/metadata";
\r
90 private static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID";
\r
91 private static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url";
\r
92 private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";
\r
93 private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";
\r
94 private static final String RESOURCE_URL_PREFIX = "resources";
\r
96 private CldsReferenceProperties refProp;
\r
99 * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic
\r
100 * dGVzdDoxMjM0NTY=).
\r
102 * @return The String with Basic Auth and password
\r
103 * @throws GeneralSecurityException
\r
104 * In case of issue when decryting the SDC password
\r
105 * @throws DecoderException
\r
106 * In case of issues with the decoding of the HexString message
\r
108 private String getSdcBasicAuth() throws GeneralSecurityException, DecoderException {
\r
109 String sdcId = refProp.getStringValue("sdc.serviceUsername");
\r
110 String sdcPw = refProp.getStringValue("sdc.servicePassword");
\r
111 String password = CryptoUtils.decrypt(sdcPw);
\r
112 String idPw = Base64.getEncoder().encodeToString((sdcId + ":" + password).getBytes(StandardCharsets.UTF_8));
\r
113 return "Basic " + idPw;
\r
117 * This method get the SDC services Information with the corresponding
\r
122 * @return A Json String with all the service list
\r
123 * @throws GeneralSecurityException
\r
124 * In case of issue when decryting the SDC password
\r
125 * @throws DecoderException
\r
126 * In case of issues with the decoding of the Hex String
\r
128 public String getSdcServicesInformation(String uuid) throws GeneralSecurityException, DecoderException {
\r
129 Date startTime = new Date();
\r
130 String baseUrl = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);
\r
131 String basicAuth = getSdcBasicAuth();
\r
132 LoggingUtils.setTargetContext("SDC", "getSdcServicesInformation");
\r
134 String url = baseUrl;
\r
135 if (uuid != null && !uuid.isEmpty()) {
\r
136 url = baseUrl + "/" + uuid + SDC_METADATA_URL_PREFIX;
\r
138 URL urlObj = new URL(url);
\r
139 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
\r
140 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);
\r
141 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
\r
142 conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
\r
143 conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
\r
144 conn.setRequestMethod("GET");
\r
145 String resp = getResponse(conn);
\r
146 logger.debug("Services list received from SDC:" + resp);
\r
148 LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
\r
150 } catch (IOException e) {
\r
151 LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());
\r
152 LoggingUtils.setErrorContext("900", "Get sdc services error");
\r
153 logger.error("not able to get any service information from sdc for uuid:" + uuid, e);
\r
155 LoggingUtils.setTimeContext(startTime, new Date());
\r
156 metricsLogger.info("getSdcServicesInformation complete");
\r
162 * To remove duplicate serviceUUIDs from sdc services List.
\r
164 * @param rawCldsSdcServiceList
\r
165 * A list of CldsSdcServiceInfo
\r
166 * @return A list of CldsSdcServiceInfo without duplicate service UUID
\r
168 public List<SdcServiceInfo> removeDuplicateServices(List<SdcServiceInfo> rawCldsSdcServiceList) {
\r
169 List<SdcServiceInfo> cldsSdcServiceInfoList = null;
\r
170 if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {
\r
172 Collections.sort(rawCldsSdcServiceList);
\r
173 // and then take only the services with the max version (last in the
\r
174 // list with the same name)
\r
175 cldsSdcServiceInfoList = new ArrayList<>();
\r
176 for (int i = 1; i < rawCldsSdcServiceList.size(); i++) {
\r
177 // compare name with previous - if not equal, then keep the
\r
178 // previous (it's the last with that name)
\r
179 SdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);
\r
180 if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {
\r
181 cldsSdcServiceInfoList.add(prev);
\r
184 // add the last in the list
\r
185 cldsSdcServiceInfoList.add(rawCldsSdcServiceList.get(rawCldsSdcServiceList.size() - 1));
\r
187 return cldsSdcServiceInfoList;
\r
191 * To remove duplicate serviceUUIDs from sdc resources List.
\r
193 * @param rawCldsSdcResourceList
\r
194 * @return List of CldsSdcResource
\r
196 public List<SdcResource> removeDuplicateSdcResourceInstances(List<SdcResource> rawCldsSdcResourceList) {
\r
197 List<SdcResource> cldsSdcResourceList = null;
\r
198 if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) {
\r
200 Collections.sort(rawCldsSdcResourceList);
\r
201 // and then take only the resources with the max version (last in
\r
202 // the list with the same name)
\r
203 cldsSdcResourceList = new ArrayList<>();
\r
204 for (int i = 1; i < rawCldsSdcResourceList.size(); i++) {
\r
205 // compare name with previous - if not equal, then keep the
\r
206 // previous (it's the last with that name)
\r
207 SdcResource prev = rawCldsSdcResourceList.get(i - 1);
\r
208 if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {
\r
209 cldsSdcResourceList.add(prev);
\r
212 // add the last in the list
\r
213 cldsSdcResourceList.add(rawCldsSdcResourceList.get(rawCldsSdcResourceList.size() - 1));
\r
215 return cldsSdcResourceList;
\r
219 * To remove duplicate basic resources with same resourceUUIDs.
\r
221 * @param rawCldsSdcResourceListBasicList
\r
222 * @return List of CldsSdcResourceBasicInfo
\r
224 public List<SdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(
\r
225 List<SdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {
\r
226 List<SdcResourceBasicInfo> cldsSdcResourceBasicInfoList = null;
\r
227 if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {
\r
229 Collections.sort(rawCldsSdcResourceListBasicList);
\r
230 // and then take only the resources with the max version (last in
\r
231 // the list with the same name)
\r
232 cldsSdcResourceBasicInfoList = new ArrayList<>();
\r
233 for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {
\r
234 // compare name with previous - if not equal, then keep the
\r
235 // previous (it's the last with that name)
\r
236 SdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);
\r
237 if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {
\r
238 cldsSdcResourceBasicInfoList.add(prev);
\r
241 // add the last in the list
\r
242 cldsSdcResourceBasicInfoList
\r
243 .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));
\r
245 return cldsSdcResourceBasicInfoList;
\r
249 * To get ServiceUUID by using serviceInvariantUUID.
\r
251 * @param invariantId
\r
253 * @return The service UUID
\r
254 * @throws GeneralSecurityException
\r
255 * In case of issue when decryting the SDC password
\r
256 * @throws DecoderException
\r
257 * In case of issues with the decoding of the Hex String
\r
259 public String getServiceUuidFromServiceInvariantId(String invariantId)
\r
260 throws GeneralSecurityException, DecoderException {
\r
261 String serviceUuid = "";
\r
262 String responseStr = getSdcServicesInformation(null);
\r
263 List<SdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);
\r
264 List<SdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);
\r
265 if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {
\r
266 for (SdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {
\r
267 if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null
\r
268 && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {
\r
269 serviceUuid = currCldsSdcServiceInfo.getUuid();
\r
274 return serviceUuid;
\r
278 * To get CldsAsdsServiceInfo class by parsing json string.
\r
281 * The Json string that must be decoded
\r
282 * @return The list of CldsSdcServiceInfo, if there is a failure it return
\r
285 private List<SdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {
\r
286 ObjectMapper objectMapper = new ObjectMapper();
\r
287 if (StringUtils.isBlank(jsonStr)) {
\r
288 return new ArrayList<>();
\r
291 return objectMapper.readValue(jsonStr,
\r
292 objectMapper.getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));
\r
293 } catch (IOException e) {
\r
294 logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);
\r
295 return new ArrayList<>();
\r
300 * To get List of CldsSdcResourceBasicInfo class by parsing json string.
\r
303 * The JSOn string that must be decoded
\r
304 * @return The list of CldsSdcResourceBasicInfo, an empty list in case of
\r
307 private List<SdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {
\r
308 ObjectMapper objectMapper = new ObjectMapper();
\r
309 if (StringUtils.isBlank(jsonStr)) {
\r
310 return new ArrayList<>();
\r
313 return objectMapper.readValue(jsonStr,
\r
314 objectMapper.getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));
\r
315 } catch (IOException e) {
\r
316 logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);
\r
317 return new ArrayList<>();
\r
322 * To get CldsSdcServiceDetail by parsing json string.
\r
327 public SdcServiceDetail decodeCldsSdcServiceDetailFromJson(String jsonStr) {
\r
328 ObjectMapper objectMapper = new ObjectMapper();
\r
330 return objectMapper.readValue(jsonStr, SdcServiceDetail.class);
\r
331 } catch (IOException e) {
\r
332 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
426 * Check if the SDC Info in cache has expired.
\r
428 * @param cldsServiceData
\r
429 * The object representing the service data
\r
430 * @return boolean flag
\r
431 * @throws GeneralSecurityException
\r
432 * In case of issues with the decryting the encrypted password
\r
433 * @throws DecoderException
\r
434 * In case of issues with the decoding of the Hex String
\r
436 public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData)
\r
437 throws GeneralSecurityException, DecoderException {
\r
438 if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
\r
439 String cachedServiceUuid = cldsServiceData.getServiceUUID();
\r
440 String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID());
\r
441 String configuredMaxAge = refProp.getStringValue("clds.service.cache.invalidate.after.seconds");
\r
442 if (configuredMaxAge == null) {
\r
444 "clds.service.cache.invalidate.after.seconds NOT set in clds-reference.properties file, taking 60s as default");
\r
445 configuredMaxAge = "60";
\r
447 return (!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null
\r
448 && cldsServiceData.getAgeOfRecord() > Long.parseLong(configuredMaxAge));
\r
455 * Get the Service Data with Alarm Conditions for a given
\r
456 * invariantServiceUuid.
\r
458 * @param invariantServiceUuid
\r
459 * @return The CldsServiceData
\r
460 * @throws GeneralSecurityException
\r
461 * In case of issues with the decryting the encrypted password
\r
462 * @throws DecoderException
\r
463 * In case of issues with the decoding of the Hex String
\r
465 public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid)
\r
466 throws GeneralSecurityException, DecoderException {
\r
467 String url = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);
\r
468 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
469 String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);
\r
470 String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX;
\r
471 String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl);
\r
472 ObjectMapper objectMapper = new ObjectMapper();
\r
473 CldsServiceData cldsServiceData = new CldsServiceData();
\r
474 if (responseStr != null) {
\r
475 SdcServiceDetail cldsSdcServiceDetail;
\r
477 cldsSdcServiceDetail = objectMapper.readValue(responseStr, SdcServiceDetail.class);
\r
478 } catch (IOException e) {
\r
479 logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);
\r
480 throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);
\r
482 // To remove duplicate resources from serviceDetail and add valid
\r
484 if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {
\r
485 cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());
\r
486 cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());
\r
487 List<SdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(
\r
488 cldsSdcServiceDetail.getResources());
\r
489 if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {
\r
490 List<CldsVfData> cldsVfDataList = new ArrayList<>();
\r
491 for (SdcResource currCldsSdcResource : cldsSdcResourceList) {
\r
492 if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null
\r
493 && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {
\r
494 CldsVfData currCldsVfData = new CldsVfData();
\r
495 currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());
\r
496 currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());
\r
497 cldsVfDataList.add(currCldsVfData);
\r
500 cldsServiceData.setCldsVfs(cldsVfDataList);
\r
501 // For each vf in the list , add all vfc's
\r
502 getAllVfcForVfList(cldsVfDataList, catalogUrl);
\r
503 logger.info("Invariant Service ID of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());
\r
507 return cldsServiceData;
\r
510 private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl)
\r
511 throws GeneralSecurityException {
\r
512 // todo : refact this..
\r
513 if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {
\r
514 List<SdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_VF_TYPE);
\r
515 List<SdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(
\r
516 RESOURCE_VFC_TYPE);
\r
517 allVfcResources.addAll(getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_CVFC_TYPE));
\r
518 for (CldsVfData currCldsVfData : cldsVfDataList) {
\r
519 if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) {
\r
520 String resourceUuid = getResourceUuidFromResourceInvariantUuid(
\r
521 currCldsVfData.getVfInvariantResourceUUID(), allVfResources);
\r
522 if (resourceUuid != null) {
\r
523 String vfResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUuid
\r
524 + SDC_METADATA_URL_PREFIX;
\r
525 String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl);
\r
526 if (vfResponse != null) {
\r
527 // Below 2 line are to get the KPI(field path) data
\r
528 // associated with the VF's
\r
529 List<CldsVfKPIData> cldsVfKPIDataList = getFieldPathFromVF(vfResponse);
\r
530 currCldsVfData.setCldsKPIList(cldsVfKPIDataList);
\r
531 List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);
\r
532 if (vfcDataListFromVfResponse != null) {
\r
533 currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);
\r
534 if (!vfcDataListFromVfResponse.isEmpty()) {
\r
535 // To get artifacts for every VFC and get
\r
536 // alarm conditions from artifact
\r
537 for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {
\r
538 if (currCldsVfcData != null
\r
539 && currCldsVfcData.getVfcInvariantResourceUUID() != null) {
\r
540 String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(
\r
541 currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);
\r
542 if (resourceVfcUuid != null) {
\r
543 String vfcResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/"
\r
544 + resourceVfcUuid + SDC_METADATA_URL_PREFIX;
\r
545 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(
\r
546 vfcResourceUuidUrl);
\r
547 if (vfcResponse != null) {
\r
548 List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(
\r
550 currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc);
\r
553 logger.info("No resourceVFC UUID found for given invariantID:"
\r
554 + currCldsVfcData.getVfcInvariantResourceUUID());
\r
562 logger.info("No resourceUUID found for given invariantREsourceUUID:"
\r
563 + currCldsVfData.getVfInvariantResourceUUID());
\r
570 private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws GeneralSecurityException {
\r
571 ObjectMapper mapper = new ObjectMapper();
\r
572 ObjectNode vfResponseNode;
\r
574 vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
\r
575 } catch (IOException e) {
\r
576 logger.error("Exception when decoding the JSON list of CldsVfcData", e);
\r
577 return new ArrayList<>();
\r
579 ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
\r
580 List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
\r
581 if (vfcArrayNode != null) {
\r
582 for (JsonNode vfcjsonNode : vfcArrayNode) {
\r
583 ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;
\r
584 TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");
\r
585 if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
\r
586 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
587 } else if (resourceTypeNode != null && "CVFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
\r
588 handleCVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
592 return cldsVfcDataList;
\r
595 private void handleVFCtypeNode(ObjectNode currVfcNode, List<CldsVfcData> cldsVfcDataList) {
\r
596 CldsVfcData currCldsVfcData = new CldsVfcData();
\r
597 TextNode vfcResourceName = (TextNode) currVfcNode.get("resourceInstanceName");
\r
598 TextNode vfcInvariantResourceUuid = (TextNode) currVfcNode.get("resourceInvariantUUID");
\r
599 currCldsVfcData.setVfcName(vfcResourceName.textValue());
\r
600 currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid.textValue());
\r
601 cldsVfcDataList.add(currCldsVfcData);
\r
604 private void handleCVFCtypeNode(ObjectNode currVfcNode, List<CldsVfcData> cldsVfcDataList) {
\r
605 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
606 cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").textValue()));
\r
609 private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {
\r
610 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
611 List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
\r
612 if (resourceUUID != null) {
\r
613 String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX;
\r
615 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl);
\r
616 ObjectMapper mapper = new ObjectMapper();
\r
617 ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
\r
618 ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");
\r
619 if (vfcArrayNode != null) {
\r
620 for (JsonNode vfcjsonNode : vfcArrayNode) {
\r
621 ObjectNode currVfcNode = (ObjectNode) vfcjsonNode;
\r
622 TextNode resourceTypeNode = (TextNode) currVfcNode.get("resoucreType");
\r
623 if (resourceTypeNode != null && "VFC".equalsIgnoreCase(resourceTypeNode.textValue())) {
\r
624 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
628 } catch (IOException e) {
\r
629 logger.error("Exception during JSON analyzis", e);
\r
632 return cldsVfcDataList;
\r
635 private String removeUnwantedBracesFromString(String id) {
\r
636 return (id != null) ? id.replaceAll("\"", "") : "";
\r
639 private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws GeneralSecurityException {
\r
640 List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
\r
641 ObjectMapper mapper = new ObjectMapper();
\r
642 ObjectNode vfcResponseNode;
\r
644 vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);
\r
645 } catch (IOException e) {
\r
646 logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);
\r
647 return cldsAlarmConditionList;
\r
649 ArrayNode artifactsArrayNode = (ArrayNode) vfcResponseNode.get("artifacts");
\r
650 if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
\r
651 for (int index = 0; index < artifactsArrayNode.size(); index++) {
\r
652 ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);
\r
653 TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");
\r
654 if (artifactUrlNode != null) {
\r
655 String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());
\r
656 cldsAlarmConditionList.addAll(parseCsvToGetAlarmConditions(responsesFromArtifactUrl));
\r
657 logger.info(responsesFromArtifactUrl);
\r
661 return cldsAlarmConditionList;
\r
664 private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) {
\r
666 List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
\r
667 Reader alarmReader = new StringReader(allAlarmCondsValues);
\r
668 Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
\r
669 if (records != null) {
\r
670 Iterator<CSVRecord> it = records.iterator();
\r
671 if (it.hasNext()) {
\r
674 it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));
\r
676 return cldsAlarmConditionList;
\r
677 } catch (IOException e) {
\r
678 logger.error("Exception when attempting to parse the CSV containing the alarm", e);
\r
679 return new ArrayList<>();
\r
683 // Method to get the artifact for any particular VF
\r
684 private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws GeneralSecurityException {
\r
685 List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
\r
686 ObjectMapper mapper = new ObjectMapper();
\r
687 ObjectNode vfResponseNode;
\r
689 vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);
\r
690 } catch (IOException e) {
\r
691 logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);
\r
692 return cldsVfKPIDataList;
\r
694 ArrayNode artifactsArrayNode = (ArrayNode) vfResponseNode.get("artifacts");
\r
695 if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
\r
696 for (int index = 0; index < artifactsArrayNode.size(); index++) {
\r
697 ObjectNode currArtifactNode = (ObjectNode) artifactsArrayNode.get(index);
\r
698 TextNode artifactUrlNode = (TextNode) currArtifactNode.get("artifactURL");
\r
699 TextNode artifactNameNode = (TextNode) currArtifactNode.get("artifactName");
\r
700 String artifactName = "";
\r
701 if (artifactNameNode != null) {
\r
702 artifactName = artifactNameNode.textValue();
\r
703 artifactName = artifactName.substring(artifactName.lastIndexOf('.') + 1);
\r
705 if (artifactUrlNode != null && "csv".equalsIgnoreCase(artifactName)) {
\r
706 String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.textValue());
\r
707 cldsVfKPIDataList.addAll(parseCsvToGetFieldPath(responsesFromArtifactUrl));
\r
708 logger.info(responsesFromArtifactUrl);
\r
712 return cldsVfKPIDataList;
\r
715 private CldsVfKPIData convertCsvRecordToKpiData(CSVRecord record) {
\r
716 if (record.size() < 6) {
\r
717 logger.debug("invalid csv field path Record,total columns less than 6: " + record);
\r
720 if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
\r
721 || StringUtils.isBlank(record.get(5))) {
\r
722 logger.debug("Invalid csv field path Record,one of column is having blank value : " + record);
\r
725 CldsVfKPIData cldsVfKPIData = new CldsVfKPIData();
\r
726 cldsVfKPIData.setNfNamingCode(record.get(0).trim());
\r
727 cldsVfKPIData.setNfNamingValue(record.get(1).trim());
\r
728 cldsVfKPIData.setFieldPath(record.get(2).trim());
\r
729 cldsVfKPIData.setFieldPathValue(record.get(3).trim());
\r
730 cldsVfKPIData.setThresholdName(record.get(4).trim());
\r
731 cldsVfKPIData.setThresholdValue(record.get(5).trim());
\r
732 return cldsVfKPIData;
\r
735 // Method to get the artifactURL Data and set the CldsVfKPIData node
\r
736 private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) {
\r
738 List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
\r
739 Reader alarmReader = new StringReader(allFieldPathValues);
\r
740 Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
\r
741 if (records != null) {
\r
742 for (CSVRecord record : records) {
\r
743 CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);
\r
744 if (kpiData != null) {
\r
745 cldsVfKPIDataList.add(kpiData);
\r
749 return cldsVfKPIDataList;
\r
750 } catch (IOException e) {
\r
751 logger.error("Exception when attempting to parse the CSV containing the alarm kpi data", e);
\r
752 return new ArrayList<>();
\r
756 private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {
\r
757 if (record == null) {
\r
760 if (record.size() < 5) {
\r
761 logger.debug("invalid csv alarm Record,total columns less than 5: " + record);
\r
764 if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
\r
765 || StringUtils.isBlank(record.get(4))) {
\r
766 logger.debug("invalid csv alarm Record,one of column is having blank value : " + record);
\r
769 CldsAlarmCondition cldsAlarmCondition = new CldsAlarmCondition();
\r
770 cldsAlarmCondition.setEventSourceType(record.get(1));
\r
771 cldsAlarmCondition.setEventName(record.get(2));
\r
772 cldsAlarmCondition.setAlarmConditionKey(record.get(3));
\r
773 cldsAlarmCondition.setSeverity(record.get(4));
\r
774 cldsAlarmConditionList.add(cldsAlarmCondition);
\r
777 // Get the responses for the current artifact from the artifacts URL.
\r
778 private String getResponsesFromArtifactUrl(String artifactsUrl) {
\r
779 String hostUrl = refProp.getStringValue("sdc.hostUrl");
\r
780 String artifactsUrlReworked = artifactsUrl.replaceAll("\"", "");
\r
781 String artifactUrl = hostUrl + artifactsUrlReworked;
\r
782 logger.info("value of artifactURl:" + artifactUrl);
\r
783 String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl);
\r
784 logger.info("value of artifactResponse:" + currArtifactResponse);
\r
785 return currArtifactResponse;
\r
789 * Service to services/resources/artifacts from sdc.Pass alarmConditions as
\r
790 * true to get alarm conditons from artifact url and else it is false
\r
793 * The URL to trigger
\r
794 * @return The String containing the payload
\r
796 public String getCldsServicesOrResourcesBasedOnURL(String url) {
\r
797 Date startTime = new Date();
\r
799 LoggingUtils.setTargetContext("SDC", "getCldsServicesOrResourcesBasedOnURL");
\r
800 String urlReworked = removeUnwantedBracesFromString(url);
\r
801 URL urlObj = new URL(urlReworked);
\r
802 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
\r
803 String basicAuth = getSdcBasicAuth();
\r
804 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);
\r
805 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
\r
806 conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
\r
807 conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
\r
808 conn.setRequestMethod("GET");
\r
809 int responseCode = conn.getResponseCode();
\r
810 logger.info("Sdc resource url - " + urlReworked + " , responseCode=" + responseCode);
\r
811 try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
\r
812 String response = IOUtils.toString(in);
\r
813 LoggingUtils.setResponseContext("0", "Get sdc resources success", this.getClass().getName());
\r
816 } catch (IOException e) {
\r
817 LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());
\r
818 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
819 logger.error("Exception occurred during query to SDC", e);
\r
821 } catch (DecoderException e) {
\r
822 LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());
\r
823 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
824 logger.error("Exception when attempting to decode the Hex string", e);
\r
825 throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);
\r
826 } catch (GeneralSecurityException e) {
\r
827 LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());
\r
828 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
829 logger.error("Exception when attempting to decrypt the encrypted password", e);
\r
830 throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);
\r
832 LoggingUtils.setTimeContext(startTime, new Date());
\r
833 metricsLogger.info("getCldsServicesOrResourcesBasedOnURL completed");
\r
838 * To create properties object by using cldsServicedata.
\r
840 * @param globalProps
\r
841 * @param cldsServiceData
\r
844 public String createPropertiesObjectByUUID(String globalProps, CldsServiceData cldsServiceData) {
\r
845 String totalPropsStr;
\r
846 ObjectMapper mapper = new ObjectMapper();
\r
847 ObjectNode globalPropsJson;
\r
848 if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
\r
849 // Objectnode to save all byservice, byvf , byvfc and byalarm nodes
\r
850 ObjectNode byIdObjectNode = mapper.createObjectNode();
\r
851 // To create vf ResourceUUID node with serviceInvariantUUID
\r
852 ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(mapper,
\r
854 byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVf);
\r
855 // To create byVf and vfcResourceNode with vfResourceUUID
\r
856 ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs());
\r
857 byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);
\r
859 ObjectNode kpiObjectNode = mapper.createObjectNode();
\r
860 if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
861 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
862 if (currCldsVfData != null) {
\r
863 createKpiObjectNodeByVfUuid(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());
\r
867 byIdObjectNode.putPOJO("byKpi", kpiObjectNode);
\r
868 // To create byVfc and alarmCondition with vfcResourceUUID
\r
869 ObjectNode vfcResourceUuidObjectNode = mapper.createObjectNode();
\r
870 if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
871 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
872 if (currCldsVfData != null) {
\r
873 createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,
\r
874 currCldsVfData.getCldsVfcs());
\r
878 byIdObjectNode.putPOJO("byVfc", vfcResourceUuidObjectNode);
\r
879 // To create byAlarmCondition with alarmConditionKey
\r
880 List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
\r
882 ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions);
\r
883 byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);
\r
884 // To create byAlertDescription with AlertDescription
\r
885 List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
\r
886 "alertDescription");
\r
887 ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(mapper, allAlertDescriptions);
\r
888 byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);
\r
889 globalPropsJson = decodeGlobalProp(globalProps, mapper);
\r
890 globalPropsJson.putPOJO("shared", byIdObjectNode);
\r
891 logger.info("Global properties JSON created with SDC info:" + globalPropsJson);
\r
894 * to create json with total properties when no serviceUUID passed
\r
896 globalPropsJson = decodeGlobalProp(globalProps, mapper);
\r
898 totalPropsStr = globalPropsJson.toString();
\r
899 return totalPropsStr;
\r
902 private ObjectNode decodeGlobalProp(String globalProps, ObjectMapper mapper) {
\r
904 return (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
\r
905 } catch (IOException e) {
\r
906 logger.error("Exception occurred during decoding of the global props, returning an empty objectNode", e);
\r
907 return mapper.createObjectNode();
\r
912 * Method to get alarm conditions/alert description from Service Data.
\r
914 * @param cldsServiceData
\r
915 * CldsServiceData the Service Data to analyze
\r
917 * The String event name that will be used to filter the alarm
\r
919 * @return The list of CldsAlarmCondition for the event name specified
\r
921 public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData,
\r
922 String eventName) {
\r
923 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
924 if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null
\r
925 && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
926 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
927 alarmCondList.addAll(getAllAlarmConditionsFromCldsVfData(currCldsVfData, eventName));
\r
930 return alarmCondList;
\r
934 * Method to get alarm conditions/alert description from VF Data.
\r
936 * @param currCldsVfData
\r
937 * The Vf Data to analyze
\r
939 * The String event name that will be used to filter the alarm
\r
941 * @return The list of CldsAlarmCondition for the event name specified
\r
943 private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfData(CldsVfData currCldsVfData, String eventName) {
\r
944 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
945 if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {
\r
946 for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
\r
947 alarmCondList.addAll(getAllAlarmConditionsFromCldsVfcData(currCldsVfcData, eventName));
\r
950 return alarmCondList;
\r
954 * Method to get alarm conditions/alert description from VFC Data.
\r
956 * @param currCldsVfcData
\r
957 * The VfC Data to analyze
\r
959 * The String event name that will be used to filter the alarm
\r
961 * @return The list of CldsAlarmCondition for the event name specified
\r
963 private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfcData(CldsVfcData currCldsVfcData,
\r
964 String eventName) {
\r
965 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
966 if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null
\r
967 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
968 for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
\r
969 if (currCldsAlarmCondition != null
\r
970 && currCldsAlarmCondition.getEventName().equalsIgnoreCase(eventName)) {
\r
971 alarmCondList.add(currCldsAlarmCondition);
\r
975 return alarmCondList;
\r
978 private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper,
\r
979 List<CldsAlarmCondition> cldsAlarmCondList) {
\r
980 ObjectNode alarmCondKeyNode = mapper.createObjectNode();
\r
981 if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {
\r
982 for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {
\r
983 if (currCldsAlarmCondition != null) {
\r
984 ObjectNode alarmCondNode = mapper.createObjectNode();
\r
985 alarmCondNode.put("eventSourceType", currCldsAlarmCondition.getEventSourceType());
\r
986 alarmCondNode.put("eventSeverity", currCldsAlarmCondition.getSeverity());
\r
987 alarmCondKeyNode.putPOJO(currCldsAlarmCondition.getAlarmConditionKey(), alarmCondNode);
\r
991 ObjectNode alarmCondNode = mapper.createObjectNode();
\r
992 alarmCondNode.put("eventSourceType", "");
\r
993 alarmCondNode.put("eventSeverity", "");
\r
994 alarmCondKeyNode.putPOJO("", alarmCondNode);
\r
996 return alarmCondKeyNode;
\r
999 private ObjectNode createVfObjectNodeByServiceInvariantUuid(ObjectMapper mapper, CldsServiceData cldsServiceData) {
\r
1000 ObjectNode invariantUuidObjectNode = mapper.createObjectNode();
\r
1001 ObjectNode vfObjectNode = mapper.createObjectNode();
\r
1002 ObjectNode vfUuidNode = mapper.createObjectNode();
\r
1003 List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();
\r
1004 if (cldsVfsList != null && !cldsVfsList.isEmpty()) {
\r
1005 for (CldsVfData currCldsVfData : cldsVfsList) {
\r
1006 if (currCldsVfData != null) {
\r
1007 vfUuidNode.put(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());
\r
1011 vfUuidNode.put("", "");
\r
1013 vfObjectNode.putPOJO("vf", vfUuidNode);
\r
1014 invariantUuidObjectNode.putPOJO(cldsServiceData.getServiceInvariantUUID(), vfObjectNode);
\r
1015 return invariantUuidObjectNode;
\r
1018 private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode,
\r
1019 List<CldsVfKPIData> cldsVfKpiDataList) {
\r
1020 if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {
\r
1021 for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {
\r
1022 if (currCldsVfKpiData != null) {
\r
1023 ObjectNode thresholdNameObjectNode = mapper.createObjectNode();
\r
1024 ObjectNode fieldPathObjectNode = mapper.createObjectNode();
\r
1025 ObjectNode nfNamingCodeNode = mapper.createObjectNode();
\r
1026 fieldPathObjectNode.put(currCldsVfKpiData.getFieldPathValue(),
\r
1027 currCldsVfKpiData.getFieldPathValue());
\r
1028 nfNamingCodeNode.put(currCldsVfKpiData.getNfNamingValue(), currCldsVfKpiData.getNfNamingValue());
\r
1029 thresholdNameObjectNode.putPOJO("fieldPath", fieldPathObjectNode);
\r
1030 thresholdNameObjectNode.putPOJO("nfNamingCode", nfNamingCodeNode);
\r
1031 vfResourceUuidObjectNode.putPOJO(currCldsVfKpiData.getThresholdValue(), thresholdNameObjectNode);
\r
1037 private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUuidObjectNode,
\r
1038 List<CldsVfcData> cldsVfcDataList) {
\r
1039 ObjectNode vfcObjectNode = mapper.createObjectNode();
\r
1040 ObjectNode alarmCondNode = mapper.createObjectNode();
\r
1041 ObjectNode alertDescNode = mapper.createObjectNode();
\r
1042 if (cldsVfcDataList != null && !cldsVfcDataList.isEmpty()) {
\r
1043 for (CldsVfcData currCldsVfcData : cldsVfcDataList) {
\r
1044 if (currCldsVfcData != null) {
\r
1045 if (currCldsVfcData.getCldsAlarmConditions() != null
\r
1046 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
1047 for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
\r
1048 if ("alarmCondition".equalsIgnoreCase(currCldsAlarmCondition.getEventName())) {
\r
1049 alarmCondNode.put(currCldsAlarmCondition.getAlarmConditionKey(),
\r
1050 currCldsAlarmCondition.getAlarmConditionKey());
\r
1052 alertDescNode.put(currCldsAlarmCondition.getAlarmConditionKey(),
\r
1053 currCldsAlarmCondition.getAlarmConditionKey());
\r
1057 vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);
\r
1058 vfcObjectNode.putPOJO("alertDescription", alertDescNode);
\r
1059 vfcResourceUuidObjectNode.putPOJO(currCldsVfcData.getVfcInvariantResourceUUID(), vfcObjectNode);
\r
1063 alarmCondNode.put("", "");
\r
1064 vfcObjectNode.putPOJO("alarmCondition", alarmCondNode);
\r
1065 alertDescNode.put("", "");
\r
1066 vfcObjectNode.putPOJO("alertDescription", alarmCondNode);
\r
1067 vfcResourceUuidObjectNode.putPOJO("", vfcObjectNode);
\r
1072 * Method to create vfc and kpi nodes inside vf node
\r
1075 * @param cldsVfDataList
\r
1078 private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {
\r
1079 ObjectNode vfUuidObjectNode = mapper.createObjectNode();
\r
1080 if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {
\r
1081 for (CldsVfData currCldsVfData : cldsVfDataList) {
\r
1082 if (currCldsVfData != null) {
\r
1083 ObjectNode vfObjectNode = mapper.createObjectNode();
\r
1084 ObjectNode vfcUuidNode = mapper.createObjectNode();
\r
1085 ObjectNode kpiObjectNode = mapper.createObjectNode();
\r
1086 if (currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {
\r
1087 for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
\r
1088 if (currCldsVfcData.getCldsAlarmConditions() != null
\r
1089 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
1090 vfcUuidNode.put(currCldsVfcData.getVfcInvariantResourceUUID(),
\r
1091 currCldsVfcData.getVfcName());
\r
1095 vfcUuidNode.put("", "");
\r
1097 if (currCldsVfData.getCldsKPIList() != null && !currCldsVfData.getCldsKPIList().isEmpty()) {
\r
1098 for (CldsVfKPIData currCldsVfKPIData : currCldsVfData.getCldsKPIList()) {
\r
1099 kpiObjectNode.put(currCldsVfKPIData.getThresholdValue(),
\r
1100 currCldsVfKPIData.getThresholdValue());
\r
1103 kpiObjectNode.put("", "");
\r
1105 vfObjectNode.putPOJO("vfc", vfcUuidNode);
\r
1106 vfObjectNode.putPOJO("kpi", kpiObjectNode);
\r
1107 vfUuidObjectNode.putPOJO(currCldsVfData.getVfInvariantResourceUUID(), vfObjectNode);
\r
1111 ObjectNode vfcUuidNode = mapper.createObjectNode();
\r
1112 vfcUuidNode.put("", "");
\r
1113 ObjectNode vfcObjectNode = mapper.createObjectNode();
\r
1114 vfcObjectNode.putPOJO("vfc", vfcUuidNode);
\r
1115 vfUuidObjectNode.putPOJO("", vfcObjectNode);
\r
1117 return vfUuidObjectNode;
\r
1121 * This method searches the equivalent artifact UUID for a specific
\r
1122 * artifactName in a SdcServiceDetail.
\r
1124 * @param cldsSdcServiceDetail
\r
1125 * The SdcServiceDetail that will be analyzed
\r
1126 * @param artifactName
\r
1127 * The artifact name that will be searched
\r
1128 * @return The artifact UUID found
\r
1130 public String getArtifactIdIfArtifactAlreadyExists(SdcServiceDetail cldsSdcServiceDetail, String artifactName) {
\r
1131 String artifactUuid = null;
\r
1132 boolean artifactExists = false;
\r
1133 if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null
\r
1134 && !cldsSdcServiceDetail.getResources().isEmpty()) {
\r
1135 for (SdcResource currCldsSdcResource : cldsSdcServiceDetail.getResources()) {
\r
1136 if (artifactExists) {
\r
1139 if (currCldsSdcResource != null && currCldsSdcResource.getArtifacts() != null
\r
1140 && !currCldsSdcResource.getArtifacts().isEmpty()) {
\r
1141 for (SdcArtifact currCldsSdcArtifact : currCldsSdcResource.getArtifacts()) {
\r
1142 if (currCldsSdcArtifact != null && currCldsSdcArtifact.getArtifactName() != null
\r
1143 && currCldsSdcArtifact.getArtifactName().equalsIgnoreCase(artifactName)) {
\r
1144 artifactUuid = currCldsSdcArtifact.getArtifactUUID();
\r
1145 artifactExists = true;
\r
1152 return artifactUuid;
\r
1155 // To get all sdc VF/VFC Resources basic info.
\r
1156 private List<SdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {
\r
1157 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
1158 String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;
\r
1159 String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl);
\r
1160 return removeDuplicateSdcResourceBasicInfo(getAllSdcResourcesListFromJson(allSdcVfcResources));
\r
1163 private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,
\r
1164 List<SdcResourceBasicInfo> resourceInfoList) {
\r
1165 String resourceUuid = null;
\r
1166 if (resourceInfoList != null && !resourceInfoList.isEmpty()) {
\r
1167 for (SdcResourceBasicInfo currResource : resourceInfoList) {
\r
1168 if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null
\r
1169 && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {
\r
1170 resourceUuid = currResource.getUuid();
\r
1175 return resourceUuid;
\r
1178 // Method to get service invariant uuid from model properties.
\r
1179 private String getServiceInvariantUuidFromProps(ModelProperties props) {
\r
1180 String invariantUuid = "";
\r
1181 Global globalProps = props.getGlobal();
\r
1182 if (globalProps != null && globalProps.getService() != null) {
\r
1183 invariantUuid = globalProps.getService();
\r
1185 return invariantUuid;
\r
1189 * This method upload the BluePrint to SDC.
\r
1192 * The Clds model Properties
\r
1194 * The user id for SDC
\r
1195 * @param sdcReqUrlsList
\r
1196 * The list of SDC URL to try
\r
1197 * @param formattedSdcReq
\r
1198 * The blueprint to upload
\r
1199 * @param formattedSdcLocationReq
\r
1200 * THe location Blueprint to upload
\r
1201 * @param artifactName
\r
1202 * The artifact name from where we can get the Artifact UUID
\r
1203 * @param locationArtifactName
\r
1204 * The location artifact name from where we can get the Artifact
\r
1206 * @throws GeneralSecurityException
\r
1207 * In case of issues with the decryting the encrypted password
\r
1208 * @throws DecoderException
\r
1209 * In case of issues with the decoding of the Hex String
\r
1211 public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,
\r
1212 String formattedSdcLocationReq, String artifactName, String locationArtifactName)
\r
1213 throws GeneralSecurityException, DecoderException {
\r
1214 logger.info("userid=" + userid);
\r
1215 String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);
\r
1216 if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {
\r
1217 for (String url : sdcReqUrlsList) {
\r
1218 if (url != null) {
\r
1219 String originalServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);
\r
1220 logger.info("ServiceUUID used before upload in url:" + originalServiceUuid);
\r
1221 String sdcServicesInformation = getSdcServicesInformation(originalServiceUuid);
\r
1222 SdcServiceDetail cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);
\r
1223 String uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,
\r
1225 // Upload artifacts to sdc
\r
1226 String updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;
\r
1227 String responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcReq);
\r
1228 logger.info("value of sdc Response of uploading to sdc :" + responseStr);
\r
1229 String updatedServiceUuid = getServiceUuidFromServiceInvariantId(serviceInvariantUuid);
\r
1230 if (!originalServiceUuid.equalsIgnoreCase(updatedServiceUuid)) {
\r
1231 url = url.replace(originalServiceUuid, updatedServiceUuid);
\r
1233 logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUuid);
\r
1234 sdcServicesInformation = getSdcServicesInformation(updatedServiceUuid);
\r
1235 cldsSdcServiceDetail = decodeCldsSdcServiceDetailFromJson(sdcServicesInformation);
\r
1236 uploadedArtifactUuid = getArtifactIdIfArtifactAlreadyExists(cldsSdcServiceDetail,
\r
1237 locationArtifactName);
\r
1238 // To send location information also to sdc
\r
1239 updateUrl = uploadedArtifactUuid != null ? url + "/" + uploadedArtifactUuid : url;
\r
1240 responseStr = uploadArtifactToSdc(prop, userid, updateUrl, formattedSdcLocationReq);
\r
1241 logger.info("value of sdc Response of uploading location to sdc :" + responseStr);
\r