summaryrefslogtreecommitdiffstats
path: root/controlloop/templates
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-04-05 11:58:19 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-05 11:58:19 +0000
commitc3f8dd9e309bcbf2c466e551f3c03125e5d3bbb3 (patch)
treea753fd4f96f54e7c3a86e2f57a9c2a04181e237e /controlloop/templates
parent07e29100f99036fe7170b7ff43dca651983b888d (diff)
parentc4c99f0d6cb5eeb7475ccac5c00c960b1d8f83ed (diff)
Merge "Add CCVPN Bandwidth on demand policy"
Diffstat (limited to 'controlloop/templates')
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/CCVPNBW.yaml36
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.bw.onset.json25
-rw-r--r--controlloop/templates/archetype-cl-usecases/src/main/resources/META-INF/maven/archetype-metadata.xml10
-rw-r--r--controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/CCVPNBW.yaml36
-rw-r--r--controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/ccvpnbw.brmsgw.params.json7
-rw-r--r--controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.bw.onset.json25
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java373
-rw-r--r--controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml37
8 files changed, 549 insertions, 0 deletions
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/CCVPNBW.yaml b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/CCVPNBW.yaml
new file mode 100644
index 000000000..7b296ce26
--- /dev/null
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/CCVPNBW.yaml
@@ -0,0 +1,36 @@
+# Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved
+#
+# 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.
+controlLoop:
+ version: 2.0.0
+ controlLoopName: ${ccvpnBwClosedLoopControlName}
+ trigger_policy: unique-policy-id-16-Reroute
+ timeout: 3600
+ abatement: false
+
+policies:
+ - id: unique-policy-id-16-BandwidthOnDemand
+ name: CCVPNBandwidthOnDemand
+ description:
+ actor: SDNC
+ recipe: BandwidthOnDemand
+ target:
+ type: VM
+ retry: 3
+ timeout: 1200
+ success: final_success
+ failure: final_failure
+ failure_timeout: final_failure_timeout
+ failure_retries: final_failure_retries
+ failure_exception: final_failure_exception
+ failure_guard: final_failure_guard
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.bw.onset.json b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.bw.onset.json
new file mode 100644
index 000000000..b2dbb7ba3
--- /dev/null
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.bw.onset.json
@@ -0,0 +1,25 @@
+{
+ "closedLoopEventClient": "DCAE.HolmesInstance",
+ "policyVersion": "2.0.0",
+ "policyName": "CCVPNBandwidthOnDemand",
+ "policyScope": "service=SITEService,type=SampleType,closedLoopControlName=CL-CCVPN-d925ed73-8231-4d02-9545-db4e101f88f8",
+ "target_type": "VM",
+ "AAI": {
+ "vserver.vserver-name" : "TBD",
+ "globalSubscriberId" : "e151059a-d924-4629-845f-264db19e50b4",
+ "serviceType" : "service-ccvpn",
+ "service-instance.service-instance-id" : "298dad9933BBBasa",
+ "vserver.is-closed-loop-disabled" : "false",
+ "vserver.prov-status":"ACTIVE",
+ "bandwidth" : "500",
+ "bandwidth-change-time":"20190321-10:59:32:321",
+ "vnfId": "2fbf0f93-c46e-42ed-9a9b-68aaa09ea11d"
+ },
+ "closedLoopAlarmStart": "1484677482204798",
+ "closedLoopEventStatus": "ONSET",
+ "closedLoopControlName": "${ccvpnBwClosedLoopControlName}",
+ "version": "1.0.2",
+ "target": "vserver.vserver-name",
+ "requestID": "97964e10-686e-4790-8c45-bdfa61df880f",
+ "from": "DCAE"
+} \ No newline at end of file
diff --git a/controlloop/templates/archetype-cl-usecases/src/main/resources/META-INF/maven/archetype-metadata.xml b/controlloop/templates/archetype-cl-usecases/src/main/resources/META-INF/maven/archetype-metadata.xml
index 18151b58d..e27e3e401 100644
--- a/controlloop/templates/archetype-cl-usecases/src/main/resources/META-INF/maven/archetype-metadata.xml
+++ b/controlloop/templates/archetype-cl-usecases/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -4,6 +4,7 @@
archetype-closed-loop-demo-rules
================================================================================
Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ Modifications Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -70,6 +71,15 @@
<requiredProperty key="ccvpnControlLoopYaml">
<defaultValue>controlLoop%3A%0D%0A++version%3A+2.0.0%0D%0A++controlLoopName%3A+ControlLoop-CCVPN-2179b738-fd36-4843-a71a-a8c24c70c66b%0D%0A++trigger_policy%3A+unique-policy-id-16-Reroute%0D%0A++timeout%3A+3600%0D%0A++abatement%3A+false%0D%0A+%0D%0Apolicies%3A%0D%0A++-+id%3A+unique-policy-id-16-Reroute%0D%0A++++name%3A+Connectivity Reroute%0D%0A++++description%3A%0D%0A++++actor%3A+SDNC%0D%0A++++recipe%3A+Reroute%0D%0A++++target%3A%0D%0A++++++type%3A+VM%0D%0A++++retry%3A+3%0D%0A++++timeout%3A+1200%0D%0A++++success%3A+final_success%0D%0A++++failure%3A+final_failure%0D%0A++++failure_timeout%3A+final_failure_timeout%0D%0A++++failure_retries%3A+final_failure_retries%0D%0A++++failure_exception%3A+final_failure_exception%0D%0A++++failure_guard%3A+final_failure_guard</defaultValue>
</requiredProperty>
+ <requiredProperty key="ccvpnBwClosedLoopControlName">
+ <defaultValue>ControlLoop-CCVPN-2179b738-fd36-4843-a71a-a8c24c70c22b</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="ccvpnBwPolicyName">
+ <defaultValue>CCVPNBandwidthOnDemand</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="ccvpnBwControlLoopYaml">
+ <defaultValue>controlLoop%3A%0D%0A++version%3A+2.0.0%0D%0A++controlLoopName%3A+ControlLoop-CCVPN-2179b738-fd36-4843-a71a-a8c24c70c22b%0D%0A++trigger_policy%3A+unique-policy-id-16-BandwidthOnDemand%0D%0A++timeout%3A+3600%0D%0A++abatement%3A+false%0D%0A%0D%0Apolicies%3A%0D%0A++-+id%3A+unique-policy-id-16-BandwidthOnDemand%0D%0A++++name%3A+CCVPNBandwidthOnDemand%0D%0A++++description%3A%0D%0A++++actor%3A+SDNC%0D%0A++++recipe%3A+BandwidthOnDemand%0D%0A++++target%3A%0D%0A++++++type%3A+VM%0D%0A++++retry%3A+3%0D%0A++++timeout%3A+1200%0D%0A++++success%3A+final_success%0D%0A++++failure%3A+final_failure%0D%0A++++failure_timeout%3A+final_failure_timeout%0D%0A++++failure_retries%3A+final_failure_retries%0D%0A++++failure_exception%3A+final_failure_exception%0D%0A++++failure_guard%3A+final_failure_guard</defaultValue>
+ </requiredProperty>
<requiredProperty key="policyScope">
<defaultValue>DCAE</defaultValue>
</requiredProperty>
diff --git a/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/CCVPNBW.yaml b/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/CCVPNBW.yaml
new file mode 100644
index 000000000..7b296ce26
--- /dev/null
+++ b/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/CCVPNBW.yaml
@@ -0,0 +1,36 @@
+# Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved
+#
+# 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.
+controlLoop:
+ version: 2.0.0
+ controlLoopName: ${ccvpnBwClosedLoopControlName}
+ trigger_policy: unique-policy-id-16-Reroute
+ timeout: 3600
+ abatement: false
+
+policies:
+ - id: unique-policy-id-16-BandwidthOnDemand
+ name: CCVPNBandwidthOnDemand
+ description:
+ actor: SDNC
+ recipe: BandwidthOnDemand
+ target:
+ type: VM
+ retry: 3
+ timeout: 1200
+ success: final_success
+ failure: final_failure
+ failure_timeout: final_failure_timeout
+ failure_retries: final_failure_retries
+ failure_exception: final_failure_exception
+ failure_guard: final_failure_guard
diff --git a/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/ccvpnbw.brmsgw.params.json b/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/ccvpnbw.brmsgw.params.json
new file mode 100644
index 000000000..6425b4098
--- /dev/null
+++ b/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/ccvpnbw.brmsgw.params.json
@@ -0,0 +1,7 @@
+{
+ "closedLoopControlName": "${ccvpnBwClosedLoopControlName}",
+ "controlLoopYaml": "${ccvpnBwControlLoopYaml}",
+ "policyName": "${ccvpnBwPolicyName}",
+ "policyScope": "${policyScope}",
+ "policyVersion": "${policyVersion}"
+} \ No newline at end of file
diff --git a/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.bw.onset.json b/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.bw.onset.json
new file mode 100644
index 000000000..b2dbb7ba3
--- /dev/null
+++ b/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.bw.onset.json
@@ -0,0 +1,25 @@
+{
+ "closedLoopEventClient": "DCAE.HolmesInstance",
+ "policyVersion": "2.0.0",
+ "policyName": "CCVPNBandwidthOnDemand",
+ "policyScope": "service=SITEService,type=SampleType,closedLoopControlName=CL-CCVPN-d925ed73-8231-4d02-9545-db4e101f88f8",
+ "target_type": "VM",
+ "AAI": {
+ "vserver.vserver-name" : "TBD",
+ "globalSubscriberId" : "e151059a-d924-4629-845f-264db19e50b4",
+ "serviceType" : "service-ccvpn",
+ "service-instance.service-instance-id" : "298dad9933BBBasa",
+ "vserver.is-closed-loop-disabled" : "false",
+ "vserver.prov-status":"ACTIVE",
+ "bandwidth" : "500",
+ "bandwidth-change-time":"20190321-10:59:32:321",
+ "vnfId": "2fbf0f93-c46e-42ed-9a9b-68aaa09ea11d"
+ },
+ "closedLoopAlarmStart": "1484677482204798",
+ "closedLoopEventStatus": "ONSET",
+ "closedLoopControlName": "${ccvpnBwClosedLoopControlName}",
+ "version": "1.0.2",
+ "target": "vserver.vserver-name",
+ "requestID": "97964e10-686e-4790-8c45-bdfa61df880f",
+ "from": "DCAE"
+} \ No newline at end of file
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java
new file mode 100644
index 000000000..395ecc234
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java
@@ -0,0 +1,373 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * ================================================================================
+ * 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.policy.template.demo;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+import java.util.UUID;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.kie.api.runtime.KieSession;
+import org.kie.api.runtime.rule.FactHandle;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
+import org.onap.policy.common.endpoints.event.comm.TopicListener;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.controlloop.ControlLoopEventStatus;
+import org.onap.policy.controlloop.ControlLoopNotificationType;
+import org.onap.policy.controlloop.ControlLoopTargetType;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.VirtualControlLoopNotification;
+import org.onap.policy.controlloop.policy.ControlLoopPolicy;
+import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolParams;
+import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
+import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.utils.logging.LoggerUtil;
+import org.onap.policy.sdnc.SdncRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CcvpnBwControlLoopTest implements TopicListener {
+
+ private static final Logger logger = LoggerFactory.getLogger(CcvpnBwControlLoopTest.class);
+
+ private static List<? extends TopicSink> noopTopics;
+
+ private static KieSession kieSession;
+ private static SupportUtil.Pair<ControlLoopPolicy, String> pair;
+
+ static {
+ /* Set environment properties */
+ SupportUtil.setAaiProps();
+ SupportUtil.setSdncProps();
+ LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
+ }
+
+ /**
+ * Setup the simulator.
+ */
+ @BeforeClass
+ public static void setUpSimulator() {
+ PolicyEngine.manager.configure(new Properties());
+ assertTrue(PolicyEngine.manager.start());
+ Properties noopSinkProperties = new Properties();
+ noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "POLICY-CL-MGT");
+ noopSinkProperties.put("noop.sink.topics.POLICY-CL-MGT.events",
+ "org.onap.policy.controlloop.VirtualControlLoopNotification");
+ noopSinkProperties.put("noop.sink.topics.POLICY-CL-MGT.events.custom.gson",
+ "org.onap.policy.controlloop.util.Serialization,gsonPretty");
+ noopTopics = TopicEndpoint.manager.addTopicSinks(noopSinkProperties);
+
+ EventProtocolCoder.manager.addEncoder(EventProtocolParams.builder()
+ .groupId("junit.groupId")
+ .artifactId("junit.artifactId")
+ .topic("POLICY-CL-MGT")
+ .eventClass("org.onap.policy.controlloop.VirtualControlLoopNotification")
+ .protocolFilter(new JsonProtocolFilter())
+ .modelClassLoaderHash(1111));
+
+ try {
+ SupportUtil.buildAaiSim();
+ SupportUtil.buildSdncSim();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ /*
+ *
+ * Start the kie session
+ */
+ try {
+ kieSession = startSession(
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
+ + "src/main/resources/__closedLoopControlName__.drl",
+ "src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml", "type=operational",
+ "BandwidthOnDemand", "2.0.0");
+ } catch (IOException e) {
+ e.printStackTrace();
+ logger.debug("Could not create kieSession");
+ fail("Could not create kieSession");
+ }
+ }
+
+ /**
+ * Tear down the simulator.
+ */
+ @AfterClass
+ public static void tearDownSimulator() {
+
+ /*
+ * Gracefully shut down the kie session
+ */
+ kieSession.dispose();
+
+ PolicyEngine.manager.stop();
+ HttpServletServer.factory.destroy();
+ PolicyController.factory.shutdown();
+ TopicEndpoint.manager.shutdown();
+ }
+
+ @Test
+ public void successTest() throws IOException {
+
+ /*
+ * Allows the PolicyEngine to callback to this object to notify that there is an event ready
+ * to be pulled from the queue
+ */
+ for (TopicSink sink : noopTopics) {
+ assertTrue(sink.start());
+ sink.register(this);
+ }
+
+ /*
+ * Simulate an onset event the policy engine will receive from DCAE to kick off processing
+ * through the rules
+ */
+ sendEvent(pair.first);
+
+ kieSession.fireUntilHalt();
+
+ // allow object clean-up
+ kieSession.fireAllRules();
+
+ /*
+ * The only fact in memory should be Params
+ */
+ assertEquals(1, kieSession.getFactCount());
+
+ /*
+ * Print what's left in memory
+ */
+ dumpFacts(kieSession);
+ }
+
+ @Test
+ public void nullRequestTest() throws IOException {
+
+ /*
+ * Allows the PolicyEngine to callback to this object to notify that there is an event ready
+ * to be pulled from the queue
+ */
+ for (TopicSink sink : noopTopics) {
+ assertTrue(sink.start());
+ sink.register(this);
+ }
+
+ /*
+ * Simulate an onset event the policy engine will receive from DCAE to kick off processing
+ * through the rules
+ */
+
+ VirtualControlLoopEvent event = new VirtualControlLoopEvent();
+ event.setClosedLoopControlName(pair.first.getControlLoop().getControlLoopName());
+ event.setRequestId(UUID.randomUUID());
+ event.setClosedLoopEventClient("DCAE.HolmesInstance");
+ event.setTargetType(ControlLoopTargetType.VM);
+ event.setTarget("vserver.vserver-name");
+ event.setFrom("DCAE");
+ event.setClosedLoopAlarmStart(Instant.now());
+ event.setAai(new HashMap<String, String>());
+ event.getAai().put("vserver.vserver-name", "nullRequest");
+ event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
+ kieSession.insert(event);
+
+ kieSession.fireUntilHalt();
+
+ // allow object clean-up
+ kieSession.fireAllRules();
+
+ /*
+ * The only fact in memory should be Params
+ */
+ assertEquals(1, kieSession.getFactCount());
+
+ /*
+ * Print what's left in memory
+ */
+ dumpFacts(kieSession);
+ }
+
+ /**
+ * This method will start a kie session and instantiate the Policy Engine.
+ *
+ * @param droolsTemplate the DRL rules file
+ * @param yamlFile the yaml file containing the policies
+ * @param policyScope scope for policy
+ * @param policyName name of the policy
+ * @param policyVersion version of the policy
+ * @return the kieSession to be used to insert facts
+ * @throws IOException IO Exception
+ */
+ private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
+ String policyName, String policyVersion) throws IOException {
+
+ /*
+ * Load policies from yaml
+ */
+ pair = SupportUtil.loadYaml(yamlFile);
+ assertNotNull(pair);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
+
+ /*
+ * Construct a kie session
+ */
+ final KieSession kieSession = SupportUtil.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second,
+ StandardCharsets.UTF_8.name()));
+
+ /*
+ * Retrieve the Policy Engine
+ */
+
+ logger.debug("============");
+ logger.debug(URLEncoder.encode(pair.second, StandardCharsets.UTF_8.name()));
+ logger.debug("============");
+
+ return kieSession;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.drools.PolicyEngineListener#newEventNotification(java.lang.String)
+ */
+ @Override
+ public void onTopicEvent(CommInfrastructure commType, String topic, String event) {
+ /*
+ * Pull the object that was sent out to DMAAP and make sure it is a ControlLoopNoticiation
+ * of type active
+ */
+ Object obj = null;
+ if ("POLICY-CL-MGT".equals(topic)) {
+ obj = org.onap.policy.controlloop.util.Serialization.gsonJunit.fromJson(event,
+ VirtualControlLoopNotification.class);
+ }
+ assertNotNull(obj);
+ if (obj instanceof VirtualControlLoopNotification) {
+ VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj;
+ String policyName = notification.getPolicyName();
+ if (policyName.endsWith("EVENT")) {
+ logger.debug("Rule Fired: " + notification.getPolicyName());
+ assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.getNotification()));
+ } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
+ logger.debug("Rule Fired: " + notification.getPolicyName());
+ assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification()));
+ assertNotNull(notification.getMessage());
+ assertTrue(notification.getMessage().startsWith("Sending guard query"));
+ } else if (policyName.endsWith("GUARD.RESPONSE")) {
+ logger.debug("Rule Fired: " + notification.getPolicyName());
+ assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification()));
+ assertNotNull(notification.getMessage());
+ assertTrue(notification.getMessage().toLowerCase().endsWith("permit"));
+ } else if (policyName.endsWith("GUARD_PERMITTED")) {
+ logger.debug("Rule Fired: " + notification.getPolicyName());
+ assertTrue(ControlLoopNotificationType.OPERATION.equals(notification.getNotification()));
+ assertNotNull(notification.getMessage());
+ assertTrue(notification.getMessage().startsWith("actor=SDNC"));
+ } else if (policyName.endsWith("OPERATION.TIMEOUT")) {
+ logger.debug("Rule Fired: " + notification.getPolicyName());
+ kieSession.halt();
+ logger.debug("The operation timed out");
+ fail("Operation Timed Out");
+ } else if (policyName.endsWith("SDNC.RESPONSE")) {
+ logger.debug("Rule Fired: " + notification.getPolicyName());
+ assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
+ assertNotNull(notification.getMessage());
+ assertTrue(notification.getMessage().startsWith("actor=SDNC"));
+ } else if (policyName.endsWith("EVENT.MANAGER")) {
+ logger.debug("Rule Fired: " + notification.getPolicyName());
+ if ("nullRequest".equals(notification.getAai().get("vserver.vserver-name"))) {
+ assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification());
+ } else {
+ assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.getNotification());
+ }
+ kieSession.halt();
+ } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) {
+ logger.debug("Rule Fired: " + notification.getPolicyName());
+ kieSession.halt();
+ logger.debug("The control loop timed out");
+ fail("Control Loop Timed Out");
+ }
+ } else if (obj instanceof SdncRequest) {
+ logger.debug("\n============ SDNC received the request!!! ===========\n");
+ }
+ }
+
+ /**
+ * This method is used to simulate event messages from DCAE that start the control loop (onset
+ * message) or end the control loop (abatement message).
+ *
+ * @param policy the controlLoopName comes from the policy
+ */
+ protected void sendEvent(ControlLoopPolicy policy) {
+ VirtualControlLoopEvent event = new VirtualControlLoopEvent();
+ event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
+ event.setRequestId(UUID.randomUUID());
+ event.setClosedLoopEventClient("DCAE.HolmesInstance");
+ event.setTargetType(ControlLoopTargetType.VM);
+ event.setTarget("vserver.vserver-name");
+ event.setFrom("DCAE");
+ event.setClosedLoopAlarmStart(Instant.now());
+ event.setAai(new HashMap<String, String>());
+ event.getAai().put("vserver.vserver-name", "TBD");
+ event.getAai().put("globalSubscriberId", "e151059a-d924-4629-845f-264db19e50b4");
+ event.getAai().put("serviceType", "siteService");
+ event.getAai().put("service-instance.service-instance-id", "service-instance-id-example-1");
+ event.getAai().put("vserver.is-closed-loop-disabled", "false");
+ event.getAai().put("vserver.prov-status", "ACTIVE");
+ event.getAai().put("bandwidth", "500");
+ event.getAai().put("bandwidth-change-time", "20190326-05:20:38:668");
+ event.getAai().put("vnfId", "vnf-id");
+ event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
+ kieSession.insert(event);
+ }
+
+ /**
+ * Dumps the kie session facts.
+ *
+ * @param kieSession input session
+ */
+ public static void dumpFacts(KieSession kieSession) {
+ logger.debug("Fact Count: " + kieSession.getFactCount());
+ for (FactHandle handle : kieSession.getFactHandles()) {
+ logger.debug("FACT: " + handle);
+ }
+ }
+} \ No newline at end of file
diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml
new file mode 100644
index 000000000..f994d4104
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml
@@ -0,0 +1,37 @@
+# Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved
+#
+# 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.
+controlLoop:
+ version: 2.0.0
+ controlLoopName: ControlLoop-CCVPN-2179b738-fd36-4843-a71a-a8c24c70c22b
+ trigger_policy: unique-policy-id-16-BandwidthOnDemand
+ timeout: 3600
+ abatement: false
+
+policies:
+ - id: unique-policy-id-16-BandwidthOnDemand
+ name: CCVPNBandwidthOnDemand
+ description:
+ actor: SDNC
+ recipe: BandwidthOnDemand
+ target:
+ type: VM
+ retry: 3
+ timeout: 1200
+ success: final_success
+ failure: final_failure
+ failure_timeout: final_failure_timeout
+ failure_retries: final_failure_retries
+ failure_exception: final_failure_exception
+ failure_guard: final_failure_guard
+