Generate SDNR notification even on timeout 56/108156/1
authorJim Hahn <jrh3@att.com>
Fri, 22 May 2020 20:05:16 +0000 (16:05 -0400)
committerJim Hahn <jrh3@att.com>
Fri, 22 May 2020 20:17:14 +0000 (16:17 -0400)
If a request to SDNR times out, the actor class does not generate a
notification for the DCAE_CL_RSP topic.  Rather than modifying the
actor, decided to modify models to handle that case.  Seems like that's
where it belongs anyway, as notifications are more of an application-
level behavior.

Issue-ID: POLICY-2580
Change-Id: Id9426c223b719efce337a604316f19335dae8a94
Signed-off-by: Jim Hahn <jrh3@att.com>
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java

index 9ef892e..3f7aca6 100644 (file)
@@ -42,6 +42,7 @@ import org.onap.policy.aai.AaiConstants;
 import org.onap.policy.aai.AaiCqResponse;
 import org.onap.policy.controlloop.ControlLoopOperation;
 import org.onap.policy.controlloop.ControlLoopResponse;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
@@ -514,7 +515,7 @@ public class ControlLoopOperationManager2 implements Serializable {
                      */
                     state = (outcome.getResult() == PolicyResult.SUCCESS ? State.OPERATION_SUCCESS
                                     : State.OPERATION_FAILURE);
-                    controlLoopResponse = outcome.getControlLoopResponse();
+                    controlLoopResponse = makeControlLoopResponse(outcome.getControlLoopResponse());
                     if (!operationHistory.isEmpty() && operationHistory.peekLast().getClOperation().getEnd() == null) {
                         operationHistory.removeLast();
                     }
@@ -529,6 +530,36 @@ public class ControlLoopOperationManager2 implements Serializable {
         operContext.updated(this);
     }
 
+    /**
+     * 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
+     */
+    protected ControlLoopResponse makeControlLoopResponse(ControlLoopResponse source) {
+        if (source != null) {
+            return source;
+        }
+
+        // only generate response for certain actors.
+        if (!actor.equals("SDNR")) {
+            return null;
+        }
+
+        VirtualControlLoopEvent event = eventContext.getEvent();
+
+        ControlLoopResponse clRsp = new ControlLoopResponse();
+        clRsp.setFrom(actor);
+        clRsp.setTarget("DCAE");
+        clRsp.setClosedLoopControlName(event.getClosedLoopControlName());
+        clRsp.setPolicyName(event.getPolicyName());
+        clRsp.setPolicyVersion(event.getPolicyVersion());
+        clRsp.setRequestId(event.getRequestId());
+        clRsp.setVersion(event.getVersion());
+
+        return clRsp;
+    }
+
     /**
      * Get the operation, as a message.
      *
index 3214add..be8b70b 100644 (file)
@@ -54,6 +54,7 @@ import org.onap.aai.domain.yang.GenericVnf;
 import org.onap.policy.aai.AaiCqResponse;
 import org.onap.policy.common.utils.time.PseudoExecutor;
 import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.ControlLoopResponse;
 import org.onap.policy.controlloop.VirtualControlLoopEvent;
 import org.onap.policy.controlloop.actor.guard.GuardActorServiceProvider;
 import org.onap.policy.controlloop.actor.guard.GuardOperation;
@@ -342,6 +343,32 @@ public class ControlLoopOperationManager2Test {
         assertSame(POLICY_TIMEOUT, params.getTimeoutSec());
     }
 
+    @Test
+    public void testMakeControlLoopResponse() {
+        // should always return its input, if non-null
+        ControlLoopResponse resp = new ControlLoopResponse();
+        assertSame(resp, mgr.makeControlLoopResponse(resp));
+
+        // not an SDNR action - should return null
+        assertNull(mgr.makeControlLoopResponse(null));
+
+        /*
+         * now work with SDNR actor
+         */
+        policy.setActor("SDNR");
+        mgr = new ControlLoopOperationManager2(mgrctx, context, policy, executor);
+
+        // should still return its input, if non-null
+        resp = new ControlLoopResponse();
+        assertSame(resp, mgr.makeControlLoopResponse(resp));
+
+        // should generate a response
+        resp = mgr.makeControlLoopResponse(null);
+        assertNotNull(resp);
+        assertEquals(REQ_ID, resp.getRequestId());
+        assertNull(resp.getPayload());
+    }
+
     @Test
     public void testGetOperationMessage() {
         // no history yet