Skip preprocessor step in Actors
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / VfModuleCreate.java
index 6a6c792..4bae1e8 100644 (file)
 
 package org.onap.policy.controlloop.actor.so;
 
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 import org.apache.commons.lang3.tuple.Pair;
 import org.onap.aai.domain.yang.CloudRegion;
 import org.onap.aai.domain.yang.GenericVnf;
@@ -34,8 +36,9 @@ import org.onap.policy.aai.AaiCqResponse;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
 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.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
 import org.onap.policy.so.SoModelInfo;
 import org.onap.policy.so.SoOperationType;
 import org.onap.policy.so.SoRelatedInstance;
@@ -43,6 +46,7 @@ import org.onap.policy.so.SoRelatedInstanceListElement;
 import org.onap.policy.so.SoRequest;
 import org.onap.policy.so.SoRequestDetails;
 import org.onap.policy.so.SoRequestParameters;
+import org.onap.policy.so.SoResponse;
 
 /**
  * Operation to create a VF Module. This gets the VF count from the A&AI Custom Query
@@ -55,14 +59,23 @@ public class VfModuleCreate extends SoOperation {
 
     private static final String PATH_PREFIX = "/";
 
+    // @formatter:off
+    private static final List<String> PROPERTY_NAMES = List.of(
+                            OperationProperties.AAI_MODEL_SERVICE,
+                            OperationProperties.AAI_MODEL_VNF,
+                            OperationProperties.AAI_MODEL_CLOUD_REGION,
+                            OperationProperties.AAI_MODEL_TENANT,
+                            OperationProperties.DATA_VF_COUNT);
+    // @formatter:off
+
     /**
      * Constructs the object.
      *
      * @param params operation parameters
      * @param config configuration for this operation
      */
-    public VfModuleCreate(ControlLoopOperationParams params, HttpConfig config) {
-        super(params, config);
+    public VfModuleCreate(ControlLoopOperationParams params, HttpPollingConfig config) {
+        super(params, config, PROPERTY_NAMES);
 
         // ensure we have the necessary parameters
         validateTarget();
@@ -74,6 +87,9 @@ public class VfModuleCreate extends SoOperation {
     @Override
     @SuppressWarnings("unchecked")
     protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
+        if (params.isPreprocessed()) {
+            return null;
+        }
 
         // need the VF count
         ControlLoopOperationParams cqParams = params.toBuilder().actor(AaiConstants.ACTOR_NAME)
@@ -101,7 +117,7 @@ public class VfModuleCreate extends SoOperation {
     protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
 
         // starting a whole new attempt - reset the count
-        resetGetCount();
+        resetPollCount();
 
         Pair<String, SoRequest> pair = makeRequest();
         String path = getPath() + pair.getLeft();
@@ -120,11 +136,18 @@ public class VfModuleCreate extends SoOperation {
     }
 
     /**
-     * Increments the VF count that's stored in the context.
+     * Increments the VF count that's stored in the context, if the request was
+     * successful.
      */
     @Override
-    protected void successfulCompletion() {
-        setVfCount(getVfCount() + 1);
+    protected Status detmStatus(Response rawResponse, SoResponse response) {
+        Status status = super.detmStatus(rawResponse, response);
+
+        if (status == Status.SUCCESS) {
+            setVfCount(getVfCount() + 1);
+        }
+
+        return status;
     }
 
     /**