aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actorServiceProvider
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-02-20 19:08:55 -0500
committerJim Hahn <jrh3@att.com>2020-02-21 20:33:06 -0500
commit7f69c5ca0a6f6018166f8fee3e811edf4dee1eb8 (patch)
treee57ab3105adbe0752b30e0e0a60ea43588cfb384 /models-interactions/model-actors/actorServiceProvider
parent3c8c5b2994e3f132385f0341283bc271e13cdb25 (diff)
Change payload to Map<String,Object> so it's more versatile
This was supposed to be two separate commits, but I goofed something. Added guard query to Operation superclass. Modified VfModuleCreate to store the VF count, pass it to the guard, and bump it once the create completes successfully. Added code to check Actors for proper plug-in to ActorService. Renamed "operation" property to "operations", to be more consistent with other parameters (e.g., TopicParameterGroup). The META-INF/services files for the actors had mixed case, which did not match the package name of the Actor class, preventing the ServiceLoader from recognizing them. Also modified the ActorService to skip any that cannot actually be loaded, for whatever reason (e.g., not in the classpath). Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: Ifa97744543f2866cc553138ec5ec644b033de780
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider')
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/ActorService.java17
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContext.java8
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java48
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParams.java12
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java2
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java13
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java4
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java4
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java124
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java9
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParamsTest.java9
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java2
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java8
-rw-r--r--models-interactions/model-actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor3
14 files changed, 188 insertions, 75 deletions
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 24c2cfc23..22c7d3365 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
@@ -24,7 +24,9 @@ package org.onap.policy.controlloop.actorserviceprovider;
import com.google.common.collect.ImmutableMap;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import org.onap.policy.common.parameters.BeanValidationResult;
@@ -57,7 +59,17 @@ public class ActorService extends StartConfigPartial<Map<String, Map<String, Obj
Map<String, Actor> map = new HashMap<>();
- for (Actor newActor : loadActors()) {
+ Iterator<Actor> iter = loadActors().iterator();
+ while (iter.hasNext()) {
+
+ Actor newActor;
+ try {
+ newActor = iter.next();
+ } catch (ServiceConfigurationError e) {
+ logger.warn("unable to load actor", e);
+ continue;
+ }
+
map.compute(newActor.getName(), (name, existingActor) -> {
if (existingActor == null) {
return newActor;
@@ -168,8 +180,7 @@ public class ActorService extends StartConfigPartial<Map<String, Map<String, Obj
@Override
protected void doStop() {
logger.info("stopping actors");
- name2actor.values()
- .forEach(actor -> Util.runFunction(actor::stop, "failed to stop actor {}", actor.getName()));
+ name2actor.values().forEach(actor -> Util.runFunction(actor::stop, "failed to stop actor {}", actor.getName()));
}
@Override
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContext.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContext.java
index 8099ea7c2..f7b58c11e 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContext.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContext.java
@@ -117,6 +117,14 @@ public class ControlLoopEventContext implements Serializable {
}
/**
+ * Removes a property.
+ * @param name property name
+ */
+ public void removeProperty(String name) {
+ properties.remove(name);
+ }
+
+ /**
* Obtains the given property.
*
* @param name name of the desired property
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 e636228f6..c998209bc 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
@@ -23,8 +23,10 @@ package org.onap.policy.controlloop.actorserviceprovider.impl;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
@@ -71,6 +73,8 @@ public abstract class OperationPartial implements Operation {
private static final Logger logger = LoggerFactory.getLogger(OperationPartial.class);
private static final Coder coder = new StandardCoder();
+ public static final String GUARD_ACTOR_NAME = "GUARD";
+ public static final String GUARD_OPERATION_NAME = "Decision";
public static final long DEFAULT_RETRY_WAIT_MS = 1000L;
private final OperatorConfig config;
@@ -187,7 +191,7 @@ public abstract class OperationPartial implements Operation {
/**
* Invokes the operation's preprocessor step(s) as a "future". This method simply
- * invokes {@link #startGuardAsync()}.
+ * returns {@code null}.
* <p/>
* This method assumes the following:
* <ul>
@@ -199,12 +203,11 @@ public abstract class OperationPartial implements Operation {
* {@code null} if this operation needs no preprocessor
*/
protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- return startGuardAsync();
+ return null;
}
/**
- * Invokes the operation's guard step(s) as a "future". This method simply returns
- * {@code null}.
+ * Invokes the operation's guard step(s) as a "future".
* <p/>
* This method assumes the following:
* <ul>
@@ -216,7 +219,42 @@ public abstract class OperationPartial implements Operation {
* {@code null} if this operation has no guard
*/
protected CompletableFuture<OperationOutcome> startGuardAsync() {
- return null;
+ // get the guard payload
+ Map<String,Object> guardPayload = makeGuardPayload();
+
+ // wrap it in a "resource"
+ Map<String,Object> resource = new LinkedHashMap<>();
+ resource.put("guard", guardPayload);
+
+ Map<String,Object> payload = new LinkedHashMap<>();
+ payload.put("resource", resource);
+
+ /*
+ * Note: can't use constants from actor.guard, because that would create a
+ * circular dependency.
+ */
+ return params.toBuilder().actor(GUARD_ACTOR_NAME).operation(GUARD_OPERATION_NAME).retry(null).timeoutSec(null)
+ .payload(payload).build().start();
+ }
+
+ /**
+ * Creates a payload to execute a guard operation.
+ *
+ * @return a new guard payload
+ */
+ protected Map<String, Object> makeGuardPayload() {
+ Map<String, Object> guard = new LinkedHashMap<>();
+ guard.put("actor", params.getActor());
+ guard.put("recipe", params.getOperation());
+ guard.put("target", params.getTargetEntity());
+ guard.put("requestId", params.getRequestId());
+
+ String clname = params.getContext().getEvent().getClosedLoopControlName();
+ if (clname != null) {
+ guard.put("clname", clname);
+ }
+
+ return guard;
}
/**
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParams.java
index dc6f2b657..b8218e53b 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParams.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParams.java
@@ -33,18 +33,22 @@ import org.onap.policy.controlloop.actorserviceprovider.Util;
/**
* Superclass for Actor parameters that have default values in "this" object, and
- * operation-specific values in {@link #operation}.
+ * operation-specific values in {@link #operations}.
*/
@Getter
@Setter
@EqualsAndHashCode
public class CommonActorParams {
+ /**
+ * Name of the "operations" field contained within actor parameters.
+ */
+ public static final String OPERATIONS_FIELD = "operations";
/**
* Maps the operation name to its parameters.
*/
@NotNull
- protected Map<String, Map<String, Object>> operation;
+ protected Map<String, Map<String, Object>> operations;
/**
@@ -57,10 +61,10 @@ public class CommonActorParams {
public Function<String, Map<String, Object>> makeOperationParameters(String name) {
Map<String, Object> defaultParams = Util.translateToMap(name, this);
- defaultParams.remove("operation");
+ defaultParams.remove(OPERATIONS_FIELD);
return operationName -> {
- Map<String, Object> specificParams = operation.get(operationName);
+ Map<String, Object> specificParams = operations.get(operationName);
if (specificParams == null) {
return null;
}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java
index 925916097..7fc15c97b 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java
@@ -86,7 +86,7 @@ public class ControlLoopOperationParams {
/**
* Payload data for the request.
*/
- private Map<String, String> payload;
+ private Map<String, Object> payload;
/**
* Number of retries allowed, or {@code null} if no retries.
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java
index cf2426214..0f44f4f36 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/controlloop/ControlLoopEventContextTest.java
@@ -41,6 +41,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
public class ControlLoopEventContextTest {
+ private static final String MY_KEY = "def";
private static final UUID REQ_ID = UUID.randomUUID();
private static final String ITEM_KEY = "obtain-C";
@@ -53,7 +54,7 @@ public class ControlLoopEventContextTest {
*/
@Before
public void setUp() {
- enrichment = Map.of("abc", "one", "def", "two");
+ enrichment = Map.of("abc", "one", MY_KEY, "two");
event = new VirtualControlLoopEvent();
event.setRequestId(REQ_ID);
@@ -81,17 +82,21 @@ public class ControlLoopEventContextTest {
}
@Test
- public void testContains_testGetProperty_testSetProperty() {
+ public void testContains_testGetProperty_testSetProperty_testRemoveProperty() {
context.setProperty("abc", "a string");
- context.setProperty("def", 100);
+ context.setProperty(MY_KEY, 100);
+ assertTrue(context.contains(MY_KEY));
assertFalse(context.contains("ghi"));
String strValue = context.getProperty("abc");
assertEquals("a string", strValue);
- int intValue = context.getProperty("def");
+ int intValue = context.getProperty(MY_KEY);
assertEquals(100, intValue);
+
+ context.removeProperty(MY_KEY);
+ assertFalse(context.contains(MY_KEY));
}
@Test
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java
index 4a4354195..dfd3f8bc6 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicActorTest.java
@@ -172,7 +172,7 @@ public class BidirectionalTopicActorTest {
new TreeMap<>(maker.apply("operB")).toString());
// with invalid actor parameters
- params.setOperation(null);
+ params.setOperations(null);
assertThatThrownBy(() -> prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params)))
.isInstanceOf(ParameterValidationRuntimeException.class);
}
@@ -212,7 +212,7 @@ public class BidirectionalTopicActorTest {
params.setTimeoutSec(TIMEOUT);
// @formatter:off
- params.setOperation(Map.of(
+ params.setOperations(Map.of(
"operA", Map.of(),
"operB", Map.of("sourceTopic", "topicB")));
// @formatter:on
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java
index dacd3a529..a28b98c81 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/HttpActorTest.java
@@ -54,7 +54,7 @@ public class HttpActorTest {
params.setTimeoutSec(TIMEOUT);
// @formatter:off
- params.setOperation(Map.of(
+ params.setOperations(Map.of(
"operA", Map.of("path", "urlA"),
"operB", Map.of("path", "urlB")));
// @formatter:on
@@ -73,7 +73,7 @@ public class HttpActorTest {
new TreeMap<>(maker.apply("operB")).toString());
// with invalid actor parameters
- params.setOperation(null);
+ params.setOperations(null);
assertThatThrownBy(() -> prov.makeOperatorParameters(Util.translateToMap(prov.getName(), params)))
.isInstanceOf(ParameterValidationRuntimeException.class);
}
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 39564a443..2893cb627 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
@@ -28,6 +28,9 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import ch.qos.logback.classic.Logger;
import java.time.Instant;
@@ -44,7 +47,6 @@ import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -55,6 +57,9 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
import org.onap.policy.common.utils.coder.Coder;
@@ -64,11 +69,14 @@ import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.onap.policy.common.utils.time.PseudoExecutor;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.Operator;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfig;
+import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.slf4j.LoggerFactory;
@@ -82,6 +90,7 @@ public class OperationPartialTest {
private static final String OPERATION = "my-operation";
private static final String MY_SINK = "my-sink";
private static final String MY_SOURCE = "my-source";
+ private static final String MY_TARGET_ENTITY = "my-entity";
private static final String TEXT = "my-text";
private static final int TIMEOUT = 1000;
private static final UUID REQ_ID = UUID.randomUUID();
@@ -95,6 +104,15 @@ public class OperationPartialTest {
private static final Logger logger = (Logger) LoggerFactory.getLogger(OperationPartial.class);
private static final ExtractAppender appender = new ExtractAppender();
+ @Mock
+ private ActorService service;
+ @Mock
+ private Actor guardActor;
+ @Mock
+ private Operator guardOperator;
+ @Mock
+ private Operation guardOperation;
+
private VirtualControlLoopEvent event;
private ControlLoopEventContext context;
private PseudoExecutor executor;
@@ -139,6 +157,8 @@ public class OperationPartialTest {
*/
@Before
public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
event = new VirtualControlLoopEvent();
event.setRequestId(REQ_ID);
@@ -146,8 +166,13 @@ public class OperationPartialTest {
executor = new PseudoExecutor();
params = ControlLoopOperationParams.builder().completeCallback(this::completer).context(context)
- .executor(executor).actor(ACTOR).operation(OPERATION).timeoutSec(TIMEOUT)
- .startCallback(this::starter).targetEntity(MY_SINK).build();
+ .executor(executor).actorService(service).actor(ACTOR).operation(OPERATION).timeoutSec(TIMEOUT)
+ .startCallback(this::starter).targetEntity(MY_TARGET_ENTITY).build();
+
+ when(service.getActor(OperationPartial.GUARD_ACTOR_NAME)).thenReturn(guardActor);
+ when(guardActor.getOperator(OperationPartial.GUARD_OPERATION_NAME)).thenReturn(guardOperator);
+ when(guardOperator.buildOperation(any())).thenReturn(guardOperation);
+ when(guardOperation.start()).thenReturn(CompletableFuture.completedFuture(makeSuccess()));
config = new OperatorConfig(executor);
@@ -189,25 +214,6 @@ public class OperationPartialTest {
}
/**
- * Tests startOperation() when the operation has a preprocessor.
- */
- @Test
- public void testStartWithPreprocessor() {
- AtomicInteger count = new AtomicInteger();
-
- CompletableFuture<OperationOutcome> preproc = CompletableFuture.supplyAsync(() -> {
- count.incrementAndGet();
- return makeSuccess();
- }, executor);
-
- oper.setGuard(preproc);
-
- verifyRun("testStartWithPreprocessor_testStartPreprocessor", 1, 1, PolicyResult.SUCCESS);
-
- assertEquals(1, count.get());
- }
-
- /**
* Tests start() with multiple running requests.
*/
@Test
@@ -232,7 +238,7 @@ public class OperationPartialTest {
*/
@Test
public void testStartPreprocessorFailure() {
- oper.setGuard(CompletableFuture.completedFuture(makeFailure()));
+ oper.setPreProc(CompletableFuture.completedFuture(makeFailure()));
verifyRun("testStartPreprocessorFailure", 1, 0, PolicyResult.FAILURE_GUARD);
}
@@ -243,7 +249,7 @@ public class OperationPartialTest {
@Test
public void testStartPreprocessorException() {
// arrange for the preprocessor to throw an exception
- oper.setGuard(CompletableFuture.failedFuture(new IllegalStateException(EXPECTED_EXCEPTION)));
+ oper.setPreProc(CompletableFuture.failedFuture(new IllegalStateException(EXPECTED_EXCEPTION)));
verifyRun("testStartPreprocessorException", 1, 0, PolicyResult.FAILURE_GUARD);
}
@@ -254,7 +260,7 @@ public class OperationPartialTest {
@Test
public void testStartPreprocessorNotRunning() {
// arrange for the preprocessor to return success, which will be ignored
- oper.setGuard(CompletableFuture.completedFuture(makeSuccess()));
+ // oper.setGuard(CompletableFuture.completedFuture(makeSuccess()));
oper.start().cancel(false);
assertTrue(executor.runAll(MAX_REQUESTS));
@@ -291,8 +297,49 @@ public class OperationPartialTest {
}
@Test
- public void testStartGuardAsync() {
- assertNull(oper.startGuardAsync());
+ public void testStartGuardAsync() throws Exception {
+ CompletableFuture<OperationOutcome> future = oper.startGuardAsync();
+ assertTrue(future.isDone());
+ assertEquals(PolicyResult.SUCCESS, future.get().getResult());
+
+ // verify the parameters that were passed
+ ArgumentCaptor<ControlLoopOperationParams> paramsCaptor =
+ ArgumentCaptor.forClass(ControlLoopOperationParams.class);
+ verify(guardOperator).buildOperation(paramsCaptor.capture());
+
+ params = paramsCaptor.getValue();
+ assertEquals(OperationPartial.GUARD_ACTOR_NAME, params.getActor());
+ assertEquals(OperationPartial.GUARD_OPERATION_NAME, params.getOperation());
+ assertNull(params.getRetry());
+ assertNull(params.getTimeoutSec());
+
+ Map<String, Object> payload = params.getPayload();
+ assertNotNull(payload);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> resource = (Map<String, Object>) payload.get("resource");
+ assertNotNull(resource);
+
+ @SuppressWarnings("unchecked")
+ Map<String, Object> guard = (Map<String, Object>) resource.get("guard");
+ assertEquals(oper.makeGuardPayload(), guard);
+ }
+
+ @Test
+ public void testMakeGuardPayload() {
+ Map<String, Object> payload = oper.makeGuardPayload();
+ assertSame(REQ_ID, payload.get("requestId"));
+
+ // request id changes, so remove it
+ payload.remove("requestId");
+
+ assertEquals("{actor=my-actor, recipe=my-operation, target=my-entity}", payload.toString());
+
+ // repeat, but with closed loop name
+ event.setClosedLoopControlName("my-loop");
+ payload = oper.makeGuardPayload();
+ payload.remove("requestId");
+ assertEquals("{actor=my-actor, recipe=my-operation, target=my-entity, clname=my-loop}", payload.toString());
}
@Test
@@ -541,7 +588,7 @@ public class OperationPartialTest {
*/
@Test
public void testHandlePreprocessorFailureTrue() {
- oper.setGuard(CompletableFuture.completedFuture(makeSuccess()));
+ oper.setPreProc(CompletableFuture.completedFuture(makeSuccess()));
verifyRun("testHandlePreprocessorFailureTrue", 1, 1, PolicyResult.SUCCESS);
}
@@ -550,7 +597,7 @@ public class OperationPartialTest {
*/
@Test
public void testHandlePreprocessorFailureFalse() throws Exception {
- oper.setGuard(CompletableFuture.completedFuture(makeFailure()));
+ oper.setPreProc(CompletableFuture.completedFuture(makeFailure()));
verifyRun("testHandlePreprocessorFailureFalse", 1, 0, PolicyResult.FAILURE_GUARD);
}
@@ -559,9 +606,8 @@ public class OperationPartialTest {
*/
@Test
public void testHandlePreprocessorFailureNull() throws Exception {
- // arrange to return null from the preprocessor
- oper.setGuard(CompletableFuture.completedFuture(null));
-
+ // arrange to return a null outcome from the preprocessor
+ oper.setPreProc(CompletableFuture.completedFuture(null));
verifyRun("testHandlePreprocessorFailureNull", 1, 0, PolicyResult.FAILURE_GUARD);
}
@@ -1211,12 +1257,10 @@ public class OperationPartialTest {
@Setter
private boolean genException;
-
@Setter
private int maxFailures = 0;
-
@Setter
- private CompletableFuture<OperationOutcome> guard;
+ private CompletableFuture<OperationOutcome> preProc;
public MyOper() {
@@ -1242,11 +1286,6 @@ public class OperationPartialTest {
}
@Override
- protected CompletableFuture<OperationOutcome> startGuardAsync() {
- return (guard != null ? guard : super.startGuardAsync());
- }
-
- @Override
protected long getRetryWaitMs() {
/*
* Sleep timers run in the background, but we want to control things via the
@@ -1254,5 +1293,10 @@ public class OperationPartialTest {
*/
return 0L;
}
+
+ @Override
+ protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
+ return (preProc != null ? preProc : super.startPreprocessorAsync());
+ }
}
}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java
index 1f38ad371..1276950a5 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/BidirectionalTopicActorParamsTest.java
@@ -76,11 +76,12 @@ public class BidirectionalTopicActorParamsTest {
assertTrue(params.validate(CONTAINER).isValid());
// only a few fields are required
- BidirectionalTopicActorParams sparse = Util.translate(CONTAINER, Map.of("operation", operMap, "timeoutSec", 1),
- BidirectionalTopicActorParams.class);
+ BidirectionalTopicActorParams sparse =
+ Util.translate(CONTAINER, Map.of(CommonActorParams.OPERATIONS_FIELD, operMap, "timeoutSec", 1),
+ BidirectionalTopicActorParams.class);
assertTrue(sparse.validate(CONTAINER).isValid());
- testValidateField("operation", "null", params2 -> params2.setOperation(null));
+ testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null));
testValidateField("timeoutSec", "minimum", params2 -> params2.setTimeoutSec(-1));
// check edge cases
@@ -111,7 +112,7 @@ public class BidirectionalTopicActorParamsTest {
params2.setSinkTopic(DFLT_SINK);
params2.setSourceTopic(DFLT_SOURCE);
params2.setTimeoutSec(DFLT_TIMEOUT);
- params2.setOperation(operMap);
+ params2.setOperations(operMap);
return params2;
}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParamsTest.java
index 901420346..99b441064 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParamsTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/CommonActorParamsTest.java
@@ -86,7 +86,7 @@ public class CommonActorParamsTest {
assertThatCode(() -> params.doValidation(CONTAINER)).doesNotThrowAnyException();
// invalid param
- params.setOperation(null);
+ params.setOperations(null);
assertThatThrownBy(() -> params.doValidation(CONTAINER))
.isInstanceOf(ParameterValidationRuntimeException.class);
}
@@ -96,11 +96,12 @@ public class CommonActorParamsTest {
assertTrue(params.validate(CONTAINER).isValid());
// only a few fields are required
- CommonActorParams sparse = Util.translate(CONTAINER, Map.of("operation", operations, "timeoutSec", 1),
+ CommonActorParams sparse = Util.translate(CONTAINER,
+ Map.of(CommonActorParams.OPERATIONS_FIELD, operations, "timeoutSec", 1),
CommonActorParams.class);
assertTrue(sparse.validate(CONTAINER).isValid());
- testValidateField("operation", "null", params2 -> params2.setOperation(null));
+ testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null));
}
private void testValidateField(String fieldName, String expected, Consumer<CommonActorParams> makeInvalid) {
@@ -119,7 +120,7 @@ public class CommonActorParamsTest {
private CommonActorParams makeCommonActorParams() {
MyParams params2 = new MyParams();
- params2.setOperation(operations);
+ params2.setOperations(operations);
params2.setText1(TEXT1);
params2.setText2(TEXT2);
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java
index a5215a48f..e4c83049b 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParamsTest.java
@@ -99,7 +99,7 @@ public class ControlLoopOperationParamsTest {
@Mock
private Consumer<OperationOutcome> starter;
- private Map<String, String> payload;
+ private Map<String, Object> payload;
private ControlLoopOperationParams params;
private OperationOutcome outcome;
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java
index 9e708535f..99bf63305 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpActorParamsTest.java
@@ -64,11 +64,11 @@ public class HttpActorParamsTest {
assertTrue(params.validate(CONTAINER).isValid());
// only a few fields are required
- HttpActorParams sparse = Util.translate(CONTAINER, Map.of("operation", operations, "timeoutSec", 1),
- HttpActorParams.class);
+ HttpActorParams sparse = Util.translate(CONTAINER,
+ Map.of(CommonActorParams.OPERATIONS_FIELD, operations, "timeoutSec", 1), HttpActorParams.class);
assertTrue(sparse.validate(CONTAINER).isValid());
- testValidateField("operation", "null", params2 -> params2.setOperation(null));
+ testValidateField(CommonActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null));
testValidateField("timeoutSec", "minimum", params2 -> params2.setTimeoutSec(-1));
// check edge cases
@@ -97,7 +97,7 @@ public class HttpActorParamsTest {
HttpActorParams params2 = new HttpActorParams();
params2.setClientName(CLIENT);
params2.setTimeoutSec(TIMEOUT);
- params2.setOperation(operations);
+ params2.setOperations(operations);
return params2;
}
diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor b/models-interactions/model-actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor
index 2a4bb5749..5f28cf4f2 100644
--- a/models-interactions/model-actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor
+++ b/models-interactions/model-actors/actorServiceProvider/src/test/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor
@@ -1 +1,2 @@
-org.onap.policy.controlloop.actorserviceprovider.DummyActor \ No newline at end of file
+org.onap.policy.controlloop.actorserviceprovider.DummyActor
+org.onap.policy.controlloop.actorserviceprovider.InvalidActor \ No newline at end of file