From f67adad42f2c857ff76b52df39f0beb5c2cabee4 Mon Sep 17 00:00:00 2001 From: Niranjana Date: Thu, 3 Feb 2022 04:50:38 +0000 Subject: [DCAEGEN2] Calculate slice utilization data Issue-ID: DCAEGEN2-2942 Signed-off-by: Niranjana Change-Id: Id16d2a36cf964b15495531a54094cad96471bdcb --- .../docker/config/sliceanalysisms/config_all.json | 47 +- .../onap/slice/analysis/ms/aai/AaiInterface.java | 36 ++ .../org/onap/slice/analysis/ms/aai/AaiService.java | 350 ++++++++++++ .../slice/analysis/ms/configdb/AaiInterface.java | 36 -- .../slice/analysis/ms/configdb/AaiService.java | 179 ------ .../slice/analysis/ms/configdb/CpsInterface.java | 39 -- .../slice/analysis/ms/configdb/CpsService.java | 137 ----- .../analysis/ms/controller/SliceConfiguraton.java | 58 ++ .../onap/slice/analysis/ms/cps/CpsInterface.java | 40 ++ .../org/onap/slice/analysis/ms/cps/CpsService.java | 141 +++++ .../analysis/ms/exception/CpsClientException.java | 34 ++ .../analysis/ms/exception/DesClientException.java | 34 ++ .../slice/analysis/ms/models/AggregatedConfig.java | 39 ++ .../slice/analysis/ms/models/Configuration.java | 613 +++++++++++---------- .../analysis/ms/models/SliceConfigDetails.java | 36 ++ .../analysis/ms/models/SliceConfigRequest.java | 42 ++ .../analysis/ms/models/SliceConfigResponse.java | 38 ++ .../slice/analysis/ms/models/aai/Relationship.java | 50 ++ .../analysis/ms/models/aai/RelationshipList.java | 38 ++ .../analysis/ms/models/aai/ServiceInstance.java | 55 ++ .../analysis/ms/restclients/DesRestClient.java | 64 +++ .../slice/analysis/ms/service/ConsumerThread.java | 150 +++-- .../analysis/ms/service/MLMessageProcessor.java | 87 +-- .../analysis/ms/service/SliceUtilization.java | 216 ++++++++ .../ms/service/SnssaiSamplesProcessor.java | 385 ++++++------- 25 files changed, 1953 insertions(+), 991 deletions(-) create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiInterface.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java delete mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiInterface.java delete mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiService.java delete mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsInterface.java delete mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsService.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/SliceConfiguraton.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsInterface.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/exception/CpsClientException.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/exception/DesClientException.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/AggregatedConfig.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigDetails.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigRequest.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigResponse.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/Relationship.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/RelationshipList.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/ServiceInstance.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/DesRestClient.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java (limited to 'components/slice-analysis-ms/src/main') diff --git a/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json b/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json index 21a82344..26da5523 100644 --- a/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json +++ b/components/slice-analysis-ms/src/main/docker/config/sliceanalysisms/config_all.json @@ -5,7 +5,7 @@ "aaf_password": null, "type": "message-router", "dmaap_info": { - "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.VES_MEASUREMENT_OUTPUT", + "topic_url": "http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.PERFORMANCE_MEASUREMENTS", "client_role": "sliceanalysis-subscriber", "location": "onap", "client_id": "sdnr-sliceanalysis-1" @@ -16,7 +16,18 @@ "aaf_password": null, "type": "message-router", "dmaap_info": { - "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/DCAE_CL_RSP", + "topic_url": "http://message-router.onap.svc.cluster.local:3904/events/DCAE_CL_RSP", + "client_role": "sliceanalysis-subscriber", + "location": "onap", + "client_id": "sdnr-sliceanalysis-1" + }, + "aaf_username": null + }, + "intelligent_slicing_topic": { + "aaf_password": null, + "type": "message-router", + "dmaap_info": { + "topic_url": "http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.ML_RESPONSE_TOPIC", "client_role": "sliceanalysis-subscriber", "location": "onap", "client_id": "sdnr-sliceanalysis-1" @@ -29,7 +40,7 @@ "aaf_password": null, "type": "message-router", "dmaap_info": { - "topic_url": "https://message-router.onap.svc.cluster.local:3905/events/unauthenticated.DCAE_CL_OUTPUT", + "topic_url": "http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.DCAE_CL_OUTPUT", "client_role": "sliceanalysis-subscriber", "location": "onap", "client_id": "sdnr-sliceanalysis-1" @@ -47,13 +58,35 @@ "cbsPollingInterval": 60, "sliceanalysisms.cg": "sliceanalysisms-cg", "sliceanalysisms.pollingInterval": 20, + "sliceanalysisms.samples": 3, + "sliceanalysisms.minPercentageChange": 5, + "sliceanalysisms.initialDelaySeconds": 300000, + "sliceanalysisms.pollingTimeout": 60, "sliceanalysisms.cid": "sliceanalysisms-cid", - "sliceanalysisms.configDb.service": "http://sdnc.onap:8181", + "sliceanalysisms.configDb.service": "http://configdb_sim:5000", + "sliceanalysisms.aai.url": "https://aai-resources:8447/aai/v21", + "sliceanalysisms.cps.url": "http://cps-tbdmt:8080/execute/ran-network", + "sliceanalysisms.configDbEnabled": "false", + "sliceanalysisms.rannfnssiDetailsTemplateId": "get-rannfnssiid-details", + "sliceanalysisms.desUrl": "http://dl-des:1681/datalake/v1/exposure/pm_data", + "sliceanalysisms.pmDataDurationInWeeks": 4, "service_calls": { "policy-req": [] - } + }, + "trust_store_path": "/opt/app/sliceanalysisms/etc/cert/trust.jks", + "trust_store_pass_path": "/opt/app/sliceanalysisms/etc/cert/trust.pass" }, - "policies": { - + "policies": { + "event": { + "action": "gathered", + "timestamp": "2019-09-18T14:57:55.320Z", + "update_id": "dbb88da8-8df1-489d-b51d-8d5cbbfbcd99", + "policies_count": 1 + }, + "items": [ + { + "policyName": "com.Config_PCIMS_CONFIG_POLICY.1.xml" + } + ] } } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiInterface.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiInterface.java new file mode 100644 index 00000000..87718a5c --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiInterface.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021-2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.aai; + +import java.util.Map; + +/** + * + * Interface for AAI + * + */ +public interface AaiInterface { + + public Map fetchServiceDetails(String snssai); + + public Map fetchCurrentConfigurationOfSlice(String snssai); +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java new file mode 100644 index 00000000..6284ddfb --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/aai/AaiService.java @@ -0,0 +1,350 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021-2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.aai; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.models.aai.ServiceInstance; +import org.onap.slice.analysis.ms.restclients.AaiRestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.stereotype.Service; + +/** + * + * Service for AAI interfaces + * + */ +@Service +public class AaiService implements AaiInterface { + + private static Logger log = LoggerFactory.getLogger(Configuration.class); + + @Autowired + AaiRestClient restclient; + + private static ObjectMapper objectMapper = new ObjectMapper(); + private static String globalSubscriberId; + private static String subscriptionServiceType; + private static String aaiBaseUrl = Configuration.getInstance().getAaiUrl(); + + /** + * Fetches the details of a service + * + * @param snssai SNSSAI ID + * @return responseMap contains service details + */ + public Map fetchServiceDetails(String snssai) { + Map responseMap = fetchSubscriberAndSubscriptionServiceType(); + String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances"; + String serviceRole = "AN-NF"; + try { + String serviceInstance = + restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() {}).getBody(); + JSONObject serviceInstanceJson = new JSONObject(serviceInstance); + JSONArray serviceInstanceList = serviceInstanceJson.getJSONArray("service-instance"); + for (int i = 0; i < serviceInstanceList.length(); i++) { + JSONObject serviceObj = serviceInstanceList.getJSONObject(i); + if (serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { + responseMap.put("sliceProfileId", serviceObj.getString("service-instance-id")); + } + } + + String serviceRoleReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + + "/service-instances/?service-role=nssi&depth=2"; + + String serviceInstanceForServiceRole = + restclient.sendGetRequest(serviceRoleReqUrl, new ParameterizedTypeReference() {}).getBody(); + JSONObject serviceInstanceForServiceRoleJson = new JSONObject(serviceInstanceForServiceRole); + JSONArray serviceInstanceListForServiceRole = + serviceInstanceForServiceRoleJson.getJSONArray("service-instance"); + for (int i = 0; i < serviceInstanceListForServiceRole.length(); i++) { + JSONObject serviceObj = serviceInstanceListForServiceRole.getJSONObject(i); + if (serviceObj.getString("workload-context").trim().equalsIgnoreCase(serviceRole)) { + responseMap.put("ranNFNSSIId", serviceObj.getString("service-instance-id")); + } + } + } catch (Exception e) { + log.info("Exception while fetching serviceDetails: " + e); + } + responseMap.put("sNSSAI", snssai); + log.info("subscriber details: " + responseMap); + return responseMap; + } + + /** + * Fetches the current configuration of a Slice from AAI + * + * @param snssai SNSSAI ID + * @return responseMap contains slice configuration + */ + public Map fetchCurrentConfigurationOfSlice(String snssai) { + log.info("AAI fetch config Slice: " + aaiBaseUrl); + String serviceInstaneId = null; + String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances"; + Map responseMap = new HashMap(); + try { + String serviceInstance = + restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() {}).getBody(); + JSONObject serviceInstanceJson = new JSONObject(serviceInstance); + + JSONArray serviceInstanceList = serviceInstanceJson.getJSONArray("service-instance"); + for (int i = 0; i < serviceInstanceList.length(); i++) { + JSONObject serviceObj = serviceInstanceList.getJSONObject(i); + if (serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { + serviceInstaneId = serviceObj.getString("service-instance-id"); + } + } + + String sliceProfileReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + + "/service-instances/service-instance/" + serviceInstaneId + "/slice-profiles"; + + String sliceProfile = restclient + .sendGetRequest(sliceProfileReqUrl, new ParameterizedTypeReference() {}).getBody(); + JSONObject sliceProfileJson = new JSONObject(sliceProfile); + JSONArray sliceProfileList = sliceProfileJson.getJSONArray("slice-profile"); + for (int i = 0; i < sliceProfileList.length(); i++) { + JSONObject sliceProfileObj = sliceProfileList.getJSONObject(i); + responseMap.put("dLThptPerSlice", sliceProfileObj.getInt("exp-data-rate-UL")); + responseMap.put("uLThptPerSlice", sliceProfileObj.getInt("exp-data-rate-DL")); + break; + } + log.info("Slice configuration: " + responseMap); + } catch (Exception e) { + log.info("AAI Slice: " + e); + } + return responseMap; + } + + /** + * Fetches the details of a subscriber and subscription Service + * + * @return responseMap contains details of subscriber and subscription service + */ + public Map fetchSubscriberAndSubscriptionServiceType() { + + Map responseMap = new HashMap(); + + log.info("Get GlobalSubscriberId"); + String subscriberReqUrl = aaiBaseUrl + "/business/customers"; + try { + String subscriberReq = + restclient.sendGetRequest(subscriberReqUrl, new ParameterizedTypeReference() {}).getBody(); + JSONObject subscriberReqJson = new JSONObject(subscriberReq); + JSONArray subscriberReqJsonList = subscriberReqJson.getJSONArray("customer"); + for (int i = 0; i < subscriberReqJsonList.length(); i++) { + JSONObject subscriberReqObj = subscriberReqJsonList.getJSONObject(i); + globalSubscriberId = subscriberReqObj.getString("global-customer-id"); + responseMap.put("globalSubscriberId", globalSubscriberId); + break; + } + + log.info("Get subscriptionServiceType"); + String subscriptionServiceReqUrl = + aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + "/service-subscriptions"; + + String subscriptionService = restclient + .sendGetRequest(subscriptionServiceReqUrl, new ParameterizedTypeReference() {}).getBody(); + JSONObject subscriptionServiceJson = new JSONObject(subscriptionService); + JSONArray subscriptionServiceListJson = subscriptionServiceJson.getJSONArray("service-subscription"); + for (int i = 0; i < subscriptionServiceListJson.length(); i++) { + JSONObject subscriptionServiceObj = subscriptionServiceListJson.getJSONObject(i); + subscriptionServiceType = subscriptionServiceObj.getString("service-type"); + responseMap.put("subscriptionServiceType", subscriptionServiceType); + break; + } + } catch (Exception e) { + log.info("Exception while fetching subscriber and subscription: " + e); + } + + log.info("responseMap: " + responseMap); + return responseMap; + + } + + /** + * Fetches the SNSSIs of a serviceInstanceId + * + * @param serviceInstanceId service instance ID + * @return snssaiList contains list of SNSSAIs + */ + public List getSnssaiList(String sliceInstanceId) { + fetchSubscriberAndSubscriptionServiceType(); + List allotedResource = new ArrayList<>(); + List sliceProfileList = new ArrayList<>(); + List snssaiList = new ArrayList<>(); + + log.info("fetch slice instance details"); + String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + + "/service-instances/service-instance/" + sliceInstanceId; + + try { + String serviceInstanceString = + restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() {}).getBody(); + ServiceInstance serviceInstance = objectMapper.readValue(serviceInstanceString, ServiceInstance.class); + if (serviceInstance.getServiceRole().equalsIgnoreCase("nsi")) { + serviceInstance.getRelationshipList().getRelationship().forEach(relationship -> { + if (relationship.getRelatedTo().equalsIgnoreCase("allotted-resource")) { + relationship.getRelationshipData().forEach(data -> { + if (data.get("relationship-key").equalsIgnoreCase("service-instance.service-instance-id")) { + allotedResource.add(data.get("relationship-value")); + } + + }); + } + }); + + return fetchSnssaiOfSliceProfile(fetchSliceProfilesOfAllotedResourceData(allotedResource)); + + } + if (serviceInstance.getServiceRole().equalsIgnoreCase("nssi")) { + serviceInstance.getRelationshipList().getRelationship().forEach(relationship -> { + if (Objects.nonNull(relationship.getRelatedToProperty())) { + relationship.getRelatedToProperty().forEach(property -> { + if (property.get("property-value").contains("sliceprofile")) { + relationship.getRelationshipData().forEach(data -> { + if (data.get("relationship-key") + .equalsIgnoreCase("service-instance.service-instance-id")) { + sliceProfileList.add(data.get("relationship-value")); + } + + }); + + } + + }); + } + }); + return fetchSnssaiOfSliceProfile(sliceProfileList); + } + + } catch (Exception e) { + log.info("Exception while fetching snssaiList: " + e); + } + + return snssaiList; + + } + + /** + * Fetches the sliceProfileList of a AllotedResource + * + * @param allotedResourceList contains list of allotedResource IDs + * @return sliceProfilesList contains list of SliceProfiles + */ + public List fetchSliceProfilesOfAllotedResourceData(List allotedResourceList) { + + List sliceProfileList = new ArrayList<>(); + + log.info("fetch Alloted Resource Data"); + + allotedResourceList.forEach(serviceInstanceId -> { + try { + String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + + "/service-instances/service-instance/" + serviceInstanceId; + String serviceInstanceString = + restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() {}).getBody(); + ServiceInstance serviceInstance = objectMapper.readValue(serviceInstanceString, ServiceInstance.class); + + serviceInstance.getRelationshipList().getRelationship().forEach(relationship -> { + relationship.getRelatedToProperty().forEach(property -> { + if (property.get("property-value").contains("sliceprofile")) { + relationship.getRelationshipData().forEach(data -> { + if (data.get("relationship-key") + .equalsIgnoreCase("service-instance.service-instance-id")) { + sliceProfileList.add(data.get("relationship-value")); + } + + }); + + } + + }); + + }); + } catch (Exception e) { + log.info("Exception while fetching AllotedResourceData: " + e); + } + + }); + + log.info("sliceProfileList: " + sliceProfileList); + + return sliceProfileList; + + } + + /** + * Fetches the snssaiList of a SliceProfile + * + * @param sliceProfileList contains list of sliceProfile IDs + * @return snssaiList contains list of SNSSAIs + */ + public List fetchSnssaiOfSliceProfile(List sliceProfileList) { + List snssaiList = new ArrayList<>(); + + log.info("fetch SliceProfile"); + sliceProfileList.forEach(serviceInstanceId -> { + String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances/" + + "service-instance/" + serviceInstanceId; + + try { + String serviceInstanceString = + restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() {}).getBody(); + ServiceInstance serviceInstance = objectMapper.readValue(serviceInstanceString, ServiceInstance.class); + + if (serviceInstance.getServiceRole().equalsIgnoreCase("slice-profile")) { + if (!snssaiList.contains(serviceInstance.getEnvironmentContext())) { + snssaiList.add(serviceInstance.getEnvironmentContext()); + } + } + + } catch (Exception e) { + log.info("Exception while fetching sliceProfile data: " + e); + } + + }); + log.info("snssaiList: " + snssaiList); + + return snssaiList; + + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiInterface.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiInterface.java deleted file mode 100644 index 68b795b5..00000000 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiInterface.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2021 Wipro Limited. - * ============================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - *******************************************************************************/ - -package org.onap.slice.analysis.ms.configdb; - -import java.util.Map; - -/** - * - * Interface for AAI - * - */ -public interface AaiInterface { - - public Map fetchServiceDetails(String snssai); - public Map fetchCurrentConfigurationOfSlice(String snssai); -} - diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiService.java deleted file mode 100644 index 16ff71a6..00000000 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiService.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2021 Wipro Limited. - * ============================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - *******************************************************************************/ - -package org.onap.slice.analysis.ms.configdb; - -import java.util.HashMap; -import java.util.Map; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.onap.slice.analysis.ms.models.Configuration; -import org.onap.slice.analysis.ms.restclients.AaiRestClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.stereotype.Service; - -/** - * - * Service for AAI interfaces - * - */ -@Service -public class AaiService implements AaiInterface { - - private static Logger log = LoggerFactory.getLogger(Configuration.class); - - @Autowired - AaiRestClient restclient; - private static String globalSubscriberId; - private static String subscriptionServiceType; - private static String aaiBaseUrl = Configuration.getInstance().getAaiUrl(); - - /** - * Fetches the details of a subscriber - */ - public Map fetchServiceDetails(String snssai) { - log.info("AAI fetch service: "); - Map responseMap = new HashMap(); - - log.info("AAI getGlobalSubscriberId: "); - String subscriberReqUrl = aaiBaseUrl + "/business/customers"; - try { - String subscriberReq = restclient - .sendGetRequest(subscriberReqUrl, new ParameterizedTypeReference() { - }).getBody(); - JSONObject subscriberReqJson = new JSONObject(subscriberReq); - JSONArray subscriberReqJsonList = subscriberReqJson.getJSONArray("customer"); - for (int i = 0; i < subscriberReqJsonList.length(); i++) { - JSONObject subscriberReqObj = subscriberReqJsonList.getJSONObject(i); - globalSubscriberId = subscriberReqObj.getString("global-customer-id"); - responseMap.put("globalSubscriberId", globalSubscriberId); - break; - } - } catch (Exception e) { - log.info("Exception while fetching getGlobalSubscriberId: " + e); - } - - String subscriptionServiceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId - + "/service-subscriptions"; - try { - String subscriptionService = restclient - .sendGetRequest(subscriptionServiceReqUrl, new ParameterizedTypeReference() { - }).getBody(); - JSONObject subscriptionServiceJson = new JSONObject(subscriptionService); - JSONArray subscriptionServiceListJson = subscriptionServiceJson.getJSONArray("service-subscription"); - for (int i = 0; i < subscriptionServiceListJson.length(); i++) { - JSONObject subscriptionServiceObj = subscriptionServiceListJson.getJSONObject(i); - subscriptionServiceType = subscriptionServiceObj.getString("service-type"); - responseMap.put("subscriptionServiceType", subscriptionServiceType); - break; - } - } catch (Exception e) { - log.info("Exception while fetching subscriptionService: " + e); - } - - String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId - + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances"; - String serviceRole = "AN-NF"; - try { - String serviceInstance = restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() { - }).getBody(); - JSONObject serviceInstanceJson = new JSONObject(serviceInstance); - JSONArray serviceInstanceList = serviceInstanceJson.getJSONArray("service-instance"); - for (int i = 0; i < serviceInstanceList.length(); i++) { - JSONObject serviceObj = serviceInstanceList.getJSONObject(i); - if (serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { - responseMap.put("sliceProfileId", serviceObj.getString("service-instance-id")); - } - } - - String serviceRoleReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId - + "/service-subscriptions/service-subscription/" + subscriptionServiceType - + "/service-instances/?service-role=nssi&depth=2"; - - String serviceInstanceForServiceRole = restclient - .sendGetRequest(serviceRoleReqUrl, new ParameterizedTypeReference() { - }).getBody(); - JSONObject serviceInstanceForServiceRoleJson = new JSONObject(serviceInstanceForServiceRole); - JSONArray serviceInstanceListForServiceRole = serviceInstanceForServiceRoleJson - .getJSONArray("service-instance"); - for (int i = 0; i < serviceInstanceListForServiceRole.length(); i++) { - JSONObject serviceObj = serviceInstanceListForServiceRole.getJSONObject(i); - if (serviceObj.getString("workload-context").trim().equalsIgnoreCase(serviceRole)) { - responseMap.put("ranNFNSSIId", serviceObj.getString("service-instance-id")); - } - } - } catch (Exception e) { - log.info("Exception while fetching serviceDetails: " + e); - } - responseMap.put("sNSSAI", snssai); - log.info("subscriber details: " + responseMap); - return responseMap; - } - - /** - * Fetches the current configuration of an Slice from AAI - */ - public Map fetchCurrentConfigurationOfSlice(String snssai) { - log.info("AAI fetch config Slice: " + aaiBaseUrl); - String serviceInstaneId = null; - String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId - + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances"; - Map responseMap = new HashMap(); - try { - String serviceInstance = restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() { - }).getBody(); - JSONObject serviceInstanceJson = new JSONObject(serviceInstance); - - JSONArray serviceInstanceList = serviceInstanceJson.getJSONArray("service-instance"); - for (int i = 0; i < serviceInstanceList.length(); i++) { - JSONObject serviceObj = serviceInstanceList.getJSONObject(i); - if (serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { - serviceInstaneId = serviceObj.getString("service-instance-id"); - } - } - - String sliceProfileReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId - + "/service-subscriptions/service-subscription/" + subscriptionServiceType - + "/service-instances/service-instance/" + serviceInstaneId + "/slice-profiles"; - - String sliceProfile = restclient - .sendGetRequest(sliceProfileReqUrl, new ParameterizedTypeReference() { - }).getBody(); - JSONObject sliceProfileJson = new JSONObject(sliceProfile); - JSONArray sliceProfileList = sliceProfileJson.getJSONArray("slice-profile"); - for (int i = 0; i < sliceProfileList.length(); i++) { - JSONObject sliceProfileObj = sliceProfileList.getJSONObject(i); - responseMap.put("dLThptPerSlice", sliceProfileObj.getInt("exp-data-rate-UL")); - responseMap.put("uLThptPerSlice", sliceProfileObj.getInt("exp-data-rate-DL")); - break; - } - log.info("Slice configuration: " + responseMap); - } catch (Exception e) { - log.info("AAI Slice: " + e); - } - return responseMap; - } -} - diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsInterface.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsInterface.java deleted file mode 100644 index ef6211c4..00000000 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsInterface.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2021 Wipro Limited. - * ============================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - *******************************************************************************/ - -package org.onap.slice.analysis.ms.configdb; - -import java.util.List; -import java.util.Map; - -/** - * - * Interface for CPS - * - */ -public interface CpsInterface { - - public Map> fetchRICsOfSnssai(String snssai); - public List fetchNetworkFunctionsOfSnssai(String snssai); - public Map> fetchCurrentConfigurationOfRIC(String snssai); - -} - diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsService.java deleted file mode 100644 index 389a75d9..00000000 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsService.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2021 Wipro Limited. - * ============================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - *******************************************************************************/ -package org.onap.slice.analysis.ms.configdb; - -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.util.ArrayList; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.onap.slice.analysis.ms.models.Configuration; -import org.onap.slice.analysis.ms.restclients.CpsRestClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.stereotype.Service; - -/** - * - * Service for CPS interfaces - * - */ -@Service -public class CpsService implements CpsInterface { - - private static Logger log = LoggerFactory.getLogger(CpsService.class); - - @Autowired - CpsRestClient restclient; - private static String cpsBaseUrl = Configuration.getInstance().getCpsUrl(); - - /** - * Fetches the current configuration of RIC from CPS - */ - public Map> fetchCurrentConfigurationOfRIC(String snssai) { - Map> responseMap = new HashMap>(); - String reqUrl = cpsBaseUrl +"/get-nearrtric-config"; - log.info("fetching current configuration of RIC from Cps: {s-NSSAI: "+snssai+"}"); - String requestBody = "{\"inputParameters\": {\"sNssai\":"+JSONObject.quote(snssai)+"}}"; - try { - String response = restclient.sendPostRequest(reqUrl,requestBody, new ParameterizedTypeReference() {}).getBody(); - JSONArray sliceArray = new JSONArray(response); - for (int i=0;i map = new HashMap(); - JSONArray configDataArray = sNSSAIList.getJSONObject(k).getJSONArray("configData"); - for(int l=0;l fetchNetworkFunctionsOfSnssai(String snssai) { - List responseList=new ArrayList<>(); - String reqUrl=cpsBaseUrl+"/get-gnbdufunction-by-snssai"; - log.info("fetching network functions of snssai from Cps: {s-NSSAI: "+snssai+"}"); - String requestBody = "{\"inputParameters\": {\"sNssai\":"+JSONObject.quote(snssai)+"}}"; - try { - String response=restclient.sendPostRequest(reqUrl,requestBody,new ParameterizedTypeReference() {}).getBody(); - JSONArray networkFunctionJsonArry = new JSONArray(response); - for (int i=0;i> fetchRICsOfSnssai(String snssai) { - Map> responseMap=new HashMap<>(); - String reqUrl=cpsBaseUrl + "/get-nrcelldu-by-snssai"; - log.info("fetching RIC of s-NSSAI from Cps: {s-NSSAI: "+snssai+"}"); - String requestBody = "{\"inputParameters\": {\"sNssai\":"+JSONObject.quote(snssai)+"}}"; - try { - String response=restclient.sendPostRequest(reqUrl,requestBody,new ParameterizedTypeReference() {}).getBody(); - JSONArray sliceArray = new JSONArray(response); - for (int i=0;i cellslist=new ArrayList<>(); - for(int k=0;k sliceConfigRequest(@RequestBody SliceConfigRequest sliceConfigRequest) { + try { + SliceConfigResponse sliceConfigResponse = sliceUtilization.getSliceUtilizationData(sliceConfigRequest); + return new ResponseEntity(sliceConfigResponse, HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsInterface.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsInterface.java new file mode 100644 index 00000000..95e7340f --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsInterface.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021-2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.cps; + +import java.util.List; +import java.util.Map; + +/** + * + * Interface for CPS + * + */ +public interface CpsInterface { + + public Map> fetchRICsOfSnssai(String snssai); + + public List fetchNetworkFunctionsOfSnssai(String snssai); + + public Map> fetchCurrentConfigurationOfRIC(String snssai); + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java new file mode 100644 index 00000000..743ac3cf --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsService.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021-2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.cps; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.restclients.CpsRestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +/** + * + * Service for CPS interfaces + * + */ +@Service +public class CpsService implements CpsInterface { + + private static Logger log = LoggerFactory.getLogger(CpsService.class); + + @Autowired + CpsRestClient restclient; + private static String cpsBaseUrl = Configuration.getInstance().getCpsUrl(); + + /** + * Fetches the current configuration of RIC from CPS + */ + public Map> fetchCurrentConfigurationOfRIC(String snssai) { + Map> responseMap = new HashMap>(); + String reqUrl = cpsBaseUrl + "/get-nearrtric-config"; + log.info("fetching current configuration of RIC from Cps: {s-NSSAI: " + snssai + "}"); + String requestBody = "{\"inputParameters\": {\"sNssai\":" + JSONObject.quote(snssai) + "}}"; + try { + String response = restclient + .sendPostRequest(reqUrl, requestBody, new ParameterizedTypeReference() {}).getBody(); + JSONArray sliceArray = new JSONArray(response); + for (int i = 0; i < sliceArray.length(); i++) { + String nearRTTICid = sliceArray.getJSONObject(i).optString("idNearRTRIC"); + JSONArray pLMNInfoList = + sliceArray.getJSONObject(i).getJSONObject("attributes").getJSONArray("pLMNInfoList"); + for (int j = 0; j < pLMNInfoList.length(); j++) { + JSONArray sNSSAIList = pLMNInfoList.getJSONObject(j).getJSONArray("sNSSAIList"); + for (int k = 0; k < sNSSAIList.length(); k++) { + Map map = new HashMap(); + JSONArray configDataArray = sNSSAIList.getJSONObject(k).getJSONArray("configData"); + for (int l = 0; l < configDataArray.length(); l++) { + JSONObject configData = configDataArray.getJSONObject(l); + map.put((String) configData.get("configParameter"), configData.get("configValue")); + } + responseMap.put(nearRTTICid, map); + } + } + } + } catch (Exception e) { + log.info("CPS fetches current configuration of RIC: " + e); + } + return responseMap; + } + + /** + * Fetches all the network functions of an S-NSSAI from CPS + */ + public List fetchNetworkFunctionsOfSnssai(String snssai) { + List responseList = new ArrayList<>(); + String reqUrl = cpsBaseUrl + "/get-gnbdufunction-by-snssai"; + log.info("fetching network functions of snssai from Cps: {s-NSSAI: " + snssai + "}"); + String requestBody = "{\"inputParameters\": {\"sNssai\":" + JSONObject.quote(snssai) + "}}"; + try { + String response = restclient + .sendPostRequest(reqUrl, requestBody, new ParameterizedTypeReference() {}).getBody(); + JSONArray networkFunctionJsonArry = new JSONArray(response); + for (int i = 0; i < networkFunctionJsonArry.length(); i++) { + JSONObject networkFunctionJson = networkFunctionJsonArry.getJSONObject(i); + responseList.add(networkFunctionJson.getJSONObject("attributes").optString("gNBDUId")); + } + } catch (Exception e) { + log.info("Fetch network functions of S-NSSAI from CPS" + e); + } + return responseList; + } + + /** + * Fetches the RICS of an S-NSSAI from CPS + */ + public Map> fetchRICsOfSnssai(String snssai) { + Map> responseMap = new HashMap<>(); + String reqUrl = cpsBaseUrl + "/get-nrcelldu-by-snssai"; + log.info("fetching RIC of s-NSSAI from Cps: {s-NSSAI: " + snssai + "}"); + String requestBody = "{\"inputParameters\": {\"sNssai\":" + JSONObject.quote(snssai) + "}}"; + try { + String response = restclient + .sendPostRequest(reqUrl, requestBody, new ParameterizedTypeReference() {}).getBody(); + JSONArray sliceArray = new JSONArray(response); + for (int i = 0; i < sliceArray.length(); i++) { + String nearRTTICid = sliceArray.getJSONObject(i).optString("idNearRTRIC"); + JSONArray GNBDUFunctionArray = sliceArray.getJSONObject(i).getJSONArray("GNBDUFunction"); + for (int j = 0; j < GNBDUFunctionArray.length(); j++) { + JSONArray NRCellDUArray = GNBDUFunctionArray.getJSONObject(j).getJSONArray("NRCellDU"); + List cellslist = new ArrayList<>(); + for (int k = 0; k < NRCellDUArray.length(); k++) { + cellslist.add( + NRCellDUArray.getJSONObject(k).getJSONObject("attributes").optString("cellLocalId")); + } + responseMap.put(nearRTTICid, cellslist); + } + } + } catch (Exception e) { + log.info("Fetch RICS of S-NSSAI from CPS" + e); + } + return responseMap; + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/exception/CpsClientException.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/exception/CpsClientException.java new file mode 100644 index 00000000..9a993d12 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/exception/CpsClientException.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.exception; + +/** + * CpsClientException is thown when expected response is not received from CPS + */ +public class CpsClientException extends Exception { + + private static final long serialVersionUID = 1L; + + public CpsClientException(final String exception) { + super(exception); + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/exception/DesClientException.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/exception/DesClientException.java new file mode 100644 index 00000000..7356b0b2 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/exception/DesClientException.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.exception; + +/** + * DesClientException is thown when expected response is not received from DES + */ +public class DesClientException extends Exception { + + private static final long serialVersionUID = 1L; + + public DesClientException(final String exception) { + super(exception); + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/AggregatedConfig.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/AggregatedConfig.java new file mode 100644 index 00000000..b754f641 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/AggregatedConfig.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * AggregatedConfig contains slice utilization data + */ +@Data +@NoArgsConstructor +public class AggregatedConfig { + + Integer dLThptPerSlice; + + Integer uLThptPerSlice; + + Integer maxNumberOfConns; +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java index 60f52f0f..2f3f6c2a 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2020-2021 Wipro Limited. + * Copyright (C) 2020-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,11 @@ package org.onap.slice.analysis.ms.models; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + import java.lang.reflect.Type; import java.util.List; import java.util.Map; @@ -29,290 +34,332 @@ import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; - /** * Model class for the application Configuration */ public class Configuration { - private static Logger log = LoggerFactory.getLogger(Configuration.class); - - private static Configuration instance = null; - private String pgHost; - private int pgPort; - private String pgUsername; - private String pgPassword; - private List dmaapServers; - private String configDbService; - private String cpsUrl; - private String aaiUrl; - private Boolean configDbEnabled; - private String cg; - private String cid; - private int pollingInterval; - private int pollingTimeout; - private String aafUsername; - private String aafPassword; - private Map streamsSubscribes; - private Map streamsPublishes; - private int samples; - private int minPercentageChange; - private long initialDelaySeconds; - - /** - * Check if topic is secure. - */ - public boolean isSecured() { - return (aafUsername != null); - - } - - public String getAafUsername() { - return aafUsername; - } - - public void setAafUsername(String aafUsername) { - this.aafUsername = aafUsername; - } - - public String getAafPassword() { - return aafPassword; - } - - public void setAafPassword(String aafPassword) { - this.aafPassword = aafPassword; - } - - public Map getStreamsSubscribes() { - return streamsSubscribes; - } - - public void setStreamsSubscribes(Map streamsSubscribes) { - this.streamsSubscribes = streamsSubscribes; - } - - public Map getStreamsPublishes() { - return streamsPublishes; - } - - public void setStreamsPublishes(Map streamsPublishes) { - this.streamsPublishes = streamsPublishes; - } - - protected Configuration() { - - } - - /** - * Get instance of class. - */ - public static Configuration getInstance() { - if (instance == null) { - instance = new Configuration(); - } - return instance; - } - - public String getCg() { - return cg; - } - - public void setCg(String cg) { - this.cg = cg; - } - - public String getCid() { - return cid; - } - - public void setCid(String cid) { - this.cid = cid; - } - - public int getPollingInterval() { - return pollingInterval; - } - - public void setPollingInterval(int pollingInterval) { - this.pollingInterval = pollingInterval; - } - - public int getPollingTimeout() { - return pollingTimeout; - } - - public void setPollingTimeout(int pollingTimeout) { - this.pollingTimeout = pollingTimeout; - } - - public String getPgHost() { - return pgHost; - } - - public void setPgHost(String pgHost) { - this.pgHost = pgHost; - } - - public int getPgPort() { - return pgPort; - } - - public void setPgPort(int pgPort) { - this.pgPort = pgPort; - } - - public String getPgUsername() { - return pgUsername; - } - - public void setPgUsername(String pgUsername) { - this.pgUsername = pgUsername; - } - - public String getPgPassword() { - return pgPassword; - } - - public void setPgPassword(String pgPassword) { - this.pgPassword = pgPassword; - } - - public List getDmaapServers() { - return dmaapServers; - } - - public void setDmaapServers(List dmaapServers) { - this.dmaapServers = dmaapServers; - } - - public String getConfigDbService() { - return configDbService; - } - - public void setConfigDbService(String configDbService) { - this.configDbService = configDbService; - } - - public String getCpsUrl() { - return cpsUrl; - } - - public void setCpsUrl(String cpsUrl) { - this.cpsUrl = cpsUrl; - } - - public String getAaiUrl() { - return aaiUrl; - } - - public void setAaiUrl(String aaiUrl) { - this.aaiUrl = aaiUrl; - } - - public Boolean getConfigDbEnabled() { - return configDbEnabled; - } - - public void setConfigDbEnabled(Boolean configDbEnabled) { - this.configDbEnabled = configDbEnabled; - } - - public int getSamples() { - return samples; - } - - public void setSamples(int samples) { - this.samples = samples; - } - - public int getMinPercentageChange() { - return minPercentageChange; - } - - public void setMinPercentageChange(int minPercentageChange) { - this.minPercentageChange = minPercentageChange; - } - - public long getInitialDelaySeconds() { - return initialDelaySeconds; - } - - public void setInitialDelaySeconds(long initialDelaySeconds) { - this.initialDelaySeconds = initialDelaySeconds; - } - - @Override - public String toString() { - return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword=" - + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService + ", cpsUrl=" - + cpsUrl + ", aaiUrl=" + aaiUrl + ", configDbEnabled=" + configDbEnabled + ", cg=" + cg + ", cid=" + cid + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" - + pollingTimeout + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword - + ", streamsSubscribes=" + streamsSubscribes + ", streamsPublishes=" + streamsPublishes + ", samples=" - + samples + ", minPercentageChange=" + minPercentageChange + ", initialDelaySeconds=" - + initialDelaySeconds + "]"; - } - - /** - * updates application configuration. - */ - public void updateConfigurationFromJsonObject(JsonObject jsonObject) { - - log.info("Updating configuration from CBS"); - - Type mapType = new TypeToken>() { - }.getType(); - - JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); - streamsSubscribes = new Gson().fromJson(subscribes, mapType); - - JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); - streamsPublishes = new Gson().fromJson(publishes, mapType); - - pgPort = jsonObject.get("postgres.port").getAsInt(); - pollingInterval = jsonObject.get("sliceanalysisms.pollingInterval").getAsInt(); - pgPassword = jsonObject.get("postgres.password").getAsString(); - pgUsername = jsonObject.get("postgres.username").getAsString(); - pgHost = jsonObject.get("postgres.host").getAsString(); - - JsonArray servers = jsonObject.getAsJsonArray("sliceanalysisms.dmaap.server"); - Type listType = new TypeToken>() { - }.getType(); - dmaapServers = new Gson().fromJson(servers, listType); - - cg = jsonObject.get("sliceanalysisms.cg").getAsString(); - cid = jsonObject.get("sliceanalysisms.cid").getAsString(); - configDbService = jsonObject.get("sliceanalysisms.configDb.service").getAsString(); - configDbEnabled = jsonObject.get("sliceanalysisms.configDbEnabled").getAsBoolean(); - - pollingTimeout = jsonObject.get("sliceanalysisms.pollingTimeout").getAsInt(); - samples = jsonObject.get("sliceanalysisms.samples").getAsInt(); - minPercentageChange = jsonObject.get("sliceanalysisms.minPercentageChange").getAsInt(); - initialDelaySeconds = jsonObject.get("sliceanalysisms.initialDelaySeconds").getAsLong(); - - if (Objects.isNull(jsonObject.get("aafUsername"))) { - aafUsername = null; - } else { - aafUsername = jsonObject.get("aafUsername").getAsString(); - } - if (Objects.isNull(jsonObject.get("aafPassword"))) { - aafPassword = null; - } else { - aafPassword = jsonObject.get("aafPassword").getAsString(); - } - if (Objects.isNull(jsonObject.get("sliceanalysisms.aai.url"))) { - aaiUrl = null; - } else { - aaiUrl = jsonObject.get("sliceanalysisms.aai.url").getAsString(); - } - if (Objects.isNull(jsonObject.get("sliceanalysisms.cps.url"))) { - cpsUrl = null; - } else { - cpsUrl = jsonObject.get("sliceanalysisms.cps.url").getAsString(); - } - log.info("configuration from CBS {}", this); - } + private static Logger log = LoggerFactory.getLogger(Configuration.class); + + private static Configuration instance = null; + private String pgHost; + private int pgPort; + private String pgUsername; + private String pgPassword; + private List dmaapServers; + private String configDbService; + private String cpsUrl; + private String aaiUrl; + private Boolean configDbEnabled; + private String cg; + private String cid; + private int pollingInterval; + private int pollingTimeout; + private String aafUsername; + private String aafPassword; + private Map streamsSubscribes; + private Map streamsPublishes; + private int samples; + private int minPercentageChange; + private long initialDelaySeconds; + private String rannfnssiDetailsTemplateId; + private String desUrl; + private int pmDataDurationInWeeks; + + /** + * Check if topic is secure. + */ + public boolean isSecured() { + return (aafUsername != null); + + } + + public String getAafUsername() { + return aafUsername; + } + + public void setAafUsername(String aafUsername) { + this.aafUsername = aafUsername; + } + + public String getAafPassword() { + return aafPassword; + } + + public void setAafPassword(String aafPassword) { + this.aafPassword = aafPassword; + } + + public Map getStreamsSubscribes() { + return streamsSubscribes; + } + + public void setStreamsSubscribes(Map streamsSubscribes) { + this.streamsSubscribes = streamsSubscribes; + } + + public Map getStreamsPublishes() { + return streamsPublishes; + } + + public void setStreamsPublishes(Map streamsPublishes) { + this.streamsPublishes = streamsPublishes; + } + + protected Configuration() { + + } + + /** + * Get instance of class. + */ + public static Configuration getInstance() { + if (instance == null) { + instance = new Configuration(); + } + return instance; + } + + public String getCg() { + return cg; + } + + public void setCg(String cg) { + this.cg = cg; + } + + public String getCid() { + return cid; + } + + public void setCid(String cid) { + this.cid = cid; + } + + public int getPollingInterval() { + return pollingInterval; + } + + public void setPollingInterval(int pollingInterval) { + this.pollingInterval = pollingInterval; + } + + public int getPollingTimeout() { + return pollingTimeout; + } + + public void setPollingTimeout(int pollingTimeout) { + this.pollingTimeout = pollingTimeout; + } + + public String getPgHost() { + return pgHost; + } + + public void setPgHost(String pgHost) { + this.pgHost = pgHost; + } + + public int getPgPort() { + return pgPort; + } + + public void setPgPort(int pgPort) { + this.pgPort = pgPort; + } + + public String getPgUsername() { + return pgUsername; + } + + public void setPgUsername(String pgUsername) { + this.pgUsername = pgUsername; + } + + public String getPgPassword() { + return pgPassword; + } + + public void setPgPassword(String pgPassword) { + this.pgPassword = pgPassword; + } + + public List getDmaapServers() { + return dmaapServers; + } + + public void setDmaapServers(List dmaapServers) { + this.dmaapServers = dmaapServers; + } + + public String getConfigDbService() { + return configDbService; + } + + public void setConfigDbService(String configDbService) { + this.configDbService = configDbService; + } + + public String getCpsUrl() { + return cpsUrl; + } + + public void setCpsUrl(String cpsUrl) { + this.cpsUrl = cpsUrl; + } + + public String getAaiUrl() { + return aaiUrl; + } + + public void setAaiUrl(String aaiUrl) { + this.aaiUrl = aaiUrl; + } + + public Boolean getConfigDbEnabled() { + return configDbEnabled; + } + + public void setConfigDbEnabled(Boolean configDbEnabled) { + this.configDbEnabled = configDbEnabled; + } + + public int getSamples() { + return samples; + } + + public void setSamples(int samples) { + this.samples = samples; + } + + public int getMinPercentageChange() { + return minPercentageChange; + } + + public void setMinPercentageChange(int minPercentageChange) { + this.minPercentageChange = minPercentageChange; + } + + public long getInitialDelaySeconds() { + return initialDelaySeconds; + } + + public void setInitialDelaySeconds(long initialDelaySeconds) { + this.initialDelaySeconds = initialDelaySeconds; + } + + /** + * Get RannfnssiDetails TemplateId from Configuration + */ + public String getRannfnssiDetailsTemplateId() { + return rannfnssiDetailsTemplateId; + } + + /** + * Set RannfnssiDetails TemplateId + */ + public void setRannfnssiDetailsTemplateId(String rannfnssiDetailsTemplateId) { + this.rannfnssiDetailsTemplateId = rannfnssiDetailsTemplateId; + } + + /** + * Get Data Extraction Service Url + */ + public String getDesUrl() { + return desUrl; + } + + /** + * Set Data Extraction Service Url + */ + public void setDesUrl(String desUrl) { + this.desUrl = desUrl; + } + + /** + * Get duration for which PM data is to be fetched from DES + */ + public int getPmDataDurationInWeeks() { + return pmDataDurationInWeeks; + } + + /** + * Set duration for which PM data is to be fetched from DES + */ + public void setPmDataDurationInWeeks(int pmDataDurationInWeeks) { + this.pmDataDurationInWeeks = pmDataDurationInWeeks; + } + + @Override + public String toString() { + return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword=" + + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService + ", cpsUrl=" + + cpsUrl + ", aaiUrl=" + aaiUrl + ", configDbEnabled=" + configDbEnabled + ", cg=" + cg + ", cid=" + cid + + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", aafUsername=" + + aafUsername + ", aafPassword=" + aafPassword + ", streamsSubscribes=" + streamsSubscribes + + ", streamsPublishes=" + streamsPublishes + ", samples=" + samples + ", minPercentageChange=" + + minPercentageChange + ", initialDelaySeconds=" + initialDelaySeconds + ", rannfnssiDetailsTemplateId=" + + rannfnssiDetailsTemplateId + ", desUrl=" + desUrl + ", pmDataDurationInWeeks=" + pmDataDurationInWeeks + + "]"; + } + + /** + * updates application configuration. + */ + public void updateConfigurationFromJsonObject(JsonObject jsonObject) { + + log.info("Updating configuration from CBS"); + + Type mapType = new TypeToken>() {}.getType(); + + JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); + streamsSubscribes = new Gson().fromJson(subscribes, mapType); + + JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); + streamsPublishes = new Gson().fromJson(publishes, mapType); + + pgPort = jsonObject.get("postgres.port").getAsInt(); + pollingInterval = jsonObject.get("sliceanalysisms.pollingInterval").getAsInt(); + pgPassword = jsonObject.get("postgres.password").getAsString(); + pgUsername = jsonObject.get("postgres.username").getAsString(); + pgHost = jsonObject.get("postgres.host").getAsString(); + + JsonArray servers = jsonObject.getAsJsonArray("sliceanalysisms.dmaap.server"); + Type listType = new TypeToken>() {}.getType(); + dmaapServers = new Gson().fromJson(servers, listType); + + cg = jsonObject.get("sliceanalysisms.cg").getAsString(); + cid = jsonObject.get("sliceanalysisms.cid").getAsString(); + configDbService = jsonObject.get("sliceanalysisms.configDb.service").getAsString(); + configDbEnabled = jsonObject.get("sliceanalysisms.configDbEnabled").getAsBoolean(); + + pollingTimeout = jsonObject.get("sliceanalysisms.pollingTimeout").getAsInt(); + samples = jsonObject.get("sliceanalysisms.samples").getAsInt(); + minPercentageChange = jsonObject.get("sliceanalysisms.minPercentageChange").getAsInt(); + initialDelaySeconds = jsonObject.get("sliceanalysisms.initialDelaySeconds").getAsLong(); + rannfnssiDetailsTemplateId = jsonObject.get("sliceanalysisms.rannfnssiDetailsTemplateId").getAsString(); + desUrl = jsonObject.get("sliceanalysisms.desUrl").getAsString(); + pmDataDurationInWeeks = jsonObject.get("sliceanalysisms.pmDataDurationInWeeks").getAsInt(); + + if (Objects.isNull(jsonObject.get("aafUsername"))) { + aafUsername = null; + } else { + aafUsername = jsonObject.get("aafUsername").getAsString(); + } + if (Objects.isNull(jsonObject.get("aafPassword"))) { + aafPassword = null; + } else { + aafPassword = jsonObject.get("aafPassword").getAsString(); + } + if (Objects.isNull(jsonObject.get("sliceanalysisms.aai.url"))) { + aaiUrl = null; + } else { + aaiUrl = jsonObject.get("sliceanalysisms.aai.url").getAsString(); + } + if (Objects.isNull(jsonObject.get("sliceanalysisms.cps.url"))) { + cpsUrl = null; + } else { + cpsUrl = jsonObject.get("sliceanalysisms.cps.url").getAsString(); + } + log.info("configuration from CBS {}", this); + } } - diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigDetails.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigDetails.java new file mode 100644 index 00000000..5f8b7434 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigDetails.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * SliceConfigDetails contains slice utilization data for requested slice + */ +@Data +@NoArgsConstructor +public class SliceConfigDetails { + + String sliceIdentifiers; + AggregatedConfig aggregatedConfig; +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigRequest.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigRequest.java new file mode 100644 index 00000000..aefbdd38 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigRequest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +import java.util.List; + +import javax.validation.constraints.NotEmpty; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Request body to get slice utilization data + */ +@Data +@NoArgsConstructor +public class SliceConfigRequest { + + @NotEmpty(message = "Slice Identifier missing") + List sliceIdentifiers; + @NotEmpty(message = "Config Param missing") + List configParams; +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigResponse.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigResponse.java new file mode 100644 index 00000000..18d28ca2 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SliceConfigResponse.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +import java.util.List; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * SliceConfigResponse contains slice utilization data for requested slices + */ +@Data +@NoArgsConstructor +public class SliceConfigResponse { + + List sliceConfigDetails; + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/Relationship.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/Relationship.java new file mode 100644 index 00000000..f4acc08b --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/Relationship.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.aai; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; +import java.util.Map; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model for receiving Relationship data of a service from AAI + */ +@Data +@NoArgsConstructor +public class Relationship { + + @JsonProperty("related-to") + private String relatedTo; + @JsonProperty("relationship-label") + private String relationshipLabel; + @JsonProperty("related-link") + private String relatedLink; + @JsonProperty("relationship-data") + private List> relationshipData; + @JsonProperty("related-to-property") + private List> relatedToProperty; + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/RelationshipList.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/RelationshipList.java new file mode 100644 index 00000000..1cda2ae5 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/RelationshipList.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.aai; + +import java.util.List; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model for receiving RelationshipList data of a service from AAI + */ +@Data +@NoArgsConstructor +public class RelationshipList { + + List relationship; + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/ServiceInstance.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/ServiceInstance.java new file mode 100644 index 00000000..ecb2c4cd --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/aai/ServiceInstance.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.aai; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Model for receiving ServiceInstance data from AAI + */ +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +@NoArgsConstructor +public class ServiceInstance { + + @JsonProperty("service-instance-id") + private String serviceInstanceId; + @JsonProperty("service-instance-name") + private String serviceInstanceName; + @JsonProperty("service-type;") + private String serviceType; + @JsonProperty("service-role") + private String serviceRole; + @JsonProperty("environment-context") + private String environmentContext; + @JsonProperty("workload-context") + private String workloadContext; + @JsonProperty("orchestration-status") + private String orchestrationStatus; + @JsonProperty("relationship-list") + private RelationshipList relationshipList; + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/DesRestClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/DesRestClient.java new file mode 100644 index 00000000..5d29af3a --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/DesRestClient.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.restclients; + +import java.util.Collections; + +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; + +/** + * This class represents rest client for DES interfaces + */ +@Component +public class DesRestClient extends RestClient { + + public DesRestClient() { + super(); + } + + /** + * Send Post Request to DES + */ + + public ResponseEntity sendPostRequest(String requestUrl, String requestBody, + ParameterizedTypeReference responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + return super.sendPostRequest(headers, requestUrl, requestBody, responseType); + } + + /** + * Send Get Request to DES + */ + + public ResponseEntity sendGetRequest(String requestUrl, ParameterizedTypeReference responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + return super.sendGetRequest(headers, requestUrl, responseType); + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java index 6098142e..5dcd9189 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2020-2021 Wipro Limited. + * Copyright (C) 2020-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,95 +24,93 @@ package org.onap.slice.analysis.ms.service; import java.util.List; import java.util.Objects; -import org.onap.slice.analysis.ms.configdb.CpsInterface; import org.onap.slice.analysis.ms.configdb.IConfigDbService; +import org.onap.slice.analysis.ms.cps.CpsInterface; import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.models.SubCounter; import org.onap.slice.analysis.ms.utils.BeanUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** +/** * This Thread class consumes message from pm data queue and sends onset message to policy */ public class ConsumerThread extends Thread { - private static Logger log = LoggerFactory.getLogger(ConsumerThread.class); - private PmDataQueue pmDataQueue; - private IConfigDbService configDbService; - private SnssaiSamplesProcessor snssaiSamplesProcessor; - private CpsInterface cpsInterface; - private long initialDelaySec; - private int samples; + private static Logger log = LoggerFactory.getLogger(ConsumerThread.class); + private PmDataQueue pmDataQueue; + private IConfigDbService configDbService; + private SnssaiSamplesProcessor snssaiSamplesProcessor; + private CpsInterface cpsInterface; + private long initialDelaySec; + private int samples; - /** - * Default constructor. - */ - public ConsumerThread() { - super(); - this.pmDataQueue = BeanUtil.getBean(PmDataQueue.class); - this.configDbService = BeanUtil.getBean(IConfigDbService.class); - this.initialDelaySec = Configuration.getInstance().getInitialDelaySeconds(); - this.samples = Configuration.getInstance().getSamples(); - this.cpsInterface = BeanUtil.getBean(CpsInterface.class); - } + /** + * Default constructor. + */ + public ConsumerThread() { + super(); + this.pmDataQueue = BeanUtil.getBean(PmDataQueue.class); + this.configDbService = BeanUtil.getBean(IConfigDbService.class); + this.initialDelaySec = Configuration.getInstance().getInitialDelaySeconds(); + this.samples = Configuration.getInstance().getSamples(); + this.cpsInterface = BeanUtil.getBean(CpsInterface.class); + } - /** - * Consumes data from PM data queue, process the data and sends onset message to policy if needed - */ - @Override - public void run() { - Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true - : Configuration.getInstance().getConfigDbEnabled(); - boolean done = false; - boolean result = false; - String snssai = ""; - List nfs = null; - while (!done) { - try { - Thread.sleep(initialDelaySec); - log.info("Starting Consumer Thread"); - snssai = pmDataQueue.getSnnsaiFromQueue(); - if (!snssai.equals("")) { - log.info("Consumer thread processing data for s-nssai {}",snssai); - try { - if (isConfigDbEnabled) { - nfs = configDbService.fetchNetworkFunctionsOfSnssai(snssai); - } - else { - nfs = cpsInterface.fetchNetworkFunctionsOfSnssai(snssai); - } - } - catch(Exception e) { - pmDataQueue.putSnssaiToQueue(snssai); - log.error("Exception caught while fetching nfs of snssai {}, {}", snssai, e.getMessage()); - } - if(nfs != null && checkForEnoughSamples(nfs, snssai)) { - this.snssaiSamplesProcessor = BeanUtil.getBean(SnssaiSamplesProcessor.class); - result = snssaiSamplesProcessor.processSamplesOfSnnsai(snssai, nfs); - if(!result) { - log.info("Not enough samples to process for {}",snssai); - pmDataQueue.putSnssaiToQueue(snssai); - } - } - } - } catch (Exception e) { - log.error("Exception in Consumer Thread, {}", e.getMessage()); - done = true; - } - } - } + /** + * Consumes data from PM data queue, process the data and sends onset message to policy if needed + */ + @Override + public void run() { + Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true + : Configuration.getInstance().getConfigDbEnabled(); + boolean done = false; + boolean result = false; + String snssai = ""; + List nfs = null; + while (!done) { + try { + Thread.sleep(initialDelaySec); + log.info("Starting Consumer Thread"); + snssai = pmDataQueue.getSnnsaiFromQueue(); + if (!snssai.equals("")) { + log.info("Consumer thread processing data for s-nssai {}", snssai); + try { + if (isConfigDbEnabled) { + nfs = configDbService.fetchNetworkFunctionsOfSnssai(snssai); + } else { + nfs = cpsInterface.fetchNetworkFunctionsOfSnssai(snssai); + } + } catch (Exception e) { + pmDataQueue.putSnssaiToQueue(snssai); + log.error("Exception caught while fetching nfs of snssai {}, {}", snssai, e.getMessage()); + } + if (nfs != null && checkForEnoughSamples(nfs, snssai)) { + this.snssaiSamplesProcessor = BeanUtil.getBean(SnssaiSamplesProcessor.class); + result = snssaiSamplesProcessor.processSamplesOfSnnsai(snssai, nfs); + if (!result) { + log.info("Not enough samples to process for {}", snssai); + pmDataQueue.putSnssaiToQueue(snssai); + } + } + } + } catch (Exception e) { + log.error("Exception in Consumer Thread, {}", e.getMessage()); + done = true; + } + } + } /** * Checks whether enough samples are available for the network functions */ - public boolean checkForEnoughSamples(List nfs, String snssai) { - for(String nf : nfs) { - if(! pmDataQueue.checkSamplesInQueue(new SubCounter(nf, snssai), samples)) { - log.info("Not enough samples to process for network function {} of snssai {}", nf, snssai); - pmDataQueue.putSnssaiToQueue(snssai); - return false; - } - } - return true; - } + public boolean checkForEnoughSamples(List nfs, String snssai) { + for (String nf : nfs) { + if (!pmDataQueue.checkSamplesInQueue(new SubCounter(nf, snssai), samples)) { + log.info("Not enough samples to process for network function {} of snssai {}", nf, snssai); + pmDataQueue.putSnssaiToQueue(snssai); + return false; + } + } + return true; + } } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java index 8bc7b0d5..f692efcc 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2020-2021 Wipro Limited. + * Copyright (C) 2020-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,9 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import org.onap.slice.analysis.ms.configdb.AaiInterface; -import org.onap.slice.analysis.ms.configdb.CpsInterface; +import org.onap.slice.analysis.ms.aai.AaiInterface; import org.onap.slice.analysis.ms.configdb.IConfigDbService; +import org.onap.slice.analysis.ms.cps.CpsInterface; import org.onap.slice.analysis.ms.models.CUModel; import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.models.MLOutputModel; @@ -44,51 +44,54 @@ import org.springframework.stereotype.Component; @Component @Scope("prototype") public class MLMessageProcessor { - private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class); + private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class); - @Autowired - private IConfigDbService configDbService; + @Autowired + private IConfigDbService configDbService; - @Autowired - private PolicyService policyService; + @Autowired + private PolicyService policyService; - @Autowired - private AaiInterface aaiInterface; + @Autowired + private AaiInterface aaiInterface; - @Autowired - private CpsInterface cpsInterface; + @Autowired + private CpsInterface cpsInterface; - public void processMLMsg(MLOutputModel mlOutputMsg) { - Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true - : Configuration.getInstance().getConfigDbEnabled(); - Map> ricToCellMapping = null; - Map serviceDetails = null; - String snssai = mlOutputMsg.getSnssai(); - List cuData = mlOutputMsg.getData(); - if (isConfigDbEnabled) { - ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); - } else { - ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai); - } - log.debug("RIC to cell mapping of S-NSSAI {} is {}", snssai, ricToCellMapping); - for (CUModel cuModel : cuData) { - String cellId = String.valueOf(cuModel.getCellCUList().get(0).getCellLocalId()); - ricToCellMapping.forEach((ricId, cells) -> { - if (cells.contains(cellId)) { - cuModel.setNearRTRICId(ricId); - } - }); - } - AdditionalProperties addProps = new AdditionalProperties<>(); - addProps.setResourceConfig(mlOutputMsg); + /** + * Process the message sent by ML service and sends notification to policy + */ + public void processMLMsg(MLOutputModel mlOutputMsg) { + Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true + : Configuration.getInstance().getConfigDbEnabled(); + Map> ricToCellMapping = null; + Map serviceDetails = null; + String snssai = mlOutputMsg.getSnssai(); + List cuData = mlOutputMsg.getData(); + if (isConfigDbEnabled) { + ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); + } else { + ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai); + } + log.debug("RIC to cell mapping of S-NSSAI {} is {}", snssai, ricToCellMapping); + for (CUModel cuModel : cuData) { + String cellId = String.valueOf(cuModel.getCellCUList().get(0).getCellLocalId()); + ricToCellMapping.forEach((ricId, cells) -> { + if (cells.contains(cellId)) { + cuModel.setNearRTRICId(ricId); + } + }); + } + AdditionalProperties addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(mlOutputMsg); - if (isConfigDbEnabled) { - serviceDetails = configDbService.fetchServiceDetails(snssai); - } else { - serviceDetails = aaiInterface.fetchServiceDetails(snssai); + if (isConfigDbEnabled) { + serviceDetails = configDbService.fetchServiceDetails(snssai); + } else { + serviceDetails = aaiInterface.fetchServiceDetails(snssai); - } - policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails); - } + } + policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails); + } } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java new file mode 100644 index 00000000..94696343 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SliceUtilization.java @@ -0,0 +1,216 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.slice.analysis.ms.aai.AaiService; +import org.onap.slice.analysis.ms.exception.DesClientException; +import org.onap.slice.analysis.ms.models.AggregatedConfig; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.models.SliceConfigDetails; +import org.onap.slice.analysis.ms.models.SliceConfigRequest; +import org.onap.slice.analysis.ms.models.SliceConfigResponse; +import org.onap.slice.analysis.ms.restclients.DesRestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +/** + * This Service calculates the slice utilization details + */ +@Service +public class SliceUtilization { + + private static Logger log = LoggerFactory.getLogger(SliceUtilization.class); + + @Autowired + private AaiService aaiService; + + @Autowired + DesRestClient desRestClient; + + /** + * Default values set for uplink and downlink throughput calculation (in + * accordance with 3GPP specifications) + * + */ + private static final Integer numOfAggregatedComponentCarries = 8; + private static final Integer maxNumOfLayers = 4; + private static final Integer maxModulationOrder = 2; + private static final Integer scalingFactor = 1; + private static final Double maxBitRate = 948.0 / 1024; + private static final Integer nrNumerology = 2; + private static final Double averageSymbolDuration = Math.pow(10, -3) / (14 * 2 * nrNumerology); + private static final Double overHeadForDl = 0.18; + private static final Double overHeadForUl = 0.10; + private static final Integer TOTAL_PRB = 132; + + /** + * Calculates the slice utilization details for requested slices. + * + * @param sliceConfigRequest contains sliceInstanceId + * @return SliceConfigResponse contains slice utilization details + */ + public SliceConfigResponse getSliceUtilizationData(SliceConfigRequest sliceConfigRequest) { + + log.info("getSliceUtilizationData"); + SliceConfigResponse sliceConfigResponse = new SliceConfigResponse(); + ArrayList sliceConfigDetailsList = new ArrayList<>(); + + try { + sliceConfigRequest.getSliceIdentifiers().forEach(sliceInstanceId -> { + List snssaiList = null; + snssaiList = aaiService.getSnssaiList(sliceInstanceId); + List pmDataList = new ArrayList<>(); + snssaiList.forEach(snssai -> { + JSONObject pmData = getPMData(snssai); + pmDataList.add(pmData); + }); + AggregatedConfig aggregatedConfig = calculateSliceUtilization(pmDataList); + SliceConfigDetails sliceConfigDetails = new SliceConfigDetails(); + sliceConfigDetails.setSliceIdentifiers(sliceInstanceId); + sliceConfigDetails.setAggregatedConfig(aggregatedConfig); + sliceConfigDetailsList.add(sliceConfigDetails); + + }); + } catch (Exception e) { + log.error("Exception caught while fetching data"); + } + sliceConfigResponse.setSliceConfigDetails(sliceConfigDetailsList); + log.info("SliceConfigResponse: " + sliceConfigResponse.toString()); + return sliceConfigResponse; + + } + + /** + * Fetches the PM data for requested SNSSAI from DES. + * + * @param snssai snssai ID + * @return PM Data for requested SNSSAI + */ + protected JSONObject getPMData(String snssai) { + String desUrl = Configuration.getInstance().getDesUrl(); + Map inputParameter = new HashMap<>(); + int duration = Configuration.getInstance().getPmDataDurationInWeeks(); + Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + calendar.add(Calendar.WEEK_OF_MONTH, -duration); + inputParameter.put("snssai", "SM.PrbUsedDl." + snssai); + inputParameter.put("time", String.valueOf(calendar.getTimeInMillis())); + ResponseEntity response = null; + JSONObject pmData = null; + try { + + String jsonRequestBody = new ObjectMapper().writeValueAsString(inputParameter); + log.info("fetching PM Data for : {}", snssai); + response = + desRestClient.sendPostRequest(desUrl, jsonRequestBody, new ParameterizedTypeReference() {}); + pmData = new JSONObject(response.getBody()); + if (response.getStatusCode().value() != 200) { + throw new DesClientException(String.format("Response code from DES other than 200: %d\", statusCode", + response.getStatusCode().value())); + } + + } catch (Exception e) { + log.error("Error while fetching PM data from DES {} ", e); + } + + return pmData; + } + + /** + * Calculates average DL and UL PRB used from the PM data and returns the + * remaining resources(utilization details) in terms of throughput + * + * @param pmDataList PM data for all SNSSAIs + * @return aggregatedConfig containing slice utilization details + */ + protected AggregatedConfig calculateSliceUtilization(List pmDataList) { + + Integer numOfPRBData = 0; + Integer dlPRBUsed = 0; + Integer ulPRBUsed = 0; + Integer dlThptIndex = 0; + Integer ulThptIndex = 1; + try { + for (JSONObject pmData : pmDataList) { + JSONArray result = pmData.getJSONArray("result"); + for (int i = 0; i < result.length(); i++) { + JSONObject measValuesObject = result.getJSONObject(i); + String measValuesListStr = measValuesObject.getString("measValuesList"); + String sMeasTypesListtStr = measValuesObject.getString("sMeasTypesList"); + JSONArray measValuesArray = new JSONArray(measValuesListStr); + JSONArray sMeasTypesArray = new JSONArray(sMeasTypesListtStr); + if (sMeasTypesArray.getString(0).contains("PrbUsedUl")) { + ulThptIndex = 0; + dlThptIndex = 1; + } + numOfPRBData += measValuesArray.length(); + for (int j = 0; j < measValuesArray.length(); j++) { + dlPRBUsed += + measValuesArray.getJSONArray(j).getJSONArray(2).getJSONArray(dlThptIndex).getInt(1); + ulPRBUsed += + measValuesArray.getJSONArray(j).getJSONArray(2).getJSONArray(ulThptIndex).getInt(1); + } + } + } + } catch (Exception e) { + log.error("Exception caught while calculating slice utilization: {}", e); + } + + Integer averageDLPrb = dlPRBUsed / numOfPRBData; + Integer averageULPrb = ulPRBUsed / numOfPRBData; + Double tempdl = 0.0; + Double tempul = 0.0; + int j = 1; + + while (j <= numOfAggregatedComponentCarries) { + tempdl += ((Math.pow(maxNumOfLayers, j) * Math.pow(maxModulationOrder, j) * Math.pow(scalingFactor, j) + * maxBitRate * (TOTAL_PRB - averageDLPrb) * 12 * (1 - Math.pow(overHeadForDl, j))) + / averageSymbolDuration) * Math.pow(10, -6); + tempul += ((Math.pow(maxNumOfLayers, j) * Math.pow(maxModulationOrder, j) * Math.pow(scalingFactor, j) + * maxBitRate * (TOTAL_PRB - averageULPrb) * 12 * (1 - Math.pow(overHeadForUl, j))) + / averageSymbolDuration) * Math.pow(10, -6); + j++; + + } + + Integer dLThptPerSliceInMbps = (int) Math.round(tempdl); + Integer uLThptPerSliceInMbps = (int) Math.round(tempul); + AggregatedConfig aggregatedConfig = new AggregatedConfig(); + aggregatedConfig.setDLThptPerSlice(dLThptPerSliceInMbps); + aggregatedConfig.setULThptPerSlice(uLThptPerSliceInMbps); + return aggregatedConfig; + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java index d802f81d..b4e06896 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2020-2021 Wipro Limited. + * Copyright (C) 2020-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * ============LICENSE_END========================================================= * *******************************************************************************/ + package org.onap.slice.analysis.ms.service; import java.util.ArrayList; @@ -29,9 +30,9 @@ import java.util.Objects; import javax.annotation.PostConstruct; -import org.onap.slice.analysis.ms.configdb.AaiInterface; -import org.onap.slice.analysis.ms.configdb.CpsInterface; +import org.onap.slice.analysis.ms.aai.AaiInterface; import org.onap.slice.analysis.ms.configdb.IConfigDbService; +import org.onap.slice.analysis.ms.cps.CpsInterface; import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.models.MeasurementObject; import org.onap.slice.analysis.ms.models.SubCounter; @@ -48,201 +49,201 @@ import org.springframework.stereotype.Component; @Component @Scope("prototype") public class SnssaiSamplesProcessor { - private static Logger log = LoggerFactory.getLogger(SnssaiSamplesProcessor.class); - - @Autowired - private PolicyService policyService; - - @Autowired - private IConfigDbService configDbService; - - @Autowired - private PmDataQueue pmDataQueue; - - @Autowired - private AverageCalculator averageCalculator; - - @Autowired - private AaiInterface aaiInterface; - - @Autowired - private CpsInterface cpsInterface; - - private List snssaiMeasurementList = new ArrayList<>(); - private Map> ricToCellMapping = new HashMap<>(); - private Map> ricToPrbsMapping = new HashMap<>(); - private Map> ricToThroughputMapping = new HashMap<>(); - private int noOfSamples; - private List pmsToCompute; - private Map prbThroughputMapping = new HashMap<>(); - private int minPercentageChange; - - @PostConstruct - public void init() { - Configuration configuration = Configuration.getInstance(); - noOfSamples = configuration.getSamples(); - pmsToCompute = new ArrayList<>(); - pmsToCompute.add("PrbUsedDl"); - pmsToCompute.add("PrbUsedUl"); - prbThroughputMapping = new HashMap<>(); - prbThroughputMapping.put("PrbUsedDl", "dLThptPerSlice"); - prbThroughputMapping.put("PrbUsedUl", "uLThptPerSlice"); - minPercentageChange = configuration.getMinPercentageChange(); + private static Logger log = LoggerFactory.getLogger(SnssaiSamplesProcessor.class); + + @Autowired + private PolicyService policyService; + + @Autowired + private IConfigDbService configDbService; + + @Autowired + private PmDataQueue pmDataQueue; + + @Autowired + private AverageCalculator averageCalculator; + + @Autowired + private AaiInterface aaiInterface; + + @Autowired + private CpsInterface cpsInterface; + + private List snssaiMeasurementList = new ArrayList<>(); + private Map> ricToCellMapping = new HashMap<>(); + private Map> ricToPrbsMapping = new HashMap<>(); + private Map> ricToThroughputMapping = new HashMap<>(); + private int noOfSamples; + private List pmsToCompute; + private Map prbThroughputMapping = new HashMap<>(); + private int minPercentageChange; + + @PostConstruct + public void init() { + Configuration configuration = Configuration.getInstance(); + noOfSamples = configuration.getSamples(); + pmsToCompute = new ArrayList<>(); + pmsToCompute.add("PrbUsedDl"); + pmsToCompute.add("PrbUsedUl"); + prbThroughputMapping = new HashMap<>(); + prbThroughputMapping.put("PrbUsedDl", "dLThptPerSlice"); + prbThroughputMapping.put("PrbUsedUl", "uLThptPerSlice"); + minPercentageChange = configuration.getMinPercentageChange(); + } + + /** + * process the measurement data of an S-NSSAI + */ + public boolean processSamplesOfSnnsai(String snssai, List networkFunctions) { + Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true + : Configuration.getInstance().getConfigDbEnabled(); + List sample = null; + List> samples = null; + Map serviceDetails = null; + log.info("Network Functions {} of snssai {}", networkFunctions, snssai); + for (String nf : networkFunctions) { + log.debug("Average of samples for {}:", snssai); + samples = pmDataQueue.getSamplesFromQueue(new SubCounter(nf, snssai), noOfSamples); + if (samples != null) { + sample = averageCalculator.findAverageOfSamples(samples); + addToMeasurementList(sample); + } else { + log.info("Not enough samples present for nf {}", nf); + return false; + } } - - /** - * process the measurement data of an S-NSSAI - */ - public boolean processSamplesOfSnnsai(String snssai, List networkFunctions) { - Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true - : Configuration.getInstance().getConfigDbEnabled(); - List sample = null; - List> samples = null; - Map serviceDetails =null; - log.info("Network Functions {} of snssai {}", networkFunctions, snssai); - for (String nf : networkFunctions) { - log.debug("Average of samples for {}:", snssai); - samples = pmDataQueue.getSamplesFromQueue(new SubCounter(nf, snssai), noOfSamples); - if (samples != null) { - sample = averageCalculator.findAverageOfSamples(samples); - addToMeasurementList(sample); - } else { - log.info("Not enough samples present for nf {}", nf); - return false; - } - } - log.info("snssai measurement list {}", snssaiMeasurementList); - Map> ricConfiguration; - Map sliceConfiguration; - if (isConfigDbEnabled) { - ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); - ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai); - sliceConfiguration = configDbService.fetchCurrentConfigurationOfSlice(snssai); - serviceDetails = configDbService.fetchServiceDetails(snssai); - } else { - ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai); - ricConfiguration = cpsInterface.fetchCurrentConfigurationOfRIC(snssai); - serviceDetails = aaiInterface.fetchServiceDetails(snssai); - sliceConfiguration = aaiInterface.fetchCurrentConfigurationOfSlice(snssai); - } - log.info("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping); - log.info("RIC Configuration {} and Slice Configuration {}", ricConfiguration, sliceConfiguration); - pmsToCompute.forEach(pm -> { - log.debug("processing for pm {}", pm); - sumOfPrbsAcrossCells(pm); - int sum = computeSum(pm); - computeThroughput(sliceConfiguration, sum, pm); - calculatePercentageChange(ricConfiguration, prbThroughputMapping.get(pm)); - }); - updateConfiguration(); - if (ricToThroughputMapping.size() > 0) { - AdditionalProperties>>> addProps = new AdditionalProperties<>(); - addProps.setResourceConfig(getChangedRIConfigFormat(ricToThroughputMapping)); - policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails); - } - return true; + log.info("snssai measurement list {}", snssaiMeasurementList); + Map> ricConfiguration; + Map sliceConfiguration; + if (isConfigDbEnabled) { + ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); + ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai); + sliceConfiguration = configDbService.fetchCurrentConfigurationOfSlice(snssai); + serviceDetails = configDbService.fetchServiceDetails(snssai); + } else { + ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai); + ricConfiguration = cpsInterface.fetchCurrentConfigurationOfRIC(snssai); + serviceDetails = aaiInterface.fetchServiceDetails(snssai); + sliceConfiguration = aaiInterface.fetchCurrentConfigurationOfSlice(snssai); } - - /** - * change the RICConfig data format to be compatible with SDN-R - */ - protected Map>> getChangedRIConfigFormat( - Map> ricToThroughputMapping) { - Iterator>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry> entry = null; - List> ricConfigList = new ArrayList<>(); - Map>> ricConfigData = new HashMap<>(); - while (it.hasNext()) { - Map newConfigMap = new HashMap<>(); - entry = it.next(); - newConfigMap = entry.getValue(); - newConfigMap.put("nearRTRICId", Integer.parseInt(entry.getKey())); - ricConfigList.add(newConfigMap); - } - ricConfigData.put("data", ricConfigList); - return ricConfigData; + log.info("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping); + log.info("RIC Configuration {} and Slice Configuration {}", ricConfiguration, sliceConfiguration); + pmsToCompute.forEach(pm -> { + log.debug("processing for pm {}", pm); + sumOfPrbsAcrossCells(pm); + int sum = computeSum(pm); + computeThroughput(sliceConfiguration, sum, pm); + calculatePercentageChange(ricConfiguration, prbThroughputMapping.get(pm)); + }); + updateConfiguration(); + if (ricToThroughputMapping.size() > 0) { + AdditionalProperties>>> addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(getChangedRIConfigFormat(ricToThroughputMapping)); + policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails); } - - /** - * process the measurement data of an S-NSSAI - */ - protected void updateConfiguration() { - Iterator>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry> entry = null; - while (it.hasNext()) { - entry = it.next(); - if (entry.getValue().size() == 0) { - it.remove(); - } - } + return true; + } + + /** + * change the RICConfig data format to be compatible with SDN-R + */ + protected Map>> getChangedRIConfigFormat( + Map> ricToThroughputMapping) { + Iterator>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry> entry = null; + List> ricConfigList = new ArrayList<>(); + Map>> ricConfigData = new HashMap<>(); + while (it.hasNext()) { + Map newConfigMap = new HashMap<>(); + entry = it.next(); + newConfigMap = entry.getValue(); + newConfigMap.put("nearRTRICId", Integer.parseInt(entry.getKey())); + ricConfigList.add(newConfigMap); } - - private void addToMeasurementList(List sample) { - snssaiMeasurementList.addAll(sample); + ricConfigData.put("data", ricConfigList); + return ricConfigData; + } + + /** + * process the measurement data of an S-NSSAI + */ + protected void updateConfiguration() { + Iterator>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry> entry = null; + while (it.hasNext()) { + entry = it.next(); + if (entry.getValue().size() == 0) { + it.remove(); + } } - - /** - * Calculate the change in the configuration value and keep the configuration - * only if it is greater than a specific limit - */ - protected void calculatePercentageChange(Map> ricConfiguration, String pm) { - Iterator>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry> entry = null; - float existing = 0; - float change = 0; - while (it.hasNext()) { - entry = it.next(); - existing = (float) ((int) ricConfiguration.get(entry.getKey()).get(pm)); - change = ((Math.abs(entry.getValue().get(pm) - existing)) / existing) * 100; - if (change <= minPercentageChange) { - ricToThroughputMapping.get(entry.getKey()).remove(pm); - log.info("Removing pm data {} for RIC {}", pm, entry.getKey()); - } - } + } + + private void addToMeasurementList(List sample) { + snssaiMeasurementList.addAll(sample); + } + + /** + * Calculate the change in the configuration value and keep the configuration + * only if it is greater than a specific limit + */ + protected void calculatePercentageChange(Map> ricConfiguration, String pm) { + Iterator>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry> entry = null; + float existing = 0; + float change = 0; + while (it.hasNext()) { + entry = it.next(); + existing = (float) ((int) ricConfiguration.get(entry.getKey()).get(pm)); + change = ((Math.abs(entry.getValue().get(pm) - existing)) / existing) * 100; + if (change <= minPercentageChange) { + ricToThroughputMapping.get(entry.getKey()).remove(pm); + log.info("Removing pm data {} for RIC {}", pm, entry.getKey()); + } } - - protected void sumOfPrbsAcrossCells(String pmName) { - ricToCellMapping.forEach((ric, cells) -> { - int sumOfPrbs = 0; - for (String cell : cells) { - int index = MeasurementObject.findIndex(cell, snssaiMeasurementList); - sumOfPrbs += snssaiMeasurementList.get(index).getPmData().get(pmName); - } - if (ricToPrbsMapping.containsKey(ric)) { - ricToPrbsMapping.get(ric).put(pmName, sumOfPrbs); - } else { - Map pmToPrbMapping = new HashMap<>(); - pmToPrbMapping.put(pmName, sumOfPrbs); - ricToPrbsMapping.put(ric, pmToPrbMapping); - } - }); - log.info("PRBs sum computed for RIC {}", ricToPrbsMapping); - } - - protected Integer computeSum(String pm) { - return ricToPrbsMapping.entrySet().stream().map(x -> x.getValue().get(pm)).reduce(0, Integer::sum); - } - - protected void computeThroughput(Map sliceConfiguration, int sum, String pm) { - Iterator>> it = ricToPrbsMapping.entrySet().iterator(); - Map.Entry> entry = null; - Map throughtputMap = null; - String ric = ""; - int value = 0; - while (it.hasNext()) { - entry = it.next(); - ric = entry.getKey(); - value = Math.round(((float) entry.getValue().get(pm) / sum) - * (float) sliceConfiguration.get(prbThroughputMapping.get(pm))); - if (ricToThroughputMapping.containsKey(ric)) { - ricToThroughputMapping.get(ric).put(prbThroughputMapping.get(pm), value); - } else { - throughtputMap = new HashMap<>(); - throughtputMap.put(prbThroughputMapping.get(pm), value); - ricToThroughputMapping.put(ric, throughtputMap); - } - } - log.info("Throughput computed for RIC {}", ricToThroughputMapping); + } + + protected void sumOfPrbsAcrossCells(String pmName) { + ricToCellMapping.forEach((ric, cells) -> { + int sumOfPrbs = 0; + for (String cell : cells) { + int index = MeasurementObject.findIndex(cell, snssaiMeasurementList); + sumOfPrbs += snssaiMeasurementList.get(index).getPmData().get(pmName); + } + if (ricToPrbsMapping.containsKey(ric)) { + ricToPrbsMapping.get(ric).put(pmName, sumOfPrbs); + } else { + Map pmToPrbMapping = new HashMap<>(); + pmToPrbMapping.put(pmName, sumOfPrbs); + ricToPrbsMapping.put(ric, pmToPrbMapping); + } + }); + log.info("PRBs sum computed for RIC {}", ricToPrbsMapping); + } + + protected Integer computeSum(String pm) { + return ricToPrbsMapping.entrySet().stream().map(x -> x.getValue().get(pm)).reduce(0, Integer::sum); + } + + protected void computeThroughput(Map sliceConfiguration, int sum, String pm) { + Iterator>> it = ricToPrbsMapping.entrySet().iterator(); + Map.Entry> entry = null; + Map throughtputMap = null; + String ric = ""; + int value = 0; + while (it.hasNext()) { + entry = it.next(); + ric = entry.getKey(); + value = Math.round(((float) entry.getValue().get(pm) / sum) + * (float) sliceConfiguration.get(prbThroughputMapping.get(pm))); + if (ricToThroughputMapping.containsKey(ric)) { + ricToThroughputMapping.get(ric).put(prbThroughputMapping.get(pm), value); + } else { + throughtputMap = new HashMap<>(); + throughtputMap.put(prbThroughputMapping.get(pm), value); + ricToThroughputMapping.put(ric, throughtputMap); + } } + log.info("Throughput computed for RIC {}", ricToThroughputMapping); + } } -- cgit 1.2.3-korg