diff options
author | Jim Hahn <jrh3@att.com> | 2020-04-01 11:03:31 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-04-01 12:04:48 -0400 |
commit | 88fedd4d3edbb581eabe20074a65c32b635fc3b2 (patch) | |
tree | b932b653aa2d89557f08570d51fc5204459dae93 /models-interactions/model-actors/actorServiceProvider/src | |
parent | 3a99e95994963c8fd04d7c038cf6b0263b2bbdeb (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/actorServiceProvider/src')
4 files changed, 36 insertions, 28 deletions
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 f598d627a..9decd8a61 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,7 +25,6 @@ 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; @@ -106,10 +105,7 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial @Override protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) { - final Pair<String, Q> pair = makeRequest(attempt); - final Q request = pair.getRight(); - outcome.setSubRequestId(pair.getLeft()); - + final Q request = makeRequest(attempt); final List<String> expectedKeyValues = getExpectedKeyValues(attempt, request); final PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>(); @@ -151,10 +147,9 @@ public abstract class BidirectionalTopicOperation<Q, S> extends OperationPartial * Makes the request. * * @param attempt operation attempt - * @return a pair containing sub request ID, which may be {@code null} and the new - * request + * @return a new request */ - protected abstract Pair<String, Q> makeRequest(int attempt); + protected abstract Q makeRequest(int attempt); /** * Gets values, expected in the response, that should match the selector keys. diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java index a9d7f4e58..4aa723614 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java @@ -28,6 +28,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; +import java.util.UUID; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -38,7 +39,9 @@ import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.Supplier; import java.util.function.UnaryOperator; +import lombok.AccessLevel; import lombok.Getter; +import lombok.Setter; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.utils.NetLoggerUtil; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; @@ -96,6 +99,10 @@ public abstract class OperationPartial implements Operation { @Getter private final String fullName; + @Getter + @Setter(AccessLevel.PROTECTED) + private String subRequestId; + /** * Constructs the object. @@ -271,6 +278,8 @@ public abstract class OperationPartial implements Operation { private CompletableFuture<OperationOutcome> startOperationAttempt( PipelineControllerFuture<OperationOutcome> controller, int attempt) { + generateSubRequestId(attempt); + // propagate "stop" to the operation attempt controller.wrap(startAttemptWithoutRetries(attempt)).thenCompose(retryOnFailure(controller, attempt)) .whenCompleteAsync(controller.delayedComplete(), params.getExecutor()); @@ -279,6 +288,16 @@ public abstract class OperationPartial implements Operation { } /** + * Generates and sets {@link #subRequestId} to a new subrequest ID. + * @param attempt attempt number, typically starting with 1 + */ + public void generateSubRequestId(int attempt) { + // Note: this should be "protected", but that makes junits much messier + + setSubRequestId(UUID.randomUUID().toString()); + } + + /** * Starts the operation attempt, without doing any retries. * * @param params operation parameters @@ -889,6 +908,7 @@ public abstract class OperationPartial implements Operation { return (outcome, thrown) -> { if (callbacks.canStart()) { + outcome.setSubRequestId(getSubRequestId()); outcome.setStart(callbacks.getStartTime()); outcome.setEnd(null); @@ -917,6 +937,7 @@ public abstract class OperationPartial implements Operation { return (outcome, thrown) -> { if (callbacks.canEnd()) { + outcome.setSubRequestId(getSubRequestId()); outcome.setStart(callbacks.getStartTime()); outcome.setEnd(callbacks.getEndTime()); 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 48669f799..55782a34d 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,7 +40,6 @@ 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; @@ -67,7 +66,6 @@ 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; @@ -138,8 +136,6 @@ public class BidirectionalTopicOperationTest { CompletableFuture<OperationOutcome> 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()); @@ -183,8 +179,6 @@ public class BidirectionalTopicOperationTest { CompletableFuture<OperationOutcome> 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()); @@ -363,8 +357,8 @@ public class BidirectionalTopicOperationTest { } @Override - protected Pair<String, String> makeRequest(int attempt) { - return Pair.of(SUB_REQID, TEXT); + protected String makeRequest(int attempt) { + return TEXT; } @Override @@ -385,8 +379,8 @@ public class BidirectionalTopicOperationTest { } @Override - protected Pair<String, MyRequest> makeRequest(int attempt) { - return Pair.of(SUB_REQID, new MyRequest()); + protected MyRequest makeRequest(int attempt) { + return new MyRequest(); } @Override @@ -407,8 +401,8 @@ public class BidirectionalTopicOperationTest { } @Override - protected Pair<String, MyRequest> makeRequest(int attempt) { - return Pair.of(SUB_REQID, new MyRequest()); + protected MyRequest makeRequest(int attempt) { + return new MyRequest(); } @Override diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java index 7b8eed59e..75463b9d7 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java @@ -531,7 +531,7 @@ public class OperationPartialTest { } }; - verifyRun("testSetRetryFlag_testRetryOnFailure_NullOutcome", 1, 1, PolicyResult.FAILURE, null, noop()); + verifyRun("testSetRetryFlag_testRetryOnFailure_NullOutcome", 1, 1, PolicyResult.FAILURE, noop()); } @Test @@ -1179,10 +1179,7 @@ public class OperationPartialTest { private void verifyRun(String testName, int expectedCallbacks, int expectedOperations, PolicyResult expectedResult) { - String expectedSubRequestId = - (expectedResult == PolicyResult.FAILURE_EXCEPTION ? null : String.valueOf(expectedOperations)); - - verifyRun(testName, expectedCallbacks, expectedOperations, expectedResult, expectedSubRequestId, noop()); + verifyRun(testName, expectedCallbacks, expectedOperations, expectedResult, noop()); } /** @@ -1192,13 +1189,12 @@ public class OperationPartialTest { * @param expectedCallbacks number of callbacks expected * @param expectedOperations number of operation invocations expected * @param expectedResult expected outcome - * @param expectedSubRequestId expected sub request ID * @param manipulator function to modify the future returned by * {@link OperationPartial#start(ControlLoopOperationParams)} before the tasks * in the executor are run */ private void verifyRun(String testName, int expectedCallbacks, int expectedOperations, PolicyResult expectedResult, - String expectedSubRequestId, Consumer<CompletableFuture<OperationOutcome>> manipulator) { + Consumer<CompletableFuture<OperationOutcome>> manipulator) { tstart = null; opstart = null; @@ -1244,7 +1240,9 @@ public class OperationPartialTest { } if (expectedOperations > 0) { - assertEquals(testName, expectedSubRequestId, opend.getSubRequestId()); + assertNotNull(testName, oper.getSubRequestId()); + assertEquals(testName + " op start", oper.getSubRequestId(), opstart.getSubRequestId()); + assertEquals(testName + " op end", oper.getSubRequestId(), opend.getSubRequestId()); } } |