From 26e713754fa52b03b0d0fd246b59db3188dd36a6 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 10 Jul 2018 16:29:13 -0400 Subject: Catch exception from missing property in operation When a new operation is started it will throw an IllegalArgumentException if a property is missing. Modified the rules to catch this exception, indicate the failure, and move on to the next operation. Modified code to catch generic exception. Change-Id: Ie8c24371eb84ee55ff0a0a5fcacda3670483efc5 Issue-ID: POLICY-869 Signed-off-by: Jim Hahn --- .../main/resources/__closedLoopControlName__.drl | 150 ++++++++++++--------- 1 file changed, 84 insertions(+), 66 deletions(-) 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 888d2b6e5..71715c075 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 @@ -521,15 +521,97 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" Object request = null; boolean caughtException = false; + try { request = $operation.startOperation($event); - } - catch (ControlLoopException e) { + + if (request != null) { + logger.debug("{}: {}: starting operation ..", + $params.getClosedLoopControlName(), drools.getRule().getName()); + // + // Tell interested parties we are performing this Operation + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.setNotification(ControlLoopNotificationType.OPERATION); + notification.setMessage($operation.getOperationMessage()); + notification.setHistory($operation.getHistory()); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + + PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); + + switch ($operation.policy.getActor()){ + + case "APPC": + + if (request instanceof Request) { + PolicyEngine.manager.deliver("APPC-CL", request); + } + else if (request instanceof LcmRequestWrapper) { + PolicyEngine.manager.deliver("APPC-LCM-READ", request); + } + break; + case "SO": + // at this point the AAI named query request should have already been made, the response recieved and used + // in the construction of the SO Request which is stored in operationRequest + + if(request instanceof SORequest) { + // Call SO. The response will be inserted into memory once it's received + SOActorServiceProvider.sendRequest($event.getRequestId().toString(), drools.getWorkingMemory(), request); + } + break; + case "VFC": + if (request instanceof VFCRequest) { + // Start VFC thread + Thread t = new Thread(new VFCManager(drools.getWorkingMemory(), (VFCRequest)request)); + t.start(); + } + break; + } + } else { + // + // What happens if its null? + // + logger.warn("{}: {}: unexpected null operation request", + $params.getClosedLoopControlName(), + drools.getRule().getName()); + if ("SO".equals($operation.policy.getActor())) { + retract($opTimer); + retract($operation); + modify($manager) {finishOperation($operation)}; + } + else if ("vfc".equalsIgnoreCase($operation.policy.getActor())) { + retract($opTimer); + retract($operation); + modify($manager) {finishOperation($operation)}; + } + } + + } catch (Exception e) { String msg = e.getMessage(); logger.warn("{}: {}: operation={}: AAI failure: {}", $params.getClosedLoopControlName(), drools.getRule().getName(), $operation, msg, e); $operation.setOperationHasException(msg); + + if(request != null) { + // + // Create a notification for it ("DB Write - end operation") + // + VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); + notification.setFrom("policy"); + notification.setPolicyName(drools.getRule().getName()); + notification.setPolicyScope("${policyScope}"); + notification.setPolicyVersion("${policyVersion}"); + notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE); + notification.setMessage($operation.getOperationHistory()); + notification.setHistory($operation.getHistory()); + + PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); + } + retract($opTimer); retract($operation); caughtException = true; @@ -539,70 +621,6 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" if (caughtException) { modify($manager) {finishOperation($operation)}; } - else if (request != null) { - logger.debug("{}: {}: starting operation ..", - $params.getClosedLoopControlName(), drools.getRule().getName()); - // - // Tell interested parties we are performing this Operation - // - VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event); - notification.setNotification(ControlLoopNotificationType.OPERATION); - notification.setMessage($operation.getOperationMessage()); - notification.setHistory($operation.getHistory()); - notification.setFrom("policy"); - notification.setPolicyName(drools.getRule().getName()); - notification.setPolicyScope("${policyScope}"); - notification.setPolicyVersion("${policyVersion}"); - - PolicyEngine.manager.deliver("POLICY-CL-MGT", notification); - - switch ($operation.policy.getActor()){ - - case "APPC": - - if (request instanceof Request) { - PolicyEngine.manager.deliver("APPC-CL", request); - } - else if (request instanceof LcmRequestWrapper) { - PolicyEngine.manager.deliver("APPC-LCM-READ", request); - } - break; - case "SO": - // at this point the AAI named query request should have already been made, the response recieved and used - // in the construction of the SO Request which is stored in operationRequest - - if(request instanceof SORequest) { - // Call SO. The response will be inserted into memory once it's received - SOActorServiceProvider.sendRequest($event.getRequestId().toString(), drools.getWorkingMemory(), request); - } - break; - case "VFC": - if (request instanceof VFCRequest) { - // Start VFC thread - Thread t = new Thread(new VFCManager(drools.getWorkingMemory(), (VFCRequest)request)); - t.start(); - } - break; - } - } else { - // - // What happens if its null? - // - logger.warn("{}: {}: unexpected null operation request", - $params.getClosedLoopControlName(), - drools.getRule().getName()); - if ("SO".equals($operation.policy.getActor())) { - retract($opTimer); - retract($operation); - modify($manager) {finishOperation($operation)}; - } - else if ("vfc".equalsIgnoreCase($operation.policy.getActor())) { - retract($opTimer); - retract($operation); - modify($manager) {finishOperation($operation)}; - } - - } end -- cgit 1.2.3-korg