aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/templates
diff options
context:
space:
mode:
authorVidyashree Rama <vidyashree.rama@huawei.com>2018-10-18 11:45:52 +0530
committerVidyashree Rama <vidyashree.rama@huawei.com>2018-10-23 18:28:01 +0530
commitb9007182f9a8fa0dea48fc970e38fb6761bf6c24 (patch)
tree8acc33b3aab928e3b7e1d4db7baee7c5ee4135af /controlloop/templates
parentecffd0e5dfe112bcc69ee420848bbc476571637c (diff)
Add CCVPN policy
CCVPN policy Issue-ID: POLICY-1209 Change-Id: I8adea233f8672c9ff43b4a169b50336d9e43c91d Signed-off-by: Vidyashree Rama <vidyashree.rama@huawei.com>
Diffstat (limited to 'controlloop/templates')
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/CCVPN.yaml36
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.onset.json21
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl5
-rw-r--r--controlloop/templates/archetype-cl-casablanca/src/main/resources/META-INF/maven/archetype-metadata.xml9
-rw-r--r--controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/CCVPN.yaml36
-rw-r--r--controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/ccvpn.brmsgw.params.json7
-rw-r--r--controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.onset.json21
-rw-r--r--controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl5
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java356
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java13
-rw-r--r--controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN.yaml37
11 files changed, 546 insertions, 0 deletions
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/CCVPN.yaml b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/CCVPN.yaml
new file mode 100644
index 000000000..b5b37b0eb
--- /dev/null
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/CCVPN.yaml
@@ -0,0 +1,36 @@
+# Copyright (C) 2018 Huawei. 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: ${ccvpnClosedLoopControlName}
+ trigger_policy: unique-policy-id-16-Reroute
+ timeout: 3600
+ abatement: false
+
+policies:
+ - id: unique-policy-id-16-Reroute
+ name: Connectivity Reroute
+ description:
+ actor: SDNC
+ recipe: Reroute
+ 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.onset.json b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.onset.json
new file mode 100644
index 000000000..474911e74
--- /dev/null
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.onset.json
@@ -0,0 +1,21 @@
+{
+ "closedLoopEventClient": "DCAE.HolmesInstance",
+ "policyVersion": "1.0.0.5",
+ "policyName": "CCVPN",
+ "policyScope": "service=SOTNService,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" : "SOTN",
+ "service-information.service-instance-id" : "service-instance-id-example-1",
+ "network-information. network-id " : "id"
+ },
+ "closedLoopAlarmStart": 1484677482204798,
+ "closedLoopEventStatus": "ONSET",
+ "closedLoopControlName": "${ccvpnClosedLoopControlName}",
+ "version": "1.0.2",
+ "target": "vserver.vserver-name",
+ "requestID": "97964e10-686e-4790-8c45-bdfa61df770f",
+ "from": "DCAE"
+}
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
index 48cfab24c..cac512eac 100644
--- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
@@ -618,6 +618,11 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
retract($operation);
modify($manager) {finishOperation($operation)};
}
+ else if ("sdnc".equalsIgnoreCase($operation.policy.getActor())) {
+ retract($opTimer);
+ retract($operation);
+ modify($manager) {finishOperation($operation)};
+ }
}
} catch (Exception e) {
diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/META-INF/maven/archetype-metadata.xml b/controlloop/templates/archetype-cl-casablanca/src/main/resources/META-INF/maven/archetype-metadata.xml
index 4ef410083..a96989acd 100644
--- a/controlloop/templates/archetype-cl-casablanca/src/main/resources/META-INF/maven/archetype-metadata.xml
+++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -61,6 +61,15 @@
<requiredProperty key="volteControlLoopYaml">
<defaultValue>controlLoop%3A%0D%0A++version%3A+2.0.0%0D%0A++controlLoopName%3A+ControlLoop-VOLTE-2179b738-fd36-4843-a71a-a8c24c70c55b%0D%0A++trigger_policy%3A+unique-policy-id-1-restart%0D%0A++timeout%3A+3600%0D%0A++abatement%3A+false%0D%0A+%0D%0Apolicies%3A%0D%0A++-+id%3A+unique-policy-id-1-restart%0D%0A++++name%3A+Restart+the+VM%0D%0A++++description%3A%0D%0A++++actor%3A+VFC%0D%0A++++recipe%3A+Restart%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="ccvpnClosedLoopControlName">
+ <defaultValue>ControlLoop-CCVPN-2179b738-fd36-4843-a71a-a8c24c70c66b</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="ccvpnPolicyName">
+ <defaultValue>CCVPN</defaultValue>
+ </requiredProperty>
+ <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="policyScope">
<defaultValue>DCAE</defaultValue>
</requiredProperty>
diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/CCVPN.yaml b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/CCVPN.yaml
new file mode 100644
index 000000000..b5b37b0eb
--- /dev/null
+++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/CCVPN.yaml
@@ -0,0 +1,36 @@
+# Copyright (C) 2018 Huawei. 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: ${ccvpnClosedLoopControlName}
+ trigger_policy: unique-policy-id-16-Reroute
+ timeout: 3600
+ abatement: false
+
+policies:
+ - id: unique-policy-id-16-Reroute
+ name: Connectivity Reroute
+ description:
+ actor: SDNC
+ recipe: Reroute
+ 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-casablanca/src/main/resources/archetype-resources/src/main/config/ccvpn.brmsgw.params.json b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/ccvpn.brmsgw.params.json
new file mode 100644
index 000000000..5feeecd9e
--- /dev/null
+++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/ccvpn.brmsgw.params.json
@@ -0,0 +1,7 @@
+{
+ "closedLoopControlName": "${ccvpnClosedLoopControlName}",
+ "controlLoopYaml": "${ccvpnControlLoopYaml}",
+ "policyName": "${ccvpnPolicyName}",
+ "policyScope": "${policyScope}",
+ "policyVersion": "${policyVersion}"
+} \ No newline at end of file
diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.onset.json b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.onset.json
new file mode 100644
index 000000000..474911e74
--- /dev/null
+++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/config/dcae.ccvpn.onset.json
@@ -0,0 +1,21 @@
+{
+ "closedLoopEventClient": "DCAE.HolmesInstance",
+ "policyVersion": "1.0.0.5",
+ "policyName": "CCVPN",
+ "policyScope": "service=SOTNService,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" : "SOTN",
+ "service-information.service-instance-id" : "service-instance-id-example-1",
+ "network-information. network-id " : "id"
+ },
+ "closedLoopAlarmStart": 1484677482204798,
+ "closedLoopEventStatus": "ONSET",
+ "closedLoopControlName": "${ccvpnClosedLoopControlName}",
+ "version": "1.0.2",
+ "target": "vserver.vserver-name",
+ "requestID": "97964e10-686e-4790-8c45-bdfa61df770f",
+ "from": "DCAE"
+}
diff --git a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
index 11855d47d..f2aa7ef16 100644
--- a/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
+++ b/controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
@@ -579,6 +579,11 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
retract($operation);
modify($manager) {finishOperation($operation)};
}
+ else if ("sdnc".equalsIgnoreCase($operation.policy.getActor())) {
+ retract($opTimer);
+ retract($operation);
+ modify($manager) {finishOperation($operation)};
+ }
}
} catch (Exception e) {
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java
new file mode 100644
index 000000000..1da3ff70c
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java
@@ -0,0 +1,356 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. 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.
+ * ============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.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.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 CcvpnControlLoopTest implements TopicListener {
+
+ private static final Logger logger = LoggerFactory.getLogger(CcvpnControlLoopTest.class);
+
+ private static List<? extends TopicSink> noopTopics;
+
+ private static KieSession kieSession;
+ private static Util.Pair<ControlLoopPolicy, String> pair;
+
+ static {
+ /* Set environment properties */
+ Util.setAaiProps();
+ Util.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("junit.groupId", "junit.artifactId", "POLICY-CL-MGT",
+ "org.onap.policy.controlloop.VirtualControlLoopNotification", new JsonProtocolFilter(),
+ null, null,1111);
+
+ try {
+ Util.buildAaiSim();
+ Util.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.yaml", "type=operational", "Connectivity Reroute",
+ "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();
+
+ /*
+ * 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();
+
+ /*
+ * 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 = Util.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 = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
+
+ /*
+ * Retrieve the Policy Engine
+ */
+
+ logger.debug("============");
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
+ 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", "SOTN");
+ event.getAai().put("service-instance.service-instance-id", "service-instance-id-example-1");
+ event.getAai().put("network-information.network-id", "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);
+ }
+ }
+}
+
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
index 4ec51772f..575068086 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
@@ -137,6 +137,10 @@ public final class Util {
return org.onap.policy.simulators.Util.buildGuardSim();
}
+ public static HttpServletServer buildSdncSim() throws InterruptedException, IOException {
+ return org.onap.policy.simulators.Util.buildSdncSim();
+ }
+
private static String generatePolicy(String ruleContents,
String closedLoopControlName,
String policyScope,
@@ -293,6 +297,15 @@ public final class Util {
}
/**
+ * Set the SDNC properties.
+ */
+ public static void setSdncProps() {
+ PolicyEngine.manager.setEnvironmentProperty("sdnc.url", "http://localhost:6670/restconf/operations");
+ PolicyEngine.manager.setEnvironmentProperty("sdnc.username", "sdnc");
+ PolicyEngine.manager.setEnvironmentProperty("sdnc.password", "sdnc");
+ }
+
+ /**
* Set the Guard properties.
*/
public static void setGuardProps() {
diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN.yaml
new file mode 100644
index 000000000..176c1dc0e
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN.yaml
@@ -0,0 +1,37 @@
+# Copyright (C) 2018 Huawei. 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-a8c24c70c66b
+ trigger_policy: unique-policy-id-16-Reroute
+ timeout: 3600
+ abatement: false
+
+policies:
+ - id: unique-policy-id-16-Reroute
+ name: Connectivity Reroute
+ description:
+ actor: SDNC
+ recipe: Reroute
+ 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
+