From 766e23f1dd95700ff1a1d9e89d8a3cf8d147036c Mon Sep 17 00:00:00 2001 From: Niranjana Date: Mon, 22 Feb 2021 12:55:18 +0000 Subject: Add AAI updates Issue-ID: DCAEGEN2-2623 Signed-off-by: Niranjana Change-Id: I0f724981c5b19d033ec1cb79c9d4d2b5120125b7 --- .../slice/analysis/ms/configdb/AaiInterface.java | 36 ++ .../slice/analysis/ms/configdb/AaiService.java | 179 +++++++++ .../ms/configdb/ConfigDbInterfaceService.java | 1 + .../slice/analysis/ms/configdb/CpsInterface.java | 39 ++ .../slice/analysis/ms/configdb/CpsService.java | 73 ++++ .../analysis/ms/configdb/IConfigDbService.java | 1 + .../slice/analysis/ms/models/Configuration.java | 431 +++++++++++---------- .../analysis/ms/restclients/AaiRestClient.java | 59 +++ .../analysis/ms/restclients/CpsRestClient.java | 65 ++++ .../slice/analysis/ms/restclients/RestClient.java | 52 ++- .../analysis/ms/service/MLMessageProcessor.java | 44 ++- .../ms/service/SnssaiSamplesProcessor.java | 112 +++--- .../onap/slice/analysis/ms/utils/AppConfig.java | 68 ++++ 13 files changed, 904 insertions(+), 256 deletions(-) create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiInterface.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiService.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsInterface.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsService.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/AaiRestClient.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/CpsRestClient.java create mode 100644 components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/AppConfig.java (limited to 'components/slice-analysis-ms/src/main/java/org/onap') diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiInterface.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiInterface.java new file mode 100644 index 00000000..68b795b5 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiInterface.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.configdb; + +import java.util.Map; + +/** + * + * Interface for AAI + * + */ +public interface AaiInterface { + + public Map fetchServiceDetails(String snssai); + public Map fetchCurrentConfigurationOfSlice(String snssai); +} + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiService.java new file mode 100644 index 00000000..16ff71a6 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/AaiService.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.configdb; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.restclients.AaiRestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.stereotype.Service; + +/** + * + * Service for AAI interfaces + * + */ +@Service +public class AaiService implements AaiInterface { + + private static Logger log = LoggerFactory.getLogger(Configuration.class); + + @Autowired + AaiRestClient restclient; + private static String globalSubscriberId; + private static String subscriptionServiceType; + private static String aaiBaseUrl = Configuration.getInstance().getAaiUrl(); + + /** + * Fetches the details of a subscriber + */ + public Map fetchServiceDetails(String snssai) { + log.info("AAI fetch service: "); + Map responseMap = new HashMap(); + + log.info("AAI getGlobalSubscriberId: "); + String subscriberReqUrl = aaiBaseUrl + "/business/customers"; + try { + String subscriberReq = restclient + .sendGetRequest(subscriberReqUrl, new ParameterizedTypeReference() { + }).getBody(); + JSONObject subscriberReqJson = new JSONObject(subscriberReq); + JSONArray subscriberReqJsonList = subscriberReqJson.getJSONArray("customer"); + for (int i = 0; i < subscriberReqJsonList.length(); i++) { + JSONObject subscriberReqObj = subscriberReqJsonList.getJSONObject(i); + globalSubscriberId = subscriberReqObj.getString("global-customer-id"); + responseMap.put("globalSubscriberId", globalSubscriberId); + break; + } + } catch (Exception e) { + log.info("Exception while fetching getGlobalSubscriberId: " + e); + } + + String subscriptionServiceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions"; + try { + String subscriptionService = restclient + .sendGetRequest(subscriptionServiceReqUrl, new ParameterizedTypeReference() { + }).getBody(); + JSONObject subscriptionServiceJson = new JSONObject(subscriptionService); + JSONArray subscriptionServiceListJson = subscriptionServiceJson.getJSONArray("service-subscription"); + for (int i = 0; i < subscriptionServiceListJson.length(); i++) { + JSONObject subscriptionServiceObj = subscriptionServiceListJson.getJSONObject(i); + subscriptionServiceType = subscriptionServiceObj.getString("service-type"); + responseMap.put("subscriptionServiceType", subscriptionServiceType); + break; + } + } catch (Exception e) { + log.info("Exception while fetching subscriptionService: " + e); + } + + String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances"; + String serviceRole = "AN-NF"; + try { + String serviceInstance = restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() { + }).getBody(); + JSONObject serviceInstanceJson = new JSONObject(serviceInstance); + JSONArray serviceInstanceList = serviceInstanceJson.getJSONArray("service-instance"); + for (int i = 0; i < serviceInstanceList.length(); i++) { + JSONObject serviceObj = serviceInstanceList.getJSONObject(i); + if (serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { + responseMap.put("sliceProfileId", serviceObj.getString("service-instance-id")); + } + } + + String serviceRoleReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + + "/service-instances/?service-role=nssi&depth=2"; + + String serviceInstanceForServiceRole = restclient + .sendGetRequest(serviceRoleReqUrl, new ParameterizedTypeReference() { + }).getBody(); + JSONObject serviceInstanceForServiceRoleJson = new JSONObject(serviceInstanceForServiceRole); + JSONArray serviceInstanceListForServiceRole = serviceInstanceForServiceRoleJson + .getJSONArray("service-instance"); + for (int i = 0; i < serviceInstanceListForServiceRole.length(); i++) { + JSONObject serviceObj = serviceInstanceListForServiceRole.getJSONObject(i); + if (serviceObj.getString("workload-context").trim().equalsIgnoreCase(serviceRole)) { + responseMap.put("ranNFNSSIId", serviceObj.getString("service-instance-id")); + } + } + } catch (Exception e) { + log.info("Exception while fetching serviceDetails: " + e); + } + responseMap.put("sNSSAI", snssai); + log.info("subscriber details: " + responseMap); + return responseMap; + } + + /** + * Fetches the current configuration of an Slice from AAI + */ + public Map fetchCurrentConfigurationOfSlice(String snssai) { + log.info("AAI fetch config Slice: " + aaiBaseUrl); + String serviceInstaneId = null; + String serviceReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + "/service-instances"; + Map responseMap = new HashMap(); + try { + String serviceInstance = restclient.sendGetRequest(serviceReqUrl, new ParameterizedTypeReference() { + }).getBody(); + JSONObject serviceInstanceJson = new JSONObject(serviceInstance); + + JSONArray serviceInstanceList = serviceInstanceJson.getJSONArray("service-instance"); + for (int i = 0; i < serviceInstanceList.length(); i++) { + JSONObject serviceObj = serviceInstanceList.getJSONObject(i); + if (serviceObj.getString("environment-context").equalsIgnoreCase(snssai)) { + serviceInstaneId = serviceObj.getString("service-instance-id"); + } + } + + String sliceProfileReqUrl = aaiBaseUrl + "/business/customers/customer/" + globalSubscriberId + + "/service-subscriptions/service-subscription/" + subscriptionServiceType + + "/service-instances/service-instance/" + serviceInstaneId + "/slice-profiles"; + + String sliceProfile = restclient + .sendGetRequest(sliceProfileReqUrl, new ParameterizedTypeReference() { + }).getBody(); + JSONObject sliceProfileJson = new JSONObject(sliceProfile); + JSONArray sliceProfileList = sliceProfileJson.getJSONArray("slice-profile"); + for (int i = 0; i < sliceProfileList.length(); i++) { + JSONObject sliceProfileObj = sliceProfileList.getJSONObject(i); + responseMap.put("dLThptPerSlice", sliceProfileObj.getInt("exp-data-rate-UL")); + responseMap.put("uLThptPerSlice", sliceProfileObj.getInt("exp-data-rate-DL")); + break; + } + log.info("Slice configuration: " + responseMap); + } catch (Exception e) { + log.info("AAI Slice: " + e); + } + return responseMap; + } +} + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java index 8a11bdb5..5798a40f 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java @@ -113,3 +113,4 @@ public class ConfigDbInterfaceService implements IConfigDbService { } } + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsInterface.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsInterface.java new file mode 100644 index 00000000..ef6211c4 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsInterface.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.configdb; + +import java.util.List; +import java.util.Map; + +/** + * + * Interface for CPS + * + */ +public interface CpsInterface { + + public Map> fetchRICsOfSnssai(String snssai); + public List fetchNetworkFunctionsOfSnssai(String snssai); + public Map> fetchCurrentConfigurationOfRIC(String snssai); + +} + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsService.java new file mode 100644 index 00000000..f72c99c2 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/CpsService.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.restclients.CpsRestClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +/** + * + * Service for CPS interfaces + * + */ +@Service +public class CpsService implements CpsInterface { + + private static Logger log = LoggerFactory.getLogger(CpsService.class); + + @Autowired + CpsRestClient restclient; + private static String cpsBaseUrl = Configuration.getInstance().getCpsUrl(); + + /** + * Fetches the current configuration of RIC from CPS + */ + public Map> fetchCurrentConfigurationOfRIC(String snssai) { + return null; + } + + /** + * Fetches all the network functions of an S-NSSAI from CPS + */ + public List fetchNetworkFunctionsOfSnssai(String snssai) { + return null; + } + + /** + * Fetches the RICS of an S-NSSAI from CPS + */ + public Map> fetchRICsOfSnssai(String snssai) { + return null; + } + +} + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java index 7413c181..2b92b091 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java @@ -37,3 +37,4 @@ public interface IConfigDbService { public Map> fetchCurrentConfigurationOfRIC(String snssai); public Map fetchServiceDetails(String snssai); } + 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 91a07d4f..60f52f0f 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 Wipro Limited. + * Copyright (C) 2020-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. @@ -24,6 +24,7 @@ package org.onap.slice.analysis.ms.models; import java.lang.reflect.Type; import java.util.List; import java.util.Map; +import java.util.Objects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +34,7 @@ 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 { @@ -46,6 +47,9 @@ public class Configuration { private String pgPassword; private List dmaapServers; private String configDbService; + private String cpsUrl; + private String aaiUrl; + private Boolean configDbEnabled; private String cg; private String cid; private int pollingInterval; @@ -57,221 +61,258 @@ public class Configuration { private int samples; private int minPercentageChange; private long initialDelaySeconds; + /** * Check if topic is secure. */ - public boolean isSecured() { - return (aafUsername != null); + public boolean isSecured() { + return (aafUsername != null); - } + } - public String getAafUsername() { - return aafUsername; - } + public String getAafUsername() { + return aafUsername; + } - public void setAafUsername(String aafUsername) { - this.aafUsername = aafUsername; - } + public void setAafUsername(String aafUsername) { + this.aafUsername = aafUsername; + } - public String getAafPassword() { - return aafPassword; - } + public String getAafPassword() { + return aafPassword; + } - public void setAafPassword(String aafPassword) { - this.aafPassword = aafPassword; - } + public void setAafPassword(String aafPassword) { + this.aafPassword = aafPassword; + } - public Map getStreamsSubscribes() { - return streamsSubscribes; - } + public Map getStreamsSubscribes() { + return streamsSubscribes; + } - public void setStreamsSubscribes(Map streamsSubscribes) { - this.streamsSubscribes = streamsSubscribes; - } + public void setStreamsSubscribes(Map streamsSubscribes) { + this.streamsSubscribes = streamsSubscribes; + } - public Map getStreamsPublishes() { - return streamsPublishes; - } + public Map getStreamsPublishes() { + return streamsPublishes; + } - public void setStreamsPublishes(Map streamsPublishes) { - this.streamsPublishes = streamsPublishes; - } + public void setStreamsPublishes(Map streamsPublishes) { + this.streamsPublishes = streamsPublishes; + } - protected Configuration() { + protected Configuration() { - } + } - /** - * Get instance of class. - */ - public static Configuration getInstance() { - if (instance == null) { - instance = new Configuration(); - } - return instance; - } + /** + * Get instance of class. + */ + public static Configuration getInstance() { + if (instance == null) { + instance = new Configuration(); + } + return instance; + } - public String getCg() { - return cg; - } + public String getCg() { + return cg; + } - public void setCg(String cg) { - this.cg = 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 String getCid() { + return cid; + } - public int getPollingTimeout() { - return pollingTimeout; - } + public void setCid(String cid) { + this.cid = cid; + } - public void setPollingTimeout(int pollingTimeout) { - this.pollingTimeout = pollingTimeout; - } + public int getPollingInterval() { + return pollingInterval; + } - public String getPgHost() { - return pgHost; - } + public void setPollingInterval(int pollingInterval) { + this.pollingInterval = pollingInterval; + } - public void setPgHost(String pgHost) { - this.pgHost = pgHost; - } + public int getPollingTimeout() { + return pollingTimeout; + } - public int getPgPort() { - return pgPort; - } + public void setPollingTimeout(int pollingTimeout) { + this.pollingTimeout = pollingTimeout; + } + + public String getPgHost() { + return pgHost; + } + + public void setPgHost(String pgHost) { + this.pgHost = pgHost; + } + + public int getPgPort() { + return pgPort; + } + + public void setPgPort(int pgPort) { + this.pgPort = pgPort; + } + + public String getPgUsername() { + return pgUsername; + } + + public void setPgUsername(String pgUsername) { + this.pgUsername = pgUsername; + } + + public String getPgPassword() { + return pgPassword; + } + + public void setPgPassword(String pgPassword) { + this.pgPassword = pgPassword; + } + + public List getDmaapServers() { + return dmaapServers; + } + + public void setDmaapServers(List dmaapServers) { + this.dmaapServers = dmaapServers; + } + + public String getConfigDbService() { + return configDbService; + } + + public void setConfigDbService(String configDbService) { + this.configDbService = configDbService; + } + + public String getCpsUrl() { + return cpsUrl; + } + + public void setCpsUrl(String cpsUrl) { + this.cpsUrl = cpsUrl; + } + + public String getAaiUrl() { + return aaiUrl; + } + + public void setAaiUrl(String aaiUrl) { + this.aaiUrl = aaiUrl; + } + + public Boolean getConfigDbEnabled() { + return configDbEnabled; + } + + public void setConfigDbEnabled(Boolean configDbEnabled) { + this.configDbEnabled = configDbEnabled; + } + + public int getSamples() { + return samples; + } + + public void setSamples(int samples) { + this.samples = samples; + } + + public int getMinPercentageChange() { + return minPercentageChange; + } + + public void setMinPercentageChange(int minPercentageChange) { + this.minPercentageChange = minPercentageChange; + } + + public long getInitialDelaySeconds() { + return initialDelaySeconds; + } + + public void setInitialDelaySeconds(long initialDelaySeconds) { + this.initialDelaySeconds = initialDelaySeconds; + } + + @Override + public String toString() { + return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword=" + + pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService + ", cpsUrl=" + + cpsUrl + ", aaiUrl=" + aaiUrl + ", configDbEnabled=" + configDbEnabled + ", cg=" + cg + ", cid=" + cid + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + + pollingTimeout + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword + + ", streamsSubscribes=" + streamsSubscribes + ", streamsPublishes=" + streamsPublishes + ", samples=" + + samples + ", minPercentageChange=" + minPercentageChange + ", initialDelaySeconds=" + + initialDelaySeconds + "]"; + } - public void setPgPort(int pgPort) { - this.pgPort = pgPort; - } - - public String getPgUsername() { - return pgUsername; - } - - public void setPgUsername(String pgUsername) { - this.pgUsername = pgUsername; - } - - public String getPgPassword() { - return pgPassword; - } - - public void setPgPassword(String pgPassword) { - this.pgPassword = pgPassword; - } - - public List getDmaapServers() { - return dmaapServers; - } - - public void setDmaapServers(List dmaapServers) { - this.dmaapServers = dmaapServers; - } - - public String getConfigDbService() { - return configDbService; - } - - public void setConfigDbService(String configDbService) { - this.configDbService = configDbService; - } - - public 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 + ", cg=" + cg - + ", cid=" + cid + ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout - + ", aafUsername=" + aafUsername + ", aafPassword=" + aafPassword + ", streamsSubscribes=" - + streamsSubscribes + ", streamsPublishes=" + streamsPublishes + ", samples=" + samples - + ", minPercentageChange=" + minPercentageChange + ", initialDelaySeconds=" + initialDelaySeconds + "]"; - } - - /** - * updates application configuration. - */ - public void updateConfigurationFromJsonObject(JsonObject jsonObject) { - - log.info("Updating configuration from CBS"); - - Type mapType = new TypeToken>() { - }.getType(); - - JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); - streamsSubscribes = new Gson().fromJson(subscribes, mapType); - - JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); - streamsPublishes = new Gson().fromJson(publishes, mapType); - - pgPort = jsonObject.get("postgres.port").getAsInt(); - pollingInterval = jsonObject.get("sliceanalysisms.pollingInterval").getAsInt(); - pgPassword = jsonObject.get("postgres.password").getAsString(); - pgUsername = jsonObject.get("postgres.username").getAsString(); - pgHost = jsonObject.get("postgres.host").getAsString(); - - JsonArray servers = jsonObject.getAsJsonArray("sliceanalysisms.dmaap.server"); - Type listType = new TypeToken>() {}.getType(); - dmaapServers = new Gson().fromJson(servers, listType); - - cg = jsonObject.get("sliceanalysisms.cg").getAsString(); - cid = jsonObject.get("sliceanalysisms.cid").getAsString(); - configDbService = jsonObject.get("sliceanalysisms.configDb.service").getAsString(); - - 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(jsonObject.get("aafUsername") == null) { - aafUsername = null; - } - else { - aafUsername = jsonObject.get("aafUsername").getAsString(); - } - if(jsonObject.get("aafPassword") == null) { - aafPassword = null; - } - else { - aafPassword = jsonObject.get("aafPassword").getAsString(); - } - log.info("configuration from CBS {}", this); - } + /** + * updates application configuration. + */ + public void updateConfigurationFromJsonObject(JsonObject jsonObject) { + + log.info("Updating configuration from CBS"); + + Type mapType = new TypeToken>() { + }.getType(); + + JsonObject subscribes = jsonObject.getAsJsonObject("streams_subscribes"); + streamsSubscribes = new Gson().fromJson(subscribes, mapType); + + JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes"); + streamsPublishes = new Gson().fromJson(publishes, mapType); + + pgPort = jsonObject.get("postgres.port").getAsInt(); + pollingInterval = jsonObject.get("sliceanalysisms.pollingInterval").getAsInt(); + pgPassword = jsonObject.get("postgres.password").getAsString(); + pgUsername = jsonObject.get("postgres.username").getAsString(); + pgHost = jsonObject.get("postgres.host").getAsString(); + + JsonArray servers = jsonObject.getAsJsonArray("sliceanalysisms.dmaap.server"); + Type listType = new TypeToken>() { + }.getType(); + dmaapServers = new Gson().fromJson(servers, listType); + + cg = jsonObject.get("sliceanalysisms.cg").getAsString(); + cid = jsonObject.get("sliceanalysisms.cid").getAsString(); + configDbService = jsonObject.get("sliceanalysisms.configDb.service").getAsString(); + configDbEnabled = jsonObject.get("sliceanalysisms.configDbEnabled").getAsBoolean(); + + pollingTimeout = jsonObject.get("sliceanalysisms.pollingTimeout").getAsInt(); + samples = jsonObject.get("sliceanalysisms.samples").getAsInt(); + minPercentageChange = jsonObject.get("sliceanalysisms.minPercentageChange").getAsInt(); + initialDelaySeconds = jsonObject.get("sliceanalysisms.initialDelaySeconds").getAsLong(); + + if (Objects.isNull(jsonObject.get("aafUsername"))) { + aafUsername = null; + } else { + aafUsername = jsonObject.get("aafUsername").getAsString(); + } + if (Objects.isNull(jsonObject.get("aafPassword"))) { + aafPassword = null; + } else { + aafPassword = jsonObject.get("aafPassword").getAsString(); + } + if (Objects.isNull(jsonObject.get("sliceanalysisms.aai.url"))) { + aaiUrl = null; + } else { + aaiUrl = jsonObject.get("sliceanalysisms.aai.url").getAsString(); + } + if (Objects.isNull(jsonObject.get("sliceanalysisms.cps.url"))) { + cpsUrl = null; + } else { + cpsUrl = jsonObject.get("sliceanalysisms.cps.url").getAsString(); + } + log.info("configuration from CBS {}", this); + } } + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/AaiRestClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/AaiRestClient.java new file mode 100644 index 00000000..62e39ad5 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/AaiRestClient.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * ============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.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 AAI interfaces + */ +@Component +public class AaiRestClient extends RestClient { + + public AaiRestClient() { + super(); + } + + public ResponseEntity sendPostRequest(String requestUrl, String requestBody, + ParameterizedTypeReference responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + return super.sendPostRequest(headers, requestUrl, requestBody, responseType); + } + + public ResponseEntity sendGetRequest(String requestUrl, ParameterizedTypeReference responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.set("X-FromAppId", "AAI"); + headers.set("X-TransactionId", "get_aai_subscr"); + return super.sendGetRequest(headers, requestUrl, responseType); + } +} + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/CpsRestClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/CpsRestClient.java new file mode 100644 index 00000000..1d6e2388 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/CpsRestClient.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * ============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.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 CPS interfaces + */ +@Component +public class CpsRestClient extends RestClient { + + public CpsRestClient() { + super(); + } + + /** + * Send Post Request to CPS + */ + + public ResponseEntity sendPostRequest(String requestUrl, String requestBody, + ParameterizedTypeReference responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + return super.sendPostRequest(headers, requestUrl, requestBody, responseType); + } + + /** + * Send Get Request to CPS + */ + + public ResponseEntity sendGetRequest(String requestUrl, ParameterizedTypeReference responseType) { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + return super.sendGetRequest(headers, requestUrl, responseType); + } +} + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java index 65de9838..3be3fc65 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2020 Wipro Limited. + * Copyright (C) 2020-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. @@ -21,6 +21,22 @@ package org.onap.slice.analysis.ms.restclients; +import java.security.KeyStoreException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; + +import javax.net.ssl.SSLContext; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.BasicHttpClientConnectionManager; +import org.apache.http.ssl.TrustStrategy; +import org.apache.http.ssl.SSLContexts; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; @@ -29,20 +45,22 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; -/** - * This class is for base rest client +/** + * This class is for base rest client */ @Component public class RestClient { private static final String EXCEPTION_MSG = "Exception caught during request {}"; private static final Logger log = org.slf4j.LoggerFactory.getLogger(RestClient.class); - + @Autowired private RestTemplate restTemplate; + protected RestClient() { } @@ -66,15 +84,37 @@ public class RestClient { * Get Request Template. */ - public ResponseEntity sendGetRequest(HttpHeaders headers, String requestUrl, ParameterizedTypeReference responseType) { + public ResponseEntity sendGetRequest(HttpHeaders headers, String requestUrl, + ParameterizedTypeReference responseType) { HttpEntity requestEntity = new HttpEntity<>(headers); try { + RestTemplate restTemplate = new RestTemplate(useApacheHttpClientWithSelfSignedSupport()); return restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, responseType); } catch (Exception e) { - log.debug(EXCEPTION_MSG, e.getMessage()); + log.info(EXCEPTION_MSG, e.getMessage()); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } + private static HttpComponentsClientHttpRequestFactory useApacheHttpClientWithSelfSignedSupport() { + + TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; + SSLContext sslContext = null; + try { + sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) { + log.error(EXCEPTION_MSG, e); + } + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); + Registry socketFactoryRegistry = RegistryBuilder.create() + .register("https", sslsf).register("http", new PlainConnectionSocketFactory()).build(); + BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager( + socketFactoryRegistry); + CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf) + .setConnectionManager(connectionManager).build(); + HttpComponentsClientHttpRequestFactory useApacheHttpClient = new HttpComponentsClientHttpRequestFactory(); + useApacheHttpClient.setHttpClient(httpClient); + return useApacheHttpClient; + } } 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 84ff3715..b67d3507 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 Wipro Limited. + * Copyright (C) 2020-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. @@ -23,9 +23,13 @@ package org.onap.slice.analysis.ms.service; 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.configdb.IConfigDbService; import org.onap.slice.analysis.ms.models.CUModel; +import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.models.MLOutputModel; import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; import org.slf4j.Logger; @@ -41,28 +45,50 @@ import org.springframework.stereotype.Component; @Scope("prototype") public class MLMessageProcessor { private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class); - + @Autowired private IConfigDbService configDbService; - + @Autowired private PolicyService policyService; - + + @Autowired + private AaiInterface aaiInterface; + + @Autowired + private CpsInterface cpsInterface; + public void processMLMsg(MLOutputModel mlOutputMsg) { + Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true + : Configuration.getInstance().getConfigDbEnabled(); + Map> ricToCellMapping = null; + Map serviceDetails = null; String snssai = mlOutputMsg.getSnssai(); List cuData = mlOutputMsg.getData(); - Map> ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); - log.debug("RIC to cell mapping of S-NSSAI {} is {}",snssai,ricToCellMapping); - for(CUModel cuModel: cuData) { + 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)) { + if (cells.contains(cellId)) { cuModel.setNearRTRICId(ricId); } }); } AdditionalProperties addProps = new AdditionalProperties<>(); addProps.setResourceConfig(mlOutputMsg); - policyService.sendOnsetMessageToPolicy(snssai, addProps, configDbService.fetchServiceDetails(snssai)); + + if (isConfigDbEnabled) { + serviceDetails = configDbService.fetchServiceDetails(snssai); + } else { + serviceDetails = aaiInterface.fetchServiceDetails(snssai); + + } + policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails); } } + 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 e8d5de3e..0c5c0eb8 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 Wipro Limited. + * Copyright (C) 2020-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. @@ -25,9 +25,12 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +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.configdb.IConfigDbService; import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.models.MeasurementObject; @@ -39,7 +42,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -/** +/** * This class process the measurement data of an S-NSSAI */ @Component @@ -49,25 +52,31 @@ public class SnssaiSamplesProcessor { @Autowired private PolicyService policyService; - + @Autowired private IConfigDbService configDbService; - + @Autowired private PmDataQueue pmDataQueue; - + @Autowired private AverageCalculator averageCalculator; - + + @Autowired + private AaiInterface aaiInterface; + + @Autowired + private CpsInterface cpsInterface; + private List snssaiMeasurementList = new ArrayList<>(); private Map> ricToCellMapping = new HashMap<>(); private Map> ricToPrbsMapping = new HashMap<>(); private Map> ricToThroughputMapping = new HashMap<>(); private int noOfSamples; - private List pmsToCompute; - private Map prbThroughputMapping = new HashMap<>(); + private List pmsToCompute; + private Map prbThroughputMapping = new HashMap<>(); private int minPercentageChange; - + @PostConstruct public void init() { Configuration configuration = Configuration.getInstance(); @@ -84,27 +93,39 @@ public class SnssaiSamplesProcessor { /** * process the measurement data of an S-NSSAI */ - public boolean processSamplesOfSnnsai(String snssai, List networkFunctions) { + public boolean processSamplesOfSnnsai(String snssai, List networkFunctions) { + Boolean isConfigDbEnabled = (Objects.isNull(Configuration.getInstance().getConfigDbEnabled())) ? true + : Configuration.getInstance().getConfigDbEnabled(); List sample = null; List> samples = null; + Map serviceDetails =null; log.info("Network Functions {} of snssai {}", networkFunctions, snssai); - for(String nf : networkFunctions) { + for (String nf : networkFunctions) { log.debug("Average of samples for {}:", snssai); samples = pmDataQueue.getSamplesFromQueue(new SubCounter(nf, snssai), noOfSamples); - if(samples != null) { + if (samples != null) { sample = averageCalculator.findAverageOfSamples(samples); addToMeasurementList(sample); - } - else { + } else { log.info("Not enough samples present for nf {}", nf); return false; } - } + } log.info("snssai measurement list {}", snssaiMeasurementList); - ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); + Map> ricConfiguration; + Map sliceConfiguration; + if (isConfigDbEnabled) { + ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); + ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai); + sliceConfiguration = configDbService.fetchCurrentConfigurationOfSlice(snssai); + serviceDetails = configDbService.fetchServiceDetails(snssai); + } else { + ricToCellMapping = cpsInterface.fetchRICsOfSnssai(snssai); + ricConfiguration = cpsInterface.fetchCurrentConfigurationOfRIC(snssai); + sliceConfiguration = aaiInterface.fetchCurrentConfigurationOfSlice(snssai); + serviceDetails = aaiInterface.fetchServiceDetails(snssai); + } log.info("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping); - Map> ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai); - Map sliceConfiguration = configDbService.fetchCurrentConfigurationOfSlice(snssai); log.info("RIC Configuration {} and Slice Configuration {}", ricConfiguration, sliceConfiguration); pmsToCompute.forEach(pm -> { log.debug("processing for pm {}", pm); @@ -113,11 +134,11 @@ public class SnssaiSamplesProcessor { computeThroughput(sliceConfiguration, sum, pm); calculatePercentageChange(ricConfiguration, prbThroughputMapping.get(pm)); }); - updateConfiguration(); - if(ricToThroughputMapping.size() > 0) { + updateConfiguration(); + if (ricToThroughputMapping.size() > 0) { AdditionalProperties>> addProps = new AdditionalProperties<>(); addProps.setResourceConfig(ricToThroughputMapping); - policyService.sendOnsetMessageToPolicy(snssai, addProps, configDbService.fetchServiceDetails(snssai)); + policyService.sendOnsetMessageToPolicy(snssai, addProps, serviceDetails); } return true; } @@ -126,11 +147,11 @@ public class SnssaiSamplesProcessor { * process the measurement data of an S-NSSAI */ protected void updateConfiguration() { - Iterator>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry> entry = null; - while(it.hasNext()) { + Iterator>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry> entry = null; + while (it.hasNext()) { entry = it.next(); - if(entry.getValue().size() == 0) { + if (entry.getValue().size() == 0) { it.remove(); } } @@ -141,37 +162,36 @@ public class SnssaiSamplesProcessor { } /** - * Calculate the change in the configuration value and keep the configuration only if it is greater than a - * specific limit + * Calculate the change in the configuration value and keep the configuration + * only if it is greater than a specific limit */ protected void calculatePercentageChange(Map> ricConfiguration, String pm) { - Iterator>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry> entry = null; + Iterator>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry> entry = null; float existing = 0; float change = 0; - while(it.hasNext()) { + 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; + 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) -> { + ricToCellMapping.forEach((ric, cells) -> { int sumOfPrbs = 0; - for(String cell : cells) { + for (String cell : cells) { int index = MeasurementObject.findIndex(cell, snssaiMeasurementList); sumOfPrbs += snssaiMeasurementList.get(index).getPmData().get(pmName); } - if(ricToPrbsMapping.containsKey(ric)) { + if (ricToPrbsMapping.containsKey(ric)) { ricToPrbsMapping.get(ric).put(pmName, sumOfPrbs); - } - else { - Map pmToPrbMapping = new HashMap<>(); + } else { + Map pmToPrbMapping = new HashMap<>(); pmToPrbMapping.put(pmName, sumOfPrbs); ricToPrbsMapping.put(ric, pmToPrbMapping); } @@ -184,19 +204,19 @@ public class SnssaiSamplesProcessor { } protected void computeThroughput(Map sliceConfiguration, int sum, String pm) { - Iterator>> it = ricToPrbsMapping.entrySet().iterator(); - Map.Entry> entry = null; + Iterator>> it = ricToPrbsMapping.entrySet().iterator(); + Map.Entry> entry = null; Map throughtputMap = null; String ric = ""; int value = 0; - while(it.hasNext()) { + 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)) { + 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 { + } else { throughtputMap = new HashMap<>(); throughtputMap.put(prbThroughputMapping.get(pm), value); ricToThroughputMapping.put(ric, throughtputMap); diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/AppConfig.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/AppConfig.java new file mode 100644 index 00000000..29d7d105 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/AppConfig.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * ============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.utils; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.ByteArrayHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class AppConfig { + + + + /** + * Rest Template bean. + */ + @Bean + public static RestTemplate initRestTemplateForPdfAsByteArrayAndSelfSignedHttps() { + RestTemplate restTemplate = new RestTemplate(useApacheHttpClientWithSelfSignedSupport()); + restTemplate.getMessageConverters().add(generateByteArrayHttpMessageConverter()); + return restTemplate; + } + + private static HttpComponentsClientHttpRequestFactory useApacheHttpClientWithSelfSignedSupport() { + CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) + .build(); + HttpComponentsClientHttpRequestFactory useApacheHttpClient = new HttpComponentsClientHttpRequestFactory(); + useApacheHttpClient.setHttpClient(httpClient); + return useApacheHttpClient; + } + + private static ByteArrayHttpMessageConverter generateByteArrayHttpMessageConverter() { + ByteArrayHttpMessageConverter byteArrayHttpMessageConverter = new ByteArrayHttpMessageConverter(); + + List supportedApplicationTypes = new ArrayList<>(); + supportedApplicationTypes.add(new MediaType("application", "pdf")); + byteArrayHttpMessageConverter.setSupportedMediaTypes(supportedApplicationTypes); + return byteArrayHttpMessageConverter; + } +} -- cgit 1.2.3-korg