diff options
Diffstat (limited to 'components/slice-analysis-ms')
84 files changed, 5148 insertions, 353 deletions
diff --git a/components/slice-analysis-ms/.checkstyle b/components/slice-analysis-ms/.checkstyle index 97b553d8..93d1ba04 100644 --- a/components/slice-analysis-ms/.checkstyle +++ b/components/slice-analysis-ms/.checkstyle @@ -1,21 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> <fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false"> - <local-check-config name="maven-checkstyle-plugin onap-license" location="jar:file:/home/reshma/.m2/repository/org/onap/oparent/checkstyle/2.0.0/checkstyle-2.0.0.jar!/onap-checkstyle/check-license.xml" type="remote" description="maven-checkstyle-plugin configuration onap-license"> - <property name="checkstyle.header.file" value="/home/reshma/eclipse-workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/slice-analysis-ms/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-onap-license.txt"/> + <local-check-config name="maven-checkstyle-plugin onap-license" location="jar:file:/C:/Users/hari/.m2/repository/org/onap/oparent/checkstyle/2.0.0/checkstyle-2.0.0.jar!/onap-checkstyle/check-license.xml" type="remote" description="maven-checkstyle-plugin configuration onap-license"> <property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/> + <property name="checkstyle.header.file" value="C:\Users\hari\eclipseworkplace2\.metadata\.plugins\org.eclipse.core.resources\.projects\slice-analysis-ms\com.basistech.m2e.code.quality.checkstyleConfigurator\checkstyle-header-onap-license.txt"/> </local-check-config> - <local-check-config name="maven-checkstyle-plugin onap-java-style" location="jar:file:/home/reshma/.m2/repository/org/onap/oparent/checkstyle/2.0.0/checkstyle-2.0.0.jar!/onap-checkstyle/onap-java-style.xml" type="remote" description="maven-checkstyle-plugin configuration onap-java-style"> - <property name="checkstyle.header.file" value="/home/reshma/eclipse-workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/slice-analysis-ms/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-onap-java-style.txt"/> + <local-check-config name="maven-checkstyle-plugin onap-java-style" location="jar:file:/C:/Users/hari/.m2/repository/org/onap/oparent/checkstyle/2.0.0/checkstyle-2.0.0.jar!/onap-checkstyle/onap-java-style.xml" type="remote" description="maven-checkstyle-plugin configuration onap-java-style"> <property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/> + <property name="checkstyle.header.file" value="C:\Users\hari\eclipseworkplace2\.metadata\.plugins\org.eclipse.core.resources\.projects\slice-analysis-ms\com.basistech.m2e.code.quality.checkstyleConfigurator\checkstyle-header-onap-java-style.txt"/> </local-check-config> <fileset name="java-sources-onap-license" enabled="true" check-config-name="maven-checkstyle-plugin onap-license" local="true"> - <file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/> - <file-match-pattern match-pattern="^src/test/java/.*\/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/test/java/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/main/java/.*\.java" include-pattern="true"/> </fileset> <fileset name="java-sources-onap-java-style" enabled="true" check-config-name="maven-checkstyle-plugin onap-java-style" local="true"> - <file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/> - <file-match-pattern match-pattern="^src/test/java/.*\/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/test/java/.*\.java" include-pattern="true"/> + <file-match-pattern match-pattern="^src/main/java/.*\.java" include-pattern="true"/> <file-match-pattern match-pattern="^src/main/resources/.*\.properties" include-pattern="true"/> <file-match-pattern match-pattern="^src/test/resources/.*\.properties" include-pattern="true"/> </fileset> diff --git a/components/slice-analysis-ms/pom.xml b/components/slice-analysis-ms/pom.xml index f8eb7fa6..08028404 100644 --- a/components/slice-analysis-ms/pom.xml +++ b/components/slice-analysis-ms/pom.xml @@ -140,6 +140,12 @@ <version>2.11.0</version> </dependency> <dependency> + <groupId>net.javacrumbs.json-unit</groupId> + <artifactId>json-unit-assertj</artifactId> + <version>2.14.0</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.11.0</version> @@ -192,6 +198,11 @@ <version>2.21.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>com.openpojo</groupId> + <artifactId>openpojo</artifactId> + <version>0.8.10</version> + </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java index f522e008..f04e86d8 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/Application.java @@ -37,9 +37,9 @@ import java.util.Map; import javax.sql.DataSource; -import org.onap.slice.analysis.ms.beans.ConfigPolicy; -import org.onap.slice.analysis.ms.beans.Configuration; import org.onap.slice.analysis.ms.controller.ConfigFetchFromCbs; +import org.onap.slice.analysis.ms.models.ConfigPolicy; +import org.onap.slice.analysis.ms.models.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.jdbc.DataSourceBuilder; diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java new file mode 100644 index 00000000..925a196f --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/MainThread.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2019-2020 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; + +import javax.annotation.PostConstruct; + +import org.onap.slice.analysis.ms.dmaap.NewPmNotification; +import org.onap.slice.analysis.ms.service.ConsumerThread; +import org.onap.slice.analysis.ms.service.PmThread; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * This class starts the pm thread and consumer thread + */ +@Component +public class MainThread { + + private static Logger log = LoggerFactory.getLogger(MainThread.class); + + @Autowired + private NewPmNotification newPmNotification; + + + /** + * main thread initialization. + */ + @PostConstruct + public void init() { + log.debug("initializing main thread"); + Thread pmThread = new Thread(new PmThread(newPmNotification)); + pmThread.start(); + Thread consumerThread = new Thread(new ConsumerThread()); + consumerThread.start(); + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/Configuration.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/Configuration.java deleted file mode 100644 index c7072343..00000000 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/Configuration.java +++ /dev/null @@ -1,242 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2020 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.beans; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; - -import java.lang.reflect.Type; -import java.util.List; -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Model class for the application Configuration - */ -public class Configuration { - private static Logger log = LoggerFactory.getLogger(Configuration.class); - - private static Configuration instance = null; - private String pgHost; - private int pgPort; - private String pgUsername; - private String pgPassword; - private List<String> dmaapServers; - private String configDbService; - private String cg; - private String cid; - private int pollingInterval; - private int pollingTimeout; - private String aafUsername; - private String aafPassword; - private Map<String, Object> streamsSubscribes; - private Map<String, Object> streamsPublishes; - - /** - * Check if topic is secure. - */ - public boolean isSecured() { - return (aafUsername != null); - - } - - public String getAafUsername() { - return aafUsername; - } - - public void setAafUsername(String aafUsername) { - this.aafUsername = aafUsername; - } - - public String getAafPassword() { - return aafPassword; - } - - public void setAafPassword(String aafPassword) { - this.aafPassword = aafPassword; - } - - public Map<String, Object> getStreamsSubscribes() { - return streamsSubscribes; - } - - public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { - this.streamsSubscribes = streamsSubscribes; - } - - public Map<String, Object> getStreamsPublishes() { - return streamsPublishes; - } - - public void setStreamsPublishes(Map<String, Object> streamsPublishes) { - this.streamsPublishes = streamsPublishes; - } - - protected Configuration() { - - } - - /** - * Get instance of class. - */ - public static Configuration getInstance() { - if (instance == null) { - instance = new Configuration(); - } - return instance; - } - - public String getCg() { - return cg; - } - - public void setCg(String cg) { - this.cg = cg; - } - - public String getCid() { - return cid; - } - - public void setCid(String cid) { - this.cid = cid; - } - - public int getPollingInterval() { - return pollingInterval; - } - - public void setPollingInterval(int pollingInterval) { - this.pollingInterval = pollingInterval; - } - - public int getPollingTimeout() { - return pollingTimeout; - } - - public void setPollingTimeout(int pollingTimeout) { - this.pollingTimeout = pollingTimeout; - } - - public String getPgHost() { - return pgHost; - } - - public void setPgHost(String pgHost) { - this.pgHost = pgHost; - } - - public int getPgPort() { - return pgPort; - } - - public void setPgPort(int pgPort) { - this.pgPort = pgPort; - } - - public String getPgUsername() { - return pgUsername; - } - - public void setPgUsername(String pgUsername) { - this.pgUsername = pgUsername; - } - - public String getPgPassword() { - return pgPassword; - } - - public void setPgPassword(String pgPassword) { - this.pgPassword = pgPassword; - } - - public List<String> getDmaapServers() { - return dmaapServers; - } - - public void setDmaapServers(List<String> dmaapServers) { - this.dmaapServers = dmaapServers; - } - - public String getConfigDbService() { - return configDbService; - } - - public void setConfigDbService(String configDbService) { - this.configDbService = configDbService; - } - - - - @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 + "]"; - } - - /** - * 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.pollingInterval").getAsInt(); - - log.info("configuration from CBS {}", this); - - } - - - -} 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 new file mode 100644 index 00000000..488aca81 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceService.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 javax.annotation.PostConstruct; + +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.models.configdb.CellsModel; +import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel; +import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +/** + * + * Service for config db interfaces + * + */ +@Service +public class ConfigDbInterfaceService implements IConfigDbService { + + private ConfigDbRestClient restclient; + private String configDbBaseUrl = Configuration.getInstance().getConfigDbService(); + + @PostConstruct + public void init() { + this.restclient = BeanUtil.getBean(ConfigDbRestClient.class); + } + + /** + * Fetches the current configuration of an S-NSSAI from config DB + */ + public Map<String, Integer> fetchCurrentConfigurationOfSlice(String snssai){ + Map<String,Integer> responseMap = null; + String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/profile-config/"+snssai; + + ResponseEntity<Map<String,Integer>> response=restclient.sendGetRequest(reqUrl,new ParameterizedTypeReference<Map<String, Integer>>() { + }); + responseMap=response.getBody(); + return responseMap; + } + + /** + * Fetches the current configuration of RIC from config DB + */ + public Map<String,Map<String,Integer>> fetchCurrentConfigurationOfRIC(String snssai){ + String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/slice-config/"+snssai; + ResponseEntity<Map<String,Map<String,Integer>>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,Map<String,Integer>>>() { + }); + return response.getBody(); + } + + /** + * Fetches all the network functions of an S-NSSAI from config DB + */ + public List<String> fetchNetworkFunctionsOfSnssai(String snssai){ + List<String> responseList=new ArrayList<>(); + String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/du-list/"+snssai; + ResponseEntity<List<NetworkFunctionModel>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<List<NetworkFunctionModel>>() { + }); + for(NetworkFunctionModel networkFn:response.getBody()) { + responseList.add(networkFn.getgNBDUId()); + } + return responseList; + } + + /** + * Fetches the RICS of an S-NSSAI from config DB + */ + public Map<String, List<String>> fetchRICsOfSnssai(String snssai){ + + Map<String,List<String>> responseMap=new HashMap<>(); + + String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/du-cell-list/"+snssai; + + ResponseEntity<Map<String,List<CellsModel>>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,List<CellsModel>>>() { + }); + + + for (Map.Entry<String, List<CellsModel>> entry : response.getBody().entrySet()) { + List<String> cellslist=new ArrayList<>(); + for(CellsModel cellmodel:entry.getValue()) { + + cellslist.add(cellmodel.getCellLocalId()); + } + responseMap.put(entry.getKey(), cellslist); + } + + return responseMap; + } + + /** + * Fetches the details of a service + */ + public Map<String,String> fetchServiceDetails(String snssai){ + String reqUrl=configDbBaseUrl+"/api/sdnc-config-db/v4/subscriber-details/"+snssai; + ResponseEntity<Map<String,String>> response=restclient.sendGetRequest(reqUrl, new ParameterizedTypeReference<Map<String,String>>() { + }); + return response.getBody(); + } + +} 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 new file mode 100644 index 00000000..3c8a9f8a --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/configdb/IConfigDbService.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 config db service + * + */ +public interface IConfigDbService { + + public Map<String, List<String>> fetchRICsOfSnssai(String snssai); + public List<String> fetchNetworkFunctionsOfSnssai(String snssai); + public Map<String, Integer> fetchCurrentConfigurationOfSlice(String snssai); + public Map<String, Map<String,Integer>> 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/controller/ConfigFetchFromCbs.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java index e8e4e11b..ea148f25 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/controller/ConfigFetchFromCbs.java @@ -34,8 +34,8 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; -import org.onap.slice.analysis.ms.beans.ConfigPolicy; -import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.models.ConfigPolicy; +import org.onap.slice.analysis.ms.models.Configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java index 6e0ea401..08a89541 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/DmaapClient.java @@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.PostConstruct; -import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.utils.DmaapUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,23 +69,29 @@ public class DmaapClient { @SuppressWarnings("unchecked") public synchronized void startClient() { - Map<String, Object> streamSubscribes = Configuration.getInstance().getStreamsSubscribes(); + Map<String, Object> streamSubscribes = configuration.getStreamsSubscribes(); String pmTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes .get("performance_management_topic")).get("dmaap_info")).get("topic_url"); String[] pmTopicSplit = pmTopicUrl.split("\\/"); String pmTopic = pmTopicSplit[pmTopicSplit.length - 1]; log.debug("pm topic : {}", pmTopic); + String policyResponseTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes .get("dcae_cl_response_topic")).get("dmaap_info")).get("topic_url"); String[] policyResponseTopicUrlSplit = policyResponseTopicUrl.split("\\/"); String policyResponseTopic = policyResponseTopicUrlSplit[policyResponseTopicUrlSplit.length - 1]; log.debug("policyResponse Topic : {}", policyResponseTopic); - CambriaConsumer pmNotifCambriaConsumer = null; - CambriaConsumer policyResponseCambriaConsumer = null; - - pmNotifCambriaConsumer = dmaapUtils.buildConsumer(configuration, pmTopic); - policyResponseCambriaConsumer = dmaapUtils.buildConsumer(configuration, policyResponseTopic); + + String intelligentSlicingTopicUrl = ((Map<String, String>) ((Map<String, Object>) streamSubscribes + .get("intelligent_slicing_topic")).get("dmaap_info")).get("topic_url"); + String[] intelligentSlicingTopicSplit = intelligentSlicingTopicUrl.split("\\/"); + String intelligentSlicingTopic = intelligentSlicingTopicSplit[intelligentSlicingTopicSplit.length - 1]; + log.debug("intelligent slicing topic : {}", pmTopic); + + CambriaConsumer pmNotifCambriaConsumer = dmaapUtils.buildConsumer(configuration, pmTopic); + CambriaConsumer policyResponseCambriaConsumer = dmaapUtils.buildConsumer(configuration, policyResponseTopic); + CambriaConsumer intelligentSlicingCambriaConsumer = dmaapUtils.buildConsumer(configuration, intelligentSlicingTopic); ScheduledExecutorService executorPool; @@ -97,16 +103,21 @@ public class DmaapClient { executorPool.scheduleAtFixedRate(pmNotificationConsumer, 0, configuration.getPollingInterval(), TimeUnit.SECONDS); - // create notification consumers for Policy - NotificationConsumer policyNotificationConsumer = new NotificationConsumer(policyResponseCambriaConsumer, - new PolicyNotificationCallback()); - // start policy notification consumer threads - executorPool = Executors.newScheduledThreadPool(10); - executorPool.scheduleAtFixedRate(policyNotificationConsumer, 0, configuration.getPollingInterval(), - TimeUnit.SECONDS); - - - + // create notification consumers for Policy + NotificationConsumer policyNotificationConsumer = new NotificationConsumer(policyResponseCambriaConsumer, + new PolicyNotificationCallback()); + // start policy notification consumer threads + executorPool = Executors.newScheduledThreadPool(10); + executorPool.scheduleAtFixedRate(policyNotificationConsumer, 0, configuration.getPollingInterval(), + TimeUnit.SECONDS); + + // create notification consumers for ML MS + NotificationConsumer intelligentSlicingConsumer = new NotificationConsumer(intelligentSlicingCambriaConsumer, + new IntelligentSlicingCallback()); + // start intelligent Slicing notification consumer threads + executorPool = Executors.newScheduledThreadPool(10); + executorPool.scheduleAtFixedRate(intelligentSlicingConsumer, 0, configuration.getPollingInterval(), + TimeUnit.SECONDS); } } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/IntelligentSlicingCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/IntelligentSlicingCallback.java new file mode 100644 index 00000000..dd6760ba --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/IntelligentSlicingCallback.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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.dmaap; + +import java.io.IOException; + +import org.onap.slice.analysis.ms.models.MLOutputModel; +import org.onap.slice.analysis.ms.service.MLMessageProcessor; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.slf4j.Logger; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Handles Notification on dmaap for ML ms events + */ +public class IntelligentSlicingCallback implements NotificationCallback { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(IntelligentSlicingCallback.class); + private MLMessageProcessor mlMsMessageProcessor; + + public IntelligentSlicingCallback() { + mlMsMessageProcessor = BeanUtil.getBean(MLMessageProcessor.class); + } + + /** + * Trigger on Notification from ML ms + */ + @Override + public void activateCallBack(String msg) { + handlePolicyNotification(msg); + } + + /** + * Parse and take actions on reception of Notification from ML ms + * @param msg + */ + private void handlePolicyNotification(String msg) { + log.info("Message received from ML ms: {}" ,msg); + ObjectMapper obj = new ObjectMapper(); + MLOutputModel output = null; + try { + output = obj.readValue(msg, new TypeReference<MLOutputModel>(){}); + mlMsMessageProcessor.processMLMsg(output); + } + catch (IOException e) { + log.error("Error converting ML msg to object, {}",e.getMessage()); + } + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java index 5c1f496b..66c3f706 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NewPmNotification.java @@ -32,7 +32,7 @@ import org.springframework.stereotype.Component; @Component public class NewPmNotification { - private Boolean newNotif; + private boolean newNotif; /** * Initialize new pm Notification flag @@ -42,15 +42,15 @@ public class NewPmNotification { newNotif = false; } - public Boolean getNewNotif() { + public boolean getNewNotif() { return newNotif; } - public void setNewNotif(Boolean newNotif) { + public void setNewNotif(boolean newNotif) { this.newNotif = newNotif; } - public NewPmNotification(Boolean newNotif) { + public NewPmNotification(boolean newNotif) { super(); this.newNotif = newNotif; } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java index 427b4048..ce1ebd6f 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/NotificationCallback.java @@ -21,7 +21,7 @@ package org.onap.slice.analysis.ms.dmaap; -public abstract class NotificationCallback { +public interface NotificationCallback { public abstract void activateCallBack(String msg); diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java index 17e50aca..963165d2 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PmNotificationCallback.java @@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory; /** * Handles Notification on dmaap for Performance events */ -public class PmNotificationCallback extends NotificationCallback { +public class PmNotificationCallback implements NotificationCallback { private static Logger log = LoggerFactory.getLogger(PmNotificationCallback.class); diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java index 81ca9ef1..06604040 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClient.java @@ -25,7 +25,7 @@ import com.att.nsa.cambria.client.CambriaBatchingPublisher; import java.io.IOException; import java.util.Map; -import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.utils.DmaapUtils; /** diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java index 57aadd18..146b60a9 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/PolicyNotificationCallback.java @@ -26,7 +26,7 @@ import org.slf4j.Logger; /** * Handles Notification on dmaap for Policy events */ -public class PolicyNotificationCallback extends NotificationCallback { +public class PolicyNotificationCallback implements NotificationCallback { private static final Logger log = org.slf4j.LoggerFactory.getLogger(PolicyNotificationCallback.class); @@ -43,7 +43,7 @@ public class PolicyNotificationCallback extends NotificationCallback { * @param msg */ private void handlePolicyNotification(String msg) { - log.info("Message received from policy: " +msg); - //TBD - actions to perform on reception of notification from policy + log.info("Message received from policy: " +msg); + //TBD - actions to perform on reception of notification from policy } } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/CUModel.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/CUModel.java new file mode 100644 index 00000000..6473ab23 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/CUModel.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +import java.util.List; + +/** + * Model class for CU model + */ +public class CUModel { + + private String gNBCUName; + private String nearRTRICId; + private List<CellCUList> cellCUList; + + public String getgNBCUName() { + return gNBCUName; + } + + public void setgNBCUName(String gNBCUName) { + this.gNBCUName = gNBCUName; + } + + public String getNearRTRICId() { + return nearRTRICId; + } + + public void setNearRTRICId(String nearRTRICId) { + this.nearRTRICId = nearRTRICId; + } + + public List<CellCUList> getCellCUList() { + return cellCUList; + } + + public void setCellCUList(List<CellCUList> cellCUList) { + this.cellCUList = cellCUList; + } + + @Override + public String toString() { + return "CUModel [gNBCUName=" + gNBCUName + ", nearRTRICId=" + nearRTRICId + ", cellCUList=" + cellCUList + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cellCUList == null) ? 0 : cellCUList.hashCode()); + result = prime * result + ((gNBCUName == null) ? 0 : gNBCUName.hashCode()); + result = prime * result + ((nearRTRICId == null) ? 0 : nearRTRICId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CUModel other = (CUModel) obj; + if (cellCUList == null) { + if (other.cellCUList != null) + return false; + } else if (!cellCUList.equals(other.cellCUList)) + return false; + if (gNBCUName == null) { + if (other.gNBCUName != null) + return false; + } else if (!gNBCUName.equals(other.gNBCUName)) + return false; + if (nearRTRICId == null) { + if (other.nearRTRICId != null) + return false; + } else if (!nearRTRICId.equals(other.nearRTRICId)) + return false; + return true; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/CellCUList.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/CellCUList.java new file mode 100644 index 00000000..cd566778 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/CellCUList.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +/** + * Model class for cell information + */ +public class CellCUList { + + private Integer cellLocalId; + private ConfigData configData; + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cellLocalId == null) ? 0 : cellLocalId.hashCode()); + result = prime * result + ((configData == null) ? 0 : configData.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CellCUList other = (CellCUList) obj; + if (cellLocalId == null) { + if (other.cellLocalId != null) + return false; + } else if (!cellLocalId.equals(other.cellLocalId)) + return false; + if (configData == null) { + if (other.configData != null) + return false; + } else if (!configData.equals(other.configData)) + return false; + return true; + } + + public Integer getCellLocalId() { + return cellLocalId; + } + + public void setCellLocalId(Integer cellLocalId) { + this.cellLocalId = cellLocalId; + } + + public ConfigData getConfigData() { + return configData; + } + + public void setConfigData(ConfigData configData) { + this.configData = configData; + } + + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/ConfigData.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/ConfigData.java new file mode 100644 index 00000000..f8711154 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/ConfigData.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +/** + * Model class for the config data + */ +public class ConfigData { + + private String maxNumberofConns; + private String predictedMaxNumberofConns; + private String lastUpdatedTS; + + public String getMaxNumberofConns() { + return maxNumberofConns; + } + + public void setMaxNumberofConns(String maxNumberofConns) { + this.maxNumberofConns = maxNumberofConns; + } + + public String getPredictedMaxNumberofConns() { + return predictedMaxNumberofConns; + } + + public void setPredictedMaxNumberofConns(String predictedMaxNumberofConns) { + this.predictedMaxNumberofConns = predictedMaxNumberofConns; + } + + public String getLastUpdatedTS() { + return lastUpdatedTS; + } + + public void setLastUpdatedTS(String lastUpdatedTS) { + this.lastUpdatedTS = lastUpdatedTS; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((lastUpdatedTS == null) ? 0 : lastUpdatedTS.hashCode()); + result = prime * result + ((maxNumberofConns == null) ? 0 : maxNumberofConns.hashCode()); + result = prime * result + ((predictedMaxNumberofConns == null) ? 0 : predictedMaxNumberofConns.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ConfigData other = (ConfigData) obj; + if (lastUpdatedTS == null) { + if (other.lastUpdatedTS != null) + return false; + } else if (!lastUpdatedTS.equals(other.lastUpdatedTS)) + return false; + if (maxNumberofConns == null) { + if (other.maxNumberofConns != null) + return false; + } else if (!maxNumberofConns.equals(other.maxNumberofConns)) + return false; + if (predictedMaxNumberofConns == null) { + if (other.predictedMaxNumberofConns != null) + return false; + } else if (!predictedMaxNumberofConns.equals(other.predictedMaxNumberofConns)) + return false; + return true; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/ConfigPolicy.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/ConfigPolicy.java index d4cd53b8..6f2b4ec6 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/beans/ConfigPolicy.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/ConfigPolicy.java @@ -19,7 +19,7 @@ * *******************************************************************************/ -package org.onap.slice.analysis.ms.beans; +package org.onap.slice.analysis.ms.models; import java.util.Map; @@ -31,42 +31,42 @@ import java.util.Map; public class ConfigPolicy { - private static ConfigPolicy instance = null; - private Map<String, Object> config; + private static ConfigPolicy instance = null; + private Map<String, Object> config; - protected ConfigPolicy() { + protected ConfigPolicy() { - } + } - /** - * Get instance of class. - */ - public static ConfigPolicy getInstance() { - if (instance == null) { - instance = new ConfigPolicy(); - } - return instance; - } + /** + * Get instance of class. + */ + public static ConfigPolicy getInstance() { + if (instance == null) { + instance = new ConfigPolicy(); + } + return instance; + } - /** - * Get config param of ConfigPolicy - */ - public Map<String, Object> getConfig() { - return config; - } + /** + * Get config param of ConfigPolicy + */ + public Map<String, Object> getConfig() { + return config; + } - /** - * set config param of ConfigPolicy - */ - public void setConfig(Map<String, Object> config) { - this.config = config; - } + /** + * set config param of ConfigPolicy + */ + public void setConfig(Map<String, Object> config) { + this.config = config; + } - /** - * Return ConfigPolicy instance as String - */ - @Override - public String toString() { - return "ConfigPolicy [config=" + config + "]"; - } + /** + * Return ConfigPolicy instance as String + */ + @Override + public String toString() { + return "ConfigPolicy [config=" + config + "]"; + } } 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 new file mode 100644 index 00000000..25a80463 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/Configuration.java @@ -0,0 +1,265 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +/** + * Model class for the application Configuration + */ +public class Configuration { + private static Logger log = LoggerFactory.getLogger(Configuration.class); + + private static Configuration instance = null; + private String pgHost; + private int pgPort; + private String pgUsername; + private String pgPassword; + private List<String> dmaapServers; + private String configDbService; + private String cg; + private String cid; + private int pollingInterval; + private int pollingTimeout; + private String aafUsername; + private String aafPassword; + private Map<String, Object> streamsSubscribes; + private Map<String, Object> streamsPublishes; + private int samples; + private int minPercentageChange; + private long initialDelaySeconds; + /** + * Check if topic is secure. + */ + public boolean isSecured() { + return (aafUsername != null); + + } + + public String getAafUsername() { + return aafUsername; + } + + public void setAafUsername(String aafUsername) { + this.aafUsername = aafUsername; + } + + public String getAafPassword() { + return aafPassword; + } + + public void setAafPassword(String aafPassword) { + this.aafPassword = aafPassword; + } + + public Map<String, Object> getStreamsSubscribes() { + return streamsSubscribes; + } + + public void setStreamsSubscribes(Map<String, Object> streamsSubscribes) { + this.streamsSubscribes = streamsSubscribes; + } + + public Map<String, Object> getStreamsPublishes() { + return streamsPublishes; + } + + public void setStreamsPublishes(Map<String, Object> streamsPublishes) { + this.streamsPublishes = streamsPublishes; + } + + protected Configuration() { + + } + + /** + * Get instance of class. + */ + public static Configuration getInstance() { + if (instance == null) { + instance = new Configuration(); + } + return instance; + } + + public String getCg() { + return cg; + } + + public void setCg(String cg) { + this.cg = cg; + } + + public String getCid() { + return cid; + } + + public void setCid(String cid) { + this.cid = cid; + } + + public int getPollingInterval() { + return pollingInterval; + } + + public void setPollingInterval(int pollingInterval) { + this.pollingInterval = pollingInterval; + } + + public int getPollingTimeout() { + return pollingTimeout; + } + + public void setPollingTimeout(int pollingTimeout) { + this.pollingTimeout = pollingTimeout; + } + + public String getPgHost() { + return pgHost; + } + + public void setPgHost(String pgHost) { + this.pgHost = pgHost; + } + + public int getPgPort() { + return pgPort; + } + + public void setPgPort(int pgPort) { + this.pgPort = pgPort; + } + + public String getPgUsername() { + return pgUsername; + } + + public void setPgUsername(String pgUsername) { + this.pgUsername = pgUsername; + } + + public String getPgPassword() { + return pgPassword; + } + + public void setPgPassword(String pgPassword) { + this.pgPassword = pgPassword; + } + + public List<String> getDmaapServers() { + return dmaapServers; + } + + public void setDmaapServers(List<String> dmaapServers) { + this.dmaapServers = dmaapServers; + } + + public String getConfigDbService() { + return configDbService; + } + + public void setConfigDbService(String configDbService) { + this.configDbService = configDbService; + } + + public 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(); + + log.info("configuration from CBS {}", this); + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MLOutputModel.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MLOutputModel.java new file mode 100644 index 00000000..7533d215 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MLOutputModel.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +import java.util.List; + +/** + * Model class for ML output object + */ +public class MLOutputModel { + private String snssai; + private List<CUModel> data; + public String getSnssai() { + return snssai; + } + public void setSnssai(String snssai) { + this.snssai = snssai; + } + public List<CUModel> getData() { + return data; + } + public void setData(List<CUModel> data) { + this.data = data; + } + + @Override + public String toString() { + return "MLOutputModel [snssai=" + snssai + ", data=" + data + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((data == null) ? 0 : data.hashCode()); + result = prime * result + ((snssai == null) ? 0 : snssai.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MLOutputModel other = (MLOutputModel) obj; + if (data == null) { + if (other.data != null) + return false; + } else if (!data.equals(other.data)) + return false; + if (snssai == null) { + if (other.snssai != null) + return false; + } else if (!snssai.equals(other.snssai)) + return false; + return true; + } + + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MeasurementObject.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MeasurementObject.java new file mode 100644 index 00000000..047c9856 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/MeasurementObject.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + + +package org.onap.slice.analysis.ms.models; + +import java.util.Map; + +/** + * Model class for the Measurement Object + */ +public class MeasurementObject { + private String measurementObjectId; + private Map<String, Integer> pmData; + + public String getMeasurementObjectId() { + return measurementObjectId; + } + + public void setMeasurementObjectId(String measurementObjectId) { + this.measurementObjectId = measurementObjectId; + } + + public Map<String, Integer> getPmData() { + return pmData; + } + + public void setPmData(Map<String, Integer> pmData) { + this.pmData = pmData; + } + + public MeasurementObject(String measurementObjectId, Map<String, Integer> pmData) { + super(); + this.measurementObjectId = measurementObjectId; + this.pmData = pmData; + } + + public MeasurementObject(String measurementObjectId) { + super(); + this.measurementObjectId = measurementObjectId; + } + + public MeasurementObject() { + + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((measurementObjectId == null) ? 0 : measurementObjectId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MeasurementObject other = (MeasurementObject) obj; + if (measurementObjectId == null) { + if (other.measurementObjectId != null) + return false; + } else if (!measurementObjectId.equals(other.measurementObjectId)) + return false; + return true; + } + + @Override + public String toString() { + return "MeasurementObject [measurementObjectId=" + measurementObjectId + ", pmData=" + pmData + "]"; + } + + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SubCounter.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SubCounter.java new file mode 100644 index 00000000..2990d365 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/SubCounter.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + + +package org.onap.slice.analysis.ms.models; + +/** + * Model class for the SubCounter Object which servers as key for PM data Queue + */ +public final class SubCounter { + final String networkFunction; + final String measuredObject; + + public SubCounter(String networkFunction, String measuredObject) { + super(); + this.networkFunction = networkFunction; + this.measuredObject = measuredObject; + } + + public String getNetworkFunction() { + return networkFunction; + } + + public String getMeasuredObject() { + return measuredObject; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((networkFunction == null) ? 0 : networkFunction.hashCode()); + result = prime * result + ((measuredObject == null) ? 0 : measuredObject.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SubCounter other = (SubCounter) obj; + if (networkFunction == null) { + if (other.networkFunction != null) + return false; + } else if (!networkFunction.equals(other.networkFunction)) + return false; + if (measuredObject == null) { + if (other.measuredObject != null) + return false; + } else if (!measuredObject.equals(other.measuredObject)) + return false; + return true; + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/configdb/CellsModel.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/configdb/CellsModel.java new file mode 100644 index 00000000..e024bf7c --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/configdb/CellsModel.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.models.configdb; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +/** + * Model class for the CellsModel Object + */ + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CellsModel { + + private String cellLocalId; + + + public String getCellLocalId() { + return cellLocalId; + } + + public void setCellLocalId(String cellLocalId) { + this.cellLocalId = cellLocalId; + } + + @Override + public String toString() { + return "CellsModel [cellLocalId=" + cellLocalId + "]"; + } + + + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/configdb/NetworkFunctionModel.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/configdb/NetworkFunctionModel.java new file mode 100644 index 00000000..46291d51 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/configdb/NetworkFunctionModel.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.models.configdb; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +/** + * Model class for the NetworkFunction Object + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class NetworkFunctionModel { + + private String gNBDUId; + + + public String getgNBDUId() { + return gNBDUId; + } + + public void setgNBDUId(String gNBDUId) { + this.gNBDUId = gNBDUId; + } + + @Override + public String toString() { + return "NetworkFunctionModel [gNBDUId=" + gNBDUId + "]"; + } + + + + + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/CommonEventHeader.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/CommonEventHeader.java new file mode 100644 index 00000000..08c2b983 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/CommonEventHeader.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +/** + * Model class for the CommonEventHeader Object + */ +public class CommonEventHeader { + + private String domain; + private String eventId; + private long sequence; + private String eventName; + private String sourceName; + private String reportingEntityName; + private String priority; + private long startEpochMicrosec; + private long lastEpochMicrosec; + private String version; + private String vesEventListenerVersion; + private String timeZoneOffset; + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public String getEventId() { + return eventId; + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public long getSequence() { + return sequence; + } + + public void setSequence(long sequence) { + this.sequence = sequence; + } + + public String getEventName() { + return eventName; + } + + public void setEventName(String eventName) { + this.eventName = eventName; + } + + public String getSourceName() { + return sourceName; + } + + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + + public String getReportingEntityName() { + return reportingEntityName; + } + + public void setReportingEntityName(String reportingEntityName) { + this.reportingEntityName = reportingEntityName; + } + + public String getPriority() { + return priority; + } + + public void setPriority(String priority) { + this.priority = priority; + } + + public long getStartEpochMicrosec() { + return startEpochMicrosec; + } + + public void setStartEpochMicrosec(long startEpochMicrosec) { + this.startEpochMicrosec = startEpochMicrosec; + } + + public long getLastEpochMicrosec() { + return lastEpochMicrosec; + } + + public void setLastEpochMicrosec(long lastEpochMicrosec) { + this.lastEpochMicrosec = lastEpochMicrosec; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getVesEventListenerVersion() { + return vesEventListenerVersion; + } + + public void setVesEventListenerVersion(String vesEventListenerVersion) { + this.vesEventListenerVersion = vesEventListenerVersion; + } + + public String getTimeZoneOffset() { + return timeZoneOffset; + } + + public void setTimeZoneOffset(String timeZoneOffset) { + this.timeZoneOffset = timeZoneOffset; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/Event.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/Event.java new file mode 100644 index 00000000..4e41e261 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/Event.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +/** + * Model class for the Event Object + */ +public class Event { + + private CommonEventHeader commonEventHeader; + private Perf3gppFields perf3gppFields; + + public CommonEventHeader getCommonEventHeader() { + return commonEventHeader; + } + + public void setCommonEventHeader(CommonEventHeader commonEventHeader) { + this.commonEventHeader = commonEventHeader; + } + + public Perf3gppFields getPerf3gppFields() { + return perf3gppFields; + } + + public void setPerf3gppFields(Perf3gppFields perf3gppFields) { + this.perf3gppFields = perf3gppFields; + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasDataCollection.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasDataCollection.java new file mode 100644 index 00000000..f5e36c28 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasDataCollection.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +import java.util.List; + +/** + * Model class for the MeasDataCollection Object + */ +public class MeasDataCollection { + + private long granularityPeriod; + private String measuredEntityUserName; + private String measuredEntityDn; + private String measuredEntitySoftwareVersion; + private List<MeasInfoList> measInfoList; + + public long getGranularityPeriod() { + return granularityPeriod; + } + + public void setGranularityPeriod(long granularityPeriod) { + this.granularityPeriod = granularityPeriod; + } + + public String getMeasuredEntityUserName() { + return measuredEntityUserName; + } + + public void setMeasuredEntityUserName(String measuredEntityUserName) { + this.measuredEntityUserName = measuredEntityUserName; + } + + public String getMeasuredEntityDn() { + return measuredEntityDn; + } + + public void setMeasuredEntityDn(String measuredEntityDn) { + this.measuredEntityDn = measuredEntityDn; + } + + public String getMeasuredEntitySoftwareVersion() { + return measuredEntitySoftwareVersion; + } + + public void setMeasuredEntitySoftwareVersion(String measuredEntitySoftwareVersion) { + this.measuredEntitySoftwareVersion = measuredEntitySoftwareVersion; + } + + public List<MeasInfoList> getMeasInfoList() { + return measInfoList; + } + + public void setMeasInfoList(List<MeasInfoList> measInfoList) { + this.measInfoList = measInfoList; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasInfoId.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasInfoId.java new file mode 100644 index 00000000..5b8f6b31 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasInfoId.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +/** + * Model class for the MeasInfoId Object + */ +public class MeasInfoId { + + private String sMeasInfoId; + + public String getsMeasInfoId() { + return sMeasInfoId; + } + + public void setsMeasInfoId(String sMeasInfoId) { + this.sMeasInfoId = sMeasInfoId; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasInfoList.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasInfoList.java new file mode 100644 index 00000000..34283a7d --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasInfoList.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +import java.util.List; + +/** + * Model class for the MeasInfoList Object + */ +public class MeasInfoList { + + private MeasInfoId measInfoId; + private MeasTypes measTypes; + private List<MeasValuesList> measValuesList = null; + + public MeasInfoId getMeasInfoId() { + return measInfoId; + } + + public void setMeasInfoId(MeasInfoId measInfoId) { + this.measInfoId = measInfoId; + } + + public MeasTypes getMeasTypes() { + return measTypes; + } + + public void setMeasTypes(MeasTypes measTypes) { + this.measTypes = measTypes; + } + + public List<MeasValuesList> getMeasValuesList() { + return measValuesList; + } + + public void setMeasValuesList(List<MeasValuesList> measValuesList) { + this.measValuesList = measValuesList; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasResult.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasResult.java new file mode 100644 index 00000000..1e418001 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasResult.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +/** + * Model class for the MeasResult Object + */ +public class MeasResult { + + private int p; + private String sValue; + + public int getP() { + return p; + } + + public void setP(int p) { + this.p = p; + } + + public String getsValue() { + return sValue; + } + + public void setsValue(String sValue) { + this.sValue = sValue; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasTypes.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasTypes.java new file mode 100644 index 00000000..f441166d --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasTypes.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +import java.util.List; + +/** + * Model class for the MeasTypes Object + */ +public class MeasTypes { + + private List<String> sMeasTypesList; + + public List<String> getsMeasTypesList() { + return sMeasTypesList; + } + + public void setsMeasTypesList(List<String> sMeasTypesList) { + this.sMeasTypesList = sMeasTypesList; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasValuesList.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasValuesList.java new file mode 100644 index 00000000..38b7c23c --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/MeasValuesList.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +import java.util.List; + +/** + * Model class for the MeasValuesList Object + */ +public class MeasValuesList { + + private String measObjInstId; + private String suspectFlag; + private List<MeasResult> measResults = null; + + public String getMeasObjInstId() { + return measObjInstId; + } + + public void setMeasObjInstId(String measObjInstId) { + this.measObjInstId = measObjInstId; + } + + public String getSuspectFlag() { + return suspectFlag; + } + + public void setSuspectFlag(String suspectFlag) { + this.suspectFlag = suspectFlag; + } + + public List<MeasResult> getMeasResults() { + return measResults; + } + + public void setMeasResults(List<MeasResult> measResults) { + this.measResults = measResults; + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/Perf3gppFields.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/Perf3gppFields.java new file mode 100644 index 00000000..dfe9cbca --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/Perf3gppFields.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +/** + * Model class for the Perf3gppFields Object + */ +public class Perf3gppFields { + + private String perf3gppFieldsVersion; + private MeasDataCollection measDataCollection; + + public String getPerf3gppFieldsVersion() { + return perf3gppFieldsVersion; + } + + public void setPerf3gppFieldsVersion(String perf3gppFieldsVersion) { + this.perf3gppFieldsVersion = perf3gppFieldsVersion; + } + + public MeasDataCollection getMeasDataCollection() { + return measDataCollection; + } + + public void setMeasDataCollection(MeasDataCollection measDataCollection) { + this.measDataCollection = measDataCollection; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/PmNotification.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/PmNotification.java new file mode 100644 index 00000000..a2dc49e8 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/pmnotification/PmNotification.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +/** + * Model class for the PmNotification Object + */ +public class PmNotification { + + Event event; + + public Event getEvent() { + return event; + } + + public void setEvent(Event event) { + this.event = event; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/AAI.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/AAI.java new file mode 100644 index 00000000..73d94d75 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/AAI.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.policy; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for the AAI Object + */ +public class AAI { + @JsonProperty("vserver.is-closed-loop-disabled") + private String vserverIsClosedLoopDisabled; + @JsonProperty("vserver.prov-status") + private String vserverProvStatus; + @JsonProperty("vserver.vserver-name") + private String vserverVserverName; + + public String getVserverIsClosedLoopDisabled() { + return vserverIsClosedLoopDisabled; + } + + public void setVserverIsClosedLoopDisabled(String vserverIsClosedLoopDisabled) { + this.vserverIsClosedLoopDisabled = vserverIsClosedLoopDisabled; + } + + public String getVserverProvStatus() { + return vserverProvStatus; + } + + public void setVserverProvStatus(String vserverProvStatus) { + this.vserverProvStatus = vserverProvStatus; + } + + public String getVserverVserverName() { + return vserverVserverName; + } + + public void setVserverVserverName(String vserverVserverName) { + this.vserverVserverName = vserverVserverName; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/AdditionalProperties.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/AdditionalProperties.java new file mode 100644 index 00000000..0d4e4bd8 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/AdditionalProperties.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.policy; + +import java.util.List; +import java.util.Map; + +/** + * Model class for the AdditionalProperties Object + */ +public class AdditionalProperties<T> { + private String modifyAction; + private List<String> snssaiList; + private String sliceProfileId; + private T resourceConfig; + private Map<String, String> nsiInfo; + private String scriptName; + public String getModifyAction() { + return modifyAction; + } + public void setModifyAction(String modifyAction) { + this.modifyAction = modifyAction; + } + public List<String> getSnssaiList() { + return snssaiList; + } + public void setSnssaiList(List<String> snssaiList) { + this.snssaiList = snssaiList; + } + public String getSliceProfileId() { + return sliceProfileId; + } + public void setSliceProfileId(String sliceProfileId) { + this.sliceProfileId = sliceProfileId; + } + public T getResourceConfig() { + return resourceConfig; + } + public void setResourceConfig(T resourceConfig) { + this.resourceConfig = resourceConfig; + } + public Map<String, String> getNsiInfo() { + return nsiInfo; + } + public void setNsiInfo(Map<String, String> nsiInfo) { + this.nsiInfo = nsiInfo; + } + public String getScriptName() { + return scriptName; + } + public void setScriptName(String scriptName) { + this.scriptName = scriptName; + } + + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/OnsetMessage.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/OnsetMessage.java new file mode 100644 index 00000000..671a9561 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/OnsetMessage.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.policy; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for the OnsetMessage Object + */ +public class OnsetMessage { + + private String closedLoopControlName; + private Long closedLoopAlarmStart; + private String closedLoopEventClient; + private String closedLoopEventStatus; + private String requestID; + + @JsonProperty("target_type") + private String targetType; + + @JsonProperty("AAI") + private AAI aai; + + private String target; + private Payload payload; + private String from; + private String version; + + public String getClosedLoopControlName() { + return closedLoopControlName; + } + + public void setClosedLoopControlName(String closedLoopControlName) { + this.closedLoopControlName = closedLoopControlName; + } + + public Long getClosedLoopAlarmStart() { + return closedLoopAlarmStart; + } + + public void setClosedLoopAlarmStart(Long closedLoopAlarmStart) { + this.closedLoopAlarmStart = closedLoopAlarmStart; + } + + public String getClosedLoopEventClient() { + return closedLoopEventClient; + } + + public void setClosedLoopEventClient(String closedLoopEventClient) { + this.closedLoopEventClient = closedLoopEventClient; + } + + public String getClosedLoopEventStatus() { + return closedLoopEventStatus; + } + + public void setClosedLoopEventStatus(String closedLoopEventStatus) { + this.closedLoopEventStatus = closedLoopEventStatus; + } + + public String getRequestID() { + return requestID; + } + + public void setRequestID(String requestID) { + this.requestID = requestID; + } + + public String getTargetType() { + return targetType; + } + + public void setTargetType(String targetType) { + this.targetType = targetType; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public AAI getAai() { + return aai; + } + + public void setAai(AAI aAI) { + this.aai = aAI; + } + + public Payload getPayload() { + return payload; + } + + public void setPayload(Payload payload) { + this.payload = payload; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/Payload.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/Payload.java new file mode 100644 index 00000000..57aab994 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/models/policy/Payload.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.models.policy; + +/** + * Model class for the Paylaod Object + */ +public class Payload { + + private String name; + private String serviceInstanceID; + private String globalSubscriberId; + private String subscriptionServiceType; + private String networkType; + private AdditionalProperties<?> additionalProperties; + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getServiceInstanceID() { + return serviceInstanceID; + } + + + public void setServiceInstanceID(String serviceInstanceId) { + this.serviceInstanceID = serviceInstanceId; + } + + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + + public String getNetworkType() { + return networkType; + } + + + public void setNetworkType(String networkType) { + this.networkType = networkType; + } + + + public AdditionalProperties<?> getAdditionalProperties() { + return additionalProperties; + } + + + public void setAdditionalProperties(AdditionalProperties<?> additionalProperties) { + this.additionalProperties = additionalProperties; + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/ConfigDbRestClient.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/ConfigDbRestClient.java new file mode 100644 index 00000000..dbc42912 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/ConfigDbRestClient.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 config db interfaces + */ +@Component +public class ConfigDbRestClient extends RestClient { + + public ConfigDbRestClient() { + super(); + } + + /** + * Send Post Request to Config DB. + */ + + 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 Config DB. + */ + + 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 new file mode 100644 index 00000000..5946fd1d --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/restclients/RestClient.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 org.onap.slice.analysis.ms.utils.BeanUtil; +import org.slf4j.Logger; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +/** + * 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); + + protected RestClient() { + + } + + /** + * Post Request Template. + */ + + public <T> ResponseEntity<T> sendPostRequest(HttpHeaders headers, String requestUrl, String requestBody, + ParameterizedTypeReference<T> responseType) { + HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); + try { + RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class); + return restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, responseType); + } catch (Exception e) { + log.debug(EXCEPTION_MSG, e.getMessage()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + /** + * Get Request Template. + */ + + public <T> ResponseEntity<T> sendGetRequest(HttpHeaders headers, String requestUrl, ParameterizedTypeReference<T> responseType) { + HttpEntity<Void> requestEntity = new HttpEntity<>(headers); + try { + RestTemplate restTemplate = BeanUtil.getBean(RestTemplate.class); + return restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, responseType); + } catch (Exception e) { + log.debug(EXCEPTION_MSG, e.getMessage()); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } + + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java new file mode 100644 index 00000000..a003e9c0 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/AverageCalculator.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * This class has utility methods for calculating the average of samples + */ +@Component +public class AverageCalculator { + private static Logger log = LoggerFactory.getLogger(AverageCalculator.class); + private List<String> pmNames; + + @PostConstruct + public void init() { + pmNames = new ArrayList<>(); + pmNames.add("PrbUsedDl"); + pmNames.add("PrbUsedUl"); + } + + /** + * Find average of samples + */ + public List<MeasurementObject> findAverageOfSamples(List<List<MeasurementObject>> samples) { + int numOfSamples = samples.size(); + List<MeasurementObject> result = new ArrayList<>(); + samples.forEach(sample -> + sample.forEach(cellMeasObj -> { + int index = result.indexOf(cellMeasObj); + if(index != -1) { + result.set(index, findSum(result.get(index), cellMeasObj)); + } + else { + result.add(cellMeasObj); + } + }) + ); + return findAvg(result, numOfSamples); + } + + /** + * Calculate the sum + */ + public MeasurementObject findSum(MeasurementObject existing, MeasurementObject current) { + pmNames.forEach(pmName -> { + int newValue = current.getPmData().get(pmName) + existing.getPmData().get(pmName); + existing.getPmData().put(pmName, newValue); + }); + return existing; + } + + /** + * Calculate the average + */ + public List<MeasurementObject> findAvg(List<MeasurementObject> result, int numOfSamples) { + result.forEach(cellMeasObj -> + pmNames.forEach(pmName -> { + int value = (cellMeasObj.getPmData().get(pmName))/numOfSamples; + cellMeasObj.getPmData().put(pmName, value); + }) + ); + log.debug("Average of measurement data samples {}",result); + return result; + } +} + diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java new file mode 100644 index 00000000..39235cd5 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConsumerThread.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import org.onap.slice.analysis.ms.configdb.IConfigDbService; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This Thread class consumes message from pm data queue and sends onset message to policy + */ +public class ConsumerThread extends Thread { + private static Logger log = LoggerFactory.getLogger(PmThread.class); + private PmDataQueue pmDataQueue; + private IConfigDbService configDbService; + private SnssaiSamplesProcessor snssaiSamplesProcessor; + private long initialDelaySec; + + /** + * Default constructor. + */ + public ConsumerThread() { + super(); + this.pmDataQueue = BeanUtil.getBean(PmDataQueue.class); + this.configDbService = BeanUtil.getBean(IConfigDbService.class); + this.snssaiSamplesProcessor = BeanUtil.getBean(SnssaiSamplesProcessor.class); + this.initialDelaySec = Configuration.getInstance().getInitialDelaySeconds(); + } + + /** + * Consumes data from PM data queue, process the data and sends onset message to policy if needed + */ + @Override + public void run() { + boolean done = false; + String snssai = ""; + while (!done) { + try { + Thread.sleep(initialDelaySec); + snssai = pmDataQueue.getSnnsaiFromQueue(); + if (!snssai.equals("")) { + log.info("Consumer thread started for s-nssai {}",snssai); + snssaiSamplesProcessor.processSamplesOfSnnsai(snssai, configDbService.fetchNetworkFunctionsOfSnssai(snssai)); + } + } catch (Exception e) { + log.error("Exception in Consumer Thread ", e); + done = true; + } + } + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/IPmEventProcessor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/IPmEventProcessor.java new file mode 100644 index 00000000..0a67df81 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/IPmEventProcessor.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import java.util.List; +import java.util.Map; + +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.pmnotification.Event; + +/** + * Interface for pm event processor + */ +public interface IPmEventProcessor { + public Map<String, List<MeasurementObject>> processEvent(Event event); +} 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 new file mode 100644 index 00000000..bee7b30e --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/MLMessageProcessor.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; + +import org.onap.slice.analysis.ms.configdb.IConfigDbService; +import org.onap.slice.analysis.ms.models.CUModel; +import org.onap.slice.analysis.ms.models.MLOutputModel; +import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +/** + * Process the message sent by ML service and sends notification to policy + */ +@Component +@Scope("Prototype") +public class MLMessageProcessor { + private static Logger log = LoggerFactory.getLogger(MLMessageProcessor.class); + + private IConfigDbService configDbService; + private PolicyService policyService; + + + @PostConstruct + public void init() { + configDbService = BeanUtil.getBean(IConfigDbService.class); + } + + public void processMLMsg(MLOutputModel mlOutputMsg) { + 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) { + String cellId = String.valueOf(cuModel.getCellCUList().get(0).getCellLocalId()); + ricToCellMapping.forEach((ricId, cells) -> { + if(cells.contains(cellId)) { + cuModel.setNearRTRICId(ricId); + } + }); + } + AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(mlOutputMsg); + policyService.sendOnsetMessageToPolicy(snssai, addProps, configDbService.fetchServiceDetails(snssai)); + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmDataQueue.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmDataQueue.java new file mode 100644 index 00000000..d907bfed --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmDataQueue.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; + +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.SubCounter; +import org.springframework.stereotype.Component; + +/** + * This class represents the data structure for storing the pm events + */ +@Component +public class PmDataQueue { + private Map<SubCounter, Queue<List<MeasurementObject>>> subCounterMap = Collections.synchronizedMap(new LinkedHashMap<SubCounter, Queue<List<MeasurementObject>>>()); + private Queue<String> snssaiList = new LinkedBlockingQueue<>(); + + /** + * put the measurement data for (an S-NSSAI from a network function) in the queue + */ + public void putDataToQueue(SubCounter subCounter, List<MeasurementObject> measurementObjectData) { + Queue<List<MeasurementObject>> measQueue; + if (subCounterMap.containsKey(subCounter)){ + subCounterMap.get(subCounter).add(measurementObjectData); + } + else { + measQueue = new LinkedBlockingQueue<>(); + measQueue.add(measurementObjectData); + subCounterMap.put(subCounter, measQueue); + } + } + + /** + * get the measurement data for (an S-NSSAI from a network function) from the queue + * returns the specified number of samples + */ + public List<List<MeasurementObject>> getSamplesFromQueue(SubCounter subCounter, int samples) { + List<List<MeasurementObject>> sampleList = new LinkedList<>(); + if (subCounterMap.containsKey(subCounter)){ + Queue<List<MeasurementObject>> measQueue = subCounterMap.get(subCounter); + while(samples > 0) { + sampleList.add(measQueue.remove()); + samples --; + } + } + return sampleList; + } + + /** + * put S-NSSAI to the queue + */ + public void putSnssaiToQueue(String snssai) { + if (!snssaiList.contains(snssai)) + snssaiList.add(snssai); + } + + /** + * get S-NSSAI from the queue + */ + public String getSnnsaiFromQueue() { + String snssai = ""; + try { + snssai = snssaiList.remove(); + } + catch(Exception e) { + + } + return snssai; + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmEventProcessor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmEventProcessor.java new file mode 100644 index 00000000..99c24c8a --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmEventProcessor.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.pmnotification.Event; +import org.onap.slice.analysis.ms.models.pmnotification.MeasInfoList; +import org.onap.slice.analysis.ms.models.pmnotification.MeasResult; +import org.onap.slice.analysis.ms.models.pmnotification.MeasValuesList; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +/** + * This class is responsible for processing PmEvent + */ +@Component +@Scope("prototype") +public class PmEventProcessor implements IPmEventProcessor{ + protected Map<String, List<MeasurementObject>> instanceMap = new HashMap<>(); + + + /** + * Process the PM event + */ + public Map<String, List<MeasurementObject>> processEvent(Event event) { + List<MeasInfoList> measurements = event.getPerf3gppFields().getMeasDataCollection().getMeasInfoList(); + measurements.forEach(measurement -> { + List<String> collectedSubCounters = measurement.getMeasTypes().getsMeasTypesList(); + List<MeasValuesList> subCounterMeasurements = measurement.getMeasValuesList(); + subCounterMeasurements.forEach(subCounterMeasurement -> processMeasurementObjectData(collectedSubCounters, subCounterMeasurement)); + }); + return instanceMap; + } + + /** + * Process the measurement data from every measurement object. eg cell + */ + public void processMeasurementObjectData(List<String> collectedSubCounters, MeasValuesList subCounterMeasurement) { + List<MeasResult> measResultList = subCounterMeasurement.getMeasResults(); + String measObjId = subCounterMeasurement.getMeasObjInstId(); + measResultList.forEach(measResult -> { + String pmName = collectedSubCounters.get(measResult.getP()-1); + Integer pmValue = Integer.valueOf(measResult.getsValue()); + Map<String,String> pmMapping = getMapKey(pmName); + String snssai = pmMapping.get("snssai"); + String pm = pmMapping.get("pm"); + Map<String, Integer> pmData = new HashMap<>(); + pmData.put(pm, pmValue); + if (instanceMap.containsKey(snssai)) { + int index = instanceMap.get(snssai).indexOf(new MeasurementObject(measObjId)); + if (index == -1) { + instanceMap.get(snssai).add(new MeasurementObject(measObjId,pmData)); + } + else { + instanceMap.get(snssai).get(index).getPmData().put(pmName, pmValue); + } + } + else { + List<MeasurementObject> l = new LinkedList<>(); + l.add(new MeasurementObject(measObjId,pmData)); + instanceMap.put(snssai, l); + } + }); + } + + /** + * Fetch pm name and S-NSSAI + */ + public Map<String, String> getMapKey(String pmName) { + String [] pmNameArr = pmName.split("\\."); + String snssai = ""; + String pm = pmNameArr[1]; + Map<String, String> result = new HashMap<>(); + result.put("pm", pm); + if ((pm.equalsIgnoreCase("PrbUsedDl")) || (pm.equalsIgnoreCase("PrbUsedUl"))){ + snssai = pmNameArr[2]; + } + result.put("snssai", snssai); + return result; + } +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmThread.java new file mode 100644 index 00000000..d9091b3c --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PmThread.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import java.util.List; +import java.util.Map; + +import org.onap.slice.analysis.ms.data.repository.PerformanceNotificationsRepository; +import org.onap.slice.analysis.ms.dmaap.NewPmNotification; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.SubCounter; +import org.onap.slice.analysis.ms.models.pmnotification.PmNotification; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * This Thread class consumes pm message from database and puts it in the queue for further processing + */ +public class PmThread extends Thread { + private static Logger log = LoggerFactory.getLogger(PmThread.class); + private NewPmNotification newPmNotification; + private PerformanceNotificationsRepository performanceNotificationsRepository; + private IPmEventProcessor pmEventProcessor; + private PmDataQueue pmDataQueue; + + /** + * parameterized constructor. + */ + public PmThread(NewPmNotification newPmNotification) { + super(); + this.newPmNotification = newPmNotification; + this.performanceNotificationsRepository = BeanUtil.getBean(PerformanceNotificationsRepository.class); + this.pmEventProcessor = BeanUtil.getBean(IPmEventProcessor.class); + this.pmDataQueue = BeanUtil.getBean(PmDataQueue.class); + } + + /** + * check for new PM notification. Fetch notification from the database, process and put it in the pm data queue + */ + @Override + public void run() { + log.info("PM thread starting ..."); + boolean done = false; + PmNotification pmNotification; + Map<String, List<MeasurementObject>> processedData; + while (!done) { + try { + Thread.sleep(1000); + if (newPmNotification.getNewNotif()) { + log.info("New PM notification from Dmaap"); + String pmNotificationString = performanceNotificationsRepository.getPerformanceNotificationFromQueue(); + if(pmNotificationString != null) { + ObjectMapper mapper = new ObjectMapper(); + pmNotification = mapper.readValue(pmNotificationString, PmNotification.class); + processedData = pmEventProcessor.processEvent(pmNotification.getEvent()); + String networkFunction = pmNotification.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasuredEntityDn(); + processedData.forEach((key,value) -> { + SubCounter subCounter = new SubCounter(networkFunction, key); + pmDataQueue.putDataToQueue(subCounter, value); + pmDataQueue.putSnssaiToQueue(subCounter.getMeasuredObject()); + }); + } + } + } catch (Exception e) { + log.error("Exception in PM Thread ", e); + done = true; + } + } + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PolicyService.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PolicyService.java new file mode 100644 index 00000000..80063398 --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/PolicyService.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.annotation.PostConstruct; + +import org.onap.slice.analysis.ms.dmaap.PolicyDmaapClient; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.models.policy.AAI; +import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; +import org.onap.slice.analysis.ms.models.policy.OnsetMessage; +import org.onap.slice.analysis.ms.models.policy.Payload; +import org.onap.slice.analysis.ms.utils.DmaapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class PolicyService { + private PolicyDmaapClient policyDmaapClient; + private static Logger log = LoggerFactory.getLogger(PolicyService.class); + + @PostConstruct + public void init() { + Configuration configuration = Configuration.getInstance(); + policyDmaapClient = new PolicyDmaapClient(new DmaapUtils(), configuration); + } + + protected <T> OnsetMessage formPolicyOnsetMessage(String snssai, AdditionalProperties<T> addProps, Map<String, String> serviceDetails) { + OnsetMessage onsetmsg = new OnsetMessage(); + Payload payload = new Payload(); + payload.setGlobalSubscriberId(serviceDetails.get("globalSubscriberId")); + payload.setSubscriptionServiceType(serviceDetails.get("subscriptionServiceType")); + payload.setNetworkType("AN"); + payload.setName(serviceDetails.get("ranNFNSSIId")); + payload.setServiceInstanceID(serviceDetails.get("ranNFNSSIId")); + + addProps.setModifyAction(""); + Map<String, String> nsiInfo = new HashMap<>(); + nsiInfo.put("nsiId", UUID.randomUUID().toString()); + nsiInfo.put("nsiName", ""); + addProps.setNsiInfo(nsiInfo); + addProps.setScriptName("AN"); + addProps.setSliceProfileId(serviceDetails.get("sliceProfileId")); + addProps.setModifyAction("reconfigure"); + List<String> snssaiList = new ArrayList<>(); + snssaiList.add(snssai); + addProps.setSnssaiList(snssaiList); + + payload.setAdditionalProperties(addProps); + onsetmsg.setPayload(payload); + + onsetmsg.setClosedLoopControlName("ControlLoop-Slicing-116d7b00-dbeb-4d03-8719-d0a658fa735b"); + onsetmsg.setClosedLoopAlarmStart(System.currentTimeMillis()); + onsetmsg.setClosedLoopEventClient("microservice.sliceAnalysisMS"); + onsetmsg.setClosedLoopEventStatus("ONSET"); + onsetmsg.setRequestID(UUID.randomUUID().toString()); + onsetmsg.setTarget("vserver.vserver-name"); + onsetmsg.setTargetType("VNF"); + onsetmsg.setFrom("DCAE"); + onsetmsg.setVersion("1.0.2"); + AAI aai = new AAI(); + aai.setVserverIsClosedLoopDisabled("false"); + aai.setVserverProvStatus("ACTIVE"); + aai.setVserverVserverName(serviceDetails.get("ranNFNSSIId")); + onsetmsg.setAai(aai); + return onsetmsg; + } + + protected <T> void sendOnsetMessageToPolicy(String snssai, AdditionalProperties<T> addProps, Map<String, String> serviceDetails) { + OnsetMessage onsetMessage = formPolicyOnsetMessage(snssai, addProps, serviceDetails); + ObjectMapper obj = new ObjectMapper(); + String msg = ""; + try { + log.debug("Policy onset message for S-NSSAI: {} is {}", snssai, msg); + msg = obj.writeValueAsString(onsetMessage); + policyDmaapClient.sendNotificationToPolicy(msg); + } + catch (Exception e) { + log.error("Error sending notification to policy, {}",e.getMessage()); + } + } + +} 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 new file mode 100644 index 00000000..2e56190f --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessor.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; + +import org.onap.slice.analysis.ms.configdb.IConfigDbService; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.SubCounter; +import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +/** + * This class process the measurement data of an S-NSSAI + */ +@Component +@Scope("Prototype") +public class SnssaiSamplesProcessor { + private static Logger log = LoggerFactory.getLogger(SnssaiSamplesProcessor.class); + + private PolicyService policyService; + private IConfigDbService configDbService; + private PmDataQueue pmDataQueue; + private AverageCalculator averageCalculator; + 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 samples; + private List<String> pmsToCompute; + private Map<String, String> prbThroughputMapping = new HashMap<>(); + private int minPercentageChange; + + @PostConstruct + public void init() { + Configuration configuration = Configuration.getInstance(); + samples = configuration.getSamples(); + pmsToCompute = new ArrayList<>(); + pmsToCompute.add("PrbUsedDl"); + pmsToCompute.add("PrbUsedUl"); + prbThroughputMapping = new HashMap<>(); + prbThroughputMapping.put("PrbUsedDl", "dLThptPerSlice"); + prbThroughputMapping.put("PrbUsedUl", "uLThptPerSlice"); + minPercentageChange = configuration.getMinPercentageChange(); + policyService = BeanUtil.getBean(PolicyService.class); + configDbService = BeanUtil.getBean(IConfigDbService.class); + pmDataQueue = BeanUtil.getBean(PmDataQueue.class); + averageCalculator = BeanUtil.getBean(AverageCalculator.class); + } + + /** + * process the measurement data of an S-NSSAI + */ + public void processSamplesOfSnnsai(String snssai, List<String> networkFunctions) { + networkFunctions.forEach(nf -> { + log.debug("Average of samples for {}:", snssai); + addToMeasurementList(averageCalculator.findAverageOfSamples(pmDataQueue.getSamplesFromQueue(new SubCounter(nf, snssai), samples))); + }); + ricToCellMapping = configDbService.fetchRICsOfSnssai(snssai); + log.debug("RIC to Cell Mapping for {} S-NSSAI: {}", snssai, ricToCellMapping); + Map<String, Map<String, Integer>> ricConfiguration = configDbService.fetchCurrentConfigurationOfRIC(snssai); + Map<String, Integer> sliceConfiguration = configDbService.fetchCurrentConfigurationOfSlice(snssai); + log.debug("RIC Configuration: {}", ricConfiguration); + log.debug("Slice Configuration: {}", sliceConfiguration); + pmsToCompute.forEach(pm -> { + sumOfPrbsAcrossCells(pm); + int sum = computeSum(pm); + computeThroughput(sliceConfiguration, sum, pm); + calculatePercentageChange(ricConfiguration, pm); + }); + updateConfiguration(); + if(ricToThroughputMapping.size() > 0) { + AdditionalProperties<Map<String, Map<String, Integer>>> addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(ricToThroughputMapping); + policyService.sendOnsetMessageToPolicy(snssai, addProps, configDbService.fetchServiceDetails(snssai)); + } + + } + + /** + * process the measurement data of an S-NSSAI + */ + protected void updateConfiguration() { + Iterator<Map.Entry<String, Map<String,Integer>>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry<String, Map<String,Integer>> entry = null; + while(it.hasNext()) { + entry = it.next(); + if(entry.getValue().size() == 0) { + it.remove(); + } + } + } + + private void addToMeasurementList(List<MeasurementObject> sample) { + snssaiMeasurementList.addAll(sample); + } + + /** + * Calculate the change in the configuration value and keep the configuration only if it is greater than a + * specific limit + */ + protected void calculatePercentageChange(Map<String, Map<String, Integer>> ricConfiguration, String pm) { + Iterator<Map.Entry<String, Map<String,Integer>>> it = ricToThroughputMapping.entrySet().iterator(); + Map.Entry<String, Map<String,Integer>> entry = null; + float existing = 0; + float change = 0; + while(it.hasNext()) { + entry = it.next(); + existing = 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); + } + } + } + + protected void sumOfPrbsAcrossCells(String pmName) { + ricToCellMapping.forEach((ric,cells) -> { + int sumOfPrbs = 0; + for(String cell : cells) { + int index = snssaiMeasurementList.indexOf(new MeasurementObject(cell)); + sumOfPrbs += snssaiMeasurementList.get(index).getPmData().get(pmName); + } + if(ricToPrbsMapping.containsKey(ric)) { + ricToPrbsMapping.get(ric).put(pmName, sumOfPrbs); + } + else { + Map<String, Integer> pmToPrbMapping = new HashMap<>(); + pmToPrbMapping.put(pmName, sumOfPrbs); + ricToPrbsMapping.put(ric, pmToPrbMapping); + } + }); + } + + protected Integer computeSum(String pm) { + return ricToPrbsMapping.entrySet().stream().map(x -> x.getValue().get(pm)).reduce(0, Integer::sum); + } + + protected void computeThroughput(Map<String, Integer> sliceConfiguration, int sum, String pm) { + Iterator<Map.Entry<String, Map<String,Integer>>> it = ricToPrbsMapping.entrySet().iterator(); + Map.Entry<String, Map<String,Integer>> entry = null; + Map<String, Integer> throughtputMap = null; + String ric = ""; + int value = 0; + while(it.hasNext()) { + entry = it.next(); + ric = entry.getKey(); + value = Math.round(((float)entry.getValue().get(pm)/sum)*(float)sliceConfiguration.get(prbThroughputMapping.get(pm))); + if(ricToThroughputMapping.containsKey(ric)) { + ricToThroughputMapping.get(ric).put(prbThroughputMapping.get(pm), value); + } + else { + throughtputMap = new HashMap<>(); + throughtputMap.put(prbThroughputMapping.get(pm), value); + ricToThroughputMapping.put(ric, throughtputMap); + } + } + + } + +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/DmaapUtils.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/DmaapUtils.java index 0952f754..7457533b 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/DmaapUtils.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/DmaapUtils.java @@ -33,7 +33,7 @@ import com.att.nsa.cambria.client.CambriaTopicManager; import java.net.MalformedURLException; import java.security.GeneralSecurityException; -import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.models.Configuration; /** * Utility class to perform actions related to Dmaap diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceServiceTest.java new file mode 100644 index 00000000..481fee6f --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceServiceTest.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.slice.analysis.ms.models.configdb.CellsModel; +import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel; +import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +@RunWith(org.mockito.junit.MockitoJUnitRunner.class) +public class ConfigDbInterfaceServiceTest { + + @InjectMocks + ConfigDbInterfaceService configdbservice; + + @Mock + ConfigDbRestClient restclient; + + @Test + public void fetchCurrentConfigurationOfSlice() { + + Map<String, Integer> responsemap=new HashMap<>(); + responsemap.put("dLThptPerSlice", 1); + responsemap.put("uLThptPerSlice", 2); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responsemap, HttpStatus.OK)); + assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai")); + } + + @Test + public void fetchCurrentConfigurationOfRIC() { + Map<String,Integer> map=new HashMap<>(); + Map<String, Map<String,Integer>> responsemap=new HashMap<>(); + map.put("dLThptPerSlice", 45); + map.put("uLThptPerSlice", 50); + responsemap.put("1", map); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responsemap, HttpStatus.OK)); + assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai")); + + } + @Test + public void fetchRICsOfSnssai() { + Map<String, List<CellsModel>> response=new HashMap<>(); + List<CellsModel> cellslist=new ArrayList<>(); + List<CellsModel> cellslist1=new ArrayList<>(); + CellsModel cellsmodel1=new CellsModel(); + cellsmodel1.setCellLocalId("1111"); + CellsModel cellsmodel2=new CellsModel(); + cellsmodel2.setCellLocalId("2222"); + cellslist.add(cellsmodel1); + cellslist.add(cellsmodel2); + response.put("1", cellslist); + CellsModel cellsmodel3=new CellsModel(); + cellsmodel3.setCellLocalId("3333"); + CellsModel cellsmodel4=new CellsModel(); + cellsmodel4.setCellLocalId("4444"); + cellslist1.add(cellsmodel3); + cellslist1.add(cellsmodel4); + response.put("2", cellslist1); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(response, HttpStatus.OK)); + List<String> outputlist=new ArrayList<>(); + outputlist.add("1111"); + outputlist.add("2222"); + Map<String,List<String>> output= configdbservice.fetchRICsOfSnssai("snssai"); + assertEquals(outputlist, output.get("1")); + + } + + @Test + public void fetchNetworkFunctionsOfSnssai() { + + List<String> responsemap=new ArrayList<>(); + List<NetworkFunctionModel> networkfunctionslist=new ArrayList<NetworkFunctionModel>(); + NetworkFunctionModel nf1=new NetworkFunctionModel(); + nf1.setgNBDUId("1111"); + NetworkFunctionModel nf2=new NetworkFunctionModel(); + nf2.setgNBDUId("2222"); + NetworkFunctionModel nf3=new NetworkFunctionModel(); + nf3.setgNBDUId("3333"); + networkfunctionslist.add(nf1); + networkfunctionslist.add(nf2); + networkfunctionslist.add(nf3); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(networkfunctionslist, HttpStatus.OK)); + responsemap=configdbservice.fetchNetworkFunctionsOfSnssai("snssai"); + assertEquals(3, responsemap.size()); + + } + public void fetchServiceProfile() { + Map<String,String> responseMap=new HashMap<String, String>(); + responseMap.put("sNSSAI", "001-010"); + responseMap.put("ranNFNSSIId","1111"); + responseMap.put("sliceProfileId","2222"); + responseMap.put("globalSubscriberId","110-345"); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responseMap, HttpStatus.OK)); + assertEquals(responseMap, configdbservice.fetchServiceDetails("snssai")); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java index f2420b02..b74056db 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java @@ -43,7 +43,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.models.Configuration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -54,10 +54,9 @@ public class DmaapClientTest { @Mock private CambriaTopicManager topicManager; - @InjectMocks DmaapClient client; - + @Before public void setup() { MockitoAnnotations.initMocks(this); @@ -77,53 +76,53 @@ public class DmaapClientTest { configuration.setPollingInterval(30); configuration.setPollingTimeout(100); configuration.setConfigDbService("sdnrService"); - + try { when(topicManager.getTopics()).thenReturn(topics); - + client=Mockito.mock(DmaapClient.class); client.initClient(); Mockito.verify(client).initClient(); - // Mockito.verifycreateAndConfigureTopics(); + // Mockito.verifycreateAndConfigureTopics(); } catch (IOException e) { e.printStackTrace(); } } - + @Test public void startClientTest() { try { Configuration configuration = Configuration.getInstance(); String configAllJson = readFromFile("src/test/resources/config_all.json"); - JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class); + JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class); - JsonObject config = configAll.getAsJsonObject("config"); - - configuration.updateConfigurationFromJsonObject(config); + JsonObject config = configAll.getAsJsonObject("config"); + System.out.println(configuration); + configuration.updateConfigurationFromJsonObject(config); DmaapClient client= new DmaapClient(); client.initClient(); //Mockito.verify(client).startClient(); - // Mockito.verifycreateAndConfigureTopics(); + // Mockito.verifycreateAndConfigureTopics(); } catch ( Exception e) { e.printStackTrace(); } } - private static String readFromFile(String file) { - String content = ""; - try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { - content = bufferedReader.readLine(); - String temp; - while ((temp = bufferedReader.readLine()) != null) { - content = content.concat(temp); - } - content = content.trim(); - } catch (Exception e) { - content = null; - } - return content; - } + private static String readFromFile(String file) { + String content = ""; + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + } catch (Exception e) { + content = null; + } + return content; + } } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java index f4b64397..9aab22c2 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java @@ -21,6 +21,11 @@ package org.onap.slice.analysis.ms.dmaap; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -28,11 +33,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import com.att.nsa.cambria.client.CambriaConsumer; diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java index a458d33c..3ff56ab1 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java @@ -22,10 +22,7 @@ package org.onap.slice.analysis.ms.dmaap; -import static org.junit.Assert.*; - -import com.att.nsa.cambria.client.CambriaBatchingPublisher; -import com.att.nsa.cambria.client.CambriaConsumer; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.HashMap; @@ -38,10 +35,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; -import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.utils.DmaapUtils; import org.springframework.boot.test.context.SpringBootTest; +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaConsumer; + @RunWith(MockitoJUnitRunner.class) @SpringBootTest(classes = PolicyDmaapClient.class) public class PolicyDmaapClientTest { diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigPolicyTest.java index 66f97d96..2b137e3a 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigPolicyTest.java @@ -20,7 +20,7 @@ *******************************************************************************/ -package org.onap.slice.analysis.ms.beans; +package org.onap.slice.analysis.ms.models; import static org.junit.Assert.assertEquals; diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java index a3487773..eb492800 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java @@ -20,7 +20,7 @@ *******************************************************************************/ -package org.onap.slice.analysis.ms.beans; +package org.onap.slice.analysis.ms.models; import static org.junit.Assert.assertEquals; diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java new file mode 100644 index 00000000..582abdce --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class ModelsTest { + + @Test + public void testGetterSetterSubCounter() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(SubCounter.class); + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .with(new EqualsAndHashCodeMatchRule()) + .build(); + validator.validate(pojoclass); + } + + @Test + public void testGetterSetterMeasurementObject() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasurementObject.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterCellCUList() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(CellCUList.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterCUModel() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(CUModel.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterConfigData() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(ConfigData.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMLOutputModel() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MLOutputModel.class); + validateMd(pojoclass); + } + + public void validateMd(PojoClass pojoclass) { + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoclass); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/pmnotification/PmModelsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/pmnotification/PmModelsTest.java new file mode 100644 index 00000000..8954ae9b --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/pmnotification/PmModelsTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.models.pmnotification; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class PmModelsTest { + @Test + public void testGetterSetterCommonEventHeader() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(CommonEventHeader.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterEvent() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(Event.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasDataCollection() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasDataCollection.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasInfoId() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasInfoId.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasInfoList() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasInfoList.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasResult() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasResult.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasTypes() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasTypes.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasValuesList() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasValuesList.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterPerf3gppFields() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(Perf3gppFields.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterPmNotification() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(PmNotification.class); + validateMd(pojoclass); + } + + public void validateMd(PojoClass pojoclass) { + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoclass); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/policy/PolicyModelsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/policy/PolicyModelsTest.java new file mode 100644 index 00000000..958a1f83 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/policy/PolicyModelsTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.models.policy; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class PolicyModelsTest { + @Test + public void testGetterSetterPayload() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(Payload.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterAAI() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(AAI.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterOnsetMessage() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(OnsetMessage.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterAdditionalProperties() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(AdditionalProperties.class); + validateMd(pojoclass); + } + + public void validateMd(PojoClass pojoclass) { + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoclass); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java new file mode 100644 index 00000000..b19b4801 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 static org.junit.Assert.assertEquals; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; + + + +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ BeanUtil.class }) +@SpringBootTest(classes = RestClient.class) +public class RestClientTest { + + + @Mock + RestTemplate restTemplate; + + + @InjectMocks + RestClient restclient; + + + @SuppressWarnings({ "static-access", "unchecked", "rawtypes" }) + @Test + public void sendGetRequestTest() { + + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(Mockito.any())).thenReturn(restTemplate); + ParameterizedTypeReference<Map<String,Integer>> responseType = null; + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity<Object> requestEntity = new HttpEntity<>( headers); + Map<String, Integer> responsemap=new HashMap<>(); + responsemap.put("dLThptPerSlice", 1); + responsemap.put("uLThptPerSlice", 2); + String requestUrl=""; + PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.GET,requestEntity,responseType)).thenReturn(ResponseEntity.ok(responsemap)); + ResponseEntity<Map<String,Integer>> resp = restclient.sendGetRequest(headers, requestUrl, responseType); + assertEquals(resp.getBody(),responsemap); + } + + @SuppressWarnings({ "static-access", "unchecked", "rawtypes" }) + @Test + public void sendPostRequestTest() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(RestTemplate.class)).thenReturn(restTemplate); + ParameterizedTypeReference<String> responseType = null; + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + String requestUrl = "Url"; String requestBody = null; + HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); + PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.OK)); + ResponseEntity<String> resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType); + assertEquals(resp.getStatusCode(), HttpStatus.OK); + } + + @Test + public void sendPostRequestTest2() { + ParameterizedTypeReference<String> responseType = null; + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + String requestUrl = "Url"; String requestBody = null; + HttpEntity<Object> requestEntity = new HttpEntity<>(requestBody, headers); + PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.NOT_FOUND)); + ResponseEntity<String> resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType); + assertEquals(resp.getStatusCode(), HttpStatus.NOT_FOUND); + } + + +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java new file mode 100644 index 00000000..e9c134f7 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AverageCalculatorTest.class) +public class AverageCalculatorTest { + + @InjectMocks + AverageCalculator averageCalculator; + + @Before + public void setup() { + List<String> pmNames = new ArrayList<>(); + pmNames.add("PrbUsedDl"); + pmNames.add("PrbUsedUl"); + ReflectionTestUtils.setField(averageCalculator, "pmNames", pmNames); + } + + @Test + public void findAverageOfSamplesTest() { + ObjectMapper obj = new ObjectMapper(); + List<List<MeasurementObject>> input = null; + List<MeasurementObject> output = null; + try { + input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference<List<List<MeasurementObject>>>(){}); + output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference<List<MeasurementObject>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + + assertEquals(output, averageCalculator.findAverageOfSamples(input)); + } + + @Test + public void findAvgTest() { + List<MeasurementObject> result = new ArrayList<>(); + Map<String, Integer> pmData = new HashMap<>(); + pmData.put("PrbUsedDl", 50); + pmData.put("PrbUsedUl", 48); + result.add(new MeasurementObject("cell11", pmData)); + pmData.put("PrbUsedDl", 40); + pmData.put("PrbUsedUl", 38); + result.add(new MeasurementObject("cell12", pmData)); + + List<MeasurementObject> exp = new ArrayList<>(); + pmData.put("PrbUsedDl", 25); + pmData.put("PrbUsedUl", 24); + exp.add(new MeasurementObject("cell11", pmData)); + pmData.put("PrbUsedDl", 20); + pmData.put("PrbUsedUl", 19); + exp.add(new MeasurementObject("cell12", pmData)); + + assertEquals(exp, averageCalculator.findAvg(result, 2)); + } + + @Test + public void findAvgSum() { + Map<String, Integer> existingMap = new HashMap<>(); + existingMap.put("PrbUsedDl", 50); + existingMap.put("PrbUsedUl", 48); + + Map<String, Integer> currentMap = new HashMap<>(); + currentMap.put("PrbUsedDl", 40); + currentMap.put("PrbUsedUl", 38); + + Map<String, Integer> result = new HashMap<>(); + result.put("PrbUsedDl", 90); + result.put("PrbUsedUl", 86); + + assertEquals(new MeasurementObject("cell1", result), + averageCalculator.findSum(new MeasurementObject("cell1", existingMap), new MeasurementObject("cell1", currentMap))); + } +} + diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java new file mode 100644 index 00000000..d80160c9 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.slice.analysis.ms.configdb.IConfigDbService; +import org.onap.slice.analysis.ms.models.MLOutputModel; +import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = MLMessageProcessorTest.class) +public class MLMessageProcessorTest { + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + private MLMessageProcessor mlMessageProcessor; + + @Mock + private IConfigDbService configDbService; + + @Mock + private PolicyService policyService; + + @SuppressWarnings({"unchecked" }) + @Test + public void processMLMsgTest() { + MLOutputModel mloutput = null; + MLOutputModel mloutputExp = null; + + Map<String, List<String>> ricToCellMapping = new HashMap<>(); + List<String> myList = new ArrayList<String>(); + myList.add("111"); + myList.add("112"); + ricToCellMapping.put("12", myList); + myList = new ArrayList<String>(); + myList.add("113"); + myList.add("114"); + ricToCellMapping.put("13", myList); + + try { + mloutput = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel1.json"))), new TypeReference<MLOutputModel>(){}); + mloutputExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel.json"))), new TypeReference<MLOutputModel>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + when(configDbService.fetchRICsOfSnssai("0001-0111")).thenReturn(ricToCellMapping); + AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(mloutputExp); + doNothing().when(policyService).sendOnsetMessageToPolicy(anyString(), any(AdditionalProperties.class), anyMap()); + mlMessageProcessor.processMLMsg(mloutput); + assertEquals(mloutputExp, mloutput); + } + +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmDataQueueTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmDataQueueTest.java new file mode 100644 index 00000000..b2c2243d --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmDataQueueTest.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.service; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.SubCounter; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = PmDataQueueTest.class) +public class PmDataQueueTest { + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + PmDataQueue pmDataQueue; + + @Before + public void setup() { + Queue<List<MeasurementObject>> measList = null; + try { + measList = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference<Queue<List<MeasurementObject>>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + SubCounter sub1 = new SubCounter("nf1", "nssai1"); + Map<SubCounter, Queue<List<MeasurementObject>>> subCounterMap = Collections.synchronizedMap(new LinkedHashMap<SubCounter, Queue<List<MeasurementObject>>>()); + subCounterMap.put(sub1, measList); + ReflectionTestUtils.setField(pmDataQueue, "subCounterMap", subCounterMap); + + Queue<String> snssaiList = new LinkedBlockingQueue<>(); + snssaiList.add("nssai1"); + snssaiList.add("nssai2"); + snssaiList.add("nssai3"); + ReflectionTestUtils.setField(pmDataQueue, "snssaiList", snssaiList); + + } + + @Test + public void putDataToQueueSameNssaiTest() { + SubCounter sub1 = new SubCounter("nf1", "nssai1"); + Map<SubCounter, Queue<List<MeasurementObject>>> subCounterMapExp = Collections.synchronizedMap(new LinkedHashMap<SubCounter, Queue<List<MeasurementObject>>>()); + List<MeasurementObject> measObj = null; + Queue<List<MeasurementObject>> measObjExp = null; + try { + measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference<List<MeasurementObject>>(){}); + measObjExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/appendData.json"))), new TypeReference<Queue<List<MeasurementObject>>>(){}); + + } + catch (IOException e) { + e.printStackTrace(); + } + subCounterMapExp.put(sub1, measObjExp); + pmDataQueue.putDataToQueue(sub1, measObj); + assertEquals(subCounterMapExp, ReflectionTestUtils.getField(pmDataQueue, "subCounterMap")); + } + + @SuppressWarnings("unchecked") + @Test + public void putDataToQueueDiffNssaiTest() { + SubCounter sub = new SubCounter("nf1", "nssai1"); + SubCounter sub1 = new SubCounter("nf1", "nssai2"); + Map<SubCounter, Queue<List<MeasurementObject>>> subCounterMapExp = Collections.synchronizedMap(new LinkedHashMap<SubCounter, Queue<List<MeasurementObject>>>()); + List<MeasurementObject> measObj = null; + Queue<List<MeasurementObject>> measObjExp = null; + Queue<List<MeasurementObject>> measObjExp1 = new LinkedBlockingQueue<>(); + try { + measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference<List<MeasurementObject>>(){}); + measObjExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference<Queue<List<MeasurementObject>>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + measObjExp1.add(measObj); + subCounterMapExp.put(sub, measObjExp); + subCounterMapExp.put(sub1, measObjExp1); + pmDataQueue.putDataToQueue(sub1, measObj); + assertEquals(subCounterMapExp.get(sub), ((Map<SubCounter,Queue<List<MeasurementObject>>>) ReflectionTestUtils.getField(pmDataQueue, "subCounterMap")).get(sub)); + assertEquals(subCounterMapExp.get(sub1).contains(measObj), ((Map<SubCounter,Queue<List<MeasurementObject>>>) ReflectionTestUtils.getField(pmDataQueue, "subCounterMap")).get(sub1).contains(measObj)); + } + + @Test + public void getSamplesFromQueueTest() { + SubCounter sub = new SubCounter("nf1", "nssai1"); + List<List<MeasurementObject>> measObj = null; + try { + measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/getResponse.json"))), new TypeReference<List<List<MeasurementObject>>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + assertEquals(measObj, pmDataQueue.getSamplesFromQueue(sub, 1)); + } + + @SuppressWarnings("unchecked") + @Test + public void putSnssaiToQueueTest() { + pmDataQueue.putSnssaiToQueue("nssai1"); + assertEquals(3, ((Queue<String>)ReflectionTestUtils.getField(pmDataQueue, "snssaiList")).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void putNewSnssaiToQueueTest() { + pmDataQueue.putSnssaiToQueue("nssai9"); + assertEquals(4, ((Queue<String>)ReflectionTestUtils.getField(pmDataQueue, "snssaiList")).size()); + } + + @Test + public void getSnnsaiFromQueueTest() { + assertEquals("nssai1", pmDataQueue.getSnnsaiFromQueue()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmEventProcessorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmEventProcessorTest.java new file mode 100644 index 00000000..ae4f5471 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmEventProcessorTest.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.pmnotification.Event; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = PmEventProcessorTest.class) +public class PmEventProcessorTest { + + @InjectMocks + PmEventProcessor pmEventProcessor; + + @Test + public void processEventTest() { + ObjectMapper obj = new ObjectMapper(); + Event input = null; + Map<String, List<MeasurementObject>> output = null; + try { + input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/event.json"))), Event.class); + output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/eventProcessorOutput.json"))), new TypeReference<Map<String, List<MeasurementObject>>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + + assertEquals(output, pmEventProcessor.processEvent(input)); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java new file mode 100644 index 00000000..1131a5e5 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; +import org.onap.slice.analysis.ms.models.policy.OnsetMessage; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = PolicyServiceTest.class) +public class PolicyServiceTest { + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + PolicyService policyService; + + @Test + public void formPolicyOnsetMessageTest() { + String snssai = "001-100001"; + Map<String, String> input = null; + OnsetMessage output = null; + String expected = ""; + String actual = ""; + Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); + Map<String, Integer> ric1 = new HashMap<>(); + Map<String, Integer> ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice",50); + ric1.put("uLThptPerSlice",40); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMapping.put("1", ric1); + ricToThroughputMapping.put("2", ric2); + try { + input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/serviceDetails.json"))), new TypeReference<Map<String,String>>(){}); + output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage.json"))), OnsetMessage.class); + expected = obj.writeValueAsString(output); + } + catch (IOException e) { + e.printStackTrace(); + } + AdditionalProperties<Map<String, Map<String, Integer>>> addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(ricToThroughputMapping); + actual = new Gson().toJson(policyService.formPolicyOnsetMessage(snssai,addProps,input)); + + assertThatJson(actual) + .whenIgnoringPaths("requestID","payload.additionalProperties.nsiInfo.nsiId","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType") + .isEqualTo(expected); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java new file mode 100644 index 00000000..b8316dfe --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SnssaiSamplesProcessorTest.class) +public class SnssaiSamplesProcessorTest { + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + SnssaiSamplesProcessor snssaiSamplesProcessor; + + @Before + public void setup() { + Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); + Map<String, Integer> ric1 = new HashMap<>(); + Map<String, Integer> ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice",50); + ric1.put("uLThptPerSlice",40); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMapping.put("1", ric1); + ricToThroughputMapping.put("2", ric2); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToThroughputMapping", ricToThroughputMapping); + + Map<String, Map<String, Integer>> ricToPrbsMapping = null; + List<MeasurementObject> sliceMeasList = null; + Map<String, List<String>> ricToCellMapping = null; + Map<String, String> prbThroughputMapping = new HashMap<>(); + prbThroughputMapping = new HashMap<>(); + prbThroughputMapping.put("PrbUsedDl", "dLThptPerSlice"); + prbThroughputMapping.put("PrbUsedUl", "uLThptPerSlice"); + + try { + ricToPrbsMapping = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToPrbMap.json"))), new TypeReference<Map<String, Map<String, Integer>>>(){}); + sliceMeasList = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/sliceMeasurementList.json"))), new TypeReference<List<MeasurementObject>>(){}); + ricToCellMapping = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToCellMapping.json"))), new TypeReference<Map<String, List<String>>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToPrbsMapping", ricToPrbsMapping); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "minPercentageChange", 6); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "snssaiMeasurementList", sliceMeasList); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToCellMapping", ricToCellMapping); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "prbThroughputMapping", prbThroughputMapping); + } + + @Test + public void computeSumTest() { + assertEquals(Integer.valueOf(100), snssaiSamplesProcessor.computeSum("PrbUsedDl")); + } + + @Test + public void updateConfigurationTest() { + Map<String, Map<String, Integer>> ricToThroughputMappingExp = new HashMap<>(); + Map<String, Integer> ric1 = new HashMap<>(); + Map<String, Integer> ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice",50); + ric1.put("uLThptPerSlice",40); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMappingExp.put("1", ric1); + ricToThroughputMappingExp.put("2", ric2); + snssaiSamplesProcessor.updateConfiguration(); + assertEquals(ricToThroughputMappingExp,ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + } + + @Test + public void updateConfigurationTrueTest() { + Map<String, Map<String, Integer>> ricToThroughputMappingExp = new HashMap<>(); + Map<String, Integer> ric2 = new HashMap<>(); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMappingExp.put("2", ric2); + + Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); + Map<String, Integer> ric1 = new HashMap<>(); + ric2 = new HashMap<>(); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMapping.put("1", ric1); + ricToThroughputMapping.put("2", ric2); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToThroughputMapping", ricToThroughputMapping); + + snssaiSamplesProcessor.updateConfiguration(); + System.out.println(); + assertEquals(ricToThroughputMappingExp, ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + } + + @Test + public void calculatePercentageChangeTest() { + Map<String, Map<String, Integer>> ricConfiguration = null; + Map<String, Map<String, Integer>> exp = new HashMap<>(); + Map<String, Integer> ric1 = new HashMap<>(); + Map<String, Integer> ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice", 50); + ric2.put("dLThptPerSlice", 50); + ric2.put("uLThptPerSlice", 30); + exp.put("1", ric1); + exp.put("2", ric2); + try { + ricConfiguration = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricConfiguration.json"))), new TypeReference<Map<String, Map<String, Integer>>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + snssaiSamplesProcessor.calculatePercentageChange(ricConfiguration, "uLThptPerSlice"); + assertEquals(exp,ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + + ricConfiguration.get("2").put("dLThptPerSlice",60); + exp.get("1").remove("dLThptPerSlice"); + snssaiSamplesProcessor.calculatePercentageChange(ricConfiguration, "dLThptPerSlice"); + assertEquals(exp,ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + } + + @Test + public void sumOfPrbsAcrossCellsTest() { + Map<String, Map<String, Integer>> ricToPrbsMapping = new HashMap<>(); + Map<String, Map<String, Integer>> ricToPrbsMappingExp = new HashMap<>(); + + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToPrbsMapping", ricToPrbsMapping); + + try { + ricToPrbsMappingExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToPrbOutput.json"))), new TypeReference<Map<String, Map<String, Integer>>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + snssaiSamplesProcessor.sumOfPrbsAcrossCells("PrbUsedDl"); + assertEquals(ricToPrbsMappingExp, ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToPrbsMapping")); + } + + @Test + public void computeThroughputTest() { + Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>(); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToThroughputMapping", ricToThroughputMapping); + + Map<String, Map<String, Integer>> ricToThroughputMappingExp = new HashMap<>(); + try { + ricToThroughputMappingExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToThroughputMappingOutput.json"))), new TypeReference<Map<String, Map<String, Integer>>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + Map<String, Integer> sliceConfiguration = new HashMap<String, Integer>(); + sliceConfiguration.put("dLThptPerSlice",120); + sliceConfiguration.put("uLThptPerSlice",100); + snssaiSamplesProcessor.computeThroughput(sliceConfiguration, 100, "PrbUsedDl"); + snssaiSamplesProcessor.computeThroughput(sliceConfiguration, 70, "PrbUsedUl"); + assertEquals(ricToThroughputMappingExp, ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + } +} diff --git a/components/slice-analysis-ms/src/test/resources/MLOutputModel.json b/components/slice-analysis-ms/src/test/resources/MLOutputModel.json new file mode 100644 index 00000000..b4082b3f --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/MLOutputModel.json @@ -0,0 +1,49 @@ +{ + "snssai":"0001-0111", + "data":[ + { + "gNBCUName":"cucpName", + "nearRTRICId": "12", + "cellCUList":[ + { + "cellLocalId":111, + "configData":{ + "maxNumberofConns":"20", + "predictedMaxNumberofConns":"25", + "lastUpdatedTS":"yyyy/MM/dd HH:mm:ss" + } + }, + { + "cellLocalId":112, + "configData":{ + "maxNumberofConns":"20", + "predictedMaxNumberofConns":"25", + "lastUpdatedTS":"yyyy/MM/dd HH:mm:ss" + } + } + ] + }, + { + "gNBCUName":"cucpName2", + "nearRTRICId": "13", + "cellCUList":[ + { + "cellLocalId":113, + "configData":{ + "maxNumberofConns":"20", + "predictedMaxNumberofConns":"25", + "lastUpdatedTS":"yyyy/MM/dd HH:mm:ss" + } + }, + { + "cellLocalId":114, + "configData":{ + "maxNumberofConns":"20", + "predictedMaxNumberofConns":"25", + "lastUpdatedTS":"yyyy/MM/dd HH:mm:ss" + } + } + ] + } + ] +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/MLOutputModel1.json b/components/slice-analysis-ms/src/test/resources/MLOutputModel1.json new file mode 100644 index 00000000..c9524807 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/MLOutputModel1.json @@ -0,0 +1,47 @@ +{ + "snssai":"0001-0111", + "data":[ + { + "gNBCUName":"cucpName", + "cellCUList":[ + { + "cellLocalId":111, + "configData":{ + "maxNumberofConns":"20", + "predictedMaxNumberofConns":"25", + "lastUpdatedTS":"yyyy/MM/dd HH:mm:ss" + } + }, + { + "cellLocalId":112, + "configData":{ + "maxNumberofConns":"20", + "predictedMaxNumberofConns":"25", + "lastUpdatedTS":"yyyy/MM/dd HH:mm:ss" + } + } + ] + }, + { + "gNBCUName":"cucpName2", + "cellCUList":[ + { + "cellLocalId":113, + "configData":{ + "maxNumberofConns":"20", + "predictedMaxNumberofConns":"25", + "lastUpdatedTS":"yyyy/MM/dd HH:mm:ss" + } + }, + { + "cellLocalId":114, + "configData":{ + "maxNumberofConns":"20", + "predictedMaxNumberofConns":"25", + "lastUpdatedTS":"yyyy/MM/dd HH:mm:ss" + } + } + ] + } + ] +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/appendData.json b/components/slice-analysis-ms/src/test/resources/appendData.json new file mode 100644 index 00000000..39802dd2 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/appendData.json @@ -0,0 +1,63 @@ +[ +[ + {"measurementObjectId":"cell1", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + }, + {"measurementObjectId":"cell2", + "pmData":{ + "PrbUsedDl":"20", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell3", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + } + ], +[ + {"measurementObjectId":"cell1", + "pmData":{ + "PrbUsedDl":"40", + "PrbUsedUl":"35" + } + }, + {"measurementObjectId":"cell2", + "pmData":{ + "PrbUsedDl":"25", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell3", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + } + ], +[ + {"measurementObjectId":"cell1", + "pmData":{ + "PrbUsedDl":"35", + "PrbUsedUl":"37" + } + }, + {"measurementObjectId":"cell2", + "pmData":{ + "PrbUsedDl":"22", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell3", + "pmData":{ + "PrbUsedDl":"25", + "PrbUsedUl":"40" + } + } +] + +]
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/average.json b/components/slice-analysis-ms/src/test/resources/average.json new file mode 100644 index 00000000..81838b6d --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/average.json @@ -0,0 +1,20 @@ +[ + {"measurementObjectId":"cell1", + "pmData":{ + "PrbUsedDl":"35", + "PrbUsedUl":"37" + } + }, + {"measurementObjectId":"cell2", + "pmData":{ + "PrbUsedDl":"22", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell3", + "pmData":{ + "PrbUsedDl":"25", + "PrbUsedUl":"40" + } + } +]
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/config_all.json b/components/slice-analysis-ms/src/test/resources/config_all.json index 21a82344..79d70202 100644 --- a/components/slice-analysis-ms/src/test/resources/config_all.json +++ b/components/slice-analysis-ms/src/test/resources/config_all.json @@ -49,6 +49,10 @@ "sliceanalysisms.pollingInterval": 20, "sliceanalysisms.cid": "sliceanalysisms-cid", "sliceanalysisms.configDb.service": "http://sdnc.onap:8181", + "sliceanalysisms.pollingTimeout":4, + "sliceanalysisms.samples": 5, + "sliceanalysisms.minPercentageChange":4, + "sliceanalysisms.initialDelaySeconds": 60000, "service_calls": { "policy-req": [] } diff --git a/components/slice-analysis-ms/src/test/resources/event.json b/components/slice-analysis-ms/src/test/resources/event.json new file mode 100644 index 00000000..b30bca81 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/event.json @@ -0,0 +1,209 @@ +{ + + "commonEventHeader":{ + + "domain":"perf3gpp", + + "eventId":"f576d0bf-ef92-45e9-a8a3-96fe7ea1d0fb", + + "sequence":0, + + "eventName":"perf3gpp_AcmeNode-Acme_pmMeasResult", + + "sourceName":"oteNB5309", + + "reportingEntityName":"", + + "priority":"Normal", + + "startEpochMicrosec":1597402800000, + + "lastEpochMicrosec":1597403700000, + + "version":"4.0", + + "vesEventListenerVersion":"7.1", + + "timeZoneOffset":"UTC+05:00" + + }, + + "perf3gppFields":{ + + "perf3gppFieldsVersion":"1.0", + + "measDataCollection":{ + + "granularityPeriod":1597407300000, + + "measuredEntityUserName":"", + + "measuredEntityDn":"ncserver1", + + "measuredEntitySoftwareVersion":"r0.1", + + "measInfoList":[ + + { + + "measInfoId":{ + + "sMeasInfoId":"some measInfoId" + + }, + + "measTypes":{ + + "sMeasTypesList":[ + + "SM.PrbUsedDl.001-100001", + + "SM.PrbUsedUl.001-100001", + + "SM.PrbUsedDl.001-100011", + + "SM.PrbUsedUl.001-100011" + + ] + + }, + + "measValuesList":[ + + { + + "measObjInstId":"chn001", + + "suspectFlag":"false", + + "measResults":[ + + { + + "p":1, + + "sValue":"55" + + }, + + { + + "p":2, + + "sValue":"53" + + }, + { + + "p":3, + + "sValue":"40" + + }, + { + + "p":4, + + "sValue":"33" + + } + + ] + + }, + + { + + "measObjInstId":"chn002", + + "suspectFlag":"false", + + "measResults":[ + + { + + "p":1, + + "sValue":"22" + + }, + + { + + "p":2, + + "sValue":"30" + + }, + { + + "p":3, + + "sValue":"22" + + }, + { + + "p":4, + + "sValue":"30" + + } + + ] + + }, + { + + "measObjInstId":"chn003", + + "suspectFlag":"false", + + "measResults":[ + + { + + "p":1, + + "sValue":"25" + + }, + + { + + "p":2, + + "sValue":"56" + + }, + { + + "p":3, + + "sValue":"50" + + }, + { + + "p":4, + + "sValue":"40" + + } + + ] + + } + + ] + + } + + ] + + } + + } + + } + diff --git a/components/slice-analysis-ms/src/test/resources/eventProcessorOutput.json b/components/slice-analysis-ms/src/test/resources/eventProcessorOutput.json new file mode 100644 index 00000000..3f29c2af --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/eventProcessorOutput.json @@ -0,0 +1,41 @@ +{"001-100001":[ + {"measurementObjectId":"chn001", + "pmData":{ + "PrbUsedDl":"55", + "PrbUsedUl":"53" + } + }, + {"measurementObjectId":"chn002", + "pmData":{ + "PrbUsedDl":"22", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"chn003", + "pmData":{ + "PrbUsedDl":"25", + "PrbUsedUl":"56" + } + } +], +"001-100011":[ + {"measurementObjectId":"chn001", + "pmData":{ + "PrbUsedDl":"40", + "PrbUsedUl":"33" + } + }, + {"measurementObjectId":"chn002", + "pmData":{ + "PrbUsedDl":"22", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"chn003", + "pmData":{ + "PrbUsedDl":"50", + "PrbUsedUl":"40" + } + } +] +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/getResponse.json b/components/slice-analysis-ms/src/test/resources/getResponse.json new file mode 100644 index 00000000..09880652 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/getResponse.json @@ -0,0 +1,21 @@ +[[ + {"measurementObjectId":"cell1", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + }, + {"measurementObjectId":"cell2", + "pmData":{ + "PrbUsedDl":"20", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell3", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + } + ] +]
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/measurementObjectList.json b/components/slice-analysis-ms/src/test/resources/measurementObjectList.json new file mode 100644 index 00000000..f398da8c --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/measurementObjectList.json @@ -0,0 +1,42 @@ +[ +[ + {"measurementObjectId":"cell1", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + }, + {"measurementObjectId":"cell2", + "pmData":{ + "PrbUsedDl":"20", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell3", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + } + ], +[ + {"measurementObjectId":"cell1", + "pmData":{ + "PrbUsedDl":"40", + "PrbUsedUl":"35" + } + }, + {"measurementObjectId":"cell2", + "pmData":{ + "PrbUsedDl":"25", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell3", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + } + ] +]
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/onsetMessage.json b/components/slice-analysis-ms/src/test/resources/onsetMessage.json new file mode 100644 index 00000000..7f91ad12 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/onsetMessage.json @@ -0,0 +1,46 @@ +{ + "closedLoopControlName": "ControlLoop-Slicing-116d7b00-dbeb-4d03-8719-d0a658fa735b", + "closedLoopAlarmStart": 1463679805324, + "closedLoopEventClient": "microservice.sliceAnalysisMS", + "closedLoopEventStatus": "ONSET", + "requestID": "c7c6a4aa-bb61-4a15-b831-ba1472dd4a65", + "target_type": "VNF", + "target": "vserver.vserver-name", + "AAI": { + "vserver.is-closed-loop-disabled": "false", + "vserver.prov-status": "ACTIVE", + "vserver.vserver-name": "e51a9b12-f313-11ea-adc1-0242ac120003" + }, + "payload": { + "name":"e51a9b12-f313-11ea-adc1-0242ac120003", + "globalSubscriberId":"5GCustomer", + "subscriptionServiceType":"5G", + "networkType":"AN", + "serviceInstanceID":"e51a9b12-f313-11ea-adc1-0242ac120003", + "additionalProperties":{ + "modifyAction":"reconfigure", + "snssaiList":[ + "001-100001" + ], + "sliceProfileId":"e51a9b12-f313-11ea-adc1-0242ac120002", + "resourceConfig":{ + "1":{ + "dLThptPerSlice":50, + "uLThptPerSlice":40 + }, + "2":{ + "dLThptPerSlice":50, + "uLThptPerSlice":30 + } + }, + "nsiInfo":{ + "nsiId":"UUID", + "nsiName":"" + }, + "scriptName": "AN" + } + +}, + "from": "DCAE", + "version": "1.0.2" +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/ricConfiguration.json b/components/slice-analysis-ms/src/test/resources/ricConfiguration.json new file mode 100644 index 00000000..add9666a --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/ricConfiguration.json @@ -0,0 +1,10 @@ +{ +"1":{ + "dLThptPerSlice":50, + "uLThptPerSlice":38 + }, + "2":{ + "dLThptPerSlice":50, + "uLThptPerSlice":40 + } +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/ricToCellMapping.json b/components/slice-analysis-ms/src/test/resources/ricToCellMapping.json new file mode 100644 index 00000000..f685580f --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/ricToCellMapping.json @@ -0,0 +1,4 @@ +{ +"1":["cell1","cell2","cell4"], +"2":["cell3","cell5","cell6"] +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/ricToPrbMap.json b/components/slice-analysis-ms/src/test/resources/ricToPrbMap.json new file mode 100644 index 00000000..c6194f02 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/ricToPrbMap.json @@ -0,0 +1,10 @@ +{ + "1":{ + "PrbUsedDl":50, + "PrbUsedUl":40 + }, + "2":{ + "PrbUsedDl":50, + "PrbUsedUl":30 + } +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/ricToPrbOutput.json b/components/slice-analysis-ms/src/test/resources/ricToPrbOutput.json new file mode 100644 index 00000000..8f134782 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/ricToPrbOutput.json @@ -0,0 +1,8 @@ +{ + "1":{ + "PrbUsedDl":90 + }, + "2":{ + "PrbUsedDl":85 + } +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/ricToThroughputMappingOutput.json b/components/slice-analysis-ms/src/test/resources/ricToThroughputMappingOutput.json new file mode 100644 index 00000000..bff52dc9 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/ricToThroughputMappingOutput.json @@ -0,0 +1,10 @@ +{ + "1":{ + "dLThptPerSlice":60, + "uLThptPerSlice":57 + }, + "2":{ + "dLThptPerSlice":60, + "uLThptPerSlice":43 + } +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/serviceDetails.json b/components/slice-analysis-ms/src/test/resources/serviceDetails.json new file mode 100644 index 00000000..accde978 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/serviceDetails.json @@ -0,0 +1,12 @@ +{ + "sNSSAI":"001-100001", + + "ranNFNSSIId":"e51a9b12-f313-11ea-adc1-0242ac120003", + + "sliceProfileId":"e51a9b12-f313-11ea-adc1-0242ac120002", + + "globalSubscriberId":"5GCustomer", + + "subscriptionServiceType":"5G" + +}
\ No newline at end of file diff --git a/components/slice-analysis-ms/src/test/resources/sliceMeasurementList.json b/components/slice-analysis-ms/src/test/resources/sliceMeasurementList.json new file mode 100644 index 00000000..1ab63aa4 --- /dev/null +++ b/components/slice-analysis-ms/src/test/resources/sliceMeasurementList.json @@ -0,0 +1,39 @@ +[ + {"measurementObjectId":"cell1", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + }, + {"measurementObjectId":"cell2", + "pmData":{ + "PrbUsedDl":"20", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell3", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + }, + {"measurementObjectId":"cell4", + "pmData":{ + "PrbUsedDl":"40", + "PrbUsedUl":"35" + } + }, + {"measurementObjectId":"cell5", + "pmData":{ + "PrbUsedDl":"25", + "PrbUsedUl":"30" + } + }, + {"measurementObjectId":"cell6", + "pmData":{ + "PrbUsedDl":"30", + "PrbUsedUl":"40" + } + } + +]
\ No newline at end of file |