Make targetEntity a property
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / main / java / org / onap / policy / controlloop / actorserviceprovider / impl / OperationPartial.java
index 0aa1122..b5cc15e 100644 (file)
@@ -53,6 +53,7 @@ import org.onap.policy.controlloop.ControlLoopOperation;
 import org.onap.policy.controlloop.actorserviceprovider.CallbackManager;
 import org.onap.policy.controlloop.actorserviceprovider.Operation;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.OperatorConfig;
 import org.onap.policy.controlloop.actorserviceprovider.pipeline.PipelineControllerFuture;
@@ -139,34 +140,19 @@ public abstract class OperationPartial implements Operation {
         return params.getOperation();
     }
 
-    /**
-     * Determines if a property has been assigned for the operation.
-     *
-     * @param name property name
-     * @return {@code true} if the given property has been assigned for the operation,
-     *         {@code false} otherwise
-     */
+    @Override
     public boolean containsProperty(String name) {
         return properties.containsKey(name);
     }
 
-    /**
-     * Sets a property.
-     *
-     * @param name property name
-     * @param value new value
-     */
+    @Override
     public void setProperty(String name, Object value) {
+        logger.info("{}: set property {}={}", getFullName(), name, value);
         properties.put(name, value);
     }
 
-    /**
-     * Gets a property's value.
-     *
-     * @param name name of the property of interest
-     * @return the property's value, or {@code null} if it has no value
-     */
     @SuppressWarnings("unchecked")
+    @Override
     public <T> T getProperty(String name) {
         return (T) properties.get(name);
     }
@@ -230,7 +216,7 @@ public abstract class OperationPartial implements Operation {
             // propagate "stop" to the callbacks
             controller.add(callbacks);
 
-            final OperationOutcome outcome2 = params.makeOutcome();
+            final OperationOutcome outcome2 = params.makeOutcome(getTargetEntity());
 
             // TODO need a FAILURE_MISSING_DATA (e.g., A&AI)
 
@@ -304,7 +290,7 @@ public abstract class OperationPartial implements Operation {
         Map<String, Object> guard = new LinkedHashMap<>();
         guard.put("actor", params.getActor());
         guard.put("operation", params.getOperation());
-        guard.put("target", params.getTargetEntity());
+        guard.put("target", getTargetEntity());
         guard.put("requestId", params.getRequestId());
 
         String clname = params.getContext().getEvent().getClosedLoopControlName();
@@ -358,7 +344,7 @@ public abstract class OperationPartial implements Operation {
         logger.info("{}: start operation attempt {} for {}", getFullName(), attempt, params.getRequestId());
 
         final Executor executor = params.getExecutor();
-        final OperationOutcome outcome = params.makeOutcome();
+        final OperationOutcome outcome = params.makeOutcome(getTargetEntity());
         final CallbackManager callbacks = new CallbackManager();
 
         // this operation attempt gets its own controller
@@ -489,7 +475,7 @@ public abstract class OperationPartial implements Operation {
                 outcome = origOutcome;
             } else {
                 logger.warn("{}: null outcome; treating as a failure for {}", getFullName(), params.getRequestId());
-                outcome = this.setOutcome(params.makeOutcome(), PolicyResult.FAILURE);
+                outcome = this.setOutcome(params.makeOutcome(getTargetEntity()), PolicyResult.FAILURE);
             }
 
             // ensure correct actor/operation
@@ -588,7 +574,7 @@ public abstract class OperationPartial implements Operation {
     private Function<Throwable, OperationOutcome> fromException(String type) {
 
         return thrown -> {
-            OperationOutcome outcome = params.makeOutcome();
+            OperationOutcome outcome = params.makeOutcome(getTargetEntity());
 
             if (thrown instanceof CancellationException || thrown.getCause() instanceof CancellationException) {
                 // do not include exception in the message, as it just clutters the log
@@ -1106,6 +1092,16 @@ public abstract class OperationPartial implements Operation {
         return DEFAULT_RETRY_WAIT_MS;
     }
 
+    /**
+     * Gets the target entity, first trying the properties and then the parameters.
+     *
+     * @return the target entity
+     */
+    protected String getTargetEntity() {
+        String targetEntity = getProperty(OperationProperties.AAI_TARGET_ENTITY);
+        return (targetEntity != null ? targetEntity : params.getTargetEntity());
+    }
+
     /**
      * Gets the operation timeout.
      *