summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.appc/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-01 11:03:31 -0400
committerJim Hahn <jrh3@att.com>2020-04-01 12:04:48 -0400
commit88fedd4d3edbb581eabe20074a65c32b635fc3b2 (patch)
treeb932b653aa2d89557f08570d51fc5204459dae93 /models-interactions/model-actors/actor.appc/src
parent3a99e95994963c8fd04d7c038cf6b0263b2bbdeb (diff)
Set sub request ID before start callback
Modified new actor code to generate the sub request ID before invoking the start callback. Issue-ID: POLICY-2461 Change-Id: I4adabd6efda2c30c0e2da31f95f01dd5fe546c0a Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.appc/src')
-rw-r--r--models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java13
-rw-r--r--models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java3
-rw-r--r--models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java69
-rw-r--r--models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java7
4 files changed, 36 insertions, 56 deletions
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 3ed23957a..75a4c9f58 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
@@ -23,9 +23,7 @@ package org.onap.policy.controlloop.actor.appc;
import java.util.List;
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;
@@ -86,14 +84,11 @@ public abstract class AppcOperation extends BidirectionalTopicOperation<Request,
* @param targetVnf target VNF
* @return a new request
*/
- protected Pair<String, Request> makeRequest(int attempt, String targetVnf) {
+ protected Request 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"?
- final String subreq = UUID.randomUUID().toString();
- request.getCommonHeader().setSubRequestId(subreq);
+ request.getCommonHeader().setSubRequestId(getSubRequestId());
request.setAction(getName());
@@ -107,7 +102,7 @@ public abstract class AppcOperation extends BidirectionalTopicOperation<Request,
// add/replace specific values
request.getPayload().put(VNF_ID_KEY, targetVnf);
- return Pair.of(subreq, request);
+ return request;
}
/**
@@ -139,7 +134,7 @@ public abstract class AppcOperation extends BidirectionalTopicOperation<Request,
*/
@Override
protected List<String> getExpectedKeyValues(int attempt, Request request) {
- return List.of(request.getCommonHeader().getSubRequestId());
+ return List.of(getSubRequestId());
}
@Override
diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java
index e4fd51c07..a318444aa 100644
--- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java
+++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java
@@ -21,7 +21,6 @@
package org.onap.policy.controlloop.actor.appc;
import java.util.concurrent.CompletableFuture;
-import org.apache.commons.lang3.tuple.Pair;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.policy.aai.AaiConstants;
import org.onap.policy.aai.AaiCqResponse;
@@ -61,7 +60,7 @@ public class ModifyConfigOperation extends AppcOperation {
}
@Override
- protected Pair<String, Request> makeRequest(int attempt) {
+ protected Request 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 7f7ac7a54..4c6477d93 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
@@ -22,14 +22,12 @@ package org.onap.policy.controlloop.actor.appc;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
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.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -40,6 +38,8 @@ import org.onap.policy.appc.Request;
import org.onap.policy.appc.ResponseCode;
import org.onap.policy.appc.ResponseStatus;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.policy.PolicyResult;
public class AppcOperationTest extends BasicAppcOperation {
@@ -64,12 +64,7 @@ public class AppcOperationTest extends BasicAppcOperation {
public void setUp() throws Exception {
super.setUp();
- oper = new AppcOperation(params, config) {
- @Override
- protected Pair<String, Request> makeRequest(int attempt) {
- return oper.makeRequest(attempt, MY_VNF);
- }
- };
+ oper = new MyOper(params, config);
}
@After
@@ -91,11 +86,11 @@ public class AppcOperationTest extends BasicAppcOperation {
@Test
public void testMakeRequest() {
- Pair<String, Request> result = oper.makeRequest(2, MY_VNF);
- String subreq = result.getLeft();
+ oper.generateSubRequestId(2);
+ String subreq = oper.getSubRequestId();
assertNotNull(subreq);
- Request request = result.getRight();
+ Request request = oper.makeRequest(2, MY_VNF);
assertEquals(DEFAULT_OPERATION, request.getAction());
assertNotNull(request.getPayload());
@@ -106,27 +101,18 @@ public class AppcOperationTest extends BasicAppcOperation {
assertEquals(subreq, header.getSubRequestId());
- // a subsequent request should have a different sub-request id
- result = oper.makeRequest(2, MY_VNF);
- assertNotEquals(subreq, result.getLeft());
-
- assertNotNull(result.getLeft());
- assertEquals(result.getLeft(), result.getRight().getCommonHeader().getSubRequestId());
+ request = oper.makeRequest(2, MY_VNF);
+ assertEquals(subreq, request.getCommonHeader().getSubRequestId());
// repeat using a null payload
params = params.toBuilder().payload(null).build();
- oper = new AppcOperation(params, config) {
- @Override
- protected Pair<String, Request> makeRequest(int attempt) {
- return oper.makeRequest(attempt, MY_VNF);
- }
- };
- assertEquals(Map.of(AppcOperation.VNF_ID_KEY, MY_VNF), oper.makeRequest(2, MY_VNF).getRight().getPayload());
+ oper = new MyOper(params, config);
+ assertEquals(Map.of(AppcOperation.VNF_ID_KEY, MY_VNF), oper.makeRequest(2, MY_VNF).getPayload());
}
@Test
public void testConvertPayload() {
- Request request = oper.makeRequest(2, MY_VNF).getRight();
+ Request request = oper.makeRequest(2, MY_VNF);
// @formatter:off
assertEquals(
@@ -145,13 +131,8 @@ public class AppcOperationTest extends BasicAppcOperation {
params = params.toBuilder().payload(payload).build();
- oper = new AppcOperation(params, config) {
- @Override
- protected Pair<String, Request> makeRequest(int attempt) {
- return oper.makeRequest(attempt, MY_VNF);
- }
- };
- request = oper.makeRequest(2, MY_VNF).getRight();
+ oper = new MyOper(params, config);
+ request = oper.makeRequest(2, MY_VNF);
// @formatter:off
assertEquals(
@@ -171,13 +152,8 @@ public class AppcOperationTest extends BasicAppcOperation {
payload.put(KEY3, "def");
params = params.toBuilder().payload(payload).build();
- oper = new AppcOperation(params, config) {
- @Override
- protected Pair<String, Request> makeRequest(int attempt) {
- return oper.makeRequest(attempt, MY_VNF);
- }
- };
- request = oper.makeRequest(2, MY_VNF).getRight();
+ oper = new MyOper(params, config);
+ request = oper.makeRequest(2, MY_VNF);
payload.put(AppcOperation.VNF_ID_KEY, MY_VNF);
payload.put(KEY1, "abc");
@@ -189,7 +165,8 @@ public class AppcOperationTest extends BasicAppcOperation {
@Test
public void testGetExpectedKeyValues() {
- Request request = oper.makeRequest(2, MY_VNF).getRight();
+ oper.generateSubRequestId(2);
+ Request request = oper.makeRequest(2, MY_VNF);
assertEquals(Arrays.asList(request.getCommonHeader().getSubRequestId()),
oper.getExpectedKeyValues(50, request));
}
@@ -250,4 +227,16 @@ public class AppcOperationTest extends BasicAppcOperation {
assertEquals(MY_DESCRIPTION, outcome.getMessage());
}
}
+
+ private static class MyOper extends AppcOperation {
+
+ public MyOper(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
+ super(params, config);
+ }
+
+ @Override
+ protected Request makeRequest(int attempt) {
+ return makeRequest(attempt, MY_VNF);
+ }
+ }
}
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 743896c18..4f4f506ce 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,7 +34,6 @@ 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.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -161,10 +160,8 @@ public class ModifyConfigOperationTest extends BasicAppcOperation {
genvnf.setModelInvariantId(RESOURCE_ID);
cq.setInventoryResponseItems(Arrays.asList(genvnf));
- Pair<String, Request> result = oper.makeRequest(2);
- assertNotNull(result.getLeft());
-
- Request request = result.getRight();
+ oper.generateSubRequestId(2);
+ Request request = oper.makeRequest(2);
assertNotNull(request);
assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY));