From 506267bf7e9d961f1a6b2a989ee8a23ca67b9d61 Mon Sep 17 00:00:00 2001 From: Charles Cole Date: Mon, 16 Oct 2017 12:05:08 -0500 Subject: Add support for AAI Named Query error handling Errors from AAI after a Named query now throw an AAIEXception. This is caught in the template to allow the resources to be removed from memory and a final failure to be thrown. Issue-ID: POLICY-314 Change-Id: I319d29ef537b2d01ca288622aac1d9dbbe05f5eb Signed-off-by: Charles Cole --- .../main/resources/__closedLoopControlName__.drl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'controlloop/templates/archetype-cl-amsterdam/src') 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 3d6d89c69..705bbcd25 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 @@ -32,6 +32,7 @@ import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager; import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager.NEW_EVENT_STATUS; import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager; import org.onap.policy.controlloop.actor.so.SOActorServiceProvider; +import org.onap.policy.aai.util.AAIException; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; import org.onap.policy.appc.CommonHeader; @@ -507,6 +508,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" $manager : ControlLoopEventManager( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID ) $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID, "Permit".equalsIgnoreCase(getGuardApprovalStatus()) ) $lock : TargetLock (requestID == $event.requestID) + $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) then Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage()); @@ -514,9 +516,23 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" $params.getClosedLoopControlName(), drools.getRule().getName(), $event, $manager, $operation, $lock); - Object request = $operation.startOperation($event); - - if (request != null) { + Object request = null; + boolean caughtException = false; + try { + request = $operation.startOperation($event); + } + catch (AAIException e) { + //We got an exception, retract everything for this current operation + $operation.setOperationHasException(e.getMessage()); + retract($opTimer); + retract($operation); + caughtException = true; + } + //Having the modify statement in the catch clause doesn't work for whatever reason + if (caughtException) { + modify($manager) {finishOperation($operation)}; + } + else if (request != null) { logger.debug("{}: {}: starting operation ..", $params.getClosedLoopControlName(), drools.getRule().getName()); // -- cgit 1.2.3-korg