From 04836227f4d74bc1041c6ceb2438d9f5371f3591 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 25 Sep 2017 15:50:33 -0500 Subject: Fix Usecase Template for VoLTE 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 --- .../archetype-resources/src/main/config/VoLTE.yaml | 23 ++++++ .../src/main/config/dcae.volte.onset.json | 18 +++++ .../main/resources/__closedLoopControlName__.drl | 81 ++++++++++++++++++++-- .../policy/template/demo/VFCControlLoopTest.java | 12 ++++ 4 files changed, 127 insertions(+), 7 deletions(-) create mode 100644 controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/VoLTE.yaml create mode 100644 controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/config/dcae.volte.onset.json (limited to 'controlloop/templates') 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; @@ -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. 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 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 { -- cgit 1.2.3-korg