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 --- .../actor/aai/AaiCustomQueryOperation.java | 1 + .../controlloop/actor/aai/AaiGetOperation.java | 1 + .../actor/aai/AaiCustomQueryOperationTest.java | 2 ++ .../controlloop/actor/aai/AaiGetOperationTest.java | 2 ++ .../controlloop/actor/appc/AppcOperation.java | 8 +++-- .../actor/appc/ModifyConfigOperation.java | 3 +- .../controlloop/actor/appc/AppcOperationTest.java | 34 +++++++++++++--------- .../actor/appc/ModifyConfigOperationTest.java | 6 +++- .../actor/appclcm/AppcLcmOperation.java | 5 ++-- .../actor/appclcm/AppcLcmOperationTest.java | 19 ++++++++---- .../controlloop/actor/guard/GuardOperation.java | 2 ++ .../actor/guard/GuardOperationTest.java | 2 ++ .../controlloop/actor/sdnc/SdncOperation.java | 1 + .../controlloop/actor/sdnc/BasicSdncOperation.java | 3 ++ .../controlloop/actor/sdnc/SdncOperationTest.java | 9 ++++++ .../actor/sdnr/ModifyConfigOperation.java | 15 ++++------ .../controlloop/actor/sdnr/SdnrOperation.java | 5 ++-- .../actor/sdnr/ModifyConfigOperationTest.java | 6 ++-- .../controlloop/actor/sdnr/SdnrOperationTest.java | 15 +++++----- .../policy/controlloop/actor/so/SoOperation.java | 15 ++++++++-- .../controlloop/actor/so/SoOperationTest.java | 4 +++ .../controlloop/actor/test/BasicOperation.java | 1 + .../impl/BidirectionalTopicOperation.java | 11 +++++-- .../impl/BidirectionalTopicOperationTest.java | 17 +++++++---- 24 files changed, 128 insertions(+), 59 deletions(-) (limited to 'models-interactions') diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java index 5b4aa0527..9f8d30a26 100644 --- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java +++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java @@ -92,6 +92,7 @@ public class AaiCustomQueryOperation extends HttpOperation { @Override protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { + outcome.setSubRequestId(String.valueOf(attempt)); final Map request = makeRequest(); Map headers = makeHeaders(); diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java index b527abc36..9ff56d61f 100644 --- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java +++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java @@ -91,6 +91,7 @@ public class AaiGetOperation extends HttpOperation { @Override protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { + outcome.setSubRequestId(String.valueOf(attempt)); Map headers = makeHeaders(); diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java index c24e45db7..dae443593 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java @@ -127,6 +127,8 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation { StandardCoderObject data = context.getProperty(AaiGetOperation.getTenantKey(TARGET_ENTITY)); assertNotNull(data); assertEquals(TEXT, data.getString(INPUT_FIELD)); + + assertEquals("1", future2.get().getSubRequestId()); } /** diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java index 43bb81de0..5e84871cc 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.appc.CommonHeader; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; @@ -85,13 +86,14 @@ public abstract class AppcOperation extends BidirectionalTopicOperation makeRequest(int attempt, String targetVnf) { Request request = new Request(); request.setCommonHeader(new CommonHeader()); request.getCommonHeader().setRequestId(params.getRequestId()); // TODO ok to use UUID, or does it have to be the "attempt"? - request.getCommonHeader().setSubRequestId(UUID.randomUUID().toString()); + final String subreq = UUID.randomUUID().toString(); + request.getCommonHeader().setSubRequestId(subreq); request.setAction(getName()); @@ -105,7 +107,7 @@ public abstract class AppcOperation extends BidirectionalTopicOperation makeRequest(int attempt) { AaiCqResponse cq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); GenericVnf genvnf = cq.getGenericVnfByModelInvariantId(params.getTarget().getResourceID()); diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java index 8b71b614d..204d95aa1 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java @@ -29,6 +29,7 @@ import static org.junit.Assert.assertSame; import java.util.Arrays; import java.util.Map; import java.util.TreeMap; +import org.apache.commons.lang3.tuple.Pair; import org.junit.Before; import org.junit.Test; import org.onap.policy.appc.CommonHeader; @@ -50,7 +51,7 @@ public class AppcOperationTest extends BasicAppcOperation { oper = new AppcOperation(params, config) { @Override - protected Request makeRequest(int attempt) { + protected Pair makeRequest(int attempt) { return oper.makeRequest(attempt, MY_VNF); } }; @@ -69,7 +70,11 @@ public class AppcOperationTest extends BasicAppcOperation { @Test public void testMakeRequest() { - Request request = oper.makeRequest(2, MY_VNF); + Pair result = oper.makeRequest(2, MY_VNF); + String subreq = result.getLeft(); + assertNotNull(subreq); + + Request request = result.getRight(); assertEquals(DEFAULT_OPERATION, request.getAction()); assertNotNull(request.getPayload()); @@ -78,26 +83,29 @@ public class AppcOperationTest extends BasicAppcOperation { assertNotNull(header); assertEquals(params.getRequestId(), header.getRequestId()); - String subreq = header.getSubRequestId(); - assertNotNull(subreq); + assertEquals(subreq, header.getSubRequestId()); // a subsequent request should have a different sub-request id - assertNotEquals(subreq, oper.makeRequest(2, MY_VNF).getCommonHeader().getSubRequestId()); + result = oper.makeRequest(2, MY_VNF); + assertNotEquals(subreq, result.getLeft()); + + assertNotNull(result.getLeft()); + assertEquals(result.getLeft(), result.getRight().getCommonHeader().getSubRequestId()); // repeat using a null payload params = params.toBuilder().payload(null).build(); oper = new AppcOperation(params, config) { @Override - protected Request makeRequest(int attempt) { + protected Pair makeRequest(int attempt) { return oper.makeRequest(attempt, MY_VNF); } }; - assertEquals(Map.of(AppcOperation.VNF_ID_KEY, MY_VNF), oper.makeRequest(2, MY_VNF).getPayload()); + assertEquals(Map.of(AppcOperation.VNF_ID_KEY, MY_VNF), oper.makeRequest(2, MY_VNF).getRight().getPayload()); } @Test public void testConvertPayload() { - Request request = oper.makeRequest(2, MY_VNF); + Request request = oper.makeRequest(2, MY_VNF).getRight(); // @formatter:off assertEquals( @@ -118,11 +126,11 @@ public class AppcOperationTest extends BasicAppcOperation { oper = new AppcOperation(params, config) { @Override - protected Request makeRequest(int attempt) { + protected Pair makeRequest(int attempt) { return oper.makeRequest(attempt, MY_VNF); } }; - request = oper.makeRequest(2, MY_VNF); + request = oper.makeRequest(2, MY_VNF).getRight(); // @formatter:off assertEquals( @@ -144,11 +152,11 @@ public class AppcOperationTest extends BasicAppcOperation { oper = new AppcOperation(params, config) { @Override - protected Request makeRequest(int attempt) { + protected Pair makeRequest(int attempt) { return oper.makeRequest(attempt, MY_VNF); } }; - request = oper.makeRequest(2, MY_VNF); + request = oper.makeRequest(2, MY_VNF).getRight(); payload.put(AppcOperation.VNF_ID_KEY, MY_VNF); payload.put(KEY1, "abc"); @@ -160,7 +168,7 @@ public class AppcOperationTest extends BasicAppcOperation { @Test public void testGetExpectedKeyValues() { - Request request = oper.makeRequest(2, MY_VNF); + Request request = oper.makeRequest(2, MY_VNF).getRight(); assertEquals(Arrays.asList(request.getCommonHeader().getSubRequestId()), oper.getExpectedKeyValues(50, request)); } diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java index 460f2c9f0..95629bccf 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java @@ -34,6 +34,7 @@ import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.commons.lang3.tuple.Pair; import org.junit.Before; import org.junit.Test; import org.onap.aai.domain.yang.GenericVnf; @@ -108,7 +109,10 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { genvnf.setModelInvariantId(RESOURCE_ID); cq.setInventoryResponseItems(Arrays.asList(genvnf)); - Request request = oper.makeRequest(2); + Pair result = oper.makeRequest(2); + assertNotNull(result.getLeft()); + + Request request = result.getRight(); assertNotNull(request); assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY)); diff --git a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java index 749622714..87ff357e9 100644 --- a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java +++ b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.appclcm.AppcLcmBody; import org.onap.policy.appclcm.AppcLcmCommonHeader; import org.onap.policy.appclcm.AppcLcmDmaapWrapper; @@ -80,7 +81,7 @@ public class AppcLcmOperation extends BidirectionalTopicOperation makeRequest(int attempt) { VirtualControlLoopEvent onset = params.getContext().getEvent(); String subRequestId = UUID.randomUUID().toString(); @@ -125,7 +126,7 @@ public class AppcLcmOperation extends BidirectionalTopicOperation result = oper.makeRequest(2); + String subreq = result.getLeft(); + assertNotNull(subreq); + + AppcLcmDmaapWrapper request = result.getRight(); assertEquals("DefaultOperation", request.getBody().getInput().getAction()); AppcLcmCommonHeader header = request.getBody().getInput().getCommonHeader(); assertNotNull(header); assertEquals(params.getRequestId(), header.getRequestId()); - String subreq = header.getSubRequestId(); - assertNotNull(subreq); + assertEquals(subreq, header.getSubRequestId()); assertEquals("{vnf-id=my-target}", request.getBody().getInput().getActionIdentifiers().toString()); // a subsequent request should have a different sub-request id - assertNotEquals(subreq, oper.makeRequest(2).getBody().getInput().getCommonHeader().getSubRequestId()); + result = oper.makeRequest(2); + assertNotEquals(subreq, result.getLeft()); + assertNotNull(result.getLeft()); + assertEquals(result.getLeft(), result.getRight().getBody().getInput().getCommonHeader().getSubRequestId()); } @Test @@ -140,7 +147,7 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { params = params.toBuilder().operation(AppcLcmConstants.OPERATION_CONFIG_MODIFY).build(); oper = new AppcLcmOperation(params, config); - AppcLcmDmaapWrapper req = oper.makeRequest(2); + AppcLcmDmaapWrapper req = oper.makeRequest(2).getRight(); assertEquals("{\"key-A\":\"value-A\"}", req.getBody().getInput().getPayload()); // coder exception @@ -162,7 +169,7 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { @Test public void testGetExpectedKeyValues() { - AppcLcmDmaapWrapper request = oper.makeRequest(2); + AppcLcmDmaapWrapper request = oper.makeRequest(2).getRight(); assertEquals(Arrays.asList(request.getBody().getInput().getCommonHeader().getSubRequestId()), oper.getExpectedKeyValues(50, request)); } diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java index dd8b9273a..431ad3711 100644 --- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java +++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java @@ -89,6 +89,8 @@ public class GuardOperation extends HttpOperation { return CompletableFuture.completedFuture(params.makeOutcome()); } + outcome.setSubRequestId(String.valueOf(attempt)); + DecisionRequest request = Util.translate(getName(), makeRequest(), DecisionRequest.class); Entity entity = Entity.entity(request, MediaType.APPLICATION_JSON); diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java index a43292a65..be40ef3b4 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java @@ -96,6 +96,8 @@ public class GuardOperationTest extends BasicHttpOperation { assertTrue(future2.isDone()); assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + + assertEquals("1", future2.get().getSubRequestId()); } /** diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java index 018578829..1aed75ce6 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java @@ -61,6 +61,7 @@ public abstract class SdncOperation extends HttpOperation { protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { SdncRequest request = makeRequest(attempt); + outcome.setSubRequestId(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); Entity entity = Entity.entity(request, MediaType.APPLICATION_JSON); diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java index 50e97496a..73b81433a 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java @@ -23,6 +23,7 @@ package org.onap.policy.controlloop.actor.sdnc; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; @@ -107,6 +108,8 @@ public abstract class BasicSdncOperation extends BasicHttpOperation assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + assertNotNull(future2.get().getSubRequestId()); + return requestCaptor.getValue().getEntity(); } diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java index a83c354d2..417029d49 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java @@ -29,6 +29,8 @@ import java.util.Map; import java.util.TreeMap; import org.junit.Before; import org.junit.Test; +import org.onap.policy.sdnc.SdncHealRequest; +import org.onap.policy.sdnc.SdncHealRequestHeaderInfo; import org.onap.policy.sdnc.SdncRequest; public class SdncOperationTest extends BasicSdncOperation { @@ -48,6 +50,13 @@ public class SdncOperationTest extends BasicSdncOperation { request = new SdncRequest(); request.setUrl(MY_URI); + SdncHealRequest healRequest = new SdncHealRequest(); + request.setHealRequest(healRequest); + + SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo(); + healRequest.setRequestHeaderInfo(headerInfo); + headerInfo.setSvcRequestId(SUB_REQ_ID); + oper = new SdncOperation(params, config) { @Override protected SdncRequest makeRequest(int attempt) { diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java index 67c3d4521..21f1562cf 100644 --- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java +++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java @@ -20,17 +20,12 @@ package org.onap.policy.controlloop.actor.sdnr; -import java.util.concurrent.CompletableFuture; -import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.sdnr.PciRequestWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class ModifyConfigOperation extends SdnrOperation { - private static final Logger logger = LoggerFactory.getLogger(ModifyConfigOperation.class); - public static final String NAME = "ModifyConfig"; /** @@ -44,14 +39,14 @@ public class ModifyConfigOperation extends SdnrOperation { } @Override - protected PciRequestWrapper makeRequest(int attempt) { - PciRequestWrapper request = super.makeRequest(attempt); + protected Pair makeRequest(int attempt) { + final Pair req = super.makeRequest(attempt); + final PciRequestWrapper request = req.getRight(); // // Set the recipe and action information // request.setRpcName(NAME.toLowerCase()); request.getBody().setAction(NAME); - logger.info("SDNR ModifyConfig Request to be sent is {}", request); - return request; + return req; } } diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java index 5faa31d7c..b11c701b2 100644 --- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java +++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java @@ -23,6 +23,7 @@ package org.onap.policy.controlloop.actor.sdnr; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation; @@ -124,7 +125,7 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation makeRequest(int attempt) { VirtualControlLoopEvent onset = params.getContext().getEvent(); String subRequestId = UUID.randomUUID().toString(); @@ -158,6 +159,6 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation result = oper.makeRequest(1); + assertNotNull(result.getLeft()); + assertNotNull(result.getRight()); } } diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java index fc7e86a94..a7bfa3322 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import java.util.Arrays; +import org.apache.commons.lang3.tuple.Pair; import org.junit.Before; import org.junit.Test; import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status; @@ -45,12 +46,7 @@ public class SdnrOperationTest extends BasicSdnrOperation { public void setUp() throws Exception { super.setUp(); - operation = new SdnrOperation(params, config) { - @Override - protected PciRequestWrapper makeRequest(int attempt) { - return super.makeRequest(attempt); - } - }; + operation = new SdnrOperation(params, config) {}; } @Test @@ -61,7 +57,10 @@ public class SdnrOperationTest extends BasicSdnrOperation { @Test public void testMakeRequest() { - PciRequestWrapper request = operation.makeRequest(1); + Pair result = operation.makeRequest(1); + assertNotNull(result.getLeft()); + + PciRequestWrapper request = result.getRight(); assertNotNull(request.getBody()); assertEquals("1.0", request.getVersion()); @@ -74,7 +73,7 @@ public class SdnrOperationTest extends BasicSdnrOperation { @Test public void testGetExpectedKeyValues() { - PciRequestWrapper request = operation.makeRequest(1); + PciRequestWrapper request = operation.makeRequest(1).getRight(); assertEquals(Arrays.asList(request.getBody().getCommonHeader().getSubRequestId()), operation.getExpectedKeyValues(50, request)); 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); diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java index dd6852d29..d6940d299 100644 --- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java +++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java @@ -54,6 +54,7 @@ import org.onap.policy.controlloop.policy.PolicyResult; */ public class BasicOperation { protected static final UUID REQ_ID = UUID.randomUUID(); + protected static final String SUB_REQ_ID = "my-sub-request-id"; protected static final String DEFAULT_ACTOR = "default-actor"; protected static final String DEFAULT_OPERATION = "default-operation"; protected static final String TARGET_ENTITY = "my-target"; diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java index b38ddb08a..ec522a405 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java @@ -25,6 +25,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.BiConsumer; import lombok.Getter; +import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoderObject; @@ -105,7 +106,10 @@ public abstract class BidirectionalTopicOperation extends OperationPartial @Override protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { - final Q request = makeRequest(attempt); + final Pair pair = makeRequest(attempt); + final Q request = pair.getRight(); + outcome.setSubRequestId(pair.getLeft()); + final List expectedKeyValues = getExpectedKeyValues(attempt, request); final PipelineControllerFuture controller = new PipelineControllerFuture<>(); @@ -142,9 +146,10 @@ public abstract class BidirectionalTopicOperation extends OperationPartial * Makes the request. * * @param attempt operation attempt - * @return a new request + * @return a pair containing sub request ID, which may be {@code null} and the new + * request */ - protected abstract Q makeRequest(int attempt); + protected abstract Pair makeRequest(int attempt); /** * Gets values, expected in the response, that should match the selector keys. diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java index 5725a6d61..587564a2e 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java @@ -40,6 +40,7 @@ import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; import lombok.Getter; import lombok.Setter; +import org.apache.commons.lang3.tuple.Pair; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -66,6 +67,7 @@ public class BidirectionalTopicOperationTest { private static final String OPERATION = "my-operation"; private static final String REQ_ID = "my-request-id"; private static final String TEXT = "some text"; + private static final String SUB_REQID = "my-sub-request-id"; private static final int TIMEOUT_SEC = 10; private static final long TIMEOUT_MS = 1000 * TIMEOUT_SEC; private static final int MAX_REQUESTS = 100; @@ -136,6 +138,8 @@ public class BidirectionalTopicOperationTest { CompletableFuture future = oper.startOperationAsync(1, outcome); assertFalse(future.isDone()); + assertEquals(SUB_REQID, outcome.getSubRequestId()); + verify(forwarder).register(eq(Arrays.asList(REQ_ID)), listenerCaptor.capture()); verify(forwarder, never()).unregister(any(), any()); @@ -323,13 +327,14 @@ public class BidirectionalTopicOperationTest { private class MyStringOperation extends BidirectionalTopicOperation { + public MyStringOperation() { super(BidirectionalTopicOperationTest.this.params, config, String.class); } @Override - protected String makeRequest(int attempt) { - return TEXT; + protected Pair makeRequest(int attempt) { + return Pair.of(SUB_REQID, TEXT); } @Override @@ -350,8 +355,8 @@ public class BidirectionalTopicOperationTest { } @Override - protected MyRequest makeRequest(int attempt) { - return new MyRequest(); + protected Pair makeRequest(int attempt) { + return Pair.of(SUB_REQID, new MyRequest()); } @Override @@ -372,8 +377,8 @@ public class BidirectionalTopicOperationTest { } @Override - protected MyRequest makeRequest(int attempt) { - return new MyRequest(); + protected Pair makeRequest(int attempt) { + return Pair.of(SUB_REQID, new MyRequest()); } @Override -- cgit 1.2.3-korg