Remove legacy actor code from models
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / main / java / org / onap / policy / controlloop / actorserviceprovider / impl / ActorImpl.java
index 0c88ebe..336860e 100644 (file)
 package org.onap.policy.controlloop.actorserviceprovider.impl;
 
 import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Function;
-import org.onap.policy.common.parameters.BeanValidationResult;
 import org.onap.policy.controlloop.actorserviceprovider.Operator;
 import org.onap.policy.controlloop.actorserviceprovider.Util;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
 import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
 import org.slf4j.Logger;
@@ -55,6 +53,14 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement
         super(name);
     }
 
+    /**
+     * This method simply returns {@code 0}.
+     */
+    @Override
+    public int getSequenceNumber() {
+        return 0;
+    }
+
     /**
      * Adds an operator supported by this actor.
      *
@@ -116,8 +122,6 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement
         final String actorName = getName();
         logger.info("configuring operations for actor {}", actorName);
 
-        BeanValidationResult valres = new BeanValidationResult(actorName, parameters);
-
         // function that creates operator-specific parameters, given the operation name
         Function<String, Map<String, Object>> opParamsMaker = makeOperatorParameters(parameters);
 
@@ -131,8 +135,8 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement
                     operator.configure(subparams);
 
                 } catch (ParameterValidationRuntimeException e) {
-                    logger.warn("failed to configure operation {}.{}", actorName, operName, e);
-                    valres.addResult(e.getResult());
+                    logger.warn("failed to configure operation {}.{} because:\n{}", actorName, operName,
+                                    e.getResult().getResult(), e);
 
                 } catch (RuntimeException e) {
                     logger.warn("failed to configure operation {}.{}", actorName, operName, e);
@@ -151,7 +155,8 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement
 
     /**
      * Extracts the operator parameters from the actor parameters, for a given operator.
-     * This method assumes each operation has its own set of parameters.
+     * This method translates the parameters to an {@link ActorParams} and then creates a function
+     * that will extract operator-specific parameters.
      *
      * @param actorParameters actor parameters
      * @return a function to extract the operator parameters from the actor parameters.
@@ -159,8 +164,13 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement
      *         the given operation name
      */
     protected Function<String, Map<String, Object>> makeOperatorParameters(Map<String, Object> actorParameters) {
+        String actorName = getName();
 
-        return operName -> Util.translateToMap(getName() + "." + operName, actorParameters.get(operName));
+        // @formatter:off
+        return Util.translate(actorName, actorParameters, ActorParams.class)
+                        .doValidation(actorName)
+                        .makeOperationParameters(actorName);
+        // @formatter:on
     }
 
     /**
@@ -208,28 +218,4 @@ public class ActorImpl extends StartConfigPartial<Map<String, Object>> implement
                         "failed to shutdown operation {}.{}", actorName, oper.getName()));
         // @formatter:on
     }
-
-    // TODO old code: remove lines down to **HERE**
-
-    @Override
-    public String actor() {
-        return null;
-    }
-
-    @Override
-    public List<String> recipes() {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public List<String> recipeTargets(String recipe) {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public List<String> recipePayloads(String recipe) {
-        return Collections.emptyList();
-    }
-
-    // **HERE**
 }