diff options
Diffstat (limited to 'components')
10 files changed, 314 insertions, 188 deletions
diff --git a/components/slice-analysis-ms/ChangeLog.md b/components/slice-analysis-ms/ChangeLog.md index 0796670f..aa92c9cd 100644 --- a/components/slice-analysis-ms/ChangeLog.md +++ b/components/slice-analysis-ms/ChangeLog.md @@ -16,9 +16,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [DCAEGEN2-3255](https://jira.onap.org/browse/DCAEGEN2-3255) - Fix bug of application failed to start - [DCAEGEN2-3264](https://jira.onap.org/browse/DCAEGEN2-3264) - Fix bug that cll service instance info didn't get updated when a cll service is deleted - + - [DCAEGEN2-3240](https://jira.onap.org/browse/DCAEGEN2-3240) - Implement runtime service configuration + - [DCAEGEN2-3273](https://jira.onap.org/browse/DCAEGEN2-3273) - Fix bug that config thread hang up when cbs policy is empty + + - [DCAEGEN2-3270](https://jira.onap.org/browse/DCAEGEN2-3270) - Dcae slicems startup error, breaking the circular dependency. + ## [1.1.4] - 2022/07/28 - [DCAEGEN2-3120](https://jira.onap.org/browse/DCAEGEN2-3120) - Enhance sliceanalysis MS to use DCAE SDK dmaap-client lib diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java index 4b880e3d..fff156cc 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/dmaap/VesNotificationCallback.java @@ -95,7 +95,6 @@ public class VesNotificationCallback implements NotificationCallback { JsonNode node = obj.readTree(msg); JsonNode notificationNode = node.get(EVENT).get(NOTIFICATIONFIELDS); output = obj.treeToValue(notificationNode, NotificationFields.class); - //Filter out target notification changeIdentifier and changeType notifChangeIdentifier = output.getChangeIdentifier(); notifChangeType = output.getChangeType(); @@ -120,7 +119,7 @@ public class VesNotificationCallback implements NotificationCallback { */ public void updateCllInstance(){ Set<String> instances = aaiService.fetchAllCllInstances(); - log.error("instances {}", instances); + log.debug("All valid instances are {}", instances); ccvpnPmDatastore.updateCllInstances(instances); } diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConfigThread.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConfigThread.java index 61e445d0..88477eb0 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConfigThread.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ConfigThread.java @@ -1,77 +1,75 @@ -/*******************************************************************************
- * ============LICENSE_START=======================================================
- * slice-analysis-ms
- * ================================================================================
- * Copyright (C) 2022 Huawei Technologies Co., Ltd.
- * ==============================================================================
- * 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.models.ConfigPolicy;
-import org.onap.slice.analysis.ms.service.ccvpn.CCVPNPmDatastore;
-import org.onap.slice.analysis.ms.utils.SpringContextUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This thread is used to convert ccvpn runtime configurations from policy to our local memory CCVPNPmDatastore
- */
-public class ConfigThread extends Thread{
-
- CCVPNPmDatastore ccvpnPmDatastore = (CCVPNPmDatastore) SpringContextUtil.getBean(CCVPNPmDatastore.class);
- private static Logger log = LoggerFactory.getLogger(ConfigThread.class);
-
-
- public ConfigThread () {
- super();
- }
-
- public void run() {
- log.info("Config Thread is starting...");
- boolean done = false;
- while(!done) {
- try {
- Thread.sleep(1000);
- ConfigPolicy configPolicy = ConfigPolicy.getInstance();
- if(configPolicy != null) {
- // config content
- String cllId = null;
- Boolean clBwAssuranceStatus = null;
- int originalBw = 0;
- if(configPolicy.getConfig().containsKey("cllId")){
- cllId = String.valueOf(configPolicy.getConfig().get("cllId"));
- }
- if(configPolicy.getConfig().containsKey("closedLoopStatus")){
- clBwAssuranceStatus = String.valueOf(configPolicy.getConfig().get("closedLoopStatus")).equalsIgnoreCase("true");
- }
- if(configPolicy.getConfig().containsKey("originalBw")){
- originalBw = Integer.parseInt(String.valueOf(configPolicy.getConfig().get("originalBw")));
- }
- if(cllId!=null && clBwAssuranceStatus!=null){
- ccvpnPmDatastore.updateConfigFromPolicy(cllId, clBwAssuranceStatus, originalBw);
- }
- } else {
- log.debug("Config policy is empty, nothing to update.");
- }
-
- } catch (Exception e) {
- log.error("Exception in Config Thread ", e);
- done = true;
- }
- }
- }
-}
+/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Technologies Co., Ltd. + * ============================================================================== + * 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.models.ConfigPolicy; +import org.onap.slice.analysis.ms.service.ccvpn.CCVPNPmDatastore; +import org.onap.slice.analysis.ms.utils.BeanUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This thread is used to convert ccvpn runtime configurations from policy to our local memory CCVPNPmDatastore + */ +public class ConfigThread extends Thread{ + + CCVPNPmDatastore ccvpnPmDatastore = BeanUtil.getBean(CCVPNPmDatastore.class); + private static Logger log = LoggerFactory.getLogger(ConfigThread.class); + + public ConfigThread () { + super(); + } + + public void run() { + log.info("Config Thread is starting..."); + boolean done = false; + while(!done) { + try { + Thread.sleep(1000); + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + if(configPolicy != null && configPolicy.getConfig() != null) { + String cllId = null; + Boolean clBwAssuranceStatus = null; + int originalBw = 0; + if(configPolicy.getConfig().containsKey("cllId")){ + cllId = String.valueOf(configPolicy.getConfig().get("cllId")); + } + if(configPolicy.getConfig().containsKey("closedLoopStatus")){ + clBwAssuranceStatus = String.valueOf(configPolicy.getConfig().get("closedLoopStatus")).equalsIgnoreCase("true"); + } + if(configPolicy.getConfig().containsKey("originalBw")){ + originalBw = Integer.parseInt(String.valueOf(configPolicy.getConfig().get("originalBw"))); + } + if(cllId!=null && clBwAssuranceStatus!=null){ + ccvpnPmDatastore.updateConfigFromPolicy(cllId, clBwAssuranceStatus, originalBw); + } + } else { + log.error("Config policy is empty, nothing to update."); + } + + } catch (Exception e) { + log.error("Exception in Config Thread ", e); + done = true; + } + } + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java index 7ca100d1..c5e3151a 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluator.java @@ -51,16 +51,9 @@ public class BandwidthEvaluator { private Configuration configuration; @Autowired - AaiService aaiService; - - @Autowired - CCVPNPmDatastore ccvpnPmDatastore; - - @Autowired StrategyFactory strategyFactory; private Loop evaluationEventLoop; - private Loop aaiEventLoop; private static final Event KILL_PILL = new SimpleEvent(null, 0); private static final int DEFAULT_EVAL_INTERVAL = 5; @@ -98,33 +91,6 @@ public class BandwidthEvaluator { } }; - /** - * AAI data consumer loop - */ - aaiEventLoop = new Loop("AAIEventLoop"){ - @Override - public void process(Event event) { - if (event.type() == SimpleEvent.Type.AAI_BW_REQ){ - log.debug("=== Processing new AAI network policy query at: {} ===", event.time()); - String serviceId = (String) event.subject(); - Map<String, Integer> maxBandwidthData = aaiService.fetchMaxBandwidthOfService(serviceId); - if (maxBandwidthData.get("maxBandwidth") != null){ - log.info("Successfully retrieved bandwidth info from AAI; service: {}, bandwidth: {}", - serviceId, maxBandwidthData.get("maxBandwidth")); - int bwValue = maxBandwidthData.get("maxBandwidth").intValue(); - if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) == 0){ - ccvpnPmDatastore.updateProvBw(serviceId, bwValue, true); - } else if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) != bwValue) { - log.info("Service modification complete; serviceId: {} with new bandwidth: {}", serviceId, bwValue); - ccvpnPmDatastore.updateProvBw(serviceId, bwValue, true); - ccvpnPmDatastore.updateSvcState(serviceId, ServiceState.RUNNING); - log.debug("Service state of {} is changed to running", serviceId); - } - } - log.debug("=== Processing AAI network policy query complete ==="); - } - } - }; scheduleEvaluation(); } @@ -134,7 +100,6 @@ public class BandwidthEvaluator { @PreDestroy public void stop(){ stopScheduleEvaluation(); - aaiEventLoop.stop(); evaluationEventLoop.stop(); } @@ -164,9 +129,7 @@ public class BandwidthEvaluator { public void post(@NonNull Event event){ log.info("A new event triggered, type: {}, subject: {}, at time: {}", event.type(), event.subject(), event.time()); - if (event.type() == SimpleEvent.Type.AAI_BW_REQ) { - aaiEventLoop.add(event); - } else if (event.type() == SimpleEvent.Type.PERIODIC_CHECK) { + if (event.type() == SimpleEvent.Type.PERIODIC_CHECK) { evaluationEventLoop.add(event); } else if (event.type() == SimpleEvent.Type.ONDEMAND_CHECK) { evaluationEventLoop.add(event); diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java index 5f3ce311..3e6c4746 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastore.java @@ -25,7 +25,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; import lombok.Getter; -import lombok.Setter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -200,15 +199,6 @@ public class CCVPNPmDatastore { public void updateCllInstances(Set<String> allValidCllInstances){ Set<String> invalidCllIds; invalidCllIds= filterInvalidCllIds(allValidCllInstances, svcStatus.keySet()); - svcStatus.keySet().removeAll(invalidCllIds); - invalidCllIds = filterInvalidCllIds(allValidCllInstances, endpointToProvBw.keySet()); - endpointToProvBw.keySet().removeAll(invalidCllIds); - invalidCllIds = filterInvalidCllIds(allValidCllInstances, upperBoundBw.keySet()); - upperBoundBw.keySet().removeAll(invalidCllIds); - invalidCllIds = filterInvalidCllIds(allValidCllInstances, endpointToOriginalBw.keySet()); - endpointToOriginalBw.keySet().removeAll(invalidCllIds); - invalidCllIds = filterInvalidCllIds(allValidCllInstances, closedLoopBwAssuranceStatus.keySet()); - closedLoopBwAssuranceStatus.keySet().removeAll(invalidCllIds); for(String invalidCllId : invalidCllIds) { log.debug("drop {} from endpointToUsedBw", invalidCllId); endpointToUsedBw.entrySet().stream().dropWhile(map -> map.getKey().getCllId().equalsIgnoreCase(invalidCllId)); @@ -220,6 +210,15 @@ public class CCVPNPmDatastore { } } } + svcStatus.keySet().removeAll(invalidCllIds); + invalidCllIds = filterInvalidCllIds(allValidCllInstances, endpointToProvBw.keySet()); + endpointToProvBw.keySet().removeAll(invalidCllIds); + invalidCllIds = filterInvalidCllIds(allValidCllInstances, upperBoundBw.keySet()); + upperBoundBw.keySet().removeAll(invalidCllIds); + invalidCllIds = filterInvalidCllIds(allValidCllInstances, endpointToOriginalBw.keySet()); + endpointToOriginalBw.keySet().removeAll(invalidCllIds); + invalidCllIds = filterInvalidCllIds(allValidCllInstances, closedLoopBwAssuranceStatus.keySet()); + closedLoopBwAssuranceStatus.keySet().removeAll(invalidCllIds); } /** diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java index ec864aa0..66dc6dc0 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategy.java @@ -59,7 +59,7 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{ private static double precision; // in Mbps; @Autowired - BandwidthEvaluator bandwidthEvaluator; + NetworkPolicyMonitor networkPolicyMonitor; @Autowired CCVPNPmDatastore ccvpnPmDatastore; @@ -166,11 +166,11 @@ public class FixedUpperBoundStrategy implements EvaluationStrategy{ } /** - * Post/broadcast event to the BandwidthEvaluator + * Post/broadcast event to the networkPolicyMonitor * @param event event object */ private void post(Event event){ - bandwidthEvaluator.post(event); + networkPolicyMonitor.post(event); } private void loadConfig() { diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java index 261794c4..6b552165 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/FlexibleThresholdStrategy.java @@ -41,7 +41,7 @@ import java.util.stream.Collectors; */ @Component public class FlexibleThresholdStrategy implements EvaluationStrategy{ - private static Logger log = LoggerFactory.getLogger(FixedUpperBoundStrategy.class); + private static Logger log = LoggerFactory.getLogger(FlexibleThresholdStrategy.class); private Configuration configuration; private static final String TYPE_NAME = "FlexibleThresholdStrategy"; private static final String SERVICE_INSTANCE_LOCATION_ID = "service-instance-location-id"; @@ -63,7 +63,7 @@ public class FlexibleThresholdStrategy implements EvaluationStrategy{ private static double precision; // in Mbps; @Autowired - BandwidthEvaluator bandwidthEvaluator; + NetworkPolicyMonitor networkPolicyMonitor; @Autowired CCVPNPmDatastore ccvpnPmDatastore; @@ -174,11 +174,11 @@ public class FlexibleThresholdStrategy implements EvaluationStrategy{ } /** - * Post/broadcast event to the BandwidthEvaluator + * Post/broadcast event to the networkPolicyMonitor * @param event event object */ private void post(Event event){ - bandwidthEvaluator.post(event); + networkPolicyMonitor.post(event); } private void loadConfig() { diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitor.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitor.java new file mode 100644 index 00000000..9948804a --- /dev/null +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitor.java @@ -0,0 +1,164 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada 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.ccvpn; + +import lombok.NonNull; +import org.onap.slice.analysis.ms.aai.AaiService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * Actor that processes aai network-policy query request + */ +@Component +public class NetworkPolicyMonitor { + private static Logger log = LoggerFactory.getLogger(NetworkPolicyMonitor.class); + private Loop aaiEventLoop; + private static final Event KILL_PILL = new SimpleEvent(null, 0); + + @Autowired + AaiService aaiService; + + @Autowired + CCVPNPmDatastore ccvpnPmDatastore; + + /** + * Initialize and start the NetworkPolicyMonitor. + */ + @PostConstruct + public void init() { + /** + * AAI data consumer loop + */ + aaiEventLoop = new Loop("AAIEventLoop"){ + @Override + public void process(Event event) { + if (event.type() == SimpleEvent.Type.AAI_BW_REQ){ + log.debug("=== Processing new AAI network policy query at: {} ===", event.time()); + String serviceId = (String) event.subject(); + Map<String, Integer> maxBandwidthData = aaiService.fetchMaxBandwidthOfService(serviceId); + if (maxBandwidthData.get("maxBandwidth") != null){ + log.debug("Successfully retrieved bandwidth info from AAI; service: {}, bandwidth: {}", + serviceId, maxBandwidthData.get("maxBandwidth")); + int bwValue = maxBandwidthData.get("maxBandwidth").intValue(); + if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) == 0){ + ccvpnPmDatastore.updateProvBw(serviceId, bwValue, true); + log.debug("Provision bw of cll {} updated from 0 to {}, max bw is {}", serviceId, ccvpnPmDatastore.getProvBwOfSvc(serviceId), bwValue); + } else if (ccvpnPmDatastore.getProvBwOfSvc(serviceId) != bwValue) { + log.debug("Service modification complete; serviceId: {} update prov bw from {} to {}", serviceId, ccvpnPmDatastore.getProvBwOfSvc(serviceId), bwValue); + ccvpnPmDatastore.updateProvBw(serviceId, bwValue, true); + ccvpnPmDatastore.updateSvcState(serviceId, ServiceState.RUNNING); + log.debug("Service state of {} is changed to running, {}", serviceId, ccvpnPmDatastore.getStatusOfSvc(serviceId)); + } + } + log.debug("=== Processing AAI network policy query complete ==="); + } + } + }; + } + + /** + * Post/broadcast event between Loops + * @param event event object + */ + public void post(@NonNull Event event) { + if (event.type() == SimpleEvent.Type.AAI_BW_REQ) { + aaiEventLoop.add(event); + } + } + /** + * Inner loop implementation. Each loop acts like an actor. + */ + private abstract class Loop implements Runnable { + private final String name; + private volatile boolean running; + private final BlockingQueue<Event> eventsQueue; + private final ExecutorService executor; + private volatile Future<?> dispatchFuture; + + /** + * Constructor that accepts a loop name + * @param name name of this loop + */ + Loop(String name){ + this.name = name; + executor = Executors.newSingleThreadExecutor(); + eventsQueue = new LinkedBlockingQueue<>(); + dispatchFuture = executor.submit(this); + } + + /** + * Add new event to this loop + * @param evt Event + * @return true + */ + public boolean add(Event evt) { + return eventsQueue.add(evt); + } + + /** + * Running loop that process event accordingly + */ + @Override + public void run(){ + running = true; + log.info("NetworkPolicyMonitor -- {} initiated", this.name); + while (running){ + try{ + Event event = eventsQueue.take(); + if (event == KILL_PILL){ + break; + } + process(event); + } catch (InterruptedException e){ + log.warn("Process loop interrupted"); + } catch (Exception | Error e){ + log.warn("Process loop hit an error {}", e.getMessage()); + } + } + } + + /** + * Operation defined by subclass for different event processing + * @param event incoming event + */ + abstract public void process(Event event); + + /** + * Stop this loop + */ + public void stop(){ + running = false; + add(KILL_PILL); + } + } +} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java index 824731fc..2feba83d 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java +++ b/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactory.java @@ -35,7 +35,7 @@ public class StrategyFactory { private static Logger log = LoggerFactory.getLogger(StrategyFactory.class); @Autowired - List<EvaluationStrategy> strategies; + public List<EvaluationStrategy> strategies; private StrategyFactory() {} diff --git a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/SpringContextUtil.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitorTest.java index ebe227d2..23366ab9 100644 --- a/components/slice-analysis-ms/src/main/java/org/onap/slice/analysis/ms/utils/SpringContextUtil.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/NetworkPolicyMonitorTest.java @@ -1,52 +1,51 @@ -/*******************************************************************************
- * ============LICENSE_START=======================================================
- * slice-analysis-ms
- * ================================================================================
- * Copyright (C) 2022 Huawei Technologies Co., Ltd.
- * ==============================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- *
- *******************************************************************************/
-
-package org.onap.slice.analysis.ms.utils;
-
-import org.springframework.beans.BeansException;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * This is provided for threads to get bean.
- */
-@Configuration
-public class SpringContextUtil implements ApplicationContextAware {
- private static ApplicationContext applicationContext = null;
-
- @Override
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- SpringContextUtil.applicationContext = applicationContext;
- }
-
- public static ApplicationContext getApplicationContext() {
- return applicationContext;
- }
-
- public static Object getBean(String beanName) {
- return applicationContext.getBean(beanName);
- }
-
- public static Object getBean(Class c) {
- return applicationContext.getBean(c);
- }
-}
+/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada 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.ccvpn; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BandwidthEvaluatorTest.class) +public class NetworkPolicyMonitorTest { + + @Spy + @InjectMocks + NetworkPolicyMonitor NetworkPolicyMonitor; + @Test + public void initTest() { + NetworkPolicyMonitor.init(); + Mockito.verify(NetworkPolicyMonitor, Mockito.atLeastOnce()).init(); + } + + @Test + public void postTest() { + Event evt = new SimpleEvent(null, "{}"); + NetworkPolicyMonitor.post(evt); + Mockito.verify(NetworkPolicyMonitor, Mockito.atLeastOnce()).post(Mockito.any(Event.class)); + } +} |