From 8f59dfa64da6617a278558ff563041d6ff7c6670 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 22 May 2020 17:28:22 -0400 Subject: Do additional processing when control loop times out When the overall control loop times out, a notification is sent to POLICY-CL-MGT, but then the event is discarded. Modified the code to update the operation history, if an operation had been started, and to generate an SDNR notification, if appropriate. Applied the same logic for when a lock is lost. Issue-ID: POLICY-2582 Change-Id: I35510ec8a3cfc6b2ca9be5751896f3c0f7d9bd09 Signed-off-by: Jim Hahn --- .../eventmanager/ControlLoopOperationManager2.java | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'controlloop/common/eventmanager/src/main') diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java index 3f7aca6e0..b2a8dd308 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java @@ -478,6 +478,7 @@ public class ControlLoopOperationManager2 implements Serializable { case CL_TIMEOUT_ACTOR: state = State.CONTROL_LOOP_TIMEOUT; + processAbort(outcome, PolicyResult.FAILURE, "Control loop timed out"); break; case LOCK_ACTOR: @@ -487,7 +488,7 @@ public class ControlLoopOperationManager2 implements Serializable { storeFailureInDataBase(outcome, PolicyResult.FAILURE_GUARD, "Operation denied by Lock"); } else { state = State.LOCK_LOST; - storeFailureInDataBase(outcome, PolicyResult.FAILURE, "Operation aborted by Lock"); + processAbort(outcome, PolicyResult.FAILURE, "Operation aborted by Lock"); } break; @@ -530,11 +531,42 @@ public class ControlLoopOperationManager2 implements Serializable { operContext.updated(this); } + /** + * Processes an operation abort, updating the DB record, if an operation has been + * started. + * + * @param outcome operation outcome + * @param result result to put into the DB + * @param message message to put into the DB + */ + private void processAbort(OperationOutcome outcome, PolicyResult result, String message) { + if (operationHistory.isEmpty() || operationHistory.peekLast().getClOperation().getEnd() != null) { + // last item was not a "start" operation + + // NOTE: do NOT generate control loop response since operation was not started + + storeFailureInDataBase(outcome, result, message); + return; + } + + // last item was a "start" operation - replace it with a failure + final Operation operOrig = operationHistory.removeLast(); + + // use start time from the operation, itself + if (operOrig != null && operOrig.getClOperation() != null) { + outcome.setStart(operOrig.getClOperation().getStart()); + } + + controlLoopResponse = makeControlLoopResponse(outcome.getControlLoopResponse()); + + storeFailureInDataBase(outcome, result, message); + } + /** * Makes a control loop response. * * @param source original control loop response or {@code null} - * @return a new control loop response, or {@code null} none is required + * @return a new control loop response, or {@code null} if none is required */ protected ControlLoopResponse makeControlLoopResponse(ControlLoopResponse source) { if (source != null) { -- cgit 1.2.3-korg