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 * Modifications copyright (c) 2018 Nokia
\r
21 * ===================================================================
\r
25 package org.onap.clamp.clds.client.req.sdc;
\r
27 import com.att.eelf.configuration.EELFLogger;
\r
28 import com.att.eelf.configuration.EELFManager;
\r
30 import com.google.gson.JsonArray;
\r
31 import com.google.gson.JsonElement;
\r
32 import com.google.gson.JsonObject;
\r
33 import com.google.gson.JsonParseException;
\r
34 import com.google.gson.reflect.TypeToken;
\r
35 import java.io.BufferedReader;
\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.lang.reflect.Type;
\r
42 import java.net.HttpURLConnection;
\r
43 import java.net.URL;
\r
44 import java.nio.charset.StandardCharsets;
\r
45 import java.security.GeneralSecurityException;
\r
46 import java.util.ArrayList;
\r
47 import java.util.Base64;
\r
48 import java.util.Collections;
\r
49 import java.util.Date;
\r
50 import java.util.Iterator;
\r
51 import java.util.List;
\r
53 import org.apache.commons.codec.DecoderException;
\r
54 import org.apache.commons.csv.CSVFormat;
\r
55 import org.apache.commons.csv.CSVRecord;
\r
56 import org.apache.commons.io.IOUtils;
\r
57 import org.apache.commons.lang3.StringUtils;
\r
58 import org.apache.http.HttpHeaders;
\r
59 import org.onap.clamp.clds.config.ClampProperties;
\r
60 import org.onap.clamp.clds.exception.sdc.SdcCommunicationException;
\r
61 import org.onap.clamp.clds.model.CldsAlarmCondition;
\r
62 import org.onap.clamp.clds.model.CldsServiceData;
\r
63 import org.onap.clamp.clds.model.CldsVfData;
\r
64 import org.onap.clamp.clds.model.CldsVfKPIData;
\r
65 import org.onap.clamp.clds.model.CldsVfcData;
\r
66 import org.onap.clamp.clds.model.sdc.SdcResource;
\r
67 import org.onap.clamp.clds.model.sdc.SdcResourceBasicInfo;
\r
68 import org.onap.clamp.clds.model.sdc.SdcServiceDetail;
\r
69 import org.onap.clamp.clds.model.sdc.SdcServiceInfo;
\r
70 import org.onap.clamp.clds.service.CldsService;
\r
71 import org.onap.clamp.clds.util.CryptoUtils;
\r
72 import org.onap.clamp.clds.util.JsonUtils;
\r
73 import org.onap.clamp.clds.util.LoggingUtils;
\r
74 import org.springframework.beans.factory.annotation.Autowired;
\r
75 import org.springframework.context.annotation.Primary;
\r
76 import org.springframework.stereotype.Component;
\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
94 private static final LoggingUtils utils = new LoggingUtils(logger);
\r
96 private static final Type LIST_SDC_SERVICE_INFO_TYPE = new TypeToken<List<SdcServiceInfo>>() {
\r
99 private static final Type LIST_SDC_RESOURCE_BASIC_INFO_TYPE = new TypeToken<List<SdcResourceBasicInfo>>() {
\r
103 private ClampProperties refProp;
\r
106 * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic
\r
107 * dGVzdDoxMjM0NTY=).
\r
109 * @return The String with Basic Auth and password
\r
110 * @throws GeneralSecurityException
\r
111 * In case of issue when decryting the SDC password
\r
112 * @throws DecoderException
\r
113 * In case of issues with the decoding of the HexString message
\r
115 public String getSdcBasicAuth() throws GeneralSecurityException, DecoderException {
\r
116 String sdcId = refProp.getStringValue("sdc.serviceUsername");
\r
117 String sdcPw = refProp.getStringValue("sdc.servicePassword");
\r
118 String password = CryptoUtils.decrypt(sdcPw);
\r
119 String idPw = Base64.getEncoder().encodeToString((sdcId + ":" + password).getBytes(StandardCharsets.UTF_8));
\r
120 return "Basic " + idPw;
\r
124 * This method get the SDC services Information with the corresponding Service
\r
129 * @return A Json String with all the service list
\r
130 * @throws GeneralSecurityException
\r
131 * In case of issue when decryting the SDC password
\r
132 * @throws DecoderException
\r
133 * In case of issues with the decoding of the Hex String
\r
135 public String getSdcServicesInformation(String uuid) throws GeneralSecurityException, DecoderException {
\r
136 Date startTime = new Date();
\r
137 String baseUrl = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);
\r
138 String basicAuth = getSdcBasicAuth();
\r
140 String url = baseUrl;
\r
141 if (uuid != null && !uuid.isEmpty()) {
\r
142 url = baseUrl + "/" + uuid + SDC_METADATA_URL_PREFIX;
\r
144 URL urlObj = new URL(url);
\r
145 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
\r
146 conn = utils.invoke(conn, "SDC", "getSdcServicesInformation");
\r
147 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);
\r
148 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
\r
149 conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
\r
150 conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
\r
151 conn.setRequestMethod("GET");
\r
152 String resp = getResponse(conn);
\r
153 logger.debug("Services list received from SDC:" + resp);
\r
154 utils.invokeReturn();
\r
156 } catch (IOException e) {
\r
157 LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());
\r
158 LoggingUtils.setErrorContext("900", "Get sdc services error");
\r
159 logger.error("not able to get any service information from sdc for uuid:" + uuid, e);
\r
161 LoggingUtils.setTimeContext(startTime, new Date());
\r
162 metricsLogger.info("getSdcServicesInformation complete");
\r
164 utils.invokeReturn();
\r
169 * To remove duplicate serviceUUIDs from sdc services List.
\r
171 * @param rawCldsSdcServiceList
\r
172 * A list of CldsSdcServiceInfo
\r
173 * @return A list of CldsSdcServiceInfo without duplicate service UUID
\r
175 public List<SdcServiceInfo> removeDuplicateServices(List<SdcServiceInfo> rawCldsSdcServiceList) {
\r
176 List<SdcServiceInfo> cldsSdcServiceInfoList = null;
\r
177 if (rawCldsSdcServiceList != null && !rawCldsSdcServiceList.isEmpty()) {
\r
179 Collections.sort(rawCldsSdcServiceList);
\r
180 // and then take only the services with the max version (last in the
\r
181 // list with the same name)
\r
182 cldsSdcServiceInfoList = new ArrayList<>();
\r
183 for (int i = 1; i < rawCldsSdcServiceList.size(); i++) {
\r
184 // compare name with previous - if not equal, then keep the
\r
185 // previous (it's the last with that name)
\r
186 SdcServiceInfo prev = rawCldsSdcServiceList.get(i - 1);
\r
187 if (!rawCldsSdcServiceList.get(i).getName().equals(prev.getName())) {
\r
188 cldsSdcServiceInfoList.add(prev);
\r
191 // add the last in the list
\r
192 cldsSdcServiceInfoList.add(rawCldsSdcServiceList.get(rawCldsSdcServiceList.size() - 1));
\r
194 return cldsSdcServiceInfoList;
\r
198 * To remove duplicate serviceUUIDs from sdc resources List.
\r
200 * @param rawCldsSdcResourceList
\r
201 * @return List of CldsSdcResource
\r
203 public List<SdcResource> removeDuplicateSdcResourceInstances(List<SdcResource> rawCldsSdcResourceList) {
\r
204 List<SdcResource> cldsSdcResourceList = null;
\r
205 if (rawCldsSdcResourceList != null && !rawCldsSdcResourceList.isEmpty()) {
\r
207 Collections.sort(rawCldsSdcResourceList);
\r
208 // and then take only the resources with the max version (last in
\r
209 // the list with the same name)
\r
210 cldsSdcResourceList = new ArrayList<>();
\r
211 for (int i = 1; i < rawCldsSdcResourceList.size(); i++) {
\r
212 // compare name with previous - if not equal, then keep the
\r
213 // previous (it's the last with that name)
\r
214 SdcResource prev = rawCldsSdcResourceList.get(i - 1);
\r
215 if (!rawCldsSdcResourceList.get(i).getResourceInstanceName().equals(prev.getResourceInstanceName())) {
\r
216 cldsSdcResourceList.add(prev);
\r
219 // add the last in the list
\r
220 cldsSdcResourceList.add(rawCldsSdcResourceList.get(rawCldsSdcResourceList.size() - 1));
\r
222 return cldsSdcResourceList;
\r
226 * To remove duplicate basic resources with same resourceUUIDs.
\r
228 * @param rawCldsSdcResourceListBasicList
\r
229 * @return List of CldsSdcResourceBasicInfo
\r
231 public List<SdcResourceBasicInfo> removeDuplicateSdcResourceBasicInfo(
\r
232 List<SdcResourceBasicInfo> rawCldsSdcResourceListBasicList) {
\r
233 List<SdcResourceBasicInfo> cldsSdcResourceBasicInfoList = new ArrayList<>();
\r
234 if (rawCldsSdcResourceListBasicList != null && !rawCldsSdcResourceListBasicList.isEmpty()) {
\r
236 Collections.sort(rawCldsSdcResourceListBasicList);
\r
237 // and then take only the resources with the max version (last in
\r
238 // the list with the same name)
\r
239 for (int i = 1; i < rawCldsSdcResourceListBasicList.size(); i++) {
\r
240 // compare name with previous - if not equal, then keep the
\r
241 // previous (it's the last with that name)
\r
242 SdcResourceBasicInfo prev = rawCldsSdcResourceListBasicList.get(i - 1);
\r
243 if (!rawCldsSdcResourceListBasicList.get(i).getName().equals(prev.getName())) {
\r
244 cldsSdcResourceBasicInfoList.add(prev);
\r
247 // add the last in the list
\r
248 cldsSdcResourceBasicInfoList
\r
249 .add(rawCldsSdcResourceListBasicList.get(rawCldsSdcResourceListBasicList.size() - 1));
\r
251 return cldsSdcResourceBasicInfoList;
\r
255 * To get ServiceUUID by using serviceInvariantUUID.
\r
257 * @param invariantId
\r
259 * @return The service UUID
\r
260 * @throws GeneralSecurityException
\r
261 * In case of issue when decryting the SDC password
\r
262 * @throws DecoderException
\r
263 * In case of issues with the decoding of the Hex String
\r
265 public String getServiceUuidFromServiceInvariantId(String invariantId)
\r
266 throws GeneralSecurityException, DecoderException {
\r
267 String serviceUuid = "";
\r
268 String responseStr = getSdcServicesInformation(null);
\r
269 List<SdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);
\r
270 List<SdcServiceInfo> cldsSdcServicesList = removeDuplicateServices(rawCldsSdcServicesList);
\r
271 if (cldsSdcServicesList != null && !cldsSdcServicesList.isEmpty()) {
\r
272 for (SdcServiceInfo currCldsSdcServiceInfo : cldsSdcServicesList) {
\r
273 if (currCldsSdcServiceInfo != null && currCldsSdcServiceInfo.getInvariantUUID() != null
\r
274 && currCldsSdcServiceInfo.getInvariantUUID().equalsIgnoreCase(invariantId)) {
\r
275 serviceUuid = currCldsSdcServiceInfo.getUuid();
\r
280 return serviceUuid;
\r
284 * To get CldsAsdsServiceInfo class by parsing json string.
\r
287 * The Json string that must be decoded
\r
288 * @return The list of CldsSdcServiceInfo, if there is a failure it return an
\r
291 private List<SdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {
\r
292 if (StringUtils.isBlank(jsonStr)) {
\r
293 return new ArrayList<>();
\r
296 return JsonUtils.GSON.fromJson(jsonStr, LIST_SDC_SERVICE_INFO_TYPE);
\r
297 } catch (JsonParseException e) {
\r
298 logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);
\r
299 return new ArrayList<>();
\r
304 * To get List of CldsSdcResourceBasicInfo class by parsing json string.
\r
307 * The JSOn string that must be decoded
\r
308 * @return The list of CldsSdcResourceBasicInfo, an empty list in case of issues
\r
310 private List<SdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {
\r
311 if (StringUtils.isBlank(jsonStr)) {
\r
312 return new ArrayList<>();
\r
315 return JsonUtils.GSON.fromJson(jsonStr, LIST_SDC_RESOURCE_BASIC_INFO_TYPE);
\r
316 } catch (JsonParseException e) {
\r
317 logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);
\r
318 return new ArrayList<>();
\r
323 * To get CldsSdcServiceDetail by parsing json string.
\r
328 public SdcServiceDetail decodeCldsSdcServiceDetailFromJson(String jsonStr) {
\r
330 return JsonUtils.GSON.fromJson(jsonStr, SdcServiceDetail.class);
\r
331 } catch (JsonParseException e) {
\r
332 logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);
\r
337 public String getResponse(HttpURLConnection conn) {
\r
338 try (InputStream is = getInputStream(conn)) {
\r
339 try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
\r
340 return IOUtils.toString(in);
\r
342 } catch (IOException e) {
\r
343 logger.error("Exception when attempting to open SDC response", e);
\r
344 throw new SdcCommunicationException("Exception when attempting to open SDC response", e);
\r
348 private InputStream getInputStream(HttpURLConnection conn) {
\r
350 InputStream inStream = conn.getErrorStream();
\r
351 if (inStream == null) {
\r
352 inStream = conn.getInputStream();
\r
355 } catch (IOException e) {
\r
356 logger.error("Exception when attempting to open SDC error stream", e);
\r
357 throw new SdcCommunicationException("Exception when attempting to open SDC error stream", e);
\r
362 * Check if the SDC Info in cache has expired.
\r
364 * @param cldsServiceData
\r
365 * The object representing the service data
\r
366 * @return boolean flag
\r
367 * @throws GeneralSecurityException
\r
368 * In case of issues with the decryting the encrypted password
\r
369 * @throws DecoderException
\r
370 * In case of issues with the decoding of the Hex String
\r
372 public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData)
\r
373 throws GeneralSecurityException, DecoderException {
\r
374 if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
\r
375 String cachedServiceUuid = cldsServiceData.getServiceUUID();
\r
376 String latestServiceUuid = getServiceUuidFromServiceInvariantId(cldsServiceData.getServiceInvariantUUID());
\r
377 String configuredMaxAge = refProp.getStringValue("clds.service.cache.invalidate.after.seconds");
\r
378 if (configuredMaxAge == null) {
\r
380 "clds.service.cache.invalidate.after.seconds NOT set in clds-reference.properties file, taking 60s as default");
\r
381 configuredMaxAge = "60";
\r
383 return (!cachedServiceUuid.equalsIgnoreCase(latestServiceUuid)) || (cldsServiceData.getAgeOfRecord() != null
\r
384 && cldsServiceData.getAgeOfRecord() > Long.parseLong(configuredMaxAge));
\r
391 * Get the Service Data with Alarm Conditions for a given invariantServiceUuid.
\r
393 * @param invariantServiceUuid
\r
394 * @return The CldsServiceData
\r
395 * @throws GeneralSecurityException
\r
396 * In case of issues with the decryting the encrypted password
\r
397 * @throws DecoderException
\r
398 * In case of issues with the decoding of the Hex String
\r
400 public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid)
\r
401 throws GeneralSecurityException, DecoderException {
\r
402 String url = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);
\r
403 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
404 String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);
\r
405 String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX;
\r
406 String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl);
\r
407 CldsServiceData cldsServiceData = new CldsServiceData();
\r
408 if (responseStr != null) {
\r
409 SdcServiceDetail cldsSdcServiceDetail;
\r
411 cldsSdcServiceDetail = JsonUtils.GSON.fromJson(responseStr, SdcServiceDetail.class);
\r
412 } catch (JsonParseException e) {
\r
413 logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);
\r
414 throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);
\r
416 // To remove duplicate resources from serviceDetail and add valid
\r
418 if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {
\r
419 cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());
\r
420 cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());
\r
421 List<SdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(
\r
422 cldsSdcServiceDetail.getResources());
\r
423 if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {
\r
424 List<CldsVfData> cldsVfDataList = new ArrayList<>();
\r
425 for (SdcResource currCldsSdcResource : cldsSdcResourceList) {
\r
426 if (currCldsSdcResource != null && currCldsSdcResource.getResoucreType() != null
\r
427 && "VF".equalsIgnoreCase(currCldsSdcResource.getResoucreType())) {
\r
428 CldsVfData currCldsVfData = new CldsVfData();
\r
429 currCldsVfData.setVfName(currCldsSdcResource.getResourceInstanceName());
\r
430 currCldsVfData.setVfInvariantResourceUUID(currCldsSdcResource.getResourceInvariantUUID());
\r
431 cldsVfDataList.add(currCldsVfData);
\r
434 cldsServiceData.setCldsVfs(cldsVfDataList);
\r
435 // For each vf in the list , add all vfc's
\r
436 getAllVfcForVfList(cldsVfDataList, catalogUrl);
\r
437 logger.info("Invariant Service ID of cldsServiceData:" + cldsServiceData.getServiceInvariantUUID());
\r
441 return cldsServiceData;
\r
444 private void getAllVfcForVfList(List<CldsVfData> cldsVfDataList, String catalogUrl)
\r
445 throws GeneralSecurityException {
\r
446 // todo : refact this..
\r
447 if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {
\r
448 List<SdcResourceBasicInfo> allVfResources = getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_VF_TYPE);
\r
449 List<SdcResourceBasicInfo> allVfcResources = getAllSdcVForVfcResourcesBasedOnResourceType(
\r
450 RESOURCE_VFC_TYPE);
\r
451 allVfcResources.addAll(getAllSdcVForVfcResourcesBasedOnResourceType(RESOURCE_CVFC_TYPE));
\r
452 for (CldsVfData currCldsVfData : cldsVfDataList) {
\r
453 if (currCldsVfData != null && currCldsVfData.getVfInvariantResourceUUID() != null) {
\r
454 String resourceUuid = getResourceUuidFromResourceInvariantUuid(
\r
455 currCldsVfData.getVfInvariantResourceUUID(), allVfResources);
\r
456 if (resourceUuid != null) {
\r
457 String vfResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUuid
\r
458 + SDC_METADATA_URL_PREFIX;
\r
459 String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl);
\r
460 if (vfResponse != null) {
\r
461 // Below 2 line are to get the KPI(field path) data
\r
462 // associated with the VF's
\r
463 List<CldsVfKPIData> cldsVfKPIDataList = getFieldPathFromVF(vfResponse);
\r
464 currCldsVfData.setCldsKPIList(cldsVfKPIDataList);
\r
465 List<CldsVfcData> vfcDataListFromVfResponse = getVfcDataListFromVfResponse(vfResponse);
\r
466 if (vfcDataListFromVfResponse != null) {
\r
467 currCldsVfData.setCldsVfcs(vfcDataListFromVfResponse);
\r
468 if (!vfcDataListFromVfResponse.isEmpty()) {
\r
469 // To get artifacts for every VFC and get
\r
470 // alarm conditions from artifact
\r
471 for (CldsVfcData currCldsVfcData : vfcDataListFromVfResponse) {
\r
472 if (currCldsVfcData != null
\r
473 && currCldsVfcData.getVfcInvariantResourceUUID() != null) {
\r
474 String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(
\r
475 currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);
\r
476 if (resourceVfcUuid != null) {
\r
477 String vfcResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/"
\r
478 + resourceVfcUuid + SDC_METADATA_URL_PREFIX;
\r
479 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(
\r
480 vfcResourceUuidUrl);
\r
481 if (vfcResponse != null) {
\r
482 List<CldsAlarmCondition> alarmCondtionsFromVfc = getAlarmCondtionsFromVfc(
\r
484 currCldsVfcData.setCldsAlarmConditions(alarmCondtionsFromVfc);
\r
487 logger.info("No resourceVFC UUID found for given invariantID:"
\r
488 + currCldsVfcData.getVfcInvariantResourceUUID());
\r
496 logger.info("No resourceUUID found for given invariantREsourceUUID:"
\r
497 + currCldsVfData.getVfInvariantResourceUUID());
\r
504 private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) {
\r
505 JsonObject vfResponseNode;
\r
507 vfResponseNode = JsonUtils.GSON.fromJson(vfResponse, JsonObject.class);
\r
508 } catch (JsonParseException e) {
\r
509 logger.error("Exception when decoding the JSON list of CldsVfcData", e);
\r
510 return new ArrayList<>();
\r
512 JsonArray vfcArrayNode = vfResponseNode.get("resources").getAsJsonArray();
\r
513 List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
\r
514 if (vfcArrayNode != null) {
\r
515 for (JsonElement vfcjsonNode : vfcArrayNode) {
\r
516 JsonObject currVfcNode = vfcjsonNode.getAsJsonObject();
\r
517 JsonElement resourceTypeNode = currVfcNode.get("resoucreType");
\r
518 if (resourceTypeNode != null && resourceTypeNode.isJsonPrimitive()) {
\r
519 if ("VFC".equalsIgnoreCase(resourceTypeNode.getAsString())) {
\r
520 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
521 } else if ("CVFC".equalsIgnoreCase(resourceTypeNode.getAsString())) {
\r
522 handleCVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
527 return cldsVfcDataList;
\r
530 private void handleVFCtypeNode(JsonObject currVfcNode, List<CldsVfcData> cldsVfcDataList) {
\r
531 CldsVfcData currCldsVfcData = new CldsVfcData();
\r
532 String vfcResourceName = currVfcNode.get("resourceInstanceName").getAsString();
\r
533 String vfcInvariantResourceUuid = currVfcNode.get("resourceInvariantUUID").getAsString();
\r
534 currCldsVfcData.setVfcName(vfcResourceName);
\r
535 currCldsVfcData.setVfcInvariantResourceUUID(vfcInvariantResourceUuid);
\r
536 cldsVfcDataList.add(currCldsVfcData);
\r
539 private void handleCVFCtypeNode(JsonObject currVfcNode, List<CldsVfcData> cldsVfcDataList) {
\r
540 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
541 cldsVfcDataList.addAll(getVFCfromCVFC(currVfcNode.get("resourceUUID").getAsString()));
\r
544 private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) {
\r
545 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
546 List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
\r
547 if (resourceUUID != null) {
\r
548 String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX;
\r
550 String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl);
\r
551 JsonObject vfResponseNode = JsonUtils.GSON.fromJson(vfcResponse, JsonObject.class);
\r
552 JsonArray vfcArrayNode = vfResponseNode.get("resources").getAsJsonArray();
\r
553 if (vfcArrayNode != null) {
\r
554 for (JsonElement vfcjsonNode : vfcArrayNode) {
\r
555 JsonObject currVfcNode = vfcjsonNode.getAsJsonObject();
\r
556 JsonElement resourceTypeNode = currVfcNode.get("resoucreType");
\r
557 if (resourceTypeNode != null && resourceTypeNode.isJsonPrimitive() && "VFC".equalsIgnoreCase(resourceTypeNode.getAsString())) {
\r
558 handleVFCtypeNode(currVfcNode, cldsVfcDataList);
\r
562 } catch (JsonParseException e) {
\r
563 logger.error("Exception during JSON analyzis", e);
\r
566 return cldsVfcDataList;
\r
569 private String removeUnwantedBracesFromString(String id) {
\r
570 return (id != null) ? id.replaceAll("\"", "") : "";
\r
573 private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws GeneralSecurityException {
\r
574 List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
\r
575 JsonObject vfcResponseNode;
\r
577 vfcResponseNode = JsonUtils.GSON.fromJson(vfcResponse, JsonObject.class);
\r
578 } catch (JsonParseException e) {
\r
579 logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);
\r
580 return cldsAlarmConditionList;
\r
582 JsonElement artifactsNode = vfcResponseNode.get("artifacts");
\r
583 if (artifactsNode != null && artifactsNode.isJsonArray() && artifactsNode.getAsJsonArray().size() > 0) {
\r
584 JsonArray artifactsList = artifactsNode.getAsJsonArray();
\r
585 for (int index = 0; index < artifactsList.size(); index++) {
\r
586 JsonObject currArtifactNode = artifactsList.get(index).getAsJsonObject();
\r
587 JsonElement artifactUrlNode = currArtifactNode.get("artifactURL");
\r
588 if (artifactUrlNode != null && artifactUrlNode.isJsonPrimitive()) {
\r
589 String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.getAsString());
\r
590 cldsAlarmConditionList.addAll(parseCsvToGetAlarmConditions(responsesFromArtifactUrl));
\r
591 logger.info(responsesFromArtifactUrl);
\r
595 return cldsAlarmConditionList;
\r
598 private List<CldsAlarmCondition> parseCsvToGetAlarmConditions(String allAlarmCondsValues) {
\r
600 List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();
\r
601 Reader alarmReader = new StringReader(allAlarmCondsValues);
\r
602 Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
\r
603 if (records != null) {
\r
604 Iterator<CSVRecord> it = records.iterator();
\r
605 if (it.hasNext()) {
\r
608 it.forEachRemaining(record -> processRecord(cldsAlarmConditionList, record));
\r
610 return cldsAlarmConditionList;
\r
611 } catch (IOException e) {
\r
612 logger.error("Exception when attempting to parse the CSV containing the alarm", e);
\r
613 return new ArrayList<>();
\r
617 // Method to get the artifact for any particular VF
\r
618 private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws GeneralSecurityException {
\r
619 List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
\r
620 JsonObject vfResponseNode;
\r
622 vfResponseNode = JsonUtils.GSON.fromJson(vfResponse, JsonObject.class);
\r
623 } catch (JsonParseException e) {
\r
624 logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);
\r
625 return cldsVfKPIDataList;
\r
627 JsonArray artifactsArrayNode = vfResponseNode.get("artifacts").getAsJsonArray();
\r
628 if (artifactsArrayNode != null && artifactsArrayNode.size() > 0) {
\r
629 for (int index = 0; index < artifactsArrayNode.size(); index++) {
\r
630 JsonObject currArtifactNode = artifactsArrayNode.get(index).getAsJsonObject();
\r
631 JsonElement artifactUrlNode = currArtifactNode.get("artifactURL");
\r
632 JsonElement artifactNameNode = currArtifactNode.get("artifactName");
\r
633 String artifactName = "";
\r
634 if (artifactNameNode != null) {
\r
635 artifactName = artifactNameNode.getAsString();
\r
636 artifactName = artifactName.substring(artifactName.lastIndexOf('.') + 1);
\r
638 if (artifactUrlNode != null && "csv".equalsIgnoreCase(artifactName)) {
\r
639 String responsesFromArtifactUrl = getResponsesFromArtifactUrl(artifactUrlNode.getAsString());
\r
640 cldsVfKPIDataList.addAll(parseCsvToGetFieldPath(responsesFromArtifactUrl));
\r
641 logger.info(responsesFromArtifactUrl);
\r
645 return cldsVfKPIDataList;
\r
648 private CldsVfKPIData convertCsvRecordToKpiData(CSVRecord record) {
\r
649 if (record.size() < 6) {
\r
650 logger.debug("invalid csv field path Record,total columns less than 6: " + record);
\r
653 if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
\r
654 || StringUtils.isBlank(record.get(5))) {
\r
655 logger.debug("Invalid csv field path Record,one of column is having blank value : " + record);
\r
658 CldsVfKPIData cldsVfKPIData = new CldsVfKPIData();
\r
659 cldsVfKPIData.setNfNamingCode(record.get(0).trim());
\r
660 cldsVfKPIData.setNfNamingValue(record.get(1).trim());
\r
661 cldsVfKPIData.setFieldPath(record.get(2).trim());
\r
662 cldsVfKPIData.setFieldPathValue(record.get(3).trim());
\r
663 cldsVfKPIData.setThresholdName(record.get(4).trim());
\r
664 cldsVfKPIData.setThresholdValue(record.get(5).trim());
\r
665 return cldsVfKPIData;
\r
668 // Method to get the artifactURL Data and set the CldsVfKPIData node
\r
669 private List<CldsVfKPIData> parseCsvToGetFieldPath(String allFieldPathValues) {
\r
671 List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();
\r
672 Reader alarmReader = new StringReader(allFieldPathValues);
\r
673 Iterable<CSVRecord> records = CSVFormat.RFC4180.parse(alarmReader);
\r
674 if (records != null) {
\r
675 for (CSVRecord record : records) {
\r
676 CldsVfKPIData kpiData = this.convertCsvRecordToKpiData(record);
\r
677 if (kpiData != null) {
\r
678 cldsVfKPIDataList.add(kpiData);
\r
682 return cldsVfKPIDataList;
\r
683 } catch (IOException e) {
\r
684 logger.error("Exception when attempting to parse the CSV containing the alarm kpi data", e);
\r
685 return new ArrayList<>();
\r
689 private void processRecord(List<CldsAlarmCondition> cldsAlarmConditionList, CSVRecord record) {
\r
690 if (record == null) {
\r
693 if (record.size() < 5) {
\r
694 logger.debug("invalid csv alarm Record,total columns less than 5: " + record);
\r
697 if (StringUtils.isBlank(record.get(1)) || StringUtils.isBlank(record.get(3))
\r
698 || StringUtils.isBlank(record.get(4))) {
\r
699 logger.debug("invalid csv alarm Record,one of column is having blank value : " + record);
\r
702 CldsAlarmCondition cldsAlarmCondition = new CldsAlarmCondition();
\r
703 cldsAlarmCondition.setEventSourceType(record.get(1));
\r
704 cldsAlarmCondition.setEventName(record.get(2));
\r
705 cldsAlarmCondition.setAlarmConditionKey(record.get(3));
\r
706 cldsAlarmCondition.setSeverity(record.get(4));
\r
707 cldsAlarmConditionList.add(cldsAlarmCondition);
\r
710 // Get the responses for the current artifact from the artifacts URL.
\r
711 private String getResponsesFromArtifactUrl(String artifactsUrl) {
\r
712 String hostUrl = refProp.getStringValue("sdc.hostUrl");
\r
713 String artifactsUrlReworked = artifactsUrl.replaceAll("\"", "");
\r
714 String artifactUrl = hostUrl + artifactsUrlReworked;
\r
715 logger.info("value of artifactURl:" + artifactUrl);
\r
716 String currArtifactResponse = getCldsServicesOrResourcesBasedOnURL(artifactUrl);
\r
717 logger.info("value of artifactResponse:" + currArtifactResponse);
\r
718 return currArtifactResponse;
\r
722 * Service to services/resources/artifacts from sdc.Pass alarmConditions as true
\r
723 * to get alarm conditons from artifact url and else it is false
\r
726 * The URL to trigger
\r
727 * @return The String containing the payload
\r
729 public String getCldsServicesOrResourcesBasedOnURL(String url) {
\r
730 Date startTime = new Date();
\r
732 LoggingUtils.setTargetContext("SDC", "getCldsServicesOrResourcesBasedOnURL");
\r
733 String urlReworked = removeUnwantedBracesFromString(url);
\r
734 URL urlObj = new URL(urlReworked);
\r
735 HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
\r
736 conn = utils.invoke(conn, "SDC", "getSdcResources");
\r
737 String basicAuth = getSdcBasicAuth();
\r
738 conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);
\r
739 conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
\r
740 conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
\r
741 conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
\r
742 conn.setRequestMethod("GET");
\r
743 int responseCode = conn.getResponseCode();
\r
744 logger.info("Sdc resource url - " + urlReworked + " , responseCode=" + responseCode);
\r
745 try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
\r
746 String response = IOUtils.toString(in);
\r
749 } catch (IOException e) {
\r
750 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
751 logger.error("Exception occurred during query to SDC", e);
\r
753 } catch (DecoderException e) {
\r
754 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
755 logger.error("Exception when attempting to decode the Hex string", e);
\r
756 throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);
\r
757 } catch (GeneralSecurityException e) {
\r
758 LoggingUtils.setErrorContext("900", "Get sdc resources error");
\r
759 logger.error("Exception when attempting to decrypt the encrypted password", e);
\r
760 throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);
\r
762 LoggingUtils.setTimeContext(startTime, new Date());
\r
763 metricsLogger.info("getCldsServicesOrResourcesBasedOnURL completed");
\r
764 utils.invokeReturn();
\r
769 * To create properties object by using cldsServicedata.
\r
771 * @throws IOException In case of issues during the parsing of the Global Properties
\r
773 public String createPropertiesObjectByUUID(CldsServiceData cldsServiceData) throws IOException {
\r
774 String totalPropsStr;
\r
775 JsonObject globalPropsJson = refProp.getJsonTemplate(CldsService.GLOBAL_PROPERTIES_KEY).getAsJsonObject();
\r
776 if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
\r
777 // Objectnode to save all byservice, byvf , byvfc and byalarm nodes
\r
778 JsonObject byIdObjectNode = new JsonObject();
\r
779 // To create vf ResourceUUID node with serviceInvariantUUID
\r
780 JsonObject invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(cldsServiceData);
\r
781 byIdObjectNode.add("byService", invariantUuidObjectNodeWithVf);
\r
782 // To create byVf and vfcResourceNode with vfResourceUUID
\r
783 JsonObject vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(cldsServiceData.getCldsVfs());
\r
784 byIdObjectNode.add("byVf", vfcObjectNodeByVfUuid);
\r
786 JsonObject kpiJsonObject = new JsonObject();
\r
787 if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
788 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
789 if (currCldsVfData != null) {
\r
790 createKpiObjectNodeByVfUuid(kpiJsonObject, currCldsVfData.getCldsKPIList());
\r
794 byIdObjectNode.add("byKpi", kpiJsonObject);
\r
795 // To create byVfc and alarmCondition with vfcResourceUUID
\r
796 JsonObject vfcResourceUuidObjectNode = new JsonObject();
\r
797 if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
798 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
799 if (currCldsVfData != null) {
\r
800 createAlarmCondObjectNodeByVfcUuid(vfcResourceUuidObjectNode, currCldsVfData.getCldsVfcs());
\r
804 byIdObjectNode.add("byVfc", vfcResourceUuidObjectNode);
\r
805 // To create byAlarmCondition with alarmConditionKey
\r
806 List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
\r
808 JsonObject alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(allAlarmConditions);
\r
809 byIdObjectNode.add("byAlarmCondition", alarmCondObjectNodeByAlarmKey);
\r
810 // To create byAlertDescription with AlertDescription
\r
811 List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,
\r
812 "alertDescription");
\r
813 JsonObject alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(allAlertDescriptions);
\r
814 byIdObjectNode.add("byAlertDescription", alertDescObjectNodeByAlert);
\r
815 globalPropsJson.add("shared", byIdObjectNode);
\r
816 logger.info("Global properties JSON created with SDC info:" + globalPropsJson);
\r
818 totalPropsStr = globalPropsJson.toString();
\r
819 return totalPropsStr;
\r
823 * Method to get alarm conditions/alert description from Service Data.
\r
825 * @param cldsServiceData
\r
826 * CldsServiceData the Service Data to analyze
\r
828 * The String event name that will be used to filter the alarm list
\r
829 * @return The list of CldsAlarmCondition for the event name specified
\r
831 public List<CldsAlarmCondition> getAllAlarmConditionsFromCldsServiceData(CldsServiceData cldsServiceData,
\r
832 String eventName) {
\r
833 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
834 if (cldsServiceData != null && cldsServiceData.getCldsVfs() != null
\r
835 && !cldsServiceData.getCldsVfs().isEmpty()) {
\r
836 for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {
\r
837 alarmCondList.addAll(getAllAlarmConditionsFromCldsVfData(currCldsVfData, eventName));
\r
840 return alarmCondList;
\r
844 * Method to get alarm conditions/alert description from VF Data.
\r
846 * @param currCldsVfData
\r
847 * The Vf Data to analyze
\r
849 * The String event name that will be used to filter the alarm list
\r
850 * @return The list of CldsAlarmCondition for the event name specified
\r
852 private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfData(CldsVfData currCldsVfData, String eventName) {
\r
853 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
854 if (currCldsVfData != null && currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {
\r
855 for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
\r
856 alarmCondList.addAll(getAllAlarmConditionsFromCldsVfcData(currCldsVfcData, eventName));
\r
859 return alarmCondList;
\r
863 * Method to get alarm conditions/alert description from VFC Data.
\r
865 * @param currCldsVfcData
\r
866 * The VfC Data to analyze
\r
868 * The String event name that will be used to filter the alarm list
\r
869 * @return The list of CldsAlarmCondition for the event name specified
\r
871 private List<CldsAlarmCondition> getAllAlarmConditionsFromCldsVfcData(CldsVfcData currCldsVfcData,
\r
872 String eventName) {
\r
873 List<CldsAlarmCondition> alarmCondList = new ArrayList<>();
\r
874 if (currCldsVfcData != null && currCldsVfcData.getCldsAlarmConditions() != null
\r
875 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
876 for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
\r
877 if (currCldsAlarmCondition != null
\r
878 && currCldsAlarmCondition.getEventName().equalsIgnoreCase(eventName)) {
\r
879 alarmCondList.add(currCldsAlarmCondition);
\r
883 return alarmCondList;
\r
886 private JsonObject createAlarmCondObjectNodeByAlarmKey(List<CldsAlarmCondition> cldsAlarmCondList) {
\r
887 JsonObject alarmCondKeyNode = new JsonObject();
\r
888 if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {
\r
889 for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {
\r
890 if (currCldsAlarmCondition != null) {
\r
891 JsonObject alarmCondNode = new JsonObject();
\r
892 alarmCondNode.addProperty("eventSourceType", currCldsAlarmCondition.getEventSourceType());
\r
893 alarmCondNode.addProperty("eventSeverity", currCldsAlarmCondition.getSeverity());
\r
894 alarmCondKeyNode.add(currCldsAlarmCondition.getAlarmConditionKey(), alarmCondNode);
\r
898 JsonObject alarmCondNode = new JsonObject();
\r
899 alarmCondNode.addProperty("eventSourceType", "");
\r
900 alarmCondNode.addProperty("eventSeverity", "");
\r
901 alarmCondKeyNode.add("", alarmCondNode);
\r
903 return alarmCondKeyNode;
\r
906 private JsonObject createVfObjectNodeByServiceInvariantUuid(CldsServiceData cldsServiceData) {
\r
907 JsonObject invariantUuidObjectNode = new JsonObject();
\r
908 JsonObject vfObjectNode = new JsonObject();
\r
909 JsonObject vfUuidNode = new JsonObject();
\r
910 List<CldsVfData> cldsVfsList = cldsServiceData.getCldsVfs();
\r
911 if (cldsVfsList != null && !cldsVfsList.isEmpty()) {
\r
912 for (CldsVfData currCldsVfData : cldsVfsList) {
\r
913 if (currCldsVfData != null) {
\r
914 vfUuidNode.addProperty(currCldsVfData.getVfInvariantResourceUUID(), currCldsVfData.getVfName());
\r
918 vfUuidNode.addProperty("", "");
\r
920 vfObjectNode.add("vf", vfUuidNode);
\r
921 invariantUuidObjectNode.add(cldsServiceData.getServiceInvariantUUID(), vfObjectNode);
\r
922 return invariantUuidObjectNode;
\r
925 private void createKpiObjectNodeByVfUuid(JsonObject vfResourceUuidObjectNode,
\r
926 List<CldsVfKPIData> cldsVfKpiDataList) {
\r
927 if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {
\r
928 for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {
\r
929 if (currCldsVfKpiData != null) {
\r
930 JsonObject thresholdNameObjectNode = new JsonObject();
\r
931 JsonObject fieldPathObjectNode = new JsonObject();
\r
932 JsonObject nfNamingCodeNode = new JsonObject();
\r
933 fieldPathObjectNode.addProperty(currCldsVfKpiData.getFieldPathValue(),
\r
934 currCldsVfKpiData.getFieldPathValue());
\r
935 nfNamingCodeNode.addProperty(currCldsVfKpiData.getNfNamingValue(), currCldsVfKpiData.getNfNamingValue());
\r
936 thresholdNameObjectNode.add("fieldPath", fieldPathObjectNode);
\r
937 thresholdNameObjectNode.add("nfNamingCode", nfNamingCodeNode);
\r
938 vfResourceUuidObjectNode.add(currCldsVfKpiData.getThresholdValue(), thresholdNameObjectNode);
\r
944 private void createAlarmCondObjectNodeByVfcUuid(JsonObject vfcResourceUuidObjectNode,
\r
945 List<CldsVfcData> cldsVfcDataList) {
\r
946 JsonObject vfcObjectNode = new JsonObject();
\r
947 JsonObject alarmCondNode = new JsonObject();
\r
948 JsonObject alertDescNode = new JsonObject();
\r
949 if (cldsVfcDataList != null && !cldsVfcDataList.isEmpty()) {
\r
950 for (CldsVfcData currCldsVfcData : cldsVfcDataList) {
\r
951 if (currCldsVfcData != null) {
\r
952 if (currCldsVfcData.getCldsAlarmConditions() != null
\r
953 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
954 for (CldsAlarmCondition currCldsAlarmCondition : currCldsVfcData.getCldsAlarmConditions()) {
\r
955 if ("alarmCondition".equalsIgnoreCase(currCldsAlarmCondition.getEventName())) {
\r
956 alarmCondNode.addProperty(currCldsAlarmCondition.getAlarmConditionKey(),
\r
957 currCldsAlarmCondition.getAlarmConditionKey());
\r
959 alertDescNode.addProperty(currCldsAlarmCondition.getAlarmConditionKey(),
\r
960 currCldsAlarmCondition.getAlarmConditionKey());
\r
964 vfcObjectNode.add("alarmCondition", alarmCondNode);
\r
965 vfcObjectNode.add("alertDescription", alertDescNode);
\r
966 vfcResourceUuidObjectNode.add(currCldsVfcData.getVfcInvariantResourceUUID(), vfcObjectNode);
\r
970 alarmCondNode.addProperty("", "");
\r
971 vfcObjectNode.add("alarmCondition", alarmCondNode);
\r
972 alertDescNode.addProperty("", "");
\r
973 vfcObjectNode.add("alertDescription", alarmCondNode);
\r
974 vfcResourceUuidObjectNode.add("", vfcObjectNode);
\r
979 * Method to create vfc and kpi nodes inside vf node
\r
982 * @param cldsVfDataList
\r
985 private JsonObject createVfcObjectNodeByVfUuid(List<CldsVfData> cldsVfDataList) {
\r
986 JsonObject vfUuidObjectNode = new JsonObject();
\r
987 if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {
\r
988 for (CldsVfData currCldsVfData : cldsVfDataList) {
\r
989 if (currCldsVfData != null) {
\r
990 JsonObject vfObjectNode = new JsonObject();
\r
991 JsonObject vfcUuidNode = new JsonObject();
\r
992 JsonObject kpiObjectNode = new JsonObject();
\r
993 if (currCldsVfData.getCldsVfcs() != null && !currCldsVfData.getCldsVfcs().isEmpty()) {
\r
994 for (CldsVfcData currCldsVfcData : currCldsVfData.getCldsVfcs()) {
\r
995 if (currCldsVfcData.getCldsAlarmConditions() != null
\r
996 && !currCldsVfcData.getCldsAlarmConditions().isEmpty()) {
\r
997 vfcUuidNode.addProperty(currCldsVfcData.getVfcInvariantResourceUUID(),
\r
998 currCldsVfcData.getVfcName());
\r
1002 vfcUuidNode.addProperty("", "");
\r
1004 if (currCldsVfData.getCldsKPIList() != null && !currCldsVfData.getCldsKPIList().isEmpty()) {
\r
1005 for (CldsVfKPIData currCldsVfKPIData : currCldsVfData.getCldsKPIList()) {
\r
1006 // ToDo: something wrong happened here
\r
1007 kpiObjectNode.addProperty(currCldsVfKPIData.getThresholdValue(),
\r
1008 currCldsVfKPIData.getThresholdValue());
\r
1011 kpiObjectNode.addProperty("", "");
\r
1013 vfObjectNode.add("vfc", vfcUuidNode);
\r
1014 vfObjectNode.add("kpi", kpiObjectNode);
\r
1015 vfUuidObjectNode.add(currCldsVfData.getVfInvariantResourceUUID(), vfObjectNode);
\r
1019 JsonObject vfcUuidNode = new JsonObject();
\r
1020 vfcUuidNode.addProperty("", "");
\r
1021 JsonObject vfcObjectNode = new JsonObject();
\r
1022 vfcObjectNode.add("vfc", vfcUuidNode);
\r
1023 vfUuidObjectNode.add("", vfcObjectNode);
\r
1025 return vfUuidObjectNode;
\r
1028 // To get all sdc VF/VFC Resources basic info.
\r
1029 private List<SdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType) {
\r
1030 String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
\r
1031 String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;
\r
1032 String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl);
\r
1033 return removeDuplicateSdcResourceBasicInfo(getAllSdcResourcesListFromJson(allSdcVfcResources));
\r
1036 private String getResourceUuidFromResourceInvariantUuid(String resourceInvariantUuid,
\r
1037 List<SdcResourceBasicInfo> resourceInfoList) {
\r
1038 String resourceUuid = null;
\r
1039 if (resourceInfoList != null && !resourceInfoList.isEmpty()) {
\r
1040 for (SdcResourceBasicInfo currResource : resourceInfoList) {
\r
1041 if (currResource != null && currResource.getInvariantUUID() != null && currResource.getUuid() != null
\r
1042 && currResource.getInvariantUUID().equalsIgnoreCase(resourceInvariantUuid)) {
\r
1043 resourceUuid = currResource.getUuid();
\r
1048 return resourceUuid;
\r