aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-09-25 21:25:04 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-25 21:25:04 +0000
commit0010271c21479a451a72f64fc8cecc4063aa5ae7 (patch)
tree956acab5288c426c96cafb985f5046fe679efdcc
parentf2686b60b5a38fee187848032115e0b022b31c77 (diff)
parent04836227f4d74bc1041c6ceb2438d9f5371f3591 (diff)
Merge "Fix Usecase Template for VoLTE"
-rw-r--r--controlloop/common/model-impl/vfc/pom.xml6
-rw-r--r--controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java13
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/VoLTE.yaml23
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.volte.onset.json18
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl81
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java12
6 files changed, 143 insertions, 10 deletions
diff --git a/controlloop/common/model-impl/vfc/pom.xml b/controlloop/common/model-impl/vfc/pom.xml
index 7672b1bc9..6b4efb879 100644
--- a/controlloop/common/model-impl/vfc/pom.xml
+++ b/controlloop/common/model-impl/vfc/pom.xml
@@ -51,5 +51,11 @@
<version>6.5.0.Final</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-management</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java
index 5cb6d6624..2d635b401 100644
--- a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java
+++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java
@@ -23,6 +23,7 @@ import java.util.Map;
import org.drools.core.WorkingMemory;
import org.onap.policy.vfc.util.Serialization;
+import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.rest.RESTManager;
import org.onap.policy.rest.RESTManager.Pair;
import org.slf4j.Logger;
@@ -42,9 +43,15 @@ public final class VFCManager implements Runnable {
public VFCManager(WorkingMemory wm, VFCRequest request) {
workingMem = wm;
vfcRequest = request;
- // TODO: Get base URL, username and password from MSB?
- // TODO: Following code is a placeholder, needs to be updated
- setVFCParams("http://localhost:6668", "username", "password");
+
+ /*
+ * TODO: What if these are null?
+ */
+ String url = PolicyEngine.manager.getEnvironmentProperty("vfc.url");
+ String username = PolicyEngine.manager.getEnvironmentProperty("vfc.username");
+ String password = PolicyEngine.manager.getEnvironmentProperty("vfc.password");
+
+ setVFCParams(url, username, password);
}
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/VoLTE.yaml b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/VoLTE.yaml
new file mode 100644
index 000000000..fd5869fc8
--- /dev/null
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/VoLTE.yaml
@@ -0,0 +1,23 @@
+controlLoop:
+ version: 2.0.0
+ controlLoopName: ${closedLoopControlName}
+ trigger_policy: unique-policy-id-1-restart
+ timeout: 3600
+
+policies:
+ - id: unique-policy-id-1-restart
+ name: Restart the VM
+ description:
+ actor: VFC
+ recipe: Restart
+ target:
+ type: VM
+ retry: 3
+ timeout: 1200
+ success: final_success
+ failure: final_failure
+ failure_timeout: final_failure_timeout
+ failure_retries: final_failure_retries
+ failure_exception: final_failure_exception
+ failure_guard: final_failure_guard
+
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.volte.onset.json b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.volte.onset.json
new file mode 100644
index 000000000..151912968
--- /dev/null
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.volte.onset.json
@@ -0,0 +1,18 @@
+{
+ "closedLoopControlName": "${closedLoopControlName}",
+ "closedLoopAlarmStart": 1484677482204798,
+ "closedLoopEventClient": "DCAE.HolmesInstance",
+ "closedLoopEventStatus": "ONSET",
+ "requestID": "97964e10-686e-4790-8c45-bdfa61df770f",
+ "target_type": "VM",
+ "target": "vserver.vserver-name",
+ "AAI": {
+ "vserver.is-closed-loop-disabled": "false",
+ "vserver.vserver-name": "dfw1lb01lb01",
+ "service-instance.service-instance-id" : "vserver-name-16102016-aai3255-data-11-1",
+ "generic-vnf.vnf-id" : "vnf-id-16102016-aai3255-data-11-1",
+ "generic-vnf.vnf-name" : "vnf-name-16102016-aai3255-data-11-1"
+ },
+ "from": "DCAE",
+ "version": "1.0.2"
+} \ No newline at end of file
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
index f56a3ff6a..b10cc3bb7 100644
--- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
@@ -41,6 +41,7 @@ import org.onap.policy.appclcm.LCMRequest;
import org.onap.policy.appclcm.LCMResponse;
import org.onap.policy.appclcm.LCMCommonHeader;
import org.onap.policy.vfc.VFCRequest;
+import org.onap.policy.vfc.VFCResponse;
import org.onap.policy.vfc.VFCManager;
import org.onap.policy.so.SOManager;
import org.onap.policy.so.SORequest;
@@ -556,13 +557,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
case "VFC":
if (request instanceof VFCRequest) {
// Start VFC thread
- VFCManager vfcManager = new VFCManager((VFCRequest) request);
- vfcManager.setVFCParams(
- PolicyEngine.manager.getEnvironmentProperty("vfc.url"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.user"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.password"));
-
- Thread t = new Thread(vfcManager);
+ Thread t = new Thread(new VFCManager(drools.getWorkingMemory(), (VFCRequest)request));
t.start();
}
break;
@@ -1014,6 +1009,78 @@ end
/*
*
+* This rule responds to VFC Response Events
+*
+*/
+rule "${policyName}.VFC.RESPONSE"
+ when
+ $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
+ $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), closedLoopEventStatus == ControlLoopEventStatus.ONSET )
+ $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName )
+ $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID )
+ $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() )
+ $lock : TargetLock (requestID == $event.requestID)
+ $response : VFCResponse( requestId.toString() == $event.requestID.toString() )
+ then
+ Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+ logger.info("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName());
+ logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}",
+ $params.getClosedLoopControlName(), drools.getRule().getName(),
+ $event, $manager, $operation, $lock, $operation, $opTimer, $response);
+
+ // Get the result of the operation
+ //
+ PolicyResult policyResult = $operation.onResponse($response);
+ if (policyResult != null) {
+ //
+ // This Operation has completed, construct a notification showing our results
+ //
+ VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
+ notification.from = "policy";
+ notification.policyName = drools.getRule().getName();
+ notification.policyScope = "${policyScope}";
+ notification.policyVersion = "${policyVersion}";
+ notification.message = $operation.getOperationHistory();
+ notification.history = $operation.getHistory();
+ //
+ // Ensure the operation is complete
+ //
+ if ($operation.isOperationComplete() == true) {
+ //
+ // It is complete, remove it from memory
+ //
+ retract($operation);
+ //
+ // We must also retract the timer object
+ // NOTE: We could write a Rule to do this
+ //
+ retract($opTimer);
+ //
+ // Complete the operation
+ //
+ modify($manager) {finishOperation($operation)};
+ } else {
+ //
+ // Just doing this will kick off the LOCKED rule again
+ //
+ modify($operation) {};
+ }
+ } else {
+ //
+ // Its not finished yet (i.e. expecting more Response objects)
+ //
+ // Or possibly it is a leftover response that we timed the request out previously
+ //
+ }
+ //
+ // We are going to retract these objects from memory
+ //
+ retract($response);
+
+end
+
+/*
+*
* This is the timer that manages the timeout for an individual operation.
*
*/
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
index d5b6e4421..29fdc195a 100644
--- 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
@@ -57,6 +57,7 @@ import org.onap.policy.controlloop.impl.ControlLoopLoggerStdOutImpl;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.drools.http.server.HttpServletServer;
import org.onap.policy.drools.impl.PolicyEngineJUnitImpl;
+import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.vfc.util.Serialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,6 +70,17 @@ public class VFCControlLoopTest {
private Util.Pair<ControlLoopPolicy, String> pair;
private PolicyEngineJUnitImpl engine;
+ static {
+ /* Set environment properties */
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
+ PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
+ PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
+
+ PolicyEngine.manager.setEnvironmentProperty("vfc.url", "http://localhost:6668");
+ PolicyEngine.manager.setEnvironmentProperty("vfc.username", "VFC");
+ PolicyEngine.manager.setEnvironmentProperty("vfc.password", "VFC");
+ }
+
@BeforeClass
public static void setUpSimulator() {
try {