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 --- .../controlloop/actor/appc/AppcOperation.java | 8 +++-- .../actor/appc/ModifyConfigOperation.java | 3 +- .../controlloop/actor/appc/AppcOperationTest.java | 34 +++++++++++++--------- .../actor/appc/ModifyConfigOperationTest.java | 6 +++- 4 files changed, 33 insertions(+), 18 deletions(-) (limited to 'models-interactions/model-actors/actor.appc/src') 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)); -- cgit 1.2.3-korg