Fix Usecase Template for VoLTE 09/15209/1
authordaniel <dc443y@att.com>
Mon, 25 Sep 2017 20:50:33 +0000 (15:50 -0500)
committerdaniel <dc443y@att.com>
Mon, 25 Sep 2017 20:57:16 +0000 (15:57 -0500)
This includes VoLTE support for the amsterdam template.
As of right now all use cases are able to get a final
success with guard disabled and no A&AI GET queries.
Currently, the GET query is not working in the lab.
I will address this in another pull request.

Issue-ID: POLICY-259
Change-Id: I216aa84daaa1e93ab12c56ee53283b4cb413a7c3
Signed-off-by: Daniel Cruz<dc443y@att.com>
controlloop/common/model-impl/vfc/pom.xml
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java
controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/VoLTE.yaml [new file with mode: 0644]
controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.volte.onset.json [new file with mode: 0644]
controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFCControlLoopTest.java

index 7672b1b..6b4efb8 100644 (file)
                        <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>
index 5cb6d66..2d635b4 100644 (file)
@@ -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 (file)
index 0000000..fd5869f
--- /dev/null
@@ -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 (file)
index 0000000..1519129
--- /dev/null
@@ -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
index f56a3ff..b10cc3b 100644 (file)
@@ -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;
@@ -1012,6 +1007,78 @@ rule "${policyName}.SO.RESPONSE"
 
 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.
index d5b6e44..29fdc19 100644 (file)
@@ -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 {