Add SO VF Module Delete Operation
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / SoOperation.java
index 41ecd07..1ca6c73 100644 (file)
 package org.onap.policy.controlloop.actor.so;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import lombok.Getter;
 import org.onap.aai.domain.yang.CloudRegion;
@@ -46,6 +48,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.so.SoCloudConfiguration;
 import org.onap.policy.so.SoModelInfo;
 import org.onap.policy.so.SoRequest;
 import org.onap.policy.so.SoRequestInfo;
@@ -63,6 +66,7 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
     private static final Logger logger = LoggerFactory.getLogger(SoOperation.class);
     private static final Coder coder = new StandardCoder();
 
+    public static final String PAYLOAD_KEY_VF_COUNT = "vfCount";
     public static final String FAILED = "FAILED";
     public static final String COMPLETE = "COMPLETE";
     public static final int SO_RESPONSE_CODE = 999;
@@ -208,7 +212,8 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
         // still incomplete
 
         // need a request ID with which to query
-        if (response.getRequestReferences() == null || response.getRequestReferences().getRequestId() == null) {
+        if (response == null || response.getRequestReferences() == null
+                        || response.getRequestReferences().getRequestId() == null) {
             throw new IllegalArgumentException("missing request ID in response");
         }
 
@@ -371,6 +376,31 @@ public abstract class SoOperation extends HttpOperation<SoResponse> {
         }
     }
 
+    /**
+     * Construct cloudConfiguration for the SO requestDetails. Overridden for custom
+     * query.
+     *
+     * @param tenantItem tenant item from A&AI named-query response
+     * @return SO cloud configuration
+     */
+    protected SoCloudConfiguration constructCloudConfigurationCq(Tenant tenantItem, CloudRegion cloudRegionItem) {
+        SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration();
+        cloudConfiguration.setTenantId(tenantItem.getTenantId());
+        cloudConfiguration.setLcpCloudRegionId(cloudRegionItem.getCloudRegionId());
+        return cloudConfiguration;
+    }
+
+    /**
+     * Create simple HTTP headers for unauthenticated requests to SO.
+     *
+     * @return the HTTP headers
+     */
+    protected Map<String, Object> createSimpleHeaders() {
+        Map<String, Object> headers = new HashMap<>();
+        headers.put("Accept", MediaType.APPLICATION_JSON);
+        return headers;
+    }
+
     /*
      * These methods extract data from the Custom Query and throw an
      * IllegalArgumentException if the desired data item is not found.