aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/controller-usecases/src
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/controller-usecases/src')
-rw-r--r--controlloop/common/controller-usecases/src/main/resources/META-INF/kmodule.xml4
-rw-r--r--controlloop/common/controller-usecases/src/main/resources/usecases.drl6
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java10
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java44
-rw-r--r--controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json37
-rw-r--r--controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json (renamed from controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json)0
6 files changed, 79 insertions, 22 deletions
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=========================================================
-->
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
- <kbase name="onap.policies.controlloop.Operational" equalsBehavior="equality">
+ <kbase name="onap.policies.controlloop.operational.common.Drools" default="false" equalsBehavior="equality"/>
+ <kbase name="onap.policies.controlloop.Operational" equalsBehavior="equality"
+ packages="org.onap.policy.controlloop" includes="onap.policies.controlloop.operational.common.Drools">
<ksession name="usecases"/>
</kbase>
</kmodule>
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 */
@@ -122,12 +122,40 @@ public class VcpeTest extends UsecasesBase {
}
/**
+ * 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));
@@ -169,16 +197,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.
*/
@After
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-vcpe.json b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json
index f42c07da9..f42c07da9 100644
--- a/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json
+++ b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json