Modify Actors to use properties when provided
[policy/models.git] / models-interactions / model-actors / actor.appc / src / main / java / org / onap / policy / controlloop / actor / appc / ModifyConfigOperation.java
index a318444..13ddaf4 100644 (file)
 
 package org.onap.policy.controlloop.actor.appc;
 
+import java.util.List;
 import java.util.concurrent.CompletableFuture;
 import org.onap.aai.domain.yang.GenericVnf;
 import org.onap.policy.aai.AaiConstants;
 import org.onap.policy.aai.AaiCqResponse;
 import org.onap.policy.appc.Request;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
 import org.slf4j.Logger;
@@ -36,6 +38,8 @@ public class ModifyConfigOperation extends AppcOperation {
 
     public static final String NAME = "ModifyConfig";
 
+    private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.AAI_RESOURCE_VNF);
+
     /**
      * Constructs the object.
      *
@@ -43,7 +47,7 @@ public class ModifyConfigOperation extends AppcOperation {
      * @param config configuration for this operation
      */
     public ModifyConfigOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
-        super(params, config);
+        super(params, config, PROPERTY_NAMES);
     }
 
     /**
@@ -52,6 +56,10 @@ public class ModifyConfigOperation extends AppcOperation {
     @Override
     @SuppressWarnings("unchecked")
     protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
+        if (params.isPreprocessed()) {
+            return null;
+        }
+
         ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
                         .operation(AaiCqResponse.OPERATION).payload(null).retry(null).timeoutSec(null).build();
 
@@ -61,7 +69,19 @@ public class ModifyConfigOperation extends AppcOperation {
 
     @Override
     protected Request makeRequest(int attempt) {
+        return makeRequest(attempt, getVnfId());
+    }
+
+    protected String getVnfId() {
+        GenericVnf vnf = this.getProperty(OperationProperties.AAI_RESOURCE_VNF);
+        if (vnf != null) {
+            return vnf.getVnfId();
+        }
+
         AaiCqResponse cq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY);
+        if (cq == null) {
+            throw new IllegalStateException("target vnf-id could not be determined");
+        }
 
         GenericVnf genvnf = cq.getGenericVnfByModelInvariantId(params.getTarget().getResourceID());
         if (genvnf == null) {
@@ -69,6 +89,6 @@ public class ModifyConfigOperation extends AppcOperation {
             throw new IllegalArgumentException("target vnf-id could not be found");
         }
 
-        return makeRequest(attempt, genvnf.getVnfId());
+        return genvnf.getVnfId();
     }
 }