Generate SDNR notification in drools-apps 14/108414/1
authorJim Hahn <jrh3@att.com>
Wed, 27 May 2020 21:57:51 +0000 (17:57 -0400)
committerJim Hahn <jrh3@att.com>
Thu, 28 May 2020 14:31:50 +0000 (10:31 -0400)
Modified drools-apps to generate the SDNR notification using the
SDNR-response provided by the actor in the operation outcome, instead of
using the controlloop-response provided in the operation outcome, as the
latter is deprecated.

Issue-ID: POLICY-2593
Change-Id: I70ee4a4b11345a4295d720250a63f407f51cb0bd
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 b2a8dd3..2d5ff39 100644 (file)
@@ -49,6 +49,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
 import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineUtil;
 import org.onap.policy.controlloop.policy.Policy;
 import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.sdnr.PciMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -212,7 +213,7 @@ public class ControlLoopOperationManager2 implements Serializable {
             policyResult = outcome.getResult();
             clOperation = outcome.toControlLoopOperation();
             clOperation.setTarget(policy.getTarget().toString());
-            clResponse = outcome.getControlLoopResponse();
+            clResponse = makeControlLoopResponse(outcome);
 
             if (outcome.getEnd() == null) {
                 clOperation.setOutcome("Started");
@@ -516,7 +517,7 @@ public class ControlLoopOperationManager2 implements Serializable {
                      */
                     state = (outcome.getResult() == PolicyResult.SUCCESS ? State.OPERATION_SUCCESS
                                     : State.OPERATION_FAILURE);
-                    controlLoopResponse = makeControlLoopResponse(outcome.getControlLoopResponse());
+                    controlLoopResponse = makeControlLoopResponse(outcome);
                     if (!operationHistory.isEmpty() && operationHistory.peekLast().getClOperation().getEnd() == null) {
                         operationHistory.removeLast();
                     }
@@ -557,7 +558,7 @@ public class ControlLoopOperationManager2 implements Serializable {
             outcome.setStart(operOrig.getClOperation().getStart());
         }
 
-        controlLoopResponse = makeControlLoopResponse(outcome.getControlLoopResponse());
+        controlLoopResponse = makeControlLoopResponse(outcome);
 
         storeFailureInDataBase(outcome, result, message);
     }
@@ -565,16 +566,13 @@ public class ControlLoopOperationManager2 implements Serializable {
     /**
      * Makes a control loop response.
      *
-     * @param source original control loop response or {@code null}
+     * @param outcome operation outcome
      * @return a new control loop response, or {@code null} if none is required
      */
-    protected ControlLoopResponse makeControlLoopResponse(ControlLoopResponse source) {
-        if (source != null) {
-            return source;
-        }
+    protected ControlLoopResponse makeControlLoopResponse(OperationOutcome outcome) {
 
         // only generate response for certain actors.
-        if (!actor.equals("SDNR")) {
+        if (outcome == null || !actor.equals("SDNR")) {
             return null;
         }
 
@@ -589,6 +587,11 @@ public class ControlLoopOperationManager2 implements Serializable {
         clRsp.setRequestId(event.getRequestId());
         clRsp.setVersion(event.getVersion());
 
+        PciMessage msg = outcome.getResponse();
+        if (msg != null && msg.getBody() != null && msg.getBody().getOutput() != null) {
+            clRsp.setPayload(msg.getBody().getOutput().getPayload());
+        }
+
         return clRsp;
     }
 
index 6fda667..90fdcca 100644 (file)
@@ -70,6 +70,9 @@ import org.onap.policy.controlloop.policy.Policy;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.controlloop.policy.Target;
 import org.onap.policy.controlloop.policy.TargetType;
+import org.onap.policy.sdnr.PciBody;
+import org.onap.policy.sdnr.PciMessage;
+import org.onap.policy.sdnr.PciResponse;
 
 public class ControlLoopOperationManager2Test {
     private static final UUID REQ_ID = UUID.randomUUID();
@@ -345,12 +348,21 @@ public class ControlLoopOperationManager2Test {
 
     @Test
     public void testMakeControlLoopResponse() {
-        // should always return its input, if non-null
-        ControlLoopResponse resp = new ControlLoopResponse();
-        assertSame(resp, mgr.makeControlLoopResponse(resp));
+        final OperationOutcome outcome = new OperationOutcome();
+        PciMessage msg = new PciMessage();
+        outcome.setResponse(msg);
+
+        PciBody body = new PciBody();
+        msg.setBody(body);
+
+        PciResponse output = new PciResponse();
+        body.setOutput(output);
+
+        output.setPayload("my-payload");
+
 
         // not an SDNR action - should return null
-        assertNull(mgr.makeControlLoopResponse(null));
+        assertNull(mgr.makeControlLoopResponse(outcome));
 
         /*
          * now work with SDNR actor
@@ -358,15 +370,26 @@ public class ControlLoopOperationManager2Test {
         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 return null for a null input
+        assertNull(mgr.makeControlLoopResponse(null));
 
-        // should generate a response
-        resp = mgr.makeControlLoopResponse(null);
-        assertNotNull(resp);
-        assertEquals(REQ_ID, resp.getRequestId());
-        assertNull(resp.getPayload());
+        // should generate a response, with a payload
+        checkResp(outcome, "my-payload");
+
+        /*
+         * these should generate a response, with null payload
+         */
+        output.setPayload(null);
+        checkResp(outcome, null);
+
+        body.setOutput(null);
+        checkResp(outcome, null);
+
+        msg.setBody(null);
+        checkResp(outcome, null);
+
+        outcome.setResponse(null);
+        checkResp(outcome, null);
     }
 
     @Test
@@ -977,6 +1000,13 @@ public class ControlLoopOperationManager2Test {
         target.setType(TargetType.VNF);
     }
 
+    private void checkResp(OperationOutcome outcome, String expectedPayload) {
+        ControlLoopResponse resp = mgr.makeControlLoopResponse(outcome);
+        assertNotNull(resp);
+        assertEquals(REQ_ID, resp.getRequestId());
+        assertEquals(expectedPayload, resp.getPayload());
+    }
+
     private void verifyDb(int nrecords, PolicyResult expectedResult, String expectedMsg) {
         ArgumentCaptor<String> entityCaptor = ArgumentCaptor.forClass(String.class);
         ArgumentCaptor<ControlLoopOperation> opCaptor = ArgumentCaptor.forClass(ControlLoopOperation.class);