diff options
author | 2021-02-22 12:55:18 +0000 | |
---|---|---|
committer | 2021-02-22 12:55:18 +0000 | |
commit | 766e23f1dd95700ff1a1d9e89d8a3cf8d147036c (patch) | |
tree | 9cb6eaca95855b89eeca4f2be73a4282c688c65a /components/slice-analysis-ms/src/main/java | |
parent | 3d80f7dc08b7785f96ade594576f7d3fcffd8f88 (diff) |
Add AAI updates1.0.4-slice-analysis-ms
Issue-ID: DCAEGEN2-2623
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: I0f724981c5b19d033ec1cb79c9d4d2b5120125b7
Diffstat (limited to 'components/slice-analysis-ms/src/main/java')
13 files changed, 904 insertions, 256 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/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<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/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<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/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<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/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<String, Map<String, Object>> fetchCurrentConfigurationOfRIC(String snssai) { + return null; + } + + /** + * Fetches all the network functions of an S-NSSAI from CPS + */ + public List<String> fetchNetworkFunctionsOfSnssai(String snssai) { + return null; + } + + /** + * Fetches the RICS of an S-NSSAI from CPS + */ + public Map<String, List<String>> 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<String, Map<String,Object>> fetchCurrentConfigurationOfRIC(String snssai); public Map<String ,String> 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<String> 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<String, Object> getStreamsSubscribes() { - return streamsSubscribes; - } + public Map<String, Object> getStreamsSubscribes() { + return streamsSubscribes; + } - public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { - this.streamsSubscribes = streamsSubscribes; - } + public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { + this.streamsSubscribes = streamsSubscribes; + } - public Map<String, Object> getStreamsPublishes() { - return streamsPublishes; - } + public Map<String, Object> getStreamsPublishes() { + return streamsPublishes; + } - public void setStreamsPublishes(Map<String, Object> streamsPublishes) { - this.streamsPublishes = streamsPublishes; - } + public void setStreamsPublishes(Map<String, Object> 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<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 + "]"; + } - 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 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<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(); - - 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<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); + } } + 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 <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); + } + + 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); + 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 <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 CPS + */ + + 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/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 <T> ResponseEntity<T> sendGetRequest(HttpHeaders headers, String requestUrl, ParameterizedTypeReference<T> responseType) { + public <T> ResponseEntity<T> sendGetRequest(HttpHeaders headers, String requestUrl, + ParameterizedTypeReference<T> responseType) { HttpEntity<Void> 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<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>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<String, List<String>> ricToCellMapping = null; + Map<String, String> serviceDetails = null; String snssai = mlOutputMsg.getSnssai(); List<CUModel> cuData = mlOutputMsg.getData(); - Map<String, List<String>> 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<MLOutputModel> 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<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 List<String> pmsToCompute; + private Map<String, String> 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<String> networkFunctions) { + 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) { + 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<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); + sliceConfiguration = aaiInterface.fetchCurrentConfigurationOfSlice(snssai); + serviceDetails = aaiInterface.fetchServiceDetails(snssai); + } log.info("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping); - Map<String, Map<String, Object>> ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai); - Map<String, Integer> 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<Map<String, Map<String, Integer>>> 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<Map.Entry<String, Map<String,Integer>>> it = ricToThroughputMapping.entrySet().iterator(); - Map.Entry<String, Map<String,Integer>> entry = null; - while(it.hasNext()) { + 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) { + 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<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; + 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()) { + 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<String, Integer> pmToPrbMapping = new HashMap<>(); + } else { + Map<String, Integer> pmToPrbMapping = new HashMap<>(); pmToPrbMapping.put(pmName, sumOfPrbs); ricToPrbsMapping.put(ric, pmToPrbMapping); } @@ -184,19 +204,19 @@ public class SnssaiSamplesProcessor { } 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; + 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()) { + 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<MediaType> supportedApplicationTypes = new ArrayList<>(); + supportedApplicationTypes.add(new MediaType("application", "pdf")); + byteArrayHttpMessageConverter.setSupportedMediaTypes(supportedApplicationTypes); + return byteArrayHttpMessageConverter; + } +} |