diff options
author | 2022-02-03 04:50:38 +0000 | |
---|---|---|
committer | 2022-03-03 13:39:38 +0000 | |
commit | f67adad42f2c857ff76b52df39f0beb5c2cabee4 (patch) | |
tree | d9c4394a5f52187d9db0a09a0759e78350df8e16 /components/slice-analysis-ms/src/main/java | |
parent | 5f69c24ad78121a2840b5299583791e557f8b535 (diff) |
[DCAEGEN2] Calculate slice utilization data
Issue-ID: DCAEGEN2-2942
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: Id16d2a36cf964b15495531a54094cad96471bdcb
Diffstat (limited to 'components/slice-analysis-ms/src/main/java')
22 files changed, 1853 insertions, 924 deletions
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/aai/AaiInterface.java index 68b795b5..87718a5c 100644 --- 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/aai/AaiInterface.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2021 Wipro Limited. + * 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. @@ -19,18 +19,18 @@ * *******************************************************************************/ -package org.onap.slice.analysis.ms.configdb; +package org.onap.slice.analysis.ms.aai; import java.util.Map; /** - * + * * Interface for AAI * */ public interface AaiInterface { - public Map<String, String> fetchServiceDetails(String snssai); - public Map<String, Integer> fetchCurrentConfigurationOfSlice(String snssai); -} + public Map<String, String> fetchServiceDetails(String snssai); + public Map<String, Integer> 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<String, String> fetchServiceDetails(String snssai) { + Map<String, String> 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<String>() {}).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<String>() {}).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<String, Integer> 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<String, Integer> responseMap = new HashMap<String, Integer>(); + try { + String serviceInstance = + restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference<String>() {}).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<String>() {}).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<String, String> fetchSubscriberAndSubscriptionServiceType() { + + Map<String, String> responseMap = new HashMap<String, String>(); + + log.info("Get GlobalSubscriberId"); + String subscriberReqUrl = aaiBaseUrl + "/business/customers"; + try { + String subscriberReq = + restclient.sendGetRequest(subscriberReqUrl, new ParameterizedTypeReference<String>() {}).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<String>() {}).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<String> getSnssaiList(String sliceInstanceId) { + fetchSubscriberAndSubscriptionServiceType(); + List<String> allotedResource = new ArrayList<>(); + List<String> sliceProfileList = new ArrayList<>(); + List<String> 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<String>() {}).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<String> fetchSliceProfilesOfAllotedResourceData(List<String> allotedResourceList) { + + List<String> 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<String>() {}).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<String> fetchSnssaiOfSliceProfile(List<String> sliceProfileList) { + List<String> 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<String>() {}).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/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<String, String> fetchServiceDetails(String snssai) { - log.info("AAI fetch service: "); - Map<String, String> responseMap = new HashMap<String, String>(); - - log.info("AAI getGlobalSubscriberId: "); - String subscriberReqUrl = aaiBaseUrl + "/business/customers"; - try { - String subscriberReq = restclient - .sendGetRequest(subscriberReqUrl, new ParameterizedTypeReference<String>() { - }).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<String>() { - }).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<String>() { - }).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<String>() { - }).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<String, Integer> 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<String, Integer> responseMap = new HashMap<String, Integer>(); - try { - String serviceInstance = restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference<String>() { - }).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<String>() { - }).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/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<String, Map<String, Object>> fetchCurrentConfigurationOfRIC(String snssai) { - Map<String, Map<String, Object>> responseMap = new HashMap<String, Map<String, Object>>(); - 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<String>() {}).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<String,Object> map = new HashMap<String,Object>(); - 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<String> fetchNetworkFunctionsOfSnssai(String snssai) { - List<String> 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<String>() {}).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<String, List<String>> fetchRICsOfSnssai(String snssai) { - Map<String,List<String>> 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<String>() {}).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<String> 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/controller/SliceConfiguraton.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/SliceConfiguraton.java new file mode 100644 index 00000000..412d8d2c --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/SliceConfiguraton.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============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.controller; + +import org.onap.slice.analysis.ms.models.SliceConfigRequest; +import org.onap.slice.analysis.ms.models.SliceConfigResponse; +import org.onap.slice.analysis.ms.service.SliceUtilization; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +/** + * This Controller provides slice configuration details + */ +@RestController +public class SliceConfiguraton { + + @Autowired + SliceUtilization sliceUtilization; + + /** + * This method provides the slice utilization details for requested slices. + * + * @param sliceConfigRequest contains sliceInstanceId + * @return sliceConfigResponse contains slice configuration details + */ + @GetMapping(value = "/api/v1/slices-config") + public ResponseEntity<SliceConfigResponse> sliceConfigRequest(@RequestBody SliceConfigRequest sliceConfigRequest) { + try { + SliceConfigResponse sliceConfigResponse = sliceUtilization.getSliceUtilizationData(sliceConfigRequest); + return new ResponseEntity<SliceConfigResponse>(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/configdb/CpsInterface.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/cps/CpsInterface.java index ef6211c4..95e7340f 100644 --- 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/cps/CpsInterface.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2021 Wipro Limited. + * 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. @@ -19,21 +19,22 @@ * *******************************************************************************/ -package org.onap.slice.analysis.ms.configdb; +package org.onap.slice.analysis.ms.cps; import java.util.List; import java.util.Map; /** - * - * Interface for CPS + * + * Interface for CPS * */ public interface CpsInterface { - public Map<String, List<String>> fetchRICsOfSnssai(String snssai); - public List<String> fetchNetworkFunctionsOfSnssai(String snssai); - public Map<String, Map<String,Object>> fetchCurrentConfigurationOfRIC(String snssai); - -} + public Map<String, List<String>> fetchRICsOfSnssai(String snssai); + + public List<String> fetchNetworkFunctionsOfSnssai(String snssai); + public Map<String, Map<String, Object>> 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<String, Map<String, Object>> fetchCurrentConfigurationOfRIC(String snssai) { + Map<String, Map<String, Object>> responseMap = new HashMap<String, Map<String, Object>>(); + 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<String>() {}).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<String, Object> map = new HashMap<String, Object>(); + 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<String> fetchNetworkFunctionsOfSnssai(String snssai) { + List<String> 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<String>() {}).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<String, List<String>> fetchRICsOfSnssai(String snssai) { + Map<String, List<String>> 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<String>() {}).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<String> 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<String> 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<String, Object> streamsSubscribes; - private Map<String, Object> 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<String, Object> getStreamsSubscribes() { - return streamsSubscribes; - } - - public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { - this.streamsSubscribes = streamsSubscribes; - } - - public Map<String, Object> getStreamsPublishes() { - return streamsPublishes; - } - - public void setStreamsPublishes(Map<String, Object> 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<String> getDmaapServers() { - return dmaapServers; - } - - public void setDmaapServers(List<String> 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<Map<String, Object>>() { - }.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<List<String>>() { - }.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<String> 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<String, Object> streamsSubscribes; + private Map<String, Object> 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<String, Object> getStreamsSubscribes() { + return streamsSubscribes; + } + + public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { + this.streamsSubscribes = streamsSubscribes; + } + + public Map<String, Object> getStreamsPublishes() { + return streamsPublishes; + } + + public void setStreamsPublishes(Map<String, Object> 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<String> getDmaapServers() { + return dmaapServers; + } + + public void setDmaapServers(List<String> 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<Map<String, Object>>() {}.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<List<String>>() {}.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<String> sliceIdentifiers; + @NotEmpty(message = "Config Param missing") + List<String> 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> 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<Map<String, String>> relationshipData; + @JsonProperty("related-to-property") + private List<Map<String, String>> 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> 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 <T> ResponseEntity<T> sendPostRequest(String requestUrl, String requestBody, + ParameterizedTypeReference<T> 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 <T> ResponseEntity<T> sendGetRequest(String requestUrl, ParameterizedTypeReference<T> 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<String> 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<String> 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<String> 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<String> 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<String, List<String>> ricToCellMapping = null; - Map<String, String> serviceDetails = null; - String snssai = mlOutputMsg.getSnssai(); - List<CUModel> 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<MLOutputModel> 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<String, List<String>> ricToCellMapping = null; + Map<String, String> serviceDetails = null; + String snssai = mlOutputMsg.getSnssai(); + List<CUModel> 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<MLOutputModel> 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<SliceConfigDetails> sliceConfigDetailsList = new ArrayList<>(); + + try { + sliceConfigRequest.getSliceIdentifiers().forEach(sliceInstanceId -> { + List<String> snssaiList = null; + snssaiList = aaiService.getSnssaiList(sliceInstanceId); + List<JSONObject> 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<String, String> 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<String> 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<String>() {}); + 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<JSONObject> 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<MeasurementObject> snssaiMeasurementList = new ArrayList<>(); - private Map<String, List<String>> ricToCellMapping = new HashMap<>(); - private Map<String, Map<String, Integer>> ricToPrbsMapping = new HashMap<>(); - private Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); - private int noOfSamples; - private List<String> pmsToCompute; - private Map<String, String> 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<MeasurementObject> snssaiMeasurementList = new ArrayList<>(); + private Map<String, List<String>> ricToCellMapping = new HashMap<>(); + private Map<String, Map<String, Integer>> ricToPrbsMapping = new HashMap<>(); + private Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); + private int noOfSamples; + private List<String> pmsToCompute; + private Map<String, String> 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<String> networkFunctions) { + Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true + : Configuration.getInstance().getConfigDbEnabled(); + List<MeasurementObject> sample = null; + List<List<MeasurementObject>> samples = null; + Map<String, String> 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<String> networkFunctions) { - Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true - : Configuration.getInstance().getConfigDbEnabled(); - List<MeasurementObject> sample = null; - List<List<MeasurementObject>> samples = null; - Map<String, String> 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<String, Map<String, Object>> ricConfiguration; - Map<String, Integer> 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<Map<String, List<Map<String, Integer>>>> addProps = new AdditionalProperties<>(); - addProps.setResourceConfig(getChangedRIConfigFormat(ricToThroughputMapping)); - policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails); - } - return true; + log.info("snssai measurement list {}", snssaiMeasurementList); + Map<String, Map<String, Object>> ricConfiguration; + Map<String, Integer> 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<String, List<Map<String, Integer>>> getChangedRIConfigFormat( - Map<String, Map<String, Integer>> ricToThroughputMapping) { - Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry<String, Map<String, Integer>> entry = null; - List<Map<String, Integer>> ricConfigList = new ArrayList<>(); - Map<String, List<Map<String, Integer>>> ricConfigData = new HashMap<>(); - while (it.hasNext()) { - Map<String, Integer> 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<Map<String, List<Map<String, Integer>>>> addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(getChangedRIConfigFormat(ricToThroughputMapping)); + policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails); } - - /** - * process the measurement data of an S-NSSAI - */ - protected void updateConfiguration() { - Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry<String, Map<String, Integer>> 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<String, List<Map<String, Integer>>> getChangedRIConfigFormat( + Map<String, Map<String, Integer>> ricToThroughputMapping) { + Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry<String, Map<String, Integer>> entry = null; + List<Map<String, Integer>> ricConfigList = new ArrayList<>(); + Map<String, List<Map<String, Integer>>> ricConfigData = new HashMap<>(); + while (it.hasNext()) { + Map<String, Integer> newConfigMap = new HashMap<>(); + entry = it.next(); + newConfigMap = entry.getValue(); + newConfigMap.put("nearRTRICId", Integer.parseInt(entry.getKey())); + ricConfigList.add(newConfigMap); } - - private void addToMeasurementList(List<MeasurementObject> sample) { - snssaiMeasurementList.addAll(sample); + ricConfigData.put("data", ricConfigList); + return ricConfigData; + } + + /** + * process the measurement data of an S-NSSAI + */ + protected void updateConfiguration() { + Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry<String, Map<String, Integer>> 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<String, Map<String, Object>> ricConfiguration, String pm) { - Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry<String, Map<String, Integer>> 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<MeasurementObject> 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<String, Map<String, Object>> ricConfiguration, String pm) { + Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry<String, Map<String, Integer>> 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<String, Integer> 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<String, Integer> sliceConfiguration, int sum, String pm) { - Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToPrbsMapping.entrySet().iterator(); - Map.Entry<String, Map<String, Integer>> entry = null; - Map<String, Integer> 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<String, Integer> 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<String, Integer> sliceConfiguration, int sum, String pm) { + Iterator<Map.Entry<String, Map<String, Integer>>> it = ricToPrbsMapping.entrySet().iterator(); + Map.Entry<String, Map<String, Integer>> entry = null; + Map<String, Integer> 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); + } } |