From 6dfab64262ea5816c761042192c84e498a3177ab Mon Sep 17 00:00:00 2001 From: jhh Date: Wed, 12 Feb 2020 18:20:06 -0600 Subject: tosca compliant op policy support + vcpe test Tosca Compliant and Toscal Legacy Operational policies are both supported for backwards compatibility. vCPE usecase junits to support 2 equivalent policies, one tosca compliant and the other one legacy. Issue-ID: POLICY-2360 Signed-off-by: jhh Change-Id: Iafbfc92bbec42e6a3fe4ceb4a9a17c85e636ea14 Signed-off-by: jhh --- .../src/main/resources/META-INF/kmodule.xml | 4 +- .../src/main/resources/usecases.drl | 6 +-- .../org/onap/policy/controlloop/UsecasesBase.java | 10 ++--- .../java/org/onap/policy/controlloop/VcpeTest.java | 44 +++++++++++++++------- .../test/resources/vcpe/tosca-compliant-vcpe.json | 37 ++++++++++++++++++ .../src/test/resources/vcpe/tosca-legacy-vcpe.json | 9 +++++ .../src/test/resources/vcpe/tosca-vcpe.json | 9 ----- 7 files changed, 88 insertions(+), 31 deletions(-) create mode 100644 controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json create mode 100644 controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json delete mode 100644 controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json (limited to 'controlloop/common/controller-usecases') diff --git a/controlloop/common/controller-usecases/src/main/resources/META-INF/kmodule.xml b/controlloop/common/controller-usecases/src/main/resources/META-INF/kmodule.xml index 4fe7da112..e1a23863a 100644 --- a/controlloop/common/controller-usecases/src/main/resources/META-INF/kmodule.xml +++ b/controlloop/common/controller-usecases/src/main/resources/META-INF/kmodule.xml @@ -19,7 +19,9 @@ ============LICENSE_END========================================================= --> - + + diff --git a/controlloop/common/controller-usecases/src/main/resources/usecases.drl b/controlloop/common/controller-usecases/src/main/resources/usecases.drl index e070b0219..3fe2cddbf 100644 --- a/controlloop/common/controller-usecases/src/main/resources/usecases.drl +++ b/controlloop/common/controller-usecases/src/main/resources/usecases.drl @@ -108,8 +108,8 @@ rule "INSERT.PARAMS" then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); - logger.info("{}: {} : YAML=[{}]", $params.getClosedLoopControlName(), $params.getPolicyName() + "." - + drools.getRule().getName(), $params.getControlLoopYaml()); + logger.info("{}: {} : TOSCA-POLICY=[{}]", $params.getClosedLoopControlName(), $params.getPolicyName() + "." + + drools.getRule().getName(), $params.getToscaPolicy()); end /* @@ -200,7 +200,7 @@ rule "EVENT" // Determine if EventManager can actively process the event // (i.e. syntax, is_closed_loop_disabled checks etc.) // - VirtualControlLoopNotification notification = manager.activate($params.getControlLoopYaml(), $event); + VirtualControlLoopNotification notification = manager.activate($params.getToscaPolicy(), $event); notification.setFrom("pdp-0001-controller=controlloop"); // Engine.getInstanceName() notification.setPolicyName($params.getPolicyName() + "." + drools.getRule().getName()); notification.setPolicyScope($params.getPolicyScope()); diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java index 1fe6ace44..618963a70 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java @@ -146,7 +146,7 @@ public abstract class UsecasesBase { return usecases .getDrools() .facts(USECASES, ControlLoopParams.class).stream() - .filter((params) -> params.getControlLoopYaml() == policy.getProperties().get("content")) + .filter((params) -> params.getToscaPolicy() == policy) .findFirst() .get(); } @@ -178,7 +178,7 @@ public abstract class UsecasesBase { usecases .getDrools() .facts(USECASES, ControlLoopParams.class).stream() - .filter((params) -> params.getControlLoopYaml() == policy.getProperties().get("content")) + .filter((params) -> params.getToscaPolicy() == policy) .count()); return policy; @@ -209,18 +209,18 @@ public abstract class UsecasesBase { usecases .getDrools() .facts(USECASES, ControlLoopParams.class).stream() - .filter((params) -> params.getControlLoopYaml() == policy.getProperties().get("content")) + .filter((params) -> params.getPolicyName() == policy.getName()) .count()); } /** * Prepare a PDP-D to test the Use Cases. */ - protected static void preparePdpD() throws IOException, InterruptedException, CoderException { + protected static void preparePdpD() throws IOException { KieUtils.installArtifact( Paths.get("src/main/resources/META-INF/kmodule.xml").toFile(), Paths.get("src/test/resources/usecases.pom").toFile(), - "src/main/resources/onap.policies.controlloop.Operational/org/onap/policy/controlloop/", + "src/main/resources/org/onap/policy/controlloop/", Collections.singletonList(Paths.get("src/main/resources/usecases.drl").toFile())); repo.setConfigurationDir("src/test/resources/config"); diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java index 8690f1a0a..1d9d0dd26 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java @@ -42,7 +42,8 @@ public class VcpeTest extends UsecasesBase { /** * VCPE Tosca Policy File. */ - private static final String TOSCA_POLICY_VCPE = "src/test/resources/vcpe/tosca-vcpe.json"; + private static final String TOSCA_LEGACY_POLICY_VCPE = "src/test/resources/vcpe/tosca-legacy-vcpe.json"; + private static final String TOSCA_COMPLIANT_POLICY_VCPE = "src/test/resources/vcpe/tosca-compliant-vcpe.json"; /* * VCPE Use case Messages. @@ -86,7 +87,6 @@ public class VcpeTest extends UsecasesBase { /** * Sunny day scenario for the VCPE use case. */ - @Test public void sunnyDay() throws IOException { /* Inject an ONSET event over the DCAE topic */ @@ -121,13 +121,41 @@ public class VcpeTest extends UsecasesBase { waitForFinalSuccess(policy, policyClMgt); } + /** + * Sunny Day with Legacy Tosca Policy. + */ + @Test + public void sunnyDayLegacy() throws InterruptedException, CoderException, IOException { + assertEquals(0, usecases.getDrools().factCount(USECASES)); + policy = setupPolicy(TOSCA_LEGACY_POLICY_VCPE); + assertEquals(2, usecases.getDrools().factCount(USECASES)); + + sunnyDay(); + } + + /** + * Sunny Day with Tosca Compliant Policy. + */ + @Test + public void sunnyDayCompliant() throws InterruptedException, CoderException, IOException { + assertEquals(0, usecases.getDrools().factCount(USECASES)); + policy = setupPolicy(TOSCA_COMPLIANT_POLICY_VCPE); + assertEquals(2, usecases.getDrools().factCount(USECASES)); + + sunnyDay(); + } + /** * An ONSET flood prevention test that injects a few ONSETs at once. * It attempts to simulate the flooding behavior of the DCAE TCA microservice. * TCA could blast tenths or hundreds of ONSETs within sub-second intervals. */ @Test - public void onsetFloodPrevention() throws IOException { + public void onsetFloodPrevention() throws IOException, InterruptedException, CoderException { + assertEquals(0, usecases.getDrools().factCount(USECASES)); + policy = setupPolicy(TOSCA_LEGACY_POLICY_VCPE); + assertEquals(2, usecases.getDrools().factCount(USECASES)); + injectOnTopic(DCAE_TOPIC, Paths.get(ONSET_1)); injectOnTopic(DCAE_TOPIC, Paths.get(ONSET_2)); injectOnTopic(DCAE_TOPIC, Paths.get(ONSET_3)); @@ -168,16 +196,6 @@ public class VcpeTest extends UsecasesBase { } } - /** - * Install Policy. - */ - @Before - public void installPolicy() throws IOException, CoderException, InterruptedException { - assertEquals(0, usecases.getDrools().factCount(USECASES)); - policy = setupPolicy(TOSCA_POLICY_VCPE); - assertEquals(2, usecases.getDrools().factCount(USECASES)); - } - /** * Uninstall Policy. */ diff --git a/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json new file mode 100644 index 000000000..c01f6898c --- /dev/null +++ b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json @@ -0,0 +1,37 @@ +{ + "type": "onap.policies.controlloop.operational.common.Drools", + "type_version": "1.0.0", + "version": "1.0.0", + "name": "operational.restart", + "metadata": { + "policy-id": "operational.restart" + }, + "properties": { + "id": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "timeout": 3600, + "abatement": false, + "trigger": "unique-policy-id-1-restart", + "operations": [ + { + "id": "unique-policy-id-1-restart", + "description": "Restart the VM", + "operation": { + "actor": "APPC", + "operation": "Restart", + "target": { + "type": "VM" + } + }, + "timeout": 1200, + "retries": 3, + "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" + } + ], + "controllerName": "usecases" + } +} \ No newline at end of file diff --git a/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json new file mode 100644 index 000000000..f42c07da9 --- /dev/null +++ b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json @@ -0,0 +1,9 @@ +{ + "type": "onap.policies.controlloop.Operational", + "type_version": "1.0.0", + "properties": { + "content": "controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20controlLoopName%3A%20ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e%0A%20%20trigger_policy%3A%20unique-policy-id-1-restart%0A%20%20timeout%3A%203600%0A%20%20abatement%3A%20false%0A%20%0Apolicies%3A%0A%20%20-%20id%3A%20unique-policy-id-1-restart%0A%20%20%20%20name%3A%20Restart%20the%20VM%0A%20%20%20%20description%3A%0A%20%20%20%20actor%3A%20APPC%0A%20%20%20%20recipe%3A%20Restart%0A%20%20%20%20target%3A%0A%20%20%20%20%20%20type%3A%20VM%0A%20%20%20%20retry%3A%203%0A%20%20%20%20timeout%3A%201200%0A%20%20%20%20success%3A%20final_success%0A%20%20%20%20failure%3A%20final_failure%0A%20%20%20%20failure_timeout%3A%20final_failure_timeout%0A%20%20%20%20failure_retries%3A%20final_failure_retries%0A%20%20%20%20failure_exception%3A%20final_failure_exception%0A%20%20%20%20failure_guard%3A%20final_failure_guard" + }, + "name": "vcpe", + "version": "1.0.0" +} \ No newline at end of file diff --git a/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json deleted file mode 100644 index f42c07da9..000000000 --- a/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "type": "onap.policies.controlloop.Operational", - "type_version": "1.0.0", - "properties": { - "content": "controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20controlLoopName%3A%20ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e%0A%20%20trigger_policy%3A%20unique-policy-id-1-restart%0A%20%20timeout%3A%203600%0A%20%20abatement%3A%20false%0A%20%0Apolicies%3A%0A%20%20-%20id%3A%20unique-policy-id-1-restart%0A%20%20%20%20name%3A%20Restart%20the%20VM%0A%20%20%20%20description%3A%0A%20%20%20%20actor%3A%20APPC%0A%20%20%20%20recipe%3A%20Restart%0A%20%20%20%20target%3A%0A%20%20%20%20%20%20type%3A%20VM%0A%20%20%20%20retry%3A%203%0A%20%20%20%20timeout%3A%201200%0A%20%20%20%20success%3A%20final_success%0A%20%20%20%20failure%3A%20final_failure%0A%20%20%20%20failure_timeout%3A%20final_failure_timeout%0A%20%20%20%20failure_retries%3A%20final_failure_retries%0A%20%20%20%20failure_exception%3A%20final_failure_exception%0A%20%20%20%20failure_guard%3A%20final_failure_guard" - }, - "name": "vcpe", - "version": "1.0.0" -} \ No newline at end of file -- cgit 1.2.3-korg