diff options
author | Jim Hahn <jrh3@att.com> | 2020-06-26 16:59:40 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-06-26 18:28:41 -0400 |
commit | f586da49681a510c79729d94a4565694d952b83b (patch) | |
tree | 3c10722cfbf01d7877d1e5eb6890aaa6db589241 /models-interactions/model-actors/actor.cds/src/main | |
parent | 93e2ba2e1756596323774398673736946b220090 (diff) |
Add CDS simulator to policy-models
Added CDS simulator to policy-models. Added a test case to the CDS
Actor to verify that it works with the simulator.
Issue-ID: POLICY-2676
Change-Id: I9b10de3bde93c69e82df983f77eecc253de8a1a2
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.cds/src/main')
-rw-r--r-- | models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java index 820f4de34..0a882ce93 100644 --- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java +++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java @@ -51,6 +51,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture; import org.onap.policy.controlloop.policy.TargetType; /** @@ -202,13 +203,26 @@ public class GrpcOperation extends OperationPartial { @Override protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) { + /* + * construct the request first so that we don't have to clean up the "client" if + * an exception is thrown + */ + ExecutionServiceInput request = constructRequest(params); + CompletableFuture<OperationOutcome> future = new CompletableFuture<>(); + client = new CdsProcessorGrpcClient(new CdsActorServiceManager(outcome, future), config.getCdsServerProperties()); - ExecutionServiceInput request = constructRequest(params); client.sendRequest(request); - return future; + + // arrange to shutdown the client when the request completes + PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>(); + + controller.wrap(future).whenCompleteAsync(controller.delayedComplete(), params.getExecutor()) + .whenCompleteAsync((arg1, arg2) -> client.close(), getBlockingExecutor()); + + return controller; } /** |