summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java5
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java9
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java4
-rw-r--r--models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java5
-rw-r--r--models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java6
-rw-r--r--models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java8
-rw-r--r--models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java40
-rw-r--r--models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java6
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java13
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java18
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java13
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java13
12 files changed, 99 insertions, 41 deletions
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java
index b8eb85c03..aa6d7273f 100644
--- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardActorParams.java
@@ -40,4 +40,9 @@ public class GuardActorParams extends HttpActorParams {
private String onapComponent;
private String onapInstance;
private String action = DEFAULT_ACTION;
+
+ /**
+ * {@code True} if guard operations are disabled.
+ */
+ private boolean disabled = false;
}
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java
index c6bf32635..0e711d1be 100644
--- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardConfig.java
@@ -23,6 +23,7 @@ package org.onap.policy.controlloop.actor.guard;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.Executor;
+import lombok.Getter;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
@@ -34,6 +35,12 @@ public class GuardConfig extends HttpConfig {
private final Map<String, Object> defaultRequest = new LinkedHashMap<>();
/**
+ * {@code True} if the associated guard operation is disabled.
+ */
+ @Getter
+ private boolean disabled;
+
+ /**
* Constructs the object.
*
* @param blockingExecutor executor to be used for tasks that may perform blocking I/O
@@ -47,6 +54,8 @@ public class GuardConfig extends HttpConfig {
addProperty("ONAPInstance", params.getOnapInstance());
addProperty("ONAPName", params.getOnapName());
addProperty("action", params.getAction());
+
+ this.disabled = params.isDisabled();
}
/**
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
index a5459f660..e35caa06c 100644
--- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java
@@ -84,6 +84,10 @@ public class GuardOperation extends HttpOperation<DecisionResponse> {
@Override
protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
+ if (config.isDisabled()) {
+ // guard is disabled, thus it is always treated as a success
+ return CompletableFuture.completedFuture(params.makeOutcome());
+ }
DecisionRequest request = Util.translate(getName(), makeRequest(), DecisionRequest.class);
diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java
index 251482525..5f8360377 100644
--- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java
+++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardParams.java
@@ -41,4 +41,9 @@ public class GuardParams extends HttpParams {
private String onapComponent;
private String onapInstance;
private String action;
+
+ /**
+ * {@code True} if the associated guard operation is disabled.
+ */
+ private boolean disabled;
}
diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java
index 1c256090e..0fef3bd29 100644
--- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java
+++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardActorParamsTest.java
@@ -65,6 +65,12 @@ public class GuardActorParamsTest {
}
@Test
+ public void testIsDisabled() {
+ // disabled by default
+ assertFalse(params.isDisabled());
+ }
+
+ @Test
public void testValidate() {
assertTrue(params.validate(CONTAINER).isValid());
diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java
index f94d122d9..49c1c916a 100644
--- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java
+++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java
@@ -21,7 +21,9 @@
package org.onap.policy.controlloop.actor.guard;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.concurrent.Executor;
@@ -85,8 +87,14 @@ public class GuardConfigTest {
// repeat, with minimal parameters
params = GuardParams.builder().clientName(MY_CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
config = new GuardConfig(executor, params, factory);
+ assertFalse(config.isDisabled());
actual = Util.translate("", config.makeRequest(), DecisionRequest.class);
assertEquals(new DecisionRequest(), actual);
+
+ // try with disabled=true
+ params = params.toBuilder().disabled(true).build();
+ config = new GuardConfig(executor, params, factory);
+ assertTrue(config.isDisabled());
}
}
diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java
index bd23a818b..a43292a65 100644
--- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java
+++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java
@@ -26,14 +26,17 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.CompletableFuture;
+import java.util.function.Consumer;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
@@ -44,6 +47,12 @@ import org.onap.policy.models.decisions.concepts.DecisionResponse;
public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> {
+ @Mock
+ private Consumer<OperationOutcome> started;
+ @Mock
+ private Consumer<OperationOutcome> completed;
+
+ private GuardConfig guardConfig;
private GuardOperation oper;
/**
@@ -53,12 +62,14 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> {
public void setUp() throws Exception {
super.setUpBasic();
- GuardConfig cguard = mock(GuardConfig.class);
- when(cguard.makeRequest()).thenAnswer(args -> new TreeMap<>(Map.of("action", "guard")));
+ guardConfig = mock(GuardConfig.class);
+ when(guardConfig.makeRequest()).thenAnswer(args -> new TreeMap<>(Map.of("action", "guard")));
- config = cguard;
+ config = guardConfig;
initConfig();
+ params = params.toBuilder().startCallback(started).completeCallback(completed).build();
+
oper = new GuardOperation(params, config);
}
@@ -87,6 +98,29 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> {
assertEquals(PolicyResult.SUCCESS, future2.get().getResult());
}
+ /**
+ * Tests startOperationAsync() when the guard is disabled.
+ */
+ @Test
+ public void testStartOperationAsyncDisabled() throws Exception {
+ // indicate that it's disabled
+ when(guardConfig.isDisabled()).thenReturn(true);
+
+ CompletableFuture<OperationOutcome> future2 = oper.start();
+ executor.runAll(100);
+
+ verify(client, never()).post(any(), any(), any(), any());
+
+ // should already be done
+ assertTrue(future2.isDone());
+
+ assertEquals(PolicyResult.SUCCESS, future2.get().getResult());
+
+ // ensure callbacks were invoked
+ verify(started).accept(any());
+ verify(completed).accept(any());
+ }
+
@Test
public void testMakeRequest() throws CoderException {
verifyPayload("makeReqStd.json", makePayload());
diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java
index b4148857a..172368349 100644
--- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java
+++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java
@@ -51,6 +51,12 @@ public class GuardParamsTest {
}
@Test
+ public void testIsDisabled() {
+ // disabled by default
+ assertFalse(params.isDisabled());
+ }
+
+ @Test
public void testValidate() {
assertTrue(params.validate(CONTAINER).isValid());
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java
index 22c7d3365..82f744421 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java
@@ -47,10 +47,6 @@ public class ActorService extends StartConfigPartial<Map<String, Map<String, Obj
private final Map<String, Actor> name2actor;
- private static class LazyHolder {
- static final ActorService INSTANCE = new ActorService();
- }
-
/**
* Constructs the object and loads the list of actors.
*/
@@ -85,15 +81,6 @@ public class ActorService extends StartConfigPartial<Map<String, Map<String, Obj
}
/**
- * Get the single instance.
- *
- * @return the instance
- */
- public static ActorService getInstance() {
- return LazyHolder.INSTANCE;
- }
-
- /**
* Gets a particular actor.
*
* @param name name of the actor of interest
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 ff1b46264..24c7ec866 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
@@ -68,6 +68,14 @@ import org.slf4j.LoggerFactory;
* returned by overridden methods will do the same. Of course, if a class overrides
* {@link #doOperation(int, OperationOutcome) doOperation()}, then there's little that can
* be done to cancel that particular operation.
+ * <p/>
+ * In general tasks in a pipeline are executed by the same thread. However, the following
+ * should always be executed via the executor specified in "params":
+ * <ul>
+ * <li>start callback</li>
+ * <li>completion callback</li>
+ * <li>controller completion (i.e., delayedComplete())</li>
+ * </ul>
*/
public abstract class OperationPartial implements Operation {
private static final Logger logger = LoggerFactory.getLogger(OperationPartial.class);
@@ -558,8 +566,7 @@ public abstract class OperationPartial implements Operation {
* canceled. Similarly, when this future completes, any incomplete futures
* will be canceled
*/
- public CompletableFuture<OperationOutcome> anyOf(
- List<Supplier<CompletableFuture<OperationOutcome>>> futureMakers) {
+ public CompletableFuture<OperationOutcome> anyOf(List<Supplier<CompletableFuture<OperationOutcome>>> futureMakers) {
PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>();
@@ -610,8 +617,7 @@ public abstract class OperationPartial implements Operation {
* canceled. Similarly, when this future completes, any incomplete futures
* will be canceled
*/
- public CompletableFuture<OperationOutcome> allOf(
- List<Supplier<CompletableFuture<OperationOutcome>>> futureMakers) {
+ public CompletableFuture<OperationOutcome> allOf(List<Supplier<CompletableFuture<OperationOutcome>>> futureMakers) {
PipelineControllerFuture<OperationOutcome> controller = new PipelineControllerFuture<>();
Queue<OperationOutcome> outcomes = new LinkedList<>();
@@ -809,7 +815,7 @@ public abstract class OperationPartial implements Operation {
// @formatter:off
controller.wrap(nextTask)
- .thenComposeAsync(nextTaskOnSuccess(controller, queue), executor)
+ .thenCompose(nextTaskOnSuccess(controller, queue))
.whenCompleteAsync(controller.delayedComplete(), executor);
// @formatter:on
@@ -843,7 +849,7 @@ public abstract class OperationPartial implements Operation {
// @formatter:off
return controller
.wrap(nextTask)
- .thenComposeAsync(nextTaskOnSuccess(controller, taskQueue), params.getExecutor());
+ .thenCompose(nextTaskOnSuccess(controller, taskQueue));
// @formatter:on
};
}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java
index 139c5179b..cca0694d7 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceProviderTest.java
@@ -23,7 +23,7 @@
package org.onap.policy.controlloop.actorserviceprovider;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
@@ -36,16 +36,11 @@ public class ActorServiceProviderTest {
@Test
public void testActorServiceProvider() {
- ActorService actorService = ActorService.getInstance();
- assertNotNull(actorService);
+ ActorService actorService = new ActorService();
- assertEquals(1, actorService.getActors().size());
+ assertTrue(actorService.getActors().size() >= 1);
- actorService = ActorService.getInstance();
- assertNotNull(actorService);
-
- Actor dummyActor = ActorService.getInstance().getActors().iterator().next();
- assertNotNull(dummyActor);
+ Actor dummyActor = actorService.getActor(DummyActor.class.getSimpleName());
assertEquals("DummyActor", dummyActor.actor());
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java
index efc7bb830..989fc8d6e 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/ActorServiceTest.java
@@ -215,14 +215,6 @@ public class ActorServiceTest {
}
@Test
- public void testGetInstance() {
- service = ActorService.getInstance();
- assertNotNull(service);
-
- assertSame(service, ActorService.getInstance());
- }
-
- @Test
public void testGetActor() {
assertSame(actor1, service.getActor(ACTOR1));
assertSame(actor3, service.getActor(ACTOR3));
@@ -360,8 +352,9 @@ public class ActorServiceTest {
@Test
public void testLoadActors() {
- assertFalse(ActorService.getInstance().getActors().isEmpty());
- assertNotNull(ActorService.getInstance().getActor("DummyActor"));
+ ActorService service = new ActorService();
+ assertFalse(service.getActors().isEmpty());
+ assertNotNull(service.getActor(DummyActor.class.getSimpleName()));
}
/**