From 268ef0de1095a30c74a0ff8144cb49b157253658 Mon Sep 17 00:00:00 2001 From: Peyton Puckett Date: Wed, 11 Mar 2020 11:09:56 -0500 Subject: Delete template.demo submodule, amsterdam controller Issue-ID: POLICY-2421 Change-Id: I0e61e7b3272f5c7babceb41e4e249716af4529cf Signed-off-by: Peyton Puckett --- .../src/main/resources/blacklist_template.xml | 117 ------ .../main/resources/frequency_limiter_template.xml | 127 ------ .../resources/frequency_limiter_template_old.xml | 101 ----- .../template/demo/CcvpnBwControlLoopTest.java | 234 ----------- .../policy/template/demo/CcvpnControlLoopTest.java | 231 ----------- .../onap/policy/template/demo/ControlLoopBase.java | 236 ----------- .../template/demo/ControlLoopEventCleanupTest.java | 377 ----------------- .../template/demo/ControlLoopFailureTest.java | 279 ------------- .../demo/ControlLoopParamsCleanupTest.java | 257 ------------ .../org/onap/policy/template/demo/SupportUtil.java | 460 --------------------- .../policy/template/demo/VcpeControlLoopTest.java | 287 ------------- .../template/demo/VdnsControlLoopCqTest.java | 258 ------------ .../policy/template/demo/VdnsControlLoopTest.java | 290 ------------- .../policy/template/demo/VfcControlLoopTest.java | 247 ----------- .../template/demo/VfwControlLoopCdsTest.java | 273 ------------ .../policy/template/demo/VfwControlLoopTest.java | 317 -------------- .../policy/template/demo/VpciControlLoopTest.java | 284 ------------- .../policy/template/demo/VsonhControlLoopTest.java | 291 ------------- .../src/test/resources/META-INF/persistence.xml | 43 -- .../test/resources/xacml/xacml_guard.properties | 72 ---- .../resources/yaml/policy_ControlLoop_CCVPN.yaml | 37 -- .../yaml/policy_ControlLoop_CCVPN_BW.yaml | 37 -- .../policy_ControlLoop_EventCleanup-test-B.yaml | 41 -- .../yaml/policy_ControlLoop_EventCleanup-test.yaml | 41 -- .../policy_ControlLoop_EventCleanup-test2.yaml | 45 -- .../policy_ControlLoop_ParamsCleanup-test-B.yaml | 35 -- .../policy_ControlLoop_ParamsCleanup-test.yaml | 35 -- .../policy_ControlLoop_ParamsCleanup-test2.yaml | 39 -- .../resources/yaml/policy_ControlLoop_SO-test.yaml | 47 --- .../yaml/policy_ControlLoop_SO_Cq-test.yaml | 47 --- .../yaml/policy_ControlLoop_Service123.yaml | 75 ---- .../resources/yaml/policy_ControlLoop_VFC.yaml | 37 -- .../resources/yaml/policy_ControlLoop_vCPE.yaml | 36 -- .../resources/yaml/policy_ControlLoop_vFW.yaml | 41 -- .../resources/yaml/policy_ControlLoop_vFW_CDS.yaml | 46 --- .../resources/yaml/policy_ControlLoop_vPCI.yaml | 38 -- .../resources/yaml/policy_ControlLoop_vSONH.yaml | 38 -- .../resources/yaml/policy_guard_appc_migrate.yaml | 39 -- .../yaml/policy_guard_appc_modifyconfig.yaml | 39 -- .../resources/yaml/policy_guard_appc_rebuild.yaml | 39 -- .../yaml/policy_guard_appc_rebuild_1.yaml | 39 -- .../resources/yaml/policy_guard_appc_restart.yaml | 40 -- .../yaml/policy_guard_appc_restart_blacklist.yaml | 40 -- 43 files changed, 5732 deletions(-) delete mode 100644 controlloop/templates/template.demo/src/main/resources/blacklist_template.xml delete mode 100644 controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml delete mode 100644 controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopParamsCleanupTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopCqTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopCdsTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java delete mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java delete mode 100644 controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml delete mode 100644 controlloop/templates/template.demo/src/test/resources/xacml/xacml_guard.properties delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test-B.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test2.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test-B.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test2.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO-test.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO_Cq-test.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_Service123.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_VFC.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vCPE.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW_CDS.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vPCI.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vSONH.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_migrate.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_rebuild.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_restart.yaml delete mode 100644 controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml (limited to 'controlloop/templates/template.demo/src') diff --git a/controlloop/templates/template.demo/src/main/resources/blacklist_template.xml b/controlloop/templates/template.demo/src/main/resources/blacklist_template.xml deleted file mode 100644 index 1563e4a7d..000000000 --- a/controlloop/templates/template.demo/src/main/resources/blacklist_template.xml +++ /dev/null @@ -1,117 +0,0 @@ - - - - Policy for frequency limiter. - - - - - - ${clname} - - - - - - ${actor} - - - - ${recipe} - - - - - - - DENY - only if target is in black list and guard is - active. - - - - - - - - - - - - - - - ${blackListElement} - - - - - - - - - - ${guardActiveStart} - ${guardActiveEnd} - - - diff --git a/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml b/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml deleted file mode 100644 index d26432f86..000000000 --- a/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - Policy for frequency limiter. - - - - - - - ${clname} - - - - - - ${actor} - - - - ${recipe} - - - - - ${targets} - - - - - - - - DENY - only if number of operations performed in - the past is larger than the limit and the Guard is active. - - - - - - - - - - - - - ${guardActiveStart} - ${guardActiveEnd} - - - - - - - - ${limit} - - - diff --git a/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml b/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml deleted file mode 100644 index e1e3451f3..000000000 --- a/controlloop/templates/template.demo/src/main/resources/frequency_limiter_template_old.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - Policy for frequency limiter. - - - - - ${actor} - - - - ${recipe} - - - - - - - DENY - only if number of operations performed in - the past is larger than the limit and the Guard is active. - - - - - - - - - - - - - ${guardActiveStart} - ${guardActiveEnd} - - - - - - - - ${limit} - - - 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()); - 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()); - 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()); - 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()); - 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 noopTopics; - - protected static KieSession kieSession; - protected static SupportUtil.Pair 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 - * two 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 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 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 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 getSessionObjects() { - // sort the objects so we know the order - LinkedList 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 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 - * two 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 facts = getSessionObjects(); - assertEquals(specifications.length, facts.size()); - Iterator 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 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 getSessionObjects() { - // sort the objects so we know the order - LinkedList 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 { - 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 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) 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()); - 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()); - 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> 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 process( - final StreamObserver responseObserver) { - - responseObserverRef.set(responseObserver); - - return new StreamObserver() { - @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 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); - } -} diff --git a/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml b/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml deleted file mode 100644 index b6d80e099..000000000 --- a/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - org.eclipse.persistence.jpa.PersistenceProvider - - org.onap.policy.database.operationshistory.Dbao - - - - - - - - - - - - - - - diff --git a/controlloop/templates/template.demo/src/test/resources/xacml/xacml_guard.properties b/controlloop/templates/template.demo/src/test/resources/xacml/xacml_guard.properties deleted file mode 100644 index 175b9d3d2..000000000 --- a/controlloop/templates/template.demo/src/test/resources/xacml/xacml_guard.properties +++ /dev/null @@ -1,72 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP -# ================================================================================ -# Copyright (C) 2017-2018 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========================================================= -### -# -# -# This files defines PIPs that will be used by XACML Guard Policies. One PIP per time window (5 min, 10min,...,1 month). -# -# -# - -# -# Default XACML Properties File -# Standard API Factories -# -xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory -xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory -xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory -xacml.pipFinderFactory=com.att.research.xacml.std.pip.StdPIPFinderFactory -xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory -# -# AT&T PDP Implementation Factories -# -xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory -xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory -xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory -xacml.att.policyFinderFactory=com.att.research.xacmlatt.pdp.std.StdPolicyFinderFactory - - -# -# NOTE: If you are testing against a RESTful PDP, then the PDP must be configured with the -# policies and PIP configuration as defined below. Otherwise, this is the configuration that -# the embedded PDP uses. -# - -# In case we have multiple applicable Guard policies, we will deny if any of them denies. -xacml.att.policyFinderFactory.combineRootPolicies=urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-unless-deny - - -# Policies to load -# -xacml.rootPolicies=p1,p2,p3,p4,p5 -p1.file=src/test/resources/xacml/autogenerated_frequency_limiter_restart.xml -p2.file=src/test/resources/xacml/autogenerated_frequency_limiter_rebuild.xml -p3.file=src/test/resources/xacml/autogenerated_frequency_limiter_migrate.xml -p4.file=src/test/resources/xacml/autogenerated_frequency_limiter_rebuild_1.xml -p5.file=src/test/resources/xacml/autogenerated_blacklist.xml - - -# PIP Engine Definition -# -xacml.pip.engines=count-recent-operations -count-recent-operations.classname=org.onap.policy.pdp.xacml.application.common.operationshistory.CountRecentOperationsPip -count-recent-operations.issuer=urn:org:onap:xacml:guard:count-recent-operations -count-recent-operations.name=CountRecentOperations -count-recent-operations.description=Returns operation counts based on time window -count-recent-operations.persistenceunit=OperationsHistoryPUTest diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN.yaml deleted file mode 100644 index 176c1dc0e..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN.yaml +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2018 Huawei. All rights reserved -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-CCVPN-2179b738-fd36-4843-a71a-a8c24c70c66b - trigger_policy: unique-policy-id-16-Reroute - timeout: 3600 - abatement: false - -policies: - - id: unique-policy-id-16-Reroute - name: Connectivity Reroute - description: - actor: SDNC - recipe: Reroute - target: - type: VM - retry: 3 - timeout: 1200 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard - diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml deleted file mode 100644 index f994d4104..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_CCVPN_BW.yaml +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-CCVPN-2179b738-fd36-4843-a71a-a8c24c70c22b - trigger_policy: unique-policy-id-16-BandwidthOnDemand - timeout: 3600 - abatement: false - -policies: - - id: unique-policy-id-16-BandwidthOnDemand - name: CCVPNBandwidthOnDemand - description: - actor: SDNC - recipe: BandwidthOnDemand - target: - type: VM - retry: 3 - timeout: 1200 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard - diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test-B.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test-B.yaml deleted file mode 100644 index 498ef766e..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test-B.yaml +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-Event-Cleanup-Test-B - services: - - serviceInvariantUUID: 5cfe6f4a-41bc-4247-8674-ebd4b98e35cc - serviceUUID: 0f40bba5-986e-4b3c-803f-ddd1b7b25f24 - serviceName: 57e66ea7-0ed6-45c7-970f - trigger_policy: unique-policy-id-1-modifyConfig - timeout: 60 - abatement: true - -policies: - - id: unique-policy-id-1-modifyConfig - name: modify packet gen config - description: - actor: APPC - recipe: ModifyConfig - target: - resourceID: Eace933104d443b496b8.nodes.heat.vpg - type: VNF - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard \ No newline at end of file diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test.yaml deleted file mode 100644 index a19b0ef6b..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test.yaml +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-Event-Cleanup-Test - services: - - serviceInvariantUUID: 5cfe6f4a-41bc-4247-8674-ebd4b98e35cc - serviceUUID: 0f40bba5-986e-4b3c-803f-ddd1b7b25f24 - serviceName: 57e66ea7-0ed6-45c7-970f - trigger_policy: unique-policy-id-1-modifyConfig - timeout: 60 - abatement: true - -policies: - - id: unique-policy-id-1-modifyConfig - name: modify packet gen config - description: - actor: APPC - recipe: ModifyConfig - target: - resourceID: Eace933104d443b496b8.nodes.heat.vpg - type: VNF - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard \ No newline at end of file diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test2.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test2.yaml deleted file mode 100644 index 57062a47a..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_EventCleanup-test2.yaml +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2018 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. - -# -# This YAML must be slightly different from test.yaml. -# -controlLoop: - version: 3.0.0 - controlLoopName: ControlLoop-Event-Cleanup-Test - services: - - serviceInvariantUUID: 5cfe6f4a-41bc-4247-8674-ebd4b98e35cc - serviceUUID: 0f40bba5-986e-4b3c-803f-ddd1b7b25f24 - serviceName: 57e66ea7-0ed6-45c7-970f - trigger_policy: unique-policy-id-1-modifyConfig - timeout: 60 - abatement: true - -policies: - - id: unique-policy-id-1-modifyConfig - name: modify packet gen config - description: - actor: APPC - recipe: ModifyConfig - target: - resourceID: Eace933104d443b496b8.nodes.heat.vpg - type: VNF - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard \ No newline at end of file diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test-B.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test-B.yaml deleted file mode 100644 index e19cb498e..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test-B.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-Params-Cleanup-Test-B - trigger_policy: unique-policy-id-1-scale-up - timeout: 60 - -policies: - - id: unique-policy-id-1-scale-up - name: Create a new VF Module - description: - actor: SO - recipe: VF Module Create - target: - type: VNF - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test.yaml deleted file mode 100644 index 6d89d58c4..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-Params-Cleanup-Test - trigger_policy: unique-policy-id-1-scale-up - timeout: 60 - -policies: - - id: unique-policy-id-1-scale-up - name: Create a new VF Module - description: - actor: SO - recipe: VF Module Create - target: - type: VNF - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test2.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test2.yaml deleted file mode 100644 index 358bbfbea..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_ParamsCleanup-test2.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2018 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. - -# -# This YAML must be slightly different from test.yaml. -# -controlLoop: - version: 3.0.0 - controlLoopName: ControlLoop-Params-Cleanup-Test - trigger_policy: unique-policy-id-1-scale-up - timeout: 60 - -policies: - - id: unique-policy-id-1-scale-up - name: Create a new VF Module - description: - actor: SO - recipe: VF Module Create - target: - type: VNF - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO-test.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO-test.yaml deleted file mode 100644 index d32f55b5d..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO-test.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3 - services: - - serviceName: d4738992-6497-4dca-9db9 - serviceInvariantUUID: dc112d6e-7e73-4777-9c6f-1a7fb5fd1b6f - serviceUUID: 2eea06c6-e1d3-4c3a-b9c4-478c506eeedf - trigger_policy: unique-policy-id-1-scale-up - timeout: 60 - -policies: - - id: unique-policy-id-1-scale-up - name: Create a new VF Module - description: - actor: SO - recipe: VF Module Create - target: - type: VFMODULE - modelInvariantId: e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e - modelVersionId: 94b18b1d-cc91-4f43-911a-e6348665f292 - modelName: VfwclVfwsnkBbefb8ce2bde..base_vfw..module-0 - modelVersion: 1 - modelCustomizationId: 47958575-138f-452a-8c8d-d89b595f8164 - payload: - requestParameters: '{"usePreload":true,"userParams":[]}' - configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[9]","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[16]","enabled":"$.vf-module-topology.vf-module-parameters.param[23]"}]' - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO_Cq-test.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO_Cq-test.yaml deleted file mode 100644 index 16c031f33..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_SO_Cq-test.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3 - services: - - serviceName: d4738992-6497-4dca-9db9 - serviceInvariantUUID: dc112d6e-7e73-4777-9c6f-1a7fb5fd1b6f - serviceUUID: 2eea06c6-e1d3-4c3a-b9c4-478c506eeedf - trigger_policy: unique-policy-id-1-scale-up - timeout: 60 - -policies: - - id: unique-policy-id-1-scale-up - name: Create a new VF Module - description: - actor: SO - recipe: VF Module Create - target: - type: VFMODULE - modelInvariantId: e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e - modelVersionId: 94b18b1d-cc91-4f43-911a-e6348665f292 - modelName: VfwclVfwsnkBbefb8ce2bde..base_vfw..module-0 - modelVersion: 1 - modelCustomizationId: 47958575-138f-452a-8c8d-d89b595f8164 - payload: - requestParameters: '{"usePreload":true,"userParams":[]}' - configurationParameters: '[{"ip-addr":"$.vf-module-topology.vf-module-parameters.param[9]","oam-ip-addr":"$.vf-module-topology.vf-module-parameters.param[16]","enabled":"$.vf-module-topology.vf-module-parameters.param[23]"}]' - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_Service123.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_Service123.yaml deleted file mode 100644 index 3892c3bb2..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_Service123.yaml +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-Service123-cbed919f-2212-4ef7-8051-fe6308da1bda - services: - - serviceName: Service123 - resources: - - resourceName: res1 - resourceType: VFC - - resourceName: res2 - resourceType: VFC - trigger_policy: unique-policy-id-1-restart - timeout: 60 - abatement: true - -policies: - - id: unique-policy-id-1-restart - name: Restart Policy - description: - actor: APPC - recipe: Restart - target: - type: VM - retry: 3 - timeout: 20 - success: final_success - failure: unique-policy-id-2-rebuild - failure_timeout: unique-policy-id-2-rebuild - failure_retries: unique-policy-id-2-rebuild - failure_guard: unique-policy-id-2-rebuild - failure_exception: final_failure_exception - - - id: unique-policy-id-2-rebuild - name: Rebuild Policy - description: - actor: APPC - recipe: Rebuild - target: - type: VM - retry: 0 - timeout: 10 - success: final_success - failure: unique-policy-id-3-migrate - failure_timeout: unique-policy-id-3-migrate - failure_retries: unique-policy-id-3-migrate - failure_guard: unique-policy-id-3-migrate - failure_exception: final_failure_exception - - - id: unique-policy-id-3-migrate - name: Migrate Policy - description: - actor: APPC - recipe: Migrate - target: - type: VM - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_guard: final_failure_guard - failure_exception: final_failure_exception diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_VFC.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_VFC.yaml deleted file mode 100644 index ea9c7ded2..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_VFC.yaml +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-VOLTE-2179b738-fd36-4843-a71a-a8c24c70c55b - - trigger_policy: unique-policy-id-1-restart - timeout: 60 - -policies: - - id: unique-policy-id-1-restart - name: Restart the VM - description: - actor: VFC - recipe: Restart - target: - type: VM - retry: 3 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard - diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vCPE.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vCPE.yaml deleted file mode 100644 index 26fc5c81b..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vCPE.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e - trigger_policy: unique-policy-id-1-restart - timeout: 60 - abatement: true - -policies: - - id: unique-policy-id-1-restart - name: Restart the VM - description: - actor: APPC - recipe: Restart - target: - type: VNF - retry: 3 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW.yaml deleted file mode 100644 index 8c94b1adc..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW.yaml +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2018 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a - services: - - serviceInvariantUUID: f6937c86-584c-47ae-ad29-8d41d6f0cc7c - serviceUUID: 7be584e2-0bb2-4126-adaf-ced2c77ca0b3 - serviceName: Service_Ete_Name7ba1fbde-6187-464a-a62d-d9dd25bdf4e8 - trigger_policy: unique-policy-id-1-modifyConfig - timeout: 60 - abatement: true - -policies: - - id: unique-policy-id-1-modifyConfig - name: modify packet gen config - description: - actor: APPC - recipe: ModifyConfig - target: - resourceID: bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38 - type: VNF - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW_CDS.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW_CDS.yaml deleted file mode 100644 index 511a9694b..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vFW_CDS.yaml +++ /dev/null @@ -1,46 +0,0 @@ -# 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. -controlLoop: - version: 2.0.0 - controlLoopName: ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a - services: - - serviceInvariantUUID: 5cfe6f4a-41bc-4247-8674-ebd4b98e35cc - serviceUUID: 0f40bba5-986e-4b3c-803f-ddd1b7b25f24 - serviceName: 57e66ea7-0ed6-45c7-970f - trigger_policy: unique-policy-id-1-modifyConfig - timeout: 60 - abatement: true - -policies: - - id: unique-policy-id-1-modifyConfig - name: modify packet gen config - description: - actor: CDS - recipe: ModifyConfig - target: - resourceID: bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38 - type: VNF - payload: - artifact_name: vfw-cds - artifact_version: 1.0.0 - mode: async - data: '{"mapInfo":{"key":"val"},"arrayInfo":["one","two"],"paramInfo":"val"}' - retry: 0 - timeout: 30 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vPCI.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vPCI.yaml deleted file mode 100644 index 42e2000db..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vPCI.yaml +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2018 Wipro Limited 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. -controlLoop: - version: 3.0.0 - controlLoopName: ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459 - trigger_policy: unique-policy-id-123-modifyconfig - timeout: 1200 - abatement: false - -policies: - - id: unique-policy-id-123-modifyconfig - name: modify PCI config - description: - actor: SDNR - recipe: ModifyConfig - target: - # These fields are not used - resourceID: bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38 - type: VNF - retry: 0 - timeout: 300 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vSONH.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vSONH.yaml deleted file mode 100644 index 4cdf8ff40..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_ControlLoop_vSONH.yaml +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2019 Wipro Limited 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. -controlLoop: - version: 3.0.0 - controlLoopName: ControlLoop-vSONH-7d4baf04-8875-4d1f-946d-06b874048b61 - trigger_policy: unique-policy-id-456-modifyconfig - timeout: 1200 - abatement: false - -policies: - - id: unique-policy-id-456-modifyconfig - name: modify ANR config - description: - actor: SDNR - recipe: ModifyConfigANR - target: - # These fields are not used - resourceID: Eace933104d443b496b8.nodes.heat.vpg - type: VNF - retry: 0 - timeout: 300 - success: final_success - failure: final_failure - failure_timeout: final_failure_timeout - failure_retries: final_failure_retries - failure_exception: final_failure_exception - failure_guard: final_failure_guard diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_migrate.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_migrate.yaml deleted file mode 100644 index 1e84f391a..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_migrate.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2018 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. -guard: - version: 2.0.0 - -guards: - - id: unique_guard_1 - name: APPC 5 Migrate - description: | - We only allow 2 restarts over 10 minute window during the day time hours (avoid midnight to 5am) - match_parameters: - #controlLoopName: ControlLoop-Service123-cbed919f-2212-4ef7-8051-fe6308da1bda - actor: APPC - recipe: Migrate - limit_constraints: - - freq_limit_per_target: 1 - time_window: - value: 10 - units: minute - active_time_range: - start: 00:00:00-05:00 - end: 23:59:59-05:00 - - - - - - \ No newline at end of file diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml deleted file mode 100644 index 9a1fd884c..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2018 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. -guard: - version: 2.0.0 - -guards: - - id: unique_guard_6 - name: APPC 6 ModifyConfig - description: | - We only allow 2 ModifyConfig over 10 minute window during the day time hours (avoid midnight to 5am) - match_parameters: - controlLoopName: ControlLoop-Service123-cbed919f-2212-4ef7-8051-fe6308da1bda - actor: APPC - recipe: ModifyConfig - targets: - - s1 - - s2 - - foobartriggersource36 - - s3 - - testGenericVnfName - limit_constraints: - - freq_limit_per_target: 1 - time_window: - value: 10 - units: minute - active_time_range: - start: 00:00:00-05:00 - end: 23:59:59-05:00 \ No newline at end of file diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_rebuild.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_rebuild.yaml deleted file mode 100644 index 1e4988636..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_rebuild.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2018 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. -guard: - version: 2.0.0 - -guards: - - id: unique_guard_3 - name: APPC 5 Rebuild - description: | - We only allow 2 restarts over 10 minute window during the day time hours (avoid midnight to 5am) - match_parameters: - controlLoopName: ControlLoop-Service123-cbed919f-2212-4ef7-8051-fe6308da1bda - actor: APPC - recipe: Rebuild - limit_constraints: - - freq_limit_per_target: 2 - time_window: - value: 10 - units: minute - active_time_range: - start: 00:00:00-05:00 - end: 23:59:59-05:00 - - - - - - \ No newline at end of file diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml deleted file mode 100644 index 57205132e..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2018 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. -guard: - version: 2.0.0 - -guards: - - id: unique_guard_2 - name: APPC 5 Rebuild - description: | - We only allow 2 restarts over 10 minute window during the day time hours (avoid midnight to 5am) - match_parameters: - controlLoopName: ControlLoop-Service123-cbed919f-2212-4ef7-8051-fe6308da1bda - actor: - recipe: Rebuild - limit_constraints: - - freq_limit_per_target: 25 - time_window: - value: 1 - units: week - active_time_range: - start: 00:00:00-05:00 - end: 23:59:59-05:00 - - - - - - \ No newline at end of file diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_restart.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_restart.yaml deleted file mode 100644 index c10050b7f..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_restart.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2018 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. -guard: - version: 2.0.0 - -guards: - - id: unique_guard_5 - name: APPC 5 Restart - description: | - We only allow 2 restarts over 10 minute window during the day time hours (avoid midnight to 5am) - match_parameters: - controlLoopName: ControlLoop-Service123-cbed919f-2212-4ef7-8051-fe6308da1bda - actor: APPC - recipe: Restart - targets: - - s1 - - s2 - - foobartriggersource36 - - s3 - - testGenericVnfName - limit_constraints: - - freq_limit_per_target: 1 - time_window: - value: 10 - units: minute - active_time_range: - start: 00:00:00-05:00 - end: 23:59:59-05:00 - diff --git a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml b/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml deleted file mode 100644 index d89577182..000000000 --- a/controlloop/templates/template.demo/src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2018 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. -guard: - version: 2.0.0 - -guards: - - id: unique_guard_4_Blacklist - name: APPC Restart Blacklist - description: | - We deny restart of the blacklisted targets (avoid midnight to 5am) - match_parameters: - actor: APPC - recipe: Restart - limit_constraints: - - blacklist: - - server123 - - server2234 - - vserver.vserver-name22 - - aaabbbccc - - foobartriggersource35 - active_time_range: - start: 00:00:00-05:00 - end: 23:59:59-05:00 - - - - - - \ No newline at end of file -- cgit 1.2.3-korg