summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actorServiceProvider/src/main
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/src/main
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/src/main')
-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
5 files changed, 74 insertions, 13 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.