Add PipelineUtil 73/102273/3
authorJim Hahn <jrh3@att.com>
Mon, 24 Feb 2020 20:11:35 +0000 (15:11 -0500)
committerJim Hahn <jrh3@att.com>
Tue, 25 Feb 2020 15:18:07 +0000 (10:18 -0500)
Issue-ID: POLICY-2385
Signed-off-by: Jim Hahn <jrh3@att.com>
Change-Id: I7745e8286dd6f086941b979f16b2328bfa066788

models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java
models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtil.java [new file with mode: 0644]
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtilTest.java [new file with mode: 0644]

index be357b8..ff1b462 100644 (file)
@@ -113,7 +113,7 @@ public abstract class OperationPartial implements Operation {
     }
 
     @Override
-    public final CompletableFuture<OperationOutcome> start() {
+    public CompletableFuture<OperationOutcome> start() {
         // allocate a controller for the entire operation
         final PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>();
 
@@ -539,7 +539,7 @@ public abstract class OperationPartial implements Operation {
      *         created. If this future is canceled, then all of the futures will be
      *         canceled
      */
-    protected CompletableFuture<OperationOutcome> anyOf(
+    public CompletableFuture<OperationOutcome> anyOf(
                     @SuppressWarnings("unchecked") Supplier<CompletableFuture<OperationOutcome>>... futureMakers) {
 
         return anyOf(Arrays.asList(futureMakers));
@@ -558,7 +558,7 @@ public abstract class OperationPartial implements Operation {
      *         canceled. Similarly, when this future completes, any incomplete futures
      *         will be canceled
      */
-    protected CompletableFuture<OperationOutcome> anyOf(
+    public CompletableFuture<OperationOutcome> anyOf(
                     List<Supplier<CompletableFuture<OperationOutcome>>> futureMakers) {
 
         PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>();
@@ -592,7 +592,7 @@ public abstract class OperationPartial implements Operation {
      *         created. If this future is canceled, then all of the futures will be
      *         canceled
      */
-    protected CompletableFuture<OperationOutcome> allOf(
+    public CompletableFuture<OperationOutcome> allOf(
                     @SuppressWarnings("unchecked") Supplier<CompletableFuture<OperationOutcome>>... futureMakers) {
 
         return allOf(Arrays.asList(futureMakers));
@@ -610,7 +610,7 @@ public abstract class OperationPartial implements Operation {
      *         canceled. Similarly, when this future completes, any incomplete futures
      *         will be canceled
      */
-    protected CompletableFuture<OperationOutcome> allOf(
+    public CompletableFuture<OperationOutcome> allOf(
                     List<Supplier<CompletableFuture<OperationOutcome>>> futureMakers) {
         PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>();
 
@@ -769,7 +769,7 @@ public abstract class OperationPartial implements Operation {
      * @param futureMakers functions to make the futures
      * @return a future to cancel the sequence or await the outcome
      */
-    protected CompletableFuture<OperationOutcome> sequence(
+    public CompletableFuture<OperationOutcome> sequence(
                     @SuppressWarnings("unchecked") Supplier<CompletableFuture<OperationOutcome>>... futureMakers) {
 
         return sequence(Arrays.asList(futureMakers));
@@ -784,7 +784,7 @@ public abstract class OperationPartial implements Operation {
      * @return a future to cancel the sequence or await the outcome, or {@code null} if
      *         there were no tasks to perform
      */
-    protected CompletableFuture<OperationOutcome> sequence(
+    public CompletableFuture<OperationOutcome> sequence(
                     List<Supplier<CompletableFuture<OperationOutcome>>> futureMakers) {
 
         Queue<Supplier<CompletableFuture<OperationOutcome>>> queue = new ArrayDeque<>(futureMakers);
@@ -926,7 +926,7 @@ public abstract class OperationPartial implements Operation {
      * @param operation operation to be updated
      * @return the updated operation
      */
-    protected OperationOutcome setOutcome(OperationOutcome operation, Throwable thrown) {
+    public OperationOutcome setOutcome(OperationOutcome operation, Throwable thrown) {
         PolicyResult result = (isTimeout(thrown) ? PolicyResult.FAILURE_TIMEOUT : PolicyResult.FAILURE_EXCEPTION);
         return setOutcome(operation, result);
     }
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtil.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtil.java
new file mode 100644 (file)
index 0000000..3854fb2
--- /dev/null
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.actorserviceprovider.pipeline;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ForkJoinPool;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfig;
+
+/**
+ * Utility class providing anyOf(), allOf(), sequence() to actor clients.
+ */
+public class PipelineUtil extends OperationPartial {
+
+    /**
+     * Constructs the utility.
+     *
+     * @param params utility parameters
+     */
+    public PipelineUtil(ControlLoopOperationParams params) {
+        super(params, new OperatorConfig(ForkJoinPool.commonPool()));
+    }
+
+    @Override
+    public CompletableFuture<OperationOutcome> start() {
+        throw new UnsupportedOperationException("cannot start() pipeline utility");
+    }
+}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtilTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/pipeline/PipelineUtilTest.java
new file mode 100644 (file)
index 0000000..fbcacbf
--- /dev/null
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.actorserviceprovider.pipeline;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.Test;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+
+public class PipelineUtilTest {
+
+    @Test
+    public void testPipelineUtil() {
+        ControlLoopOperationParams params = ControlLoopOperationParams.builder().build();
+        PipelineUtil util = new PipelineUtil(params);
+
+        assertThatThrownBy(() -> util.start()).isInstanceOf(UnsupportedOperationException.class);
+    }
+}