From 88fedd4d3edbb581eabe20074a65c32b635fc3b2 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 1 Apr 2020 11:03:31 -0400 Subject: 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 --- .../impl/BidirectionalTopicOperation.java | 11 +++-------- .../actorserviceprovider/impl/OperationPartial.java | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'models-interactions/model-actors/actorServiceProvider/src/main') 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 extends OperationPartial @Override protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { - final Pair pair = makeRequest(attempt); - final Q request = pair.getRight(); - outcome.setSubRequestId(pair.getLeft()); - + final Q request = makeRequest(attempt); final List expectedKeyValues = getExpectedKeyValues(attempt, request); final PipelineControllerFuture controller = new PipelineControllerFuture<>(); @@ -151,10 +147,9 @@ public abstract class BidirectionalTopicOperation 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 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 startOperationAttempt( PipelineControllerFuture controller, int attempt) { + generateSubRequestId(attempt); + // propagate "stop" to the operation attempt controller.wrap(startAttemptWithoutRetries(attempt)).thenCompose(retryOnFailure(controller, attempt)) .whenCompleteAsync(controller.delayedComplete(), params.getExecutor()); @@ -278,6 +287,16 @@ public abstract class OperationPartial implements Operation { return controller; } + /** + * 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. * @@ -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()); -- cgit 1.2.3-korg