From 2440b81428fa4bfa28a51f87c58e12c78ced744b Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 6 Mar 2020 18:22:28 -0500 Subject: Add subrequest ID to OperationOutcome Rule notifications need the subrequest ID to be populated in the OperationOutcome object, where possible. Issue-ID: POLICY-2385 Signed-off-by: Jim Hahn Change-Id: Ic44320f67ad8df7bcb3000cfa667f95427818e71 --- .../org/onap/policy/controlloop/actor/so/SoOperation.java | 15 +++++++++++++-- .../onap/policy/controlloop/actor/so/SoOperationTest.java | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'models-interactions/model-actors/actor.so') diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java index 1ca6c734c..3a14c3bde 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java @@ -198,12 +198,14 @@ public abstract class SoOperation extends HttpOperation { if (rawResponse.getStatus() == 200) { String requestState = getRequestState(response); if (COMPLETE.equalsIgnoreCase(requestState)) { + populateSubRequestId(outcome, response); successfulCompletion(); return CompletableFuture .completedFuture(setOutcome(outcome, PolicyResult.SUCCESS, rawResponse, response)); } if (FAILED.equalsIgnoreCase(requestState)) { + populateSubRequestId(outcome, response); return CompletableFuture .completedFuture(setOutcome(outcome, PolicyResult.FAILURE, rawResponse, response)); } @@ -212,8 +214,7 @@ public abstract class SoOperation extends HttpOperation { // still incomplete // need a request ID with which to query - if (response == null || response.getRequestReferences() == null - || response.getRequestReferences().getRequestId() == null) { + if (!populateSubRequestId(outcome, response)) { throw new IllegalArgumentException("missing request ID in response"); } @@ -230,6 +231,16 @@ public abstract class SoOperation extends HttpOperation { return sleep(getWaitMsGet(), TimeUnit.MILLISECONDS).thenComposeAsync(doGet); } + private boolean populateSubRequestId(OperationOutcome outcome, SoResponse response) { + if (response == null || response.getRequestReferences() == null + || response.getRequestReferences().getRequestId() == null) { + return false; + } + + outcome.setSubRequestId(response.getRequestReferences().getRequestId()); + return true; + } + /** * Invoked when a request completes successfully. */ diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java index 129c19381..992065638 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java @@ -166,17 +166,21 @@ public class SoOperationTest extends BasicSoOperation { @Test public void testPostProcess() throws Exception { // completed + outcome.setSubRequestId(null); CompletableFuture future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); assertTrue(future2.isDone()); assertSame(outcome, future2.get()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); + assertNotNull(outcome.getSubRequestId()); // failed + outcome.setSubRequestId(null); response.getRequest().getRequestStatus().setRequestState(SoOperation.FAILED); future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); assertTrue(future2.isDone()); assertSame(outcome, future2.get()); assertEquals(PolicyResult.FAILURE, outcome.getResult()); + assertNotNull(outcome.getSubRequestId()); // no request id in the response response.getRequestReferences().setRequestId(null); -- cgit 1.2.3-korg