summaryrefslogtreecommitdiffstats
path: root/controlloop/templates/template.demo/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/templates/template.demo/src/test/java')
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java234
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java231
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java236
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java377
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java279
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopParamsCleanupTest.java257
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java460
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java287
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java258
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java290
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java247
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopCdsTest.java273
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java317
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java284
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java291
15 files changed, 0 insertions, 4321 deletions
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
deleted file mode 100644
index ab0070724..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
- * Modifications Copyright (C) 2019-2020 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.sdnc.SdncRequest;
-
-public class CcvpnBwControlLoopTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../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");
- }
-
- @Test
- public void testSuccess() 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 testNullRequest() 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);
- }
-
- /*
- * (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);
- }
-}
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
deleted file mode 100644
index 3599d47d0..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Huawei. All rights reserved.
- * Modifications Copyright (C) 2019-2020 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.sdnc.SdncRequest;
-
-public class CcvpnControlLoopTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../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");
- }
-
- @Test
- public void testSuccess() 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 testNullRequest() 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);
- }
-
- /*
- * (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);
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java
deleted file mode 100644
index a311ba0b0..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Bell Canada.
- * ================================================================================
- * 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.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.util.List;
-import java.util.Properties;
-import java.util.UUID;
-import org.junit.AfterClass;
-import org.kie.api.runtime.KieSession;
-import org.kie.api.runtime.rule.FactHandle;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
-import org.onap.policy.drools.protocol.coders.EventProtocolParams;
-import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
-import org.onap.policy.drools.system.PolicyControllerConstants;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Common super class used by various Control Loop test classes. It manages the simulators
- * and the kie session.
- */
-public class ControlLoopBase {
-
- private static final String JUNIT_ARTIFACT_ID = "junit.artifactId";
-
- private static final String JUNIT_GROUP_ID = "junit.groupId";
-
- protected static final Logger logger = LoggerFactory.getLogger(ControlLoopBase.class);
-
- protected static List<? extends TopicSink> noopTopics;
-
- protected static KieSession kieSession;
- protected static SupportUtil.Pair<ControlLoopPolicy, String> pair;
-
- protected UUID requestId;
-
- /**
- * Starts the simulator and the kie session.
- *
- * @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
- */
- public static void setUpBeforeClass(String droolsTemplate, String yamlFile, String policyScope,
- String policyName, String policyVersion) {
-
- SupportUtil.setCustomQuery("false");
-
- /* Set environment properties */
- SupportUtil.setAaiProps();
- SupportUtil.setGuardProps();
- SupportUtil.setSdncProps();
- SupportUtil.setSoProps();
- SupportUtil.setVfcProps();
- SupportUtil.setPuProp();
- SupportUtil.setCdsProps();
-
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
-
- PolicyEngineConstants.getManager().configure(new Properties());
- assertTrue(PolicyEngineConstants.getManager().start());
- Properties noopSinkProperties = new Properties();
- noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS,
- "APPC-LCM-READ,APPC-CL,SDNR-CL,POLICY-CL-MGT");
- noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events", "org.onap.policy.appclcm.AppcLcmDmaapWrapper");
- noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events.custom.gson",
- "org.onap.policy.appclcm.util.Serialization,gson");
- noopSinkProperties.put("noop.sink.topics.APPC-CL.events", "org.onap.policy.appc.Response");
- noopSinkProperties.put("noop.sink.topics.APPC-CL.events.custom.gson",
- "org.onap.policy.appc.util.Serialization,gsonPretty");
- 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 = TopicEndpointManager.getManager().addTopicSinks(noopSinkProperties);
-
- EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
- .groupId(JUNIT_GROUP_ID)
- .artifactId(JUNIT_ARTIFACT_ID)
- .topic("POLICY-CL-MGT")
- .eventClass("org.onap.policy.controlloop.VirtualControlLoopNotification")
- .protocolFilter(new JsonProtocolFilter())
- .modelClassLoaderHash(1111));
- EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
- .groupId(JUNIT_GROUP_ID)
- .artifactId(JUNIT_ARTIFACT_ID)
- .topic("APPC-LCM-READ")
- .eventClass("org.onap.policy.appclcm.AppcLcmDmaapWrapper")
- .protocolFilter(new JsonProtocolFilter())
- .modelClassLoaderHash(1111));
- EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
- .groupId(JUNIT_GROUP_ID)
- .artifactId(JUNIT_ARTIFACT_ID)
- .topic("APPC-CL")
- .eventClass("org.onap.policy.appc.Request")
- .protocolFilter(new JsonProtocolFilter())
- .modelClassLoaderHash(1111));
- EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
- .groupId(JUNIT_GROUP_ID)
- .artifactId(JUNIT_ARTIFACT_ID)
- .topic("SDNR-CL")
- .eventClass("org.onap.policy.sdnr.PciRequestWrapper")
- .protocolFilter(new JsonProtocolFilter())
- .modelClassLoaderHash(1111));
- try {
- SupportUtil.buildAaiSim();
- SupportUtil.buildSdncSim();
- SupportUtil.buildSoSim();
- SupportUtil.buildVfcSim();
- SupportUtil.buildGuardSim();
- } catch (Exception e) {
- fail(e.getMessage());
- }
-
-
- /*
- * Start the kie session
- */
- try {
- kieSession = startSession(droolsTemplate, yamlFile, policyScope,
- policyName, policyVersion);
- } catch (IOException e) {
- e.printStackTrace();
- logger.debug("Could not create kieSession");
- fail("Could not create kieSession");
- }
- }
-
- /**
- * Stops the simulators and the kie session.
- */
- @AfterClass
- public static void tearDownAfterClass() {
-
- SupportUtil.setCustomQuery("false");
-
- /*
- * Gracefully shut down the kie session
- */
- kieSession.dispose();
-
- PolicyEngineConstants.getManager().stop();
- HttpServletServerFactoryInstance.getServerFactory().destroy();
- PolicyControllerConstants.getFactory().shutdown();
- TopicEndpointManager.getManager().shutdown();
- }
-
- /**
- * 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, "UTF-8"));
-
- /*
- * Retrieve the Policy Engine
- */
-
- logger.debug("============");
- logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
- logger.debug("============");
-
- return kieSession;
- }
-
- /**
- * This method will dump all the facts in the working memory.
- *
- * @param kieSession the session containing the facts
- */
- public 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/ControlLoopEventCleanupTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java
deleted file mode 100644
index 151819c4d..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. 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.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-import java.util.UUID;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.kie.api.runtime.KieSession;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
-import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
-import org.onap.policy.controlloop.ControlLoopEventStatus;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
-import org.onap.policy.drools.protocol.coders.EventProtocolParams;
-import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
-import org.onap.policy.drools.system.PolicyControllerConstants;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
-import org.onap.policy.template.demo.SupportUtil.Pair;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Verifies that event objects are cleaned up when rules are updated. This loads
- * <b>two</b> copies of the rule set into a single policy to ensure that the two copies
- * interact appropriately with each other's event objects.
- */
-public class ControlLoopEventCleanupTest {
- private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventCleanupTest.class);
-
- /**
- * Number of objects per control loop, including the Params object.
- */
- private static int CL_OBJECTS = 7;
-
- private static final String YAML = "src/test/resources/yaml/policy_ControlLoop_EventCleanup-test.yaml";
-
- /**
- * YAML to be used when the first rule set is updated.
- */
- private static final String YAML2 = "src/test/resources/yaml/policy_ControlLoop_EventCleanup-test2.yaml";
-
- private static final String POLICY_VERSION = "v2.0";
-
- private static final String POLICY_NAME = "CL_CleanupTest";
-
- private static final String POLICY_SCOPE = "type=operational";
-
- private static final String CONTROL_LOOP_NAME = "ControlLoop-Event-Cleanup-Test";
-
- private static final String DROOLS_TEMPLATE = "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
- + "src/main/resources/__closedLoopControlName__.drl";
-
- // values specific to the second copy of the rules
-
- private static final String YAML_B = "src/test/resources/yaml/policy_ControlLoop_EventCleanup-test-B.yaml";
- private static final String POLICY_NAME_B = "CL_CleanupTest_B";
- private static final String CONTROL_LOOP_NAME_B = "ControlLoop-Event-Cleanup-Test-B";
-
- private static final String GUARD_DISABLED = "guard.disabled";
-
- private static String saveGuardFlag;
-
- private static KieSession kieSession;
- private static SupportUtil.RuleSpec[] specifications;
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpSimulator() {
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
-
- saveGuardFlag = PolicyEngineConstants.getManager().getEnvironmentProperty(GUARD_DISABLED);
- PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_DISABLED, "true");
-
- SupportUtil.setAaiProps();
-
- PolicyEngineConstants.getManager().configure(new Properties());
- assertTrue(PolicyEngineConstants.getManager().start());
- Properties noopSinkProperties = new Properties();
- noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-CL,POLICY-CL-MGT");
- noopSinkProperties.put("noop.sink.topics.APPC-CL.events", "org.onap.policy.appc.Response");
- noopSinkProperties.put("noop.sink.topics.APPC-CL.events.custom.gson",
- "org.onap.policy.appc.util.Serialization,gsonPretty");
- 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");
- final List<TopicSink> noopTopics = TopicEndpointManager.getManager().addTopicSinks(noopSinkProperties);
-
- EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
- .groupId("junit.groupId")
- .artifactId("junit.artifactId")
- .topic("POLICY-CL-MGT")
- .eventClass("org.onap.policy.controlloop.VirtualControlLoopNotification")
- .protocolFilter(new JsonProtocolFilter())
- .modelClassLoaderHash(1111));
- EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
- .groupId("junit.groupId")
- .artifactId("junit.artifactId")
- .topic("APPC-CL")
- .eventClass("org.onap.policy.appc.Request")
- .protocolFilter(new JsonProtocolFilter())
- .modelClassLoaderHash(1111));
-
- try {
- SupportUtil.buildAaiSim();
-
- } catch (Exception e) {
- logger.error("Could not create simulator", e);
- fail("Could not create simulator");
- }
-
- for (TopicSink sink : noopTopics) {
- assertTrue(sink.start());
- }
-
- try {
- specifications = new SupportUtil.RuleSpec[2];
-
- specifications[0] = new SupportUtil.RuleSpec(DROOLS_TEMPLATE, CONTROL_LOOP_NAME, POLICY_SCOPE, POLICY_NAME,
- POLICY_VERSION, loadYaml(YAML));
-
- specifications[1] = new SupportUtil.RuleSpec(DROOLS_TEMPLATE, CONTROL_LOOP_NAME_B, POLICY_SCOPE,
- POLICY_NAME_B, POLICY_VERSION, loadYaml(YAML_B));
-
- kieSession = SupportUtil.buildContainer(POLICY_VERSION, specifications);
-
- } catch (IOException e) {
- logger.error("Could not create kieSession", e);
- fail("Could not create kieSession");
- }
- }
-
- /**
- * Tear down.
- */
- @AfterClass
- public static void tearDown() {
- kieSession.dispose();
-
- PolicyEngineConstants.getManager().stop();
- HttpServletServerFactoryInstance.getServerFactory().destroy();
- PolicyControllerConstants.getFactory().shutdown();
- TopicEndpointManager.getManager().shutdown();
-
- if (saveGuardFlag == null) {
- PolicyEngineConstants.getManager().getEnvironment().remove(GUARD_DISABLED);
-
- } else {
- PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_DISABLED, saveGuardFlag);
- }
- }
-
- @Ignore
- @Test
- public void test() throws IOException {
-
- /*
- * Let rules create Params objects.
- */
- kieSession.fireAllRules();
-
- injectEvent(CONTROL_LOOP_NAME);
- injectEvent(CONTROL_LOOP_NAME_B);
-
- kieSession.fireAllRules();
- List<Object> facts = getSessionObjects();
-
- // should have events for both control loops
- assertEquals(2 * CL_OBJECTS, facts.size());
- assertTrue(hasEvent(facts, CONTROL_LOOP_NAME));
- assertTrue(hasEvent(facts, CONTROL_LOOP_NAME_B));
-
- logger.info("UPDATING VERSION TO v3.0");
- updatePolicy(YAML2, "v3.0");
-
- /*
- * Let rules update Params objects. The Params for the first set of rules should
- * now be deleted and replaced with a new one, while the Params for the second set
- * should be unchanged.
- */
- kieSession.fireAllRules();
- facts = getSessionObjects();
-
- // should only have event for second control loop + 1 Params for first control loop
- assertEquals(CL_OBJECTS + 1, facts.size());
- assertTrue(hasEvent(facts, CONTROL_LOOP_NAME_B));
-
- // add event for first control loop again
- injectEvent(CONTROL_LOOP_NAME);
- kieSession.fireAllRules();
-
- logger.info("UPDATING VERSION TO v4.0");
- updatePolicy(YAML, "v4.0");
-
- /*
- * Let rules update Params objects. The Params for the first set of rules should
- * now be deleted and replaced with a new one, while the Params for the second set
- * should be unchanged.
- */
- kieSession.fireAllRules();
- facts = getSessionObjects();
-
- // should only have event for second control loop + 1 Params for first control loop
- assertEquals(CL_OBJECTS + 1, facts.size());
- assertTrue(hasEvent(facts, CONTROL_LOOP_NAME_B));
-
- // add event for first control loop again
- injectEvent(CONTROL_LOOP_NAME);
- kieSession.fireAllRules();
-
- logger.info("UPDATING VERSION TO v4.0 (i.e., unchanged)");
- updatePolicy(YAML, "v4.0");
-
- /*
- * Let rules update Params objects. As the version (and YAML) are unchanged for
- * either rule set, both Params objects should be unchanged.
- */
- kieSession.fireAllRules();
- facts = getSessionObjects();
-
- // should have events for both control loops
- assertEquals(2 * CL_OBJECTS, facts.size());
- assertTrue(hasEvent(facts, CONTROL_LOOP_NAME));
- assertTrue(hasEvent(facts, CONTROL_LOOP_NAME_B));
-
- /*
- * Now we'll delete the first rule set. That won't actually have any immediate
- * effect, so then we'll update the second rule set, which should trigger a
- * clean-up of both.
- */
- SupportUtil.RuleSpec[] specs = new SupportUtil.RuleSpec[1];
- specs[0] = specifications[1];
-
- logger.info("UPDATING VERSION TO v5.0 - DELETED RULE SET");
- SupportUtil.updateContainer("v5.0", specs);
-
- specs[0] = new SupportUtil.RuleSpec(DROOLS_TEMPLATE, CONTROL_LOOP_NAME_B, POLICY_SCOPE, POLICY_NAME_B,
- POLICY_VERSION, loadYaml(YAML));
-
- logger.info("UPDATING VERSION TO v6.0 - UPDATED SECOND RULE SET");
- SupportUtil.updateContainer("v6.0", specs);
-
- kieSession.fireAllRules();
- facts = getSessionObjects();
-
- // only 1 Params should remain, for second rule set, but events should be gone
- assertEquals(1, facts.size());
- assertTrue(facts.stream().anyMatch(obj -> obj.toString().startsWith("Params( ")));
- }
-
- /**
- * Updates the policy, changing the YAML associated with the first rule set.
- *
- * @param yamlFile name of the YAML file
- * @param policyVersion policy version
- * @throws IOException if an error occurs
- */
- private static void updatePolicy(String yamlFile, String policyVersion) throws IOException {
-
- specifications[0] = new SupportUtil.RuleSpec(DROOLS_TEMPLATE, CONTROL_LOOP_NAME, POLICY_SCOPE, POLICY_NAME,
- policyVersion, loadYaml(yamlFile));
-
- /*
- * Update the policy within the container.
- */
- SupportUtil.updateContainer(policyVersion, specifications);
- }
-
- /**
- * Loads a YAML file and URL-encodes it.
- *
- * @param yamlFile name of the YAML file
- * @return the contents of the specified file, URL-encoded
- * @throws UnsupportedEncodingException if an error occurs
- */
- private static String loadYaml(String yamlFile) throws UnsupportedEncodingException {
- Pair<ControlLoopPolicy, String> 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);
-
- return URLEncoder.encode(pair.second, "UTF-8");
- }
-
- /**
- * Gets the session objects.
- *
- * @return the session objects
- */
- private static List<Object> getSessionObjects() {
- // sort the objects so we know the order
- LinkedList<Object> lst = new LinkedList<>(kieSession.getObjects());
- lst.sort((left, right) -> left.toString().compareTo(right.toString()));
-
- lst.forEach(obj -> logger.info("obj={}", obj));
-
- return lst;
- }
-
- /**
- * Injects an ONSET event into the rule engine.
- *
- * @param controlLoopName the control loop name
- */
- private void injectEvent(String controlLoopName) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
-
- event.setClosedLoopControlName(controlLoopName);
-
- UUID reqid = UUID.randomUUID();
- event.setRequestId(reqid);
-
- event.setTarget("generic-vnf.vnf-id");
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-id", "vnf-" + reqid.toString());
- event.getAai().put(ControlLoopEventManager.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, "false");
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
-
- kieSession.insert(event);
- }
-
- /**
- * Determines if the facts contain an event for the given control loop.
- *
- * @param facts session facts to be checked
- * @param controlLoopName name of the control loop of interest
- * @return {@code true} if the facts contain an event for the given control loop,
- * {@code false} otherwise
- */
- private boolean hasEvent(List<Object> facts, String controlLoopName) {
- return (facts.stream().anyMatch(obj -> obj instanceof VirtualControlLoopEvent
- && controlLoopName.equals(((VirtualControlLoopEvent) obj).getClosedLoopControlName())));
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
deleted file mode 100644
index e3409146f..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.appclcm.AppcLcmBody;
-import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
-import org.onap.policy.appclcm.AppcLcmInput;
-import org.onap.policy.appclcm.AppcLcmOutput;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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;
-
-public class ControlLoopFailureTest extends ControlLoopBase implements TopicListener {
-
- private UUID requestId2;
- private UUID requestId3;
- private int eventCount;
- private int nsuccess = 0;
- private int nreject = 0;
-
- /**
- * Setup simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources"
- + "/src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vCPE.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational",
- "CL_vCPE",
- "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
- }
-
- /**
- * This test case tests the scenario where 3 events occur and 2 of the requests refer to the
- * same target entity while the 3rd is for another entity. The expected result is that the event
- * with the duplicate target entity will have a final success result for one of the events, and
- * a rejected message for the one that was unable to obtain the lock. The event that is
- * referring to a different target entity should be able to obtain a lock since it is a
- * different target. After processing of all events there should only be the params object left
- * in memory.
- */
- @Test
- public void targetLockedTest() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * This will be a unique request for another target entity
- */
- requestId2 = UUID.randomUUID();
-
- /*
- * This will be a request duplicating the target entity of the first request
- */
- requestId3 = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "vnf01");
-
- /*
- * Send a second event for a different target to ensure there are no problems with obtaining
- * a lock
- */
- sendEvent(pair.first, requestId2, ControlLoopEventStatus.ONSET, "vnf02");
-
- /*
- * Send a third event requesting an action for a duplicate target entity
- */
- sendEvent(pair.first, requestId3, ControlLoopEventStatus.ONSET, "vnf01");
-
- kieSession.fireUntilHalt();
-
- // allow object clean-up
- kieSession.fireAllRules();
-
- // should be one success and one failure for vnf01
- assertEquals(1, nsuccess);
- assertEquals(1, nreject);
-
- /*
- * The only fact in memory should be Params
- */
- assertEquals(1, kieSession.getFactCount());
-
- /*
- * Print what's left in memory
- */
- dumpFacts(kieSession);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.onap.policy.drools.PolicyEngineListener#newEventNotification(java.lang.String)
- */
- @Override
- public synchronized 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,
- org.onap.policy.controlloop.VirtualControlLoopNotification.class);
- } else if ("APPC-LCM-READ".equals(topic)) {
- obj = org.onap.policy.appclcm.util.Serialization.gsonJunit.fromJson(event,
- org.onap.policy.appclcm.AppcLcmDmaapWrapper.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("DENIED")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertTrue(ControlLoopNotificationType.REJECTED.equals(notification.getNotification()));
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().contains("is already locked"));
- if (requestId.equals(notification.getRequestId()) || requestId3.equals(notification.getRequestId())) {
- ++nreject;
- }
- if (++eventCount == 3) {
- kieSession.halt();
- }
- } 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=APPC"));
- } 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("APPC.LCM.RESPONSE")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=APPC"));
- if (requestId.equals(notification.getRequestId()) || requestId3.equals(notification.getRequestId())) {
- sendEvent(pair.first, notification.getRequestId(), ControlLoopEventStatus.ABATED, "vnf01");
- } else if (requestId2.equals(notification.getRequestId())) {
- sendEvent(pair.first, requestId2, ControlLoopEventStatus.ABATED, "vnf02");
- }
- } else if (policyName.endsWith("EVENT.MANAGER")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- if (requestId.equals(notification.getRequestId()) || requestId3.equals(notification.getRequestId())) {
- assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.getNotification()));
- ++nsuccess;
- } else {
- assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.getNotification()));
- }
- if (++eventCount == 3) {
- 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 AppcLcmDmaapWrapper) {
- /*
- * The request should be of type LCMRequestWrapper and the subrequestid should be 1
- */
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) obj;
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertTrue(appcRequest.getCommonHeader().getSubRequestId().equals("1"));
-
- logger.debug("\n============ APPC received the request!!! ===========\n");
-
- /*
- * Simulate a success response from APPC and insert the response into the working memory
- */
- AppcLcmDmaapWrapper dmaapResponse = new AppcLcmDmaapWrapper();
- AppcLcmOutput appcResponse = new AppcLcmOutput(appcRequest);
- appcResponse.getStatus().setCode(400);
- appcResponse.getStatus().setMessage("AppC success");
- dmaapResponse.setBody(new AppcLcmBody());
- dmaapResponse.getBody().setOutput(appcResponse);
-
- /*
- * Interrupting with a different request for the same target entity to check if lock
- * will be denied
- */
- if (requestId.equals(appcResponse.getCommonHeader().getRequestId())) {
- sendEvent(pair.first, requestId3, ControlLoopEventStatus.ONSET, "vnf01");
- }
- kieSession.insert(dmaapResponse);
- }
- }
-
- /**
- * 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
- * @param requestId the requestId for this event
- * @param status could be onset or abated
- * @param target the target entity to take an action on
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String target) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-id", target);
- event.getAai().put("vserver.vserver-name", "OzVServer");
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopParamsCleanupTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopParamsCleanupTest.java
deleted file mode 100644
index ae12d0469..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopParamsCleanupTest.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. 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.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.kie.api.runtime.KieSession;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
-import org.onap.policy.template.demo.SupportUtil.Pair;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Verifies that Params objects are cleaned up when rules are updated. This loads
- * <b>two</b> copies of the rule set into a single policy to ensure that the two copies
- * interact appropriately with each other's Params objects.
- */
-public class ControlLoopParamsCleanupTest {
- private static final Logger logger = LoggerFactory.getLogger(ControlLoopParamsCleanupTest.class);
-
- private static final String YAML = "src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test.yaml";
-
- /**
- * YAML to be used when the first rule set is updated.
- */
- private static final String YAML2 = "src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test2.yaml";
-
- private static final String POLICY_VERSION = "v2.0";
-
- private static final String POLICY_NAME = "CL_CleanupTest";
-
- private static final String POLICY_SCOPE = "type=operational";
-
- private static final String CONTROL_LOOP_NAME = "ControlLoop-Params-Cleanup-Test";
-
- private static final String DROOLS_TEMPLATE = "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
- + "src/main/resources/__closedLoopControlName__.drl";
-
- // values specific to the second copy of the rules
-
- private static final String YAML_B = "src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test-B.yaml";
- private static final String POLICY_NAME_B = "CL_CleanupTest_B";
- private static final String CONTROL_LOOP_NAME_B = "ControlLoop-Params-Cleanup-Test-B";
-
- private static KieSession kieSession;
- private static SupportUtil.RuleSpec[] specifications;
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpSimulator() {
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
-
- try {
- specifications = new SupportUtil.RuleSpec[2];
-
- specifications[0] = new SupportUtil.RuleSpec(DROOLS_TEMPLATE, CONTROL_LOOP_NAME, POLICY_SCOPE, POLICY_NAME,
- POLICY_VERSION, loadYaml(YAML));
-
- specifications[1] = new SupportUtil.RuleSpec(DROOLS_TEMPLATE, CONTROL_LOOP_NAME_B, POLICY_SCOPE,
- POLICY_NAME_B, POLICY_VERSION, loadYaml(YAML_B));
-
- kieSession = SupportUtil.buildContainer(POLICY_VERSION, specifications);
-
- } catch (IOException e) {
- logger.error("Could not create kieSession", e);
- fail("Could not create kieSession");
- }
- }
-
- /**
- * Tear down.
- */
- @AfterClass
- public static void tearDown() {
- kieSession.dispose();
- }
-
- @Ignore
- @Test
- public void test() throws IOException {
-
- /*
- * Let rules create Params objects. There should be one object for each set of
- * rules.
- */
- kieSession.fireAllRules();
- List<Object> facts = getSessionObjects();
- assertEquals(specifications.length, facts.size());
- Iterator<Object> iter = facts.iterator();
-
- final Object fact1 = iter.next();
- assertTrue(fact1.toString().contains(loadYaml(YAML)));
-
- final Object fact1b = iter.next();
- assertTrue(fact1b.toString().contains(loadYaml(YAML_B)));
-
- logger.info("UPDATING VERSION TO v3.0");
- updatePolicy(YAML2, "v3.0");
-
- /*
- * Let rules update Params objects. The Params for the first set of rules should
- * now be deleted and replaced with a new one, while the Params for the second set
- * should be unchanged.
- */
- kieSession.fireAllRules();
- facts = getSessionObjects();
- assertEquals(specifications.length, facts.size());
- iter = facts.iterator();
-
- final Object fact2 = iter.next();
- assertTrue(fact2 != fact1);
- assertTrue(fact2 != fact1b);
- assertTrue(fact2.toString().contains(loadYaml(YAML2)));
-
- assertTrue(iter.next() == fact1b);
-
- logger.info("UPDATING VERSION TO v4.0");
- updatePolicy(YAML, "v4.0");
-
- /*
- * Let rules update Params objects. The Params for the first set of rules should
- * now be deleted and replaced with a new one, while the Params for the second set
- * should be unchanged.
- */
- kieSession.fireAllRules();
- facts = getSessionObjects();
- assertEquals(specifications.length, facts.size());
- iter = facts.iterator();
-
- final Object fact3 = iter.next();
- assertTrue(fact3.toString().contains(loadYaml(YAML)));
- assertTrue(fact3 != fact2);
- assertTrue(fact3 != fact1b);
-
- assertTrue(iter.next() == fact1b);
-
- logger.info("UPDATING VERSION TO v4.0 (i.e., unchanged)");
- updatePolicy(YAML, "v4.0");
-
- /*
- * Let rules update Params objects. As the version (and YAML) are unchanged for
- * either rule set, both Params objects should be unchanged.
- */
- kieSession.fireAllRules();
- facts = getSessionObjects();
- assertEquals(specifications.length, facts.size());
- iter = facts.iterator();
- assertTrue(iter.next() == fact3);
- assertTrue(iter.next() == fact1b);
-
- /*
- * Now we'll delete the first rule set. That won't actually have any immediate
- * effect, so then we'll update the second rule set, which should trigger a
- * clean-up of both.
- */
- SupportUtil.RuleSpec[] specs = new SupportUtil.RuleSpec[1];
- specs[0] = specifications[1];
-
- logger.info("UPDATING VERSION TO v5.0 - DELETED RULE SET");
- SupportUtil.updateContainer("v5.0", specs);
-
- specs[0] = new SupportUtil.RuleSpec(DROOLS_TEMPLATE, CONTROL_LOOP_NAME_B, POLICY_SCOPE, POLICY_NAME_B,
- POLICY_VERSION, loadYaml(YAML));
-
- logger.info("UPDATING VERSION TO v6.0 - UPDATED SECOND RULE SET");
- SupportUtil.updateContainer("v6.0", specs);
-
- kieSession.fireAllRules();
- facts = getSessionObjects();
- assertEquals(specs.length, facts.size());
- iter = facts.iterator();
- assertTrue(iter.next().toString().contains(CONTROL_LOOP_NAME_B));
- }
-
- /**
- * Updates the policy, changing the YAML associated with the first rule set.
- *
- * @param yamlFile name of the YAML file
- * @param policyVersion policy version
- * @throws IOException if an error occurs
- */
- private static void updatePolicy(String yamlFile, String policyVersion) throws IOException {
-
- specifications[0] = new SupportUtil.RuleSpec(DROOLS_TEMPLATE, CONTROL_LOOP_NAME, POLICY_SCOPE, POLICY_NAME,
- policyVersion, loadYaml(yamlFile));
-
- /*
- * Update the policy within the container.
- */
- SupportUtil.updateContainer(policyVersion, specifications);
- }
-
- /**
- * Loads a YAML file and URL-encodes it.
- *
- * @param yamlFile name of the YAML file
- * @return the contents of the specified file, URL-encoded
- * @throws UnsupportedEncodingException if an error occurs
- */
- private static String loadYaml(String yamlFile) throws UnsupportedEncodingException {
- Pair<ControlLoopPolicy, String> 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);
-
- return URLEncoder.encode(pair.second, "UTF-8");
- }
-
- /**
- * Gets the session objects.
- *
- * @return the session objects
- */
- private static List<Object> getSessionObjects() {
- // sort the objects so we know the order
- LinkedList<Object> lst = new LinkedList<>(kieSession.getObjects());
- lst.sort((left, right) -> left.toString().compareTo(right.toString()));
-
- return lst;
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java
deleted file mode 100644
index 878f94be1..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java
+++ /dev/null
@@ -1,460 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Bell Canada.
- * ================================================================================
- * 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.fail;
-
-import com.att.research.xacml.util.XACMLProperties;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.apache.commons.io.IOUtils;
-import org.kie.api.KieServices;
-import org.kie.api.builder.KieBuilder;
-import org.kie.api.builder.KieFileSystem;
-import org.kie.api.builder.Message;
-import org.kie.api.builder.ReleaseId;
-import org.kie.api.builder.Results;
-import org.kie.api.runtime.KieContainer;
-import org.kie.api.runtime.KieSession;
-import org.onap.policy.common.endpoints.http.server.HttpServletServer;
-import org.onap.policy.common.utils.network.NetworkUtil;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.guard.PolicyGuardYamlToXacml;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-
-public final class SupportUtil {
-
- private static final String OPSHISTPUPROP = "OperationsHistoryPU";
- private static final Logger logger = LoggerFactory.getLogger(SupportUtil.class);
-
- static final int GRPC_SERVER_PORT;
-
- static {
- try {
- GRPC_SERVER_PORT = NetworkUtil.allocPort();
- } catch (IOException e) {
- throw new RuntimeException("Socket cannot be created for grpc server port", e);
- }
- }
-
- public static class Pair<A, B> {
- public final A first;
- public final B second;
-
- public Pair(A first, B second) {
- this.first = first;
- this.second = second;
- }
- }
-
- // values from the last call to buildContainer()
-
- private static KieServices kieServices;
- private static KieContainer keyContainer;
-
- /**
- * Load YAML.
- *
- * @param testFile test file to load
- * @return the Pair of a policy and the yaml contents
- */
- public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) {
- try (InputStream is = new FileInputStream(new File(testFile))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
- //
- // Read the yaml into our Java Object
- //
- Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- Object obj = yaml.load(contents);
-
- logger.debug(contents);
-
- return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- }
- return null;
- }
-
- /**
- * Load the YAML guard policy.
- *
- * @param testFile the test file to load
- * @return return the guard object
- */
- public static ControlLoopGuard loadYamlGuard(String testFile) {
- try (InputStream is = new FileInputStream(new File(testFile))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
- //
- // Read the yaml into our Java Object
- //
- Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
- Object obj = yaml.load(contents);
- return (ControlLoopGuard) obj;
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- }
- return null;
- }
-
- public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildAaiSim();
- }
-
- public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildSoSim();
- }
-
- public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildVfcSim();
- }
-
- public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildGuardSim();
- }
-
- public static HttpServletServer buildSdncSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildSdncSim();
- }
-
- /**
- * Build a container containing a single set of rules.
- *
- * @param droolsTemplate template
- * @param closedLoopControlName control loop id
- * @param policyScope policy scope
- * @param policyName policy name
- * @param policyVersion policy version
- * @param yamlSpecification incoming yaml specification
- * @return the Kie session
- * @throws IOException if the container cannot be built
- */
- public static KieSession buildContainer(String droolsTemplate, String closedLoopControlName,
- String policyScope, String policyName, String policyVersion, String yamlSpecification)
- throws IOException {
-
- RuleSpec spec = new RuleSpec(droolsTemplate, closedLoopControlName, policyScope, policyName,
- policyVersion, yamlSpecification);
-
- return buildContainer(policyVersion, new RuleSpec[] {spec});
- }
-
- /**
- * Build a container containing all of the specified rules.
- *
- * @param policyVersion policy version
- * @param specifications rule specifications
- * @return the Kie session
- * @throws IOException if the container cannot be built
- */
- public static KieSession buildContainer(String policyVersion, RuleSpec[] specifications)
- throws IOException {
- //
- // Get our Drools Kie factory
- //
- kieServices = KieServices.Factory.get();
-
- ReleaseId releaseId = buildPolicy(policyVersion, specifications);
- logger.debug(releaseId.toString());
-
- //
- // Create our kie Session and container
- //
- keyContainer = kieServices.newKieContainer(releaseId);
-
- return setupSession(keyContainer.newKieSession());
- }
-
- /**
- * Update the container with new rules.
- *
- * @param policyVersion new policy version
- * @param specifications new rule specifications
- * @throws IOException if the container cannot be built
- */
- public static void updateContainer(String policyVersion, RuleSpec[] specifications)
- throws IOException {
- ReleaseId releaseId = buildPolicy(policyVersion, specifications);
- logger.debug(releaseId.toString());
-
- keyContainer.updateToVersion(releaseId);
- }
-
- /**
- * Build the Policy so it can be loaded into a KIE container.
- *
- * @param policyVersion policy version
- * @param specifications rule specifications
- * @return the release
- * @throws IOException if the container cannot be built
- */
- private static ReleaseId buildPolicy(String policyVersion, RuleSpec[] specifications)
- throws IOException {
- //
- // Generate our drools rule from our template
- //
- KieFileSystem kfs = kieServices.newKieFileSystem();
- ReleaseId releaseId = kieServices.getRepository().getDefaultReleaseId();
- releaseId = kieServices.newReleaseId(releaseId.getGroupId(), releaseId.getArtifactId(),
- policyVersion);
-
- kfs.generateAndWritePomXML(releaseId);
-
- for (RuleSpec spec : specifications) {
- String drlContents = spec.generateRules();
- kfs.write("src/main/resources/" + spec.policyName + ".drl",
- kieServices.getResources().newByteArrayResource(drlContents.getBytes()));
- }
-
- //
- // Compile the rule
- //
- KieBuilder builder = kieServices.newKieBuilder(kfs).buildAll();
- Results results = builder.getResults();
- if (results.hasMessages(Message.Level.ERROR)) {
- for (Message msg : results.getMessages()) {
- logger.error(msg.toString());
- }
- throw new RuntimeException("Drools Rule has Errors");
- }
- for (Message msg : results.getMessages()) {
- logger.debug(msg.toString());
- }
-
- return releaseId;
- }
-
- private static KieSession setupSession(KieSession kieSession) {
-
- //
- // Create XACML Guard policy from YAML
- // We prepare 4 Guards. Notice that Rebuilds recipe has two Guards (for checking policy
- // combining algorithm)
- //
- PolicyGuardYamlToXacml.fromYamlToXacml(
- "src/test/resources/yaml/policy_guard_appc_restart.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_restart.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml(
- "src/test/resources/yaml/policy_guard_appc_rebuild.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml(
- "src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild_1.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml(
- "src/test/resources/yaml/policy_guard_appc_migrate.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_migrate.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml(
- "src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_modifyconfig.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist(
- "src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml",
- "src/main/resources/blacklist_template.xml",
- "src/test/resources/xacml/autogenerated_blacklist.xml");
-
- //
- // Creating an embedded XACML PDP
- //
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,
- "src/test/resources/xacml/xacml_guard.properties");
-
- return kieSession;
- }
-
- /**
- * Set the A&AI properties.
- */
- public static void setAaiProps() {
- PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url",
- "http://localhost:6666");
- PolicyEngineConstants.getManager().setEnvironmentProperty("aai.username", "AAI");
- PolicyEngineConstants.getManager().setEnvironmentProperty("aai.password", "AAI");
- }
-
- /**
- * Set the SO properties.
- */
- public static void setSoProps() {
- PolicyEngineConstants.getManager().setEnvironmentProperty("so.url",
- "http://localhost:6667");
- PolicyEngineConstants.getManager().setEnvironmentProperty("so.username", "SO");
- PolicyEngineConstants.getManager().setEnvironmentProperty("so.password", "SO");
- }
-
- /**
- * Set the SDNC properties.
- */
- public static void setSdncProps() {
- PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.url",
- "http://localhost:6670/restconf/operations");
- PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.username", "sdnc");
- PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.password", "sdnc");
- }
-
- /**
- * Set the Guard properties.
- */
- public static void setGuardProps() {
- /*
- * Guard PDP-x connection Properties
- */
- PolicyEngineConstants.getManager().setEnvironmentProperty(
- org.onap.policy.guard.Util.PROP_GUARD_URL,
- "http://localhost:6669/policy/pdpx/v1/decision");
- PolicyEngineConstants.getManager()
- .setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python");
- PolicyEngineConstants.getManager()
- .setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test");
- PolicyEngineConstants.getManager()
- .setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, "false");
- }
-
- /**
- * Sets the value of customQuery Environment property.
- *
- * @param value of the custom query boolean.
- */
- public static void setCustomQuery(String value) {
- PolicyEngineConstants.getManager().setEnvironmentProperty("aai.customQuery", value);
- }
-
- /**
- * Set the VFC properties.
- */
- public static void setVfcProps() {
- PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.url",
- "http://localhost:6668/api/nslcm/v1");
- PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.username", "VFC");
- PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.password", "VFC");
- }
-
- /**
- * Set the operation history properties.
- */
- public static void setPuProp() {
- System.setProperty(OPSHISTPUPROP, "OperationsHistoryPUTest");
- }
-
- /**
- * Set cds properties.
- */
- public static void setCdsProps() {
- PolicyEngineConstants.getManager().setEnvironmentProperty("cds.grpcHost", "localhost");
- PolicyEngineConstants.getManager().setEnvironmentProperty("cds.grpcPort", Integer.toString(GRPC_SERVER_PORT));
- PolicyEngineConstants.getManager().setEnvironmentProperty("cds.grpcUsername", "grpc-username");
- PolicyEngineConstants.getManager().setEnvironmentProperty("cds.grpcPassword", "grpc-password");
- PolicyEngineConstants.getManager().setEnvironmentProperty("cds.grpcTimeout", "5");
- }
-
- /**
- * Rule specification.
- */
- public static class RuleSpec {
- private String droolsTemplate;
- private String closedLoopControlName;
- private String policyScope;
- private String policyName;
- private String policyVersion;
- private String yamlSpecification;
-
- /**
- * Constructs the object.
- *
- * @param droolsTemplate template
- * @param closedLoopControlName control loop id
- * @param policyScope policy scope
- * @param policyName policy name
- * @param policyVersion policy version
- * @param yamlSpecification incoming yaml specification
- */
- public RuleSpec(String droolsTemplate, String closedLoopControlName, String policyScope,
- String policyName, String policyVersion, String yamlSpecification) {
-
- this.droolsTemplate = droolsTemplate;
- this.closedLoopControlName = closedLoopControlName;
- this.policyScope = policyScope;
- this.policyName = policyName;
- this.policyVersion = policyVersion;
- this.yamlSpecification = yamlSpecification;
- }
-
- /**
- * Generates the rules by reading the template and making variable substitutions.
- *
- * @return the rules
- * @throws IOException if an error occurs
- */
- private String generateRules() throws IOException {
- Path rule = Paths.get(droolsTemplate);
- String ruleTemplate = new String(Files.readAllBytes(rule));
-
- Pattern pattern = Pattern.compile("\\$\\{closedLoopControlName\\}");
- Matcher matcher = pattern.matcher(ruleTemplate);
- ruleTemplate = matcher.replaceAll(closedLoopControlName);
-
- pattern = Pattern.compile("\\$\\{policyScope\\}");
- matcher = pattern.matcher(ruleTemplate);
- ruleTemplate = matcher.replaceAll(policyScope);
-
- pattern = Pattern.compile("\\$\\{policyName\\}");
- matcher = pattern.matcher(ruleTemplate);
- ruleTemplate = matcher.replaceAll(policyName);
-
- pattern = Pattern.compile("\\$\\{policyVersion\\}");
- matcher = pattern.matcher(ruleTemplate);
- ruleTemplate = matcher.replaceAll(policyVersion);
-
- pattern = Pattern.compile("\\$\\{controlLoopYaml\\}");
- matcher = pattern.matcher(ruleTemplate);
- ruleTemplate = matcher.replaceAll(yamlSpecification);
-
- return ruleTemplate;
- }
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java
deleted file mode 100644
index e0cb0ef1f..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import org.onap.policy.appclcm.AppcLcmBody;
-import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
-import org.onap.policy.appclcm.AppcLcmInput;
-import org.onap.policy.appclcm.AppcLcmOutput;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class VcpeControlLoopTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources"
- + "/src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vCPE.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vCPE",
- "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
- }
-
- @Test
- public void testASuccess() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "OzVServer", true);
-
- 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 testBAaiGetFail() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail", false);
-
- 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);
- }
-
- /*
- * (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,
- org.onap.policy.controlloop.VirtualControlLoopNotification.class);
- } else if ("APPC-LCM-READ".equals(topic)) {
- obj = org.onap.policy.appclcm.util.Serialization.gsonJunit.fromJson(event,
- org.onap.policy.appclcm.AppcLcmDmaapWrapper.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=APPC"));
- } 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("APPC.LCM.RESPONSE")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS
- .equals(notification.getNotification()));
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=APPC"));
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED);
- } else if (policyName.endsWith("EVENT.MANAGER")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- if ("getFail".equals(notification.getAai().get("generic-vnf.vnf-name"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE,
- notification.getNotification());
- kieSession.halt();
- } 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 AppcLcmDmaapWrapper) {
- /*
- * The request should be of type LcmRequestWrapper and the subrequestid should be 1
- */
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) obj;
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertTrue(appcRequest.getCommonHeader().getSubRequestId().equals("1"));
- assertNotNull(appcRequest.getActionIdentifiers().get("vnf-id"));
-
- logger.debug("\n============ APPC received the request!!! ===========\n");
-
- /*
- * Simulate a success response from APPC and insert the response into the working memory
- */
- AppcLcmDmaapWrapper dmaapResponse = new AppcLcmDmaapWrapper();
- AppcLcmOutput appcResponse = new AppcLcmOutput(appcRequest);
- appcResponse.getStatus().setCode(400);
- appcResponse.getStatus().setMessage("AppC success");
- dmaapResponse.setBody(new AppcLcmBody());
- dmaapResponse.getBody().setOutput(appcResponse);
-
- kieSession.insert(dmaapResponse);
- }
- }
-
- /**
- * 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
- * @param requestId the requestId for this event
- * @param status could be onset or abated
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId,
- ControlLoopEventStatus status) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-name");
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "testGenericVnfName");
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId,
- ControlLoopEventStatus status, String vnfName, boolean isEnriched) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-name");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", vnfName);
- event.getAai().put("vserver.vserver-name", vnfName);
- if (isEnriched) {
- event.getAai().put("generic-vnf.in-maint", "false");
- event.getAai().put("generic-vnf.is-closed-loop-disabled", "false");
- event.getAai().put("generic-vnf.orchestration-status", "Created");
- event.getAai().put("generic-vnf.prov-status", "ACTIVE");
- event.getAai().put("generic-vnf.resource-version", "1");
- event.getAai().put("generic-vnf.service-id", "e8cb8968-5411-478b-906a-f28747de72cd");
- event.getAai().put("generic-vnf.vnf-id", "63b31229-9a3a-444f-9159-04ce2dca3be9");
- event.getAai().put("generic-vnf.vnf-type", "vCPEInfraService10/vCPEInfraService10 0");
- }
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java
deleted file mode 100644
index 88c9e6ef7..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.so.SoRequest;
-
-public class VdnsControlLoopCqTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
- + "src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_SO_Cq-test.yaml", "type=operational",
- "CL_vDNS", "v2.0");
- SupportUtil.setCustomQuery("true");
- }
-
- @Test
- public void testSuccess() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
-
- 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 testAaiGetFail() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail");
-
- try {
- kieSession.fireUntilHalt();
-
- // allow object clean-up
- kieSession.fireAllRules();
-
- } catch (Exception e) {
- e.printStackTrace();
- logger.warn(e.toString());
- fail(e.getMessage());
- }
-
- /*
- * The only fact in memory should be Params
- */
- assertEquals(1, kieSession.getFactCount());
-
- /*
- * Print what's left in memory
- */
- dumpFacts(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,
- org.onap.policy.controlloop.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=SO"));
- } 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("SO.RESPONSE")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS
- .equals(notification.getNotification()));
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=SO"));
- } else if (policyName.endsWith("EVENT.MANAGER")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- if ("error".equals(notification.getAai().get("vserver.vserver-name"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE,
- notification.getNotification());
- } else if ("getFail".equals(notification.getAai().get("vserver.vserver-name"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE,
- notification.getNotification());
- } else {
- assertTrue(ControlLoopNotificationType.FINAL_SUCCESS
- .equals(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 SoRequest) {
- logger.debug("\n============ SO 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
- * @param requestId the requestId for this event
- * @param status could be onset or abated
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId,
- ControlLoopEventStatus status) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("vserver.vserver-name");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("vserver.vserver-name", "OzVServer");
- event.getAai().put("vserver.is-closed-loop-disabled", "false");
- event.getAai().put("vserver.prov-status", "ACTIVE");
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId,
- ControlLoopEventStatus status, String vserverName) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("vserver.vserver-name");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("vserver.vserver-name", vserverName);
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java
deleted file mode 100644
index b7b034a9c..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.so.SoRequest;
-
-public class VdnsControlLoopTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
- + "src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_SO-test.yaml",
- "type=operational",
- "CL_vDNS",
- "v2.0");
- }
-
- @Test
- public void testSuccessTest() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
-
- 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 testNamedQueryFail() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "error");
-
- 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 testAaiGetFail() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail");
-
- try {
- kieSession.fireUntilHalt();
-
- // allow object clean-up
- kieSession.fireAllRules();
-
- } catch (Exception e) {
- e.printStackTrace();
- logger.warn(e.toString());
- fail(e.getMessage());
- }
-
-
- /*
- * The only fact in memory should be Params
- */
- assertEquals(1, kieSession.getFactCount());
-
- /*
- * Print what's left in memory
- */
- dumpFacts(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,
- org.onap.policy.controlloop.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=SO"));
- } 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("SO.RESPONSE")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=SO"));
- } else if (policyName.endsWith("EVENT.MANAGER")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- if ("error".equals(notification.getAai().get("vserver.vserver-name"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification());
- } else if ("getFail".equals(notification.getAai().get("vserver.vserver-name"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification());
- } else {
- assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(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 SoRequest) {
- logger.debug("\n============ SO 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
- * @param requestId the requestId for this event
- * @param status could be onset or abated
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("vserver.vserver-name");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("vserver.vserver-name", "OzVServer");
- event.getAai().put("vserver.is-closed-loop-disabled", "false");
- event.getAai().put("vserver.prov-status", "ACTIVE");
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status,
- String vserverName) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("vserver.vserver-name");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("vserver.vserver-name", vserverName);
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java
deleted file mode 100644
index 4f472a07b..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2017-2018 Intel Corp. All rights reserved.
- * Modifications Copyright (C) 2018-2020 AT&T Intellectual Property. 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.vfc.VfcRequest;
-
-
-public class VfcControlLoopTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
- + "src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_VFC.yaml",
- "type=operational",
- "CL_VoLTE",
- "v2.0");
- }
-
- @Test
- public void testSuccess() 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
-
- 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 testNullRequest() 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * 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("tca.instance00009");
- 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);
- }
-
- /*
- * (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,
- org.onap.policy.controlloop.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=VFC"));
- } 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("VFC.RESPONSE")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=VFC"));
- } 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 VfcRequest) {
- logger.debug("\n============ VFC 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
- * @param requestId the requestId for this event
- * @param status could be onset or abated
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(UUID.randomUUID());
- event.setClosedLoopEventClient("tca.instance00009");
- 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", "vserver-name-16102016-aai3255-data-11-1");
- event.getAai().put("vserver.vserver-id", "vserver-id-16102016-aai3255-data-11-1");
- event.getAai().put("generic-vnf.vnf-id", "vnf-id-16102016-aai3255-data-11-1");
- event.getAai().put("service-instance.service-instance-id", "service-instance-id-16102016-aai3255-data-11-1");
- event.getAai().put("vserver.is-closed-loop-disabled", "false");
- event.getAai().put("vserver.prov-status", "ACTIVE");
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- kieSession.insert(event);
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopCdsTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopCdsTest.java
deleted file mode 100644
index c480db71e..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopCdsTest.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Bell Canada.
- * Modifications Copyright (C) 2020 AT&T Intellectual Property. 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 io.grpc.Server;
-import io.grpc.ServerBuilder;
-import io.grpc.stub.StreamObserver;
-
-import java.io.IOException;
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader;
-import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType;
-import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
-import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc;
-import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
-import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.controlloop.util.Serialization;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Test class for vfirewall use case using CDS actor.
- */
-public class VfwControlLoopCdsTest extends ControlLoopBase implements TopicListener {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(VfwControlLoopCdsTest.class);
-
- private final AtomicReference<StreamObserver<ExecutionServiceOutput>> responseObserverRef = new AtomicReference<>();
- private Server server;
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass("../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/"
- + "main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vFW_CDS.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vFW",
- "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
- SupportUtil.setCustomQuery("true");
- }
-
- @Before
- public void setUp() throws IOException {
- this.startGrpcServer();
- }
-
- @After
- public void tearDown() {
- this.stopGrpcServer();
- }
-
- private void startGrpcServer() throws IOException {
-
- BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase cdsBlueprintServerImpl =
-
- new BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase() {
-
- @Override
- public StreamObserver<ExecutionServiceInput> process(
- final StreamObserver<ExecutionServiceOutput> responseObserver) {
-
- responseObserverRef.set(responseObserver);
-
- return new StreamObserver<ExecutionServiceInput>() {
- @Override
- public void onNext(final ExecutionServiceInput input) {
- LOGGER.info("gRPC server onNext() for input: {} ...", input);
- ExecutionServiceOutput output =
- ExecutionServiceOutput.newBuilder()
- .setCommonHeader(
- CommonHeader.newBuilder().setRequestId(
- input.getCommonHeader().getRequestId()).build())
- .setStatus(
- Status.newBuilder().setEventType(
- EventType.EVENT_COMPONENT_EXECUTED).build())
- .build();
- responseObserver.onNext(output);
- }
-
- @Override
- public void onError(final Throwable throwable) {
- LOGGER.error("gRPC server onError() for throwable: {} ...", throwable);
- }
-
- @Override
- public void onCompleted() {
- LOGGER.info("gRPC server onCompleted() ...");
- responseObserver.onCompleted();
- }
- };
- }
- };
-
- server = ServerBuilder.forPort(SupportUtil.GRPC_SERVER_PORT).addService(cdsBlueprintServerImpl).build().start();
- LOGGER.info("gRPC server is listening for CDS requests on port {}", SupportUtil.GRPC_SERVER_PORT);
-
- }
-
- private void stopGrpcServer() {
- if (server != null) {
- this.server.shutdown();
- LOGGER.info("gRPC server handling CDS requests has been successfully shut down.");
- }
- }
-
- @Test
- public void testSuccess() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
-
- kieSession.fireUntilHalt();
- kieSession.fireAllRules();
-
- /*
- * The only fact in memory should be Params
- */
- assertEquals(1, kieSession.getFactCount());
-
- /*
- * Print what's left in memory
- */
- dumpFacts(kieSession);
- }
-
-
- /*
- * @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 ControlLoopNotification
- * of type active
- */
- assertEquals("POLICY-CL-MGT", topic);
- VirtualControlLoopNotification notification =
- Serialization.gsonJunit.fromJson(event, VirtualControlLoopNotification.class);
- assertNotNull(notification);
- String policyName = notification.getPolicyName();
- if (policyName.endsWith("EVENT")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
- } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("Sending guard query"));
- } else if (policyName.endsWith("GUARD.RESPONSE")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().toLowerCase().endsWith("permit"));
- } else if (policyName.endsWith("GUARD_PERMITTED")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=CDS"));
- } 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("CDS.RESPONSE")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertEquals(ControlLoopNotificationType.OPERATION_SUCCESS, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=CDS"));
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED);
- } else if (policyName.endsWith("EVENT.MANAGER")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- if ("error".equals(notification.getAai().get("generic-vnf.vnf-name"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification());
- assertEquals("Target vnf-id could not be found", notification.getMessage());
- } else if ("getFail".equals(notification.getAai().get("generic-vnf.vnf-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");
- }
- }
-
- /**
- * 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
- * @param requestId the requestId for this event
- * @param status could be onset or abated
- */
- private void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setTarget("generic-vnf.vnf-name");
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "testGenericVnfID");
- event.getAai().put("vserver.vserver-name", "OzVServer");
- event.setClosedLoopEventStatus(status);
- Map<String, String> map = new HashMap<>();
- map.put("my-key", "my-value");
- event.setAdditionalEventParams(map);
- kieSession.insert(event);
- }
-
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java
deleted file mode 100644
index 09c5927a8..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import org.onap.policy.appc.Request;
-import org.onap.policy.appc.Response;
-import org.onap.policy.appc.ResponseCode;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class VfwControlLoopTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/"
- + "main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vFW.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational",
- "CL_vFW",
- "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
- }
-
- @Test
- public void testASuccess() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
-
- try {
- kieSession.fireUntilHalt();
-
- // allow object clean-up
- kieSession.fireAllRules();
-
- } catch (Exception e) {
- e.printStackTrace();
- logger.warn(e.toString());
- fail("fail");
- }
-
-
- /*
- * The only fact in memory should be Params
- */
- assertEquals(1, kieSession.getFactCount());
-
- /*
- * Print what's left in memory
- */
- dumpFacts(kieSession);
- }
-
- @Test
- public void testBAaiFail() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "error");
- try {
- kieSession.fireUntilHalt();
-
- // allow object clean-up
- kieSession.fireAllRules();
-
- } catch (Exception e) {
- e.printStackTrace();
- logger.warn(e.toString());
- fail(e.getMessage());
- }
-
- /*
- * The only fact in memory should be Params
- */
- assertEquals(1, kieSession.getFactCount());
-
- /*
- * Print what's left in memory
- */
- dumpFacts(kieSession);
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off processing
- * through the rules
- */
-
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail");
-
- try {
- kieSession.fireUntilHalt();
-
- // allow object clean-up
- kieSession.fireAllRules();
-
- } catch (Exception e) {
- e.printStackTrace();
- logger.warn(e.toString());
- fail(e.getMessage());
- }
-
- /*
- * The only fact in memory should be Params
- */
- assertEquals(1, kieSession.getFactCount());
-
- /*
- * Print what's left in memory
- */
- dumpFacts(kieSession);
- }
-
- /*
- * @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,
- org.onap.policy.controlloop.VirtualControlLoopNotification.class);
- } else if ("APPC-CL".equals(topic)) {
- obj = org.onap.policy.appc.util.Serialization.gsonPretty.fromJson(event,
- org.onap.policy.appc.Request.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=APPC"));
- } 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("APPC.RESPONSE")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=APPC"));
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED);
- } else if (policyName.endsWith("EVENT.MANAGER")) {
- logger.debug("Rule Fired: " + notification.getPolicyName());
- if ("error".equals(notification.getAai().get("generic-vnf.vnf-name"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification());
- assertEquals("Target vnf-id could not be found", notification.getMessage());
- } else if ("getFail".equals(notification.getAai().get("generic-vnf.vnf-name"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification());
- } else {
- assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(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 Request) {
- assertTrue(((Request) obj).getCommonHeader().getSubRequestId().equals("1"));
- assertNotNull(((Request) obj).getPayload().get("generic-vnf.vnf-id"));
-
- logger.debug("\n============ APPC received the request!!! ===========\n");
-
- /*
- * Simulate a success response from APPC and insert the response into the working memory
- */
- Response appcResponse = new Response((Request) obj);
- appcResponse.getStatus().setCode(ResponseCode.SUCCESS.getValue());
- appcResponse.getStatus().setValue("SUCCESS");
- kieSession.insert(appcResponse);
- }
- }
-
- /**
- * 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
- * @param requestId the requestId for this event
- * @param status could be onset or abated
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-name");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", "testGenericVnfID");
- event.getAai().put("vserver.vserver-name", "testVserverName");
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-
- /**
- * 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
- * @param requestId the requestId for this event
- * @param status could be onset or abated
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String vnfId) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-name");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- event.getAai().put("generic-vnf.vnf-name", vnfId);
- event.getAai().put("vserver.vserver-name", vnfId);
- event.setClosedLoopEventStatus(status);
- kieSession.insert(event);
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java
deleted file mode 100644
index e57af7760..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2018-2020 AT&T Intellectual Property. 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.sdnr.PciRequest;
-import org.onap.policy.sdnr.PciRequestWrapper;
-import org.onap.policy.sdnr.PciResponse;
-import org.onap.policy.sdnr.PciResponseWrapper;
-
-public class VpciControlLoopTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources"
- + "/src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vPCI.yaml",
- "type=operational",
- "CL_vPCI",
- "v3.0.0");
- }
-
- @Test
- public void testSuccess() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off
- * processing through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, true);
-
- 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 testAaiGetFail() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off
- * processing through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, false);
-
- 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);
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.onap.policy.drools.PolicyEngineListener#newEventNotification(java.lang.
- * String)
- */
- @Override
- public void onTopicEvent(CommInfrastructure commType, String topic, String event) {
- logger.debug("\n============ onTopicEvent!!! ===========\n");
- logger.debug("topic: {}, event: {}", topic, 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,
- org.onap.policy.controlloop.VirtualControlLoopNotification.class);
- } else if ("SDNR-CL".equals(topic)) {
- obj = org.onap.policy.sdnr.util.Serialization.gsonJunit.fromJson(event,
- org.onap.policy.sdnr.PciRequestWrapper.class);
- }
- assertNotNull(obj);
- if (obj instanceof VirtualControlLoopNotification) {
- VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj;
- String policyName = notification.getPolicyName();
- logger.debug("Rule Fired: {}", policyName);
- if (policyName.endsWith("EVENT")) {
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
- } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("Sending guard query"));
- } else if (policyName.endsWith("GUARD.RESPONSE")) {
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().toLowerCase().endsWith("permit"));
- } else if (policyName.endsWith("GUARD_PERMITTED")) {
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=SDNR"));
- } else if (policyName.endsWith("OPERATION.TIMEOUT")) {
- kieSession.halt();
- logger.debug("The operation timed out");
- fail("Operation Timed Out");
- } else if (policyName.endsWith("SDNR.RESPONSE")) {
- assertEquals(ControlLoopNotificationType.OPERATION_SUCCESS, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=SDNR"));
- } else if (policyName.endsWith("EVENT.MANAGER")) {
- if ("getFail".equals(notification.getAai().get("generic-vnf.vnf-id"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification());
- kieSession.halt();
- } else {
- assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.getNotification());
- kieSession.halt();
- }
- } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) {
- kieSession.halt();
- logger.debug("The control loop timed out");
- fail("Control Loop Timed Out");
- }
- } else if (obj instanceof PciRequestWrapper) {
- /*
- * The request should be of type PciRequestWrapper and the subrequestid should
- * be 1
- */
- PciRequestWrapper dmaapRequest = (PciRequestWrapper) obj;
- PciRequest pciRequest = dmaapRequest.getBody();
- assertEquals("1", pciRequest.getCommonHeader().getSubRequestId());
-
- logger.debug("\n============ SDNR received the request!!! ===========\n");
- logger.debug("\n============ dmaapRequest ===========\n {} ", dmaapRequest);
- logger.debug("\n============ pciRequest ===========\n {}", pciRequest);
-
- /*
- * Simulate a success response from SDNR and insert the response into the
- * working memory
- */
- PciResponse pciResponse = new PciResponse(pciRequest);
- pciResponse.getStatus().setCode(200);
- pciResponse.getStatus().setValue("SUCCESS");
- StringBuilder sb = new StringBuilder();
- sb.append("{ \"Configurations\":[ { \"Status\": { \"Code\": 200, \"Value\":"
- + " \"SUCCESS\" }, \"data\":{ \"FAPService\":{ \"alias\":"
- + "\"Network1\", \"X0005b9Lte\" : { \"PnfName\" : \"cu1\" }, \"CellConfig\":"
- + "{ \"LTE\":{ \"RAN\":{ \"Common\":{ \"CellIdentity\":" + "\"1\" } } } } } } } ] }");
-
- pciResponse.setPayload(sb.toString());
- PciResponseWrapper dmaapResponse = new PciResponseWrapper();
- dmaapResponse.setBody(pciResponse);
- dmaapResponse.setType("response");
- logger.debug("\n============ SDNR sending response!!! ===========\n");
- logger.debug("\n============ dmaapResponse ===========\n {}", dmaapResponse);
- logger.debug("\n============ pciResponse ===========\n {}", pciResponse);
- kieSession.insert(dmaapResponse);
- }
- }
-
- /**
- * This method is used to simulate event messages from DCAE that start the
- * control loop (onset message).
- *
- * @param policy
- * the controlLoopName comes from the policy
- * @param requestId
- * the requestId for this event
- * @param status
- * could be onset
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status,
- boolean isEnriched) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- if (isEnriched) {
- event.getAai().put("generic-vnf.is-closed-loop-disabled", "false");
- event.getAai().put("generic-vnf.prov-status", "ACTIVE");
- event.getAai().put("generic-vnf.vnf-id", "notused");
- event.getAai().put("vserver.vserver-name", "OzVServer");
- } else {
- event.getAai().put("generic-vnf.vnf-id", "getFail");
- }
- event.setClosedLoopEventStatus(status);
- StringBuilder sb = new StringBuilder();
- sb.append("{ \"Configurations\":[ { \"data\":{ \"FAPService\":"
- + " { \"alias\":\"Cell1\", \"X0005b9Lte\" : { \"PhyCellIdInUse\" :"
- + " \"35\", \"PnfName\" : \"cu1\" }, \"CellConfig\":{ \"LTE\":{ \"RAN\":"
- + "{ \"Common\":{ \"CellIdentity\":\"1\" } } } } } } } ] }");
-
- event.setPayload(sb.toString());
- logger.debug("\n============ Policy receiving ONSET event !!! ===========\n");
- logger.debug("\n============ event ===========\n {}", event);
- kieSession.insert(event);
- }
-}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java
deleted file mode 100644
index 5aaab40bb..000000000
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * demo
- * ================================================================================
- * Copyright (C) 2019 Wipro Limited Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. 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.time.Instant;
-import java.util.HashMap;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.event.comm.TopicListener;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
-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.sdnr.PciRequest;
-import org.onap.policy.sdnr.PciRequestWrapper;
-import org.onap.policy.sdnr.PciResponse;
-import org.onap.policy.sdnr.PciResponseWrapper;
-
-public class VsonhControlLoopTest extends ControlLoopBase implements TopicListener {
-
- /**
- * Setup the simulator.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- ControlLoopBase.setUpBeforeClass(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources"
- + "/src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vSONH.yaml",
- "type=operational",
- "CL_vSONH",
- "v4.0.0");
- }
-
- @Test
- public void testSuccess() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off
- * processing through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, true);
-
- 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 testAaiGetFailTest() {
-
- /*
- * 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);
- }
-
- /*
- * Create a unique requestId
- */
- requestId = UUID.randomUUID();
-
- /*
- * Simulate an onset event the policy engine will receive from DCAE to kick off
- * processing through the rules
- */
- sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, false);
-
- 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);
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.onap.policy.drools.PolicyEngineListener#newEventNotification(java.lang.
- * String)
- */
- @Override
- public void onTopicEvent(CommInfrastructure commType, String topic, String event) {
- logger.debug("\n============ onTopicEvent!!! ===========\n");
- logger.debug("topic: {}, event: {}", topic, 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,
- org.onap.policy.controlloop.VirtualControlLoopNotification.class);
- } else if ("SDNR-CL".equals(topic)) {
- obj = org.onap.policy.sdnr.util.Serialization.gsonJunit.fromJson(event,
- org.onap.policy.sdnr.PciRequestWrapper.class);
- }
- assertNotNull(obj);
- if (obj instanceof VirtualControlLoopNotification) {
- VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj;
- String policyName = notification.getPolicyName();
- logger.debug("Rule Fired: {}", policyName);
- if (policyName.endsWith("EVENT")) {
- assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
- } else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("Sending guard query"));
- } else if (policyName.endsWith("GUARD.RESPONSE")) {
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().toLowerCase().endsWith("permit"));
- } else if (policyName.endsWith("GUARD_PERMITTED")) {
- assertEquals(ControlLoopNotificationType.OPERATION, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=SDNR"));
- } else if (policyName.endsWith("OPERATION.TIMEOUT")) {
- kieSession.halt();
- logger.debug("The operation timed out");
- fail("Operation Timed Out");
- } else if (policyName.endsWith("SDNR.RESPONSE")) {
- assertEquals(ControlLoopNotificationType.OPERATION_SUCCESS, notification.getNotification());
- assertNotNull(notification.getMessage());
- assertTrue(notification.getMessage().startsWith("actor=SDNR"));
- } else if (policyName.endsWith("EVENT.MANAGER")) {
- if ("getFail".equals(notification.getAai().get("generic-vnf.vnf-id"))) {
- assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.getNotification());
- kieSession.halt();
- } else {
- assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notification.getNotification());
- kieSession.halt();
- }
- } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) {
- kieSession.halt();
- logger.debug("The control loop timed out");
- fail("Control Loop Timed Out");
- }
- } else if (obj instanceof PciRequestWrapper) {
- /*
- * The request should be of type PciRequestWrapper and the subrequestid should
- * be 1
- */
- PciRequestWrapper dmaapRequest = (PciRequestWrapper) obj;
- PciRequest pciRequest = dmaapRequest.getBody();
- assertEquals("1", pciRequest.getCommonHeader().getSubRequestId());
-
- logger.debug("\n============ SDNR received the request!!! ===========\n");
- logger.debug("\n============ dmaapRequest ===========\n {} ", dmaapRequest);
- logger.debug("\n============ pciRequest ===========\n {}", pciRequest);
-
- /*
- * Simulate a success response from SDNR and insert the response into the
- * working memory
- */
- PciResponse pciResponse = new PciResponse(pciRequest);
- pciResponse.getStatus().setCode(200);
- pciResponse.getStatus().setValue("SUCCESS");
- StringBuilder sb = new StringBuilder();
- sb.append("{ \"Configurations\":[ { \"Status\": { \"Code\": 200, \"Value\":"
- + " \"SUCCESS\" }, \"data\":{ \"FAPService\":{ \"alias\":"
- + "\"Network1\", \"CellConfig\":{ \"LTE\":{ \"RAN\":{ \"Common\":"
- + "{ \"CellIdentity\":\"1\" }, \"NeighborListInUse\" : "
- + "{ \"LTECellNumberOfEntries\" : \"1\" , \"LTECell\" : "
- + "[ { \"PLMNID\" :\"plmnid1\", \"CID\":\"Chn0001\", \"PhyCellID\":"
- + "\"3\", \"PNFName\":\"ncserver01\", \"Blacklisted\":\"false\" "
- + "} ] } } } } } } } ] }");
-
- pciResponse.setPayload(sb.toString());
- PciResponseWrapper dmaapResponse = new PciResponseWrapper();
- dmaapResponse.setBody(pciResponse);
- dmaapResponse.setType("response");
- logger.debug("\n============ SDNR sending response!!! ===========\n");
- logger.debug("\n============ dmaapResponse ===========\n {}", dmaapResponse);
- logger.debug("\n============ pciResponse ===========\n {}", pciResponse);
- kieSession.insert(dmaapResponse);
- }
- }
-
- /**
- * This method is used to simulate event messages from DCAE that start the
- * control loop (onset message).
- *
- * @param policy
- * the controlLoopName comes from the policy
- * @param requestId
- * the requestId for this event
- * @param status
- * could be onset
- */
- protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status,
- boolean isEnriched) {
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestId);
- event.setTarget("generic-vnf.vnf-id");
- event.setTargetType(ControlLoopTargetType.VNF);
- event.setClosedLoopAlarmStart(Instant.now());
- event.setAai(new HashMap<>());
- if (isEnriched) {
- event.getAai().put("generic-vnf.is-closed-loop-disabled", "false");
- event.getAai().put("generic-vnf.prov-status", "ACTIVE");
- event.getAai().put("generic-vnf.vnf-id", "notused");
- event.getAai().put("vserver.vserver-name", "OzVServer");
- } else {
- event.getAai().put("generic-vnf.vnf-id", "getFail");
- }
- event.setClosedLoopEventStatus(status);
- StringBuilder sb = new StringBuilder();
- sb.append("{ \"Configurations\":[ { \"data\":{ \"FAPService\":"
- + " { \"alias\":\"Cell1\", \"CellConfig\":{ \"LTE\":{ \"RAN\":{ \"Common\":"
- + "{ \"CellIdentity\":\"1\" }, \"NeighborListInUse\" : "
- + "{ \"LTECellNumberOfEntries\" : \"1\" , \"LTECell\" : "
- + "[ { \"PLMNID\" :\"plmnid1\", \"CID\":\"Chn0001\", \"PhyCellID\":"
- + "\"3\", \"PNFName\":\"ncserver01\", \"Blacklisted\":\"false\" "
- + "} ] } } } } } } } ] }");
-
- event.setPayload(sb.toString());
- logger.debug("\n============ Policy receiving ONSET event !!! ===========\n");
- logger.debug("\n============ event ===========\n {}", event);
- kieSession.insert(event);
- }
-}