summaryrefslogtreecommitdiffstats
path: root/controlloop
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-05-27 17:57:51 -0400
committerJim Hahn <jrh3@att.com>2020-05-28 10:31:50 -0400
commitf9bd8844ef8f572cd0db639a9721caa42c17dfe2 (patch)
treeb76001ba365fa04af9225341e427f017d0127e8d /controlloop
parentba13401d2878da975b7decd0cf72f40bda1de7bc (diff)
Generate SDNR notification in drools-apps
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>
Diffstat (limited to 'controlloop')
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2.java21
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java54
2 files changed, 54 insertions, 21 deletions
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 b2a8dd308..2d5ff3974 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
@@ -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;
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
index 6fda667eb..90fdccabb 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
@@ -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);