Moving common polling code into HttpOperation
[policy/models.git] / models-interactions / model-actors / actor.so / src / main / java / org / onap / policy / controlloop / actor / so / SoActorServiceProvider.java
index eef6e7c..642e2b4 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * SOActorServiceProvider
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,13 +28,16 @@ import java.lang.reflect.Type;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import org.drools.core.WorkingMemory;
-import org.onap.policy.aai.AaiNqExtraProperty;
-import org.onap.policy.aai.AaiNqInventoryResponseItem;
-import org.onap.policy.aai.AaiNqResponseWrapper;
+import org.onap.aai.domain.yang.CloudRegion;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.aai.domain.yang.Tenant;
+import org.onap.policy.aai.AaiCqResponse;
 import org.onap.policy.controlloop.ControlLoopOperation;
 import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
+import org.onap.policy.controlloop.actorserviceprovider.impl.HttpActor;
+import org.onap.policy.controlloop.actorserviceprovider.impl.HttpPollingOperator;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingActorParams;
 import org.onap.policy.controlloop.policy.Policy;
 import org.onap.policy.so.SoCloudConfiguration;
 import org.onap.policy.so.SoManager;
@@ -50,11 +53,15 @@ import org.onap.policy.so.util.Serialization;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SoActorServiceProvider implements Actor {
+public class SoActorServiceProvider extends HttpActor<HttpPollingActorParams> {
     private static final Logger logger = LoggerFactory.getLogger(SoActorServiceProvider.class);
 
-    // Strings for SO Actor
-    private static final String SO_ACTOR = "SO";
+    public static final String NAME = "SO";
+
+    // TODO old code: remove lines down to **HERE**
+
+    private static final String TENANT_NOT_FOUND = "Tenant Item not found in AAI response {}";
+    private static final String CONSTRUCTED_SO_MSG = "Constructed SO request: {}";
 
     // Strings for targets
     private static final String TARGET_VFC = "VFC";
@@ -63,10 +70,10 @@ public class SoActorServiceProvider implements Actor {
     private static final String RECIPE_VF_MODULE_CREATE = "VF Module Create";
     private static final String RECIPE_VF_MODULE_DELETE = "VF Module Delete";
 
-    private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_VF_MODULE_CREATE,
-            RECIPE_VF_MODULE_DELETE);
-    private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
-                    .put(RECIPE_VF_MODULE_CREATE, ImmutableList.of(TARGET_VFC))
+    private static final ImmutableList<String> recipes =
+            ImmutableList.of(RECIPE_VF_MODULE_CREATE, RECIPE_VF_MODULE_DELETE);
+    private static final ImmutableMap<String, List<String>> targets =
+            new ImmutableMap.Builder<String, List<String>>().put(RECIPE_VF_MODULE_CREATE, ImmutableList.of(TARGET_VFC))
                     .put(RECIPE_VF_MODULE_DELETE, ImmutableList.of(TARGET_VFC)).build();
 
     // name of request parameters within policy payload
@@ -75,10 +82,6 @@ public class SoActorServiceProvider implements Actor {
     // name of configuration parameters within policy payload
     public static final String CONFIG_PARAM_NM = "configurationParameters";
 
-    private static final String MODEL_NAME_PROPERTY_KEY = "model-ver.model-name";
-    private static final String MODEL_VERSION_PROPERTY_KEY = "model-ver.model-version";
-    private static final String MODEL_VERSION_ID_PROPERTY_KEY = "model-ver.model-version-id";
-
     // used to decode configuration parameters via gson
     private static final Type CONFIG_TYPE = new TypeToken<List<Map<String, String>>>() {}.getType();
 
@@ -89,9 +92,23 @@ public class SoActorServiceProvider implements Actor {
     private static String lastServiceItemServiceInstanceId;
     private static String lastVfModuleItemVfModuleInstanceId;
 
+    // **HERE**
+
+    /**
+     * Constructs the object.
+     */
+    public SoActorServiceProvider() {
+        super(NAME, HttpPollingActorParams.class);
+
+        addOperator(new HttpPollingOperator(NAME, VfModuleCreate.NAME, VfModuleCreate::new));
+        addOperator(new HttpPollingOperator(NAME, VfModuleDelete.NAME, VfModuleDelete::new));
+    }
+
+    // TODO old code: remove lines down to **HERE**
+
     @Override
     public String actor() {
-        return SO_ACTOR;
+        return NAME;
     }
 
     @Override
@@ -109,96 +126,214 @@ public class SoActorServiceProvider implements Actor {
         return Collections.emptyList();
     }
 
+    private SoModelInfo prepareSoModelInfo(Policy policy) {
+
+        if (policy.getTarget() == null || policy.getTarget().getModelCustomizationId() == null
+                        || policy.getTarget().getModelInvariantId() == null) {
+            return null;
+        }
+
+        if (policy.getTarget().getModelName() == null || policy.getTarget().getModelVersion() == null
+                        || policy.getTarget().getModelVersionId() == null) {
+            return null;
+        }
+
+        SoModelInfo soModelInfo = new SoModelInfo();
+        soModelInfo.setModelCustomizationId(policy.getTarget().getModelCustomizationId());
+        soModelInfo.setModelInvariantId(policy.getTarget().getModelInvariantId());
+        soModelInfo.setModelName(policy.getTarget().getModelName());
+        soModelInfo.setModelVersion(policy.getTarget().getModelVersion());
+        soModelInfo.setModelVersionId(policy.getTarget().getModelVersionId());
+        soModelInfo.setModelType("vfModule");
+        return soModelInfo;
+    }
+
     /**
-     * Constructs a SO request conforming to the lcm API. The actual request is
-     * constructed and then placed in a wrapper object used to send through DMAAP.
+     * Construct requestInfo for the SO requestDetails.
+     *
+     * @return SO request information
+     */
+    private SoRequestInfo constructRequestInfo() {
+        SoRequestInfo soRequestInfo = new SoRequestInfo();
+        soRequestInfo.setSource("POLICY");
+        soRequestInfo.setSuppressRollback(false);
+        soRequestInfo.setRequestorId("policy");
+        return soRequestInfo;
+    }
+
+    /**
+     * This method is needed to get the serviceInstanceId and vnfInstanceId which is used in the asyncSORestCall.
+     *
+     * @param requestId the request Id
+     * @param callback callback method
+     * @param request the request
+     * @param url SO REST URL
+     * @param user username
+     * @param password password
+     */
+    public static void sendRequest(String requestId, SoManager.SoCallback callback, Object request, String url,
+            String user, String password) {
+        SoManager soManager = new SoManager(url, user, password);
+        soManager.asyncSoRestCall(requestId, callback, lastServiceItemServiceInstanceId, lastVNFItemVnfId,
+                lastVfModuleItemVfModuleInstanceId, (SoRequest) request);
+    }
+
+
+    /**
+     * Builds the request parameters from the policy payload.
+     *
+     * @param policy the policy
+     * @param request request into which to stick the request parameters
+     */
+    private void buildRequestParameters(Policy policy, SoRequestDetails request) {
+        // assume null until proven otherwise
+        request.setRequestParameters(null);
+
+        if (policy.getPayload() == null) {
+            return;
+        }
+
+        String json = policy.getPayload().get(REQ_PARAM_NM);
+        if (json == null) {
+            return;
+        }
+
+        request.setRequestParameters(Serialization.gsonPretty.fromJson(json, SoRequestParameters.class));
+    }
+
+    /**
+     * Builds the configuration parameters from the policy payload.
+     *
+     * @param policy the policy
+     * @param request request into which to stick the configuration parameters
+     */
+    private void buildConfigurationParameters(Policy policy, SoRequestDetails request) {
+        // assume null until proven otherwise
+        request.setConfigurationParameters(null);
+
+        if (policy.getPayload() == null) {
+            return;
+        }
+
+        String json = policy.getPayload().get(CONFIG_PARAM_NM);
+        if (json == null) {
+            return;
+        }
+
+        request.setConfigurationParameters(Serialization.gsonPretty.fromJson(json, CONFIG_TYPE));
+    }
+
+    /**
+     * This method is called to remember the last service instance ID, VNF Item VNF ID and vf module ID. Note these
+     * fields are static, beware for multithreaded deployments
+     *
+     * @param vnfInstanceId update the last VNF instance ID to this value
+     * @param serviceInstanceId update the last service instance ID to this value
+     * @param vfModuleId update the vfModule instance ID to this value
+     */
+    private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId,
+            final String vfModuleId) {
+        lastVNFItemVnfId = vnfInstanceId;
+        lastServiceItemServiceInstanceId = serviceInstanceId;
+        lastVfModuleItemVfModuleInstanceId = vfModuleId;
+    }
+
+    /**
+     * Constructs a SO request conforming to the lcm API. The actual request is constructed and then placed in a wrapper
+     * object used to send through DMAAP.
      *
      * @param onset the event that is reporting the alert for policy to perform an action
-     * @param operation the control loop operation specifying the actor, operation,
-     *        target, etc.
-     * @param policy the policy the was specified from the yaml generated by CLAMP or
-     *        through the Policy GUI/API
-     * @param aaiResponseWrapper wrapper for AAI vserver named-query response
+     * @param operation the control loop operation specifying the actor, operation, target, etc.
+     * @param policy the policy the was specified from the yaml generated by CLAMP or through the Policy GUI/API
+     * @param aaiCqResponse response from A&AI custom query
      * @return a SO request conforming to the lcm API using the DMAAP wrapper
      */
-    public SoRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy,
-                    AaiNqResponseWrapper aaiResponseWrapper) {
-        if (!SO_ACTOR.equals(policy.getActor()) || !recipes().contains(policy.getRecipe())) {
+    public SoRequest constructRequestCq(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy,
+            AaiCqResponse aaiCqResponse) {
+        if (!NAME.equals(policy.getActor()) || !recipes().contains(policy.getRecipe())) {
             return null;
         }
 
         // A&AI named query should have been performed by now. If not, return null
-        if (aaiResponseWrapper == null) {
+        if (aaiCqResponse == null) {
+            return null;
+        }
+
+        SoModelInfo soModelInfo = prepareSoModelInfo(policy);
+
+        // Report the error vf module is not found
+        if (soModelInfo == null) {
+            logger.error("vf module is not found.");
             return null;
         }
 
-        AaiNqInventoryResponseItem vnfItem;
-        AaiNqInventoryResponseItem vnfServiceItem;
-        AaiNqInventoryResponseItem tenantItem;
+        GenericVnf vnfItem;
+        ServiceInstance vnfServiceItem;
+        Tenant tenantItem;
+        CloudRegion cloudRegionItem;
 
         // Extract the items we're interested in from the response
         try {
-            vnfItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems()
-                            .getInventoryResponseItems().get(0);
+            vnfItem = aaiCqResponse.getGenericVnfByVfModuleModelInvariantId(soModelInfo.getModelInvariantId());
+            //Report VNF not found
+            if (vnfItem == null) {
+                logger.error("Generic Vnf is not found.");
+                return null;
+            }
         } catch (Exception e) {
-            logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper),
-                            e);
+            logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiCqResponse), e);
             return null;
         }
 
         try {
-            vnfServiceItem = vnfItem.getItems().getInventoryResponseItems().get(0);
+            vnfServiceItem = aaiCqResponse.getServiceInstance();
         } catch (Exception e) {
             logger.error("VNF Service Item not found in AAI response {}",
-                            Serialization.gsonPretty.toJson(aaiResponseWrapper), e);
+                    Serialization.gsonPretty.toJson(aaiCqResponse), e);
             return null;
         }
 
         try {
-            tenantItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems()
-                            .getInventoryResponseItems().get(1);
+            tenantItem = aaiCqResponse.getDefaultTenant();
         } catch (Exception e) {
-            logger.error("Tenant Item not found in AAI response {}",
-                            Serialization.gsonPretty.toJson(aaiResponseWrapper), e);
+            logger.error(TENANT_NOT_FOUND, Serialization.gsonPretty.toJson(aaiCqResponse), e);
             return null;
         }
 
-        // Find the index for base vf module and non-base vf module
-        AaiNqInventoryResponseItem baseItem = findVfModule(aaiResponseWrapper, true);
-        AaiNqInventoryResponseItem vfModuleItem = findVfModule(aaiResponseWrapper, false);
-
-        // Report the error if either base vf module or non-base vf module is not found
-        if (baseItem == null || vfModuleItem == null) {
-            logger.error("Either base or non-base vf module is not found from AAI response.");
+        try {
+            cloudRegionItem = aaiCqResponse.getDefaultCloudRegion();
+        } catch (Exception e) {
+            logger.error(TENANT_NOT_FOUND, Serialization.gsonPretty.toJson(aaiCqResponse), e);
             return null;
         }
 
+
+
         // Construct SO Request for a policy's recipe
         if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) {
-            return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem,
-                    vfModuleItem);
+            return constructCreateRequestCq(aaiCqResponse, policy, tenantItem, vnfItem, vnfServiceItem, soModelInfo,
+                    cloudRegionItem);
         } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
-            return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, vfModuleItem);
+            return constructDeleteRequestCq(tenantItem, vnfItem, vnfServiceItem, policy, cloudRegionItem);
         } else {
             return null;
         }
     }
 
     /**
-     * Construct SO request to create vf-module.
+     * Construct the So request, based on Custom Query response from A&AI.
      *
-     * @param aaiResponseWrapper the AAI response containing the VF modules
-     * @param policy             the policy
-     * @param tenantItem         tenant item from A&AI named-query response
-     * @param vnfItem            vnf item from A&AI named-query response
-     * @param vnfServiceItem     vnf service item from A&AI named-query response
-     * @param vfModuleItem       vf module item from A&AI named-query response
-     * @return SO create vf-module request
+     * @param aaiCqResponse Custom query response from A&AI
+     * @param policy policy information
+     * @param tenantItem Tenant from CQ response
+     * @param vnfItem Generic VNF from CQ response
+     * @param vnfServiceItem Service Instance from CQ response
+     * @param vfModuleItem VF Module from CustomQuery response
+     * @param cloudRegionItem Cloud Region from Custom query response
+     * @return SoRequest well formed So Request
      */
-    private SoRequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy,
-                                             AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem,
-                                             AaiNqInventoryResponseItem vnfServiceItem,
-                                             AaiNqInventoryResponseItem vfModuleItem) {
+    private SoRequest constructCreateRequestCq(AaiCqResponse aaiCqResponse, Policy policy, Tenant tenantItem,
+            GenericVnf vnfItem, ServiceInstance vnfServiceItem, SoModelInfo vfModuleItem, CloudRegion cloudRegionItem) {
         SoRequest request = new SoRequest();
         request.setOperationType(SoOperationType.SCALE_OUT);
         //
@@ -210,15 +345,14 @@ public class SoActorServiceProvider implements Actor {
         request.getRequestDetails().getRequestParameters().setUserParams(null);
 
         // cloudConfiguration
-        request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem));
+        request.getRequestDetails().setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem));
         // modelInfo
-        request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem));
-        request.getRequestDetails().getModelInfo().setModelVersionId(vfModuleItem.getVfModule().getModelVersionId());
+        request.getRequestDetails().setModelInfo(vfModuleItem);
+
 
         // requestInfo
         request.getRequestDetails().setRequestInfo(constructRequestInfo());
-        String vfModuleName = aaiResponseWrapper.genVfModuleName();
-        request.getRequestDetails().getRequestInfo().setInstanceName(vfModuleName);
+        request.getRequestDetails().getRequestInfo().setInstanceName("vfModuleName");
 
         // relatedInstanceList
         SoRelatedInstanceListElement relatedInstanceListElement1 = new SoRelatedInstanceListElement();
@@ -227,46 +361,36 @@ public class SoActorServiceProvider implements Actor {
         relatedInstanceListElement2.setRelatedInstance(new SoRelatedInstance());
 
         // Service Item
-        relatedInstanceListElement1.getRelatedInstance()
-                .setInstanceId(vnfServiceItem.getServiceInstance().getServiceInstanceId());
+        relatedInstanceListElement1.getRelatedInstance().setInstanceId(vnfServiceItem.getServiceInstanceId());
         relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SoModelInfo());
         relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service");
         relatedInstanceListElement1.getRelatedInstance().getModelInfo()
-                .setModelInvariantId(vnfServiceItem.getServiceInstance().getModelInvariantId());
-        for (AaiNqExtraProperty prop : vnfServiceItem.getExtraProperties().getExtraProperty()) {
-            if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
-                relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue());
-            } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
-                relatedInstanceListElement1.getRelatedInstance().getModelInfo()
-                        .setModelVersion(prop.getPropertyValue());
-            } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) {
-                relatedInstanceListElement1.getRelatedInstance().getModelInfo()
-                        .setModelVersionId(prop.getPropertyValue());
-            }
-        }
+                .setModelInvariantId(vnfServiceItem.getModelInvariantId());
+        relatedInstanceListElement1.getRelatedInstance().getModelInfo()
+                .setModelVersionId(vnfServiceItem.getModelVersionId());
+        relatedInstanceListElement1.getRelatedInstance().getModelInfo()
+                .setModelName(aaiCqResponse.getModelVerByVersionId(vnfServiceItem.getModelVersionId()).getModelName());
+        relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelVersion(
+                aaiCqResponse.getModelVerByVersionId(vnfServiceItem.getModelVersionId()).getModelVersion());
+
 
         // VNF Item
-        relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getGenericVnf().getVnfId());
+        relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getVnfId());
         relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SoModelInfo());
         relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf");
         relatedInstanceListElement2.getRelatedInstance().getModelInfo()
-                .setModelInvariantId(vnfItem.getGenericVnf().getModelInvariantId());
-        for (AaiNqExtraProperty prop : vnfItem.getExtraProperties().getExtraProperty()) {
-            if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
-                relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue());
-            } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
-                relatedInstanceListElement2.getRelatedInstance().getModelInfo()
-                        .setModelVersion(prop.getPropertyValue());
-            } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) {
-                relatedInstanceListElement2.getRelatedInstance().getModelInfo()
-                        .setModelVersionId(prop.getPropertyValue());
-            }
-        }
+                .setModelInvariantId(vnfItem.getModelInvariantId());
+        relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersionId(vnfItem.getModelVersionId());
+
         relatedInstanceListElement2.getRelatedInstance().getModelInfo()
-                .setModelCustomizationName(vnfItem.getGenericVnf().getVnfType()
-                        .substring(vnfItem.getGenericVnf().getVnfType().lastIndexOf('/') + 1));
+                .setModelName(aaiCqResponse.getModelVerByVersionId(vnfItem.getModelVersionId()).getModelName());
+        relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersion(
+                aaiCqResponse.getModelVerByVersionId(vnfItem.getModelVersionId()).getModelVersion());
+
+
         relatedInstanceListElement2.getRelatedInstance().getModelInfo()
-                .setModelCustomizationId(vnfItem.getGenericVnf().getModelCustomizationId());
+                .setModelCustomizationId(vnfItem.getModelCustomizationId());
+
 
         // Insert the Service Item and VNF Item
         request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1);
@@ -279,25 +403,25 @@ public class SoActorServiceProvider implements Actor {
         buildConfigurationParameters(policy, request.getRequestDetails());
         // Save the instance IDs for the VNF and service to static fields
         // vfModuleId is not required for the create vf-module
-        preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance()
-                .getServiceInstanceId(), null);
+        preserveInstanceIds(vnfItem.getVnfId(), vnfServiceItem.getServiceInstanceId(), null);
         if (logger.isDebugEnabled()) {
-            logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
+            logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request));
         }
         return request;
     }
 
     /**
-     * Construct SO request to delete vf-module.
+     * constructs delete request for So.
      *
-     * @param tenantItem         tenant item from A&AI named-query response
-     * @param vnfItem            vnf item from A&AI named-query response
-     * @param vnfServiceItem     vnf service item from A&AI named-query response
-     * @param vfModuleItem       vf module item from A&AI named-query response
-     * @return SO delete vf-module request
+     * @param tenantItem Tenant from A&AI CQ request
+     * @param vnfItem Generic VNF from A&AI CQ request
+     * @param vnfServiceItem ServiceInstance from A&AI CQ request
+     * @param policy policy information
+     * @param cloudRegionItem CloudRegion from A&AI CQ request
+     * @return SoRequest deleted
      */
-    private SoRequest constructDeleteRequest(AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem
-            vnfItem, AaiNqInventoryResponseItem vnfServiceItem, AaiNqInventoryResponseItem vfModuleItem) {
+    private SoRequest constructDeleteRequestCq(Tenant tenantItem, GenericVnf vnfItem, ServiceInstance vnfServiceItem,
+            Policy policy, CloudRegion cloudRegionItem) {
         SoRequest request = new SoRequest();
         request.setOperationType(SoOperationType.DELETE_VF_MODULE);
         request.setRequestDetails(new SoRequestDetails());
@@ -305,154 +429,34 @@ public class SoActorServiceProvider implements Actor {
         request.getRequestDetails().setConfigurationParameters(null);
 
         // cloudConfiguration
-        request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem));
+        request.getRequestDetails().setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem));
         // modelInfo
-        request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem));
+        request.getRequestDetails().setModelInfo(prepareSoModelInfo(policy));
         // requestInfo
         request.getRequestDetails().setRequestInfo(constructRequestInfo());
         // Save the instance IDs for the VNF, service and vfModule to static fields
-        preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance()
-                .getServiceInstanceId(), vfModuleItem.getVfModule().getVfModuleId());
+        preserveInstanceIds(vnfItem.getVnfId(), vnfServiceItem.getServiceInstanceId(), null);
 
         if (logger.isDebugEnabled()) {
-            logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
+            logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request));
         }
         return request;
     }
 
-    /**
-     * Construct requestInfo for the SO requestDetails.
-     *
-     * @return SO request information
-     */
-    private SoRequestInfo constructRequestInfo() {
-        SoRequestInfo soRequestInfo = new SoRequestInfo();
-        soRequestInfo.setSource("POLICY");
-        soRequestInfo.setSuppressRollback(false);
-        soRequestInfo.setRequestorId("policy");
-        return soRequestInfo;
-    }
-
-    /**
-     * Construct modelInfo of the vfModule for the SO requestDetails.
-     *
-     * @param vfModuleItem vf module item from A&AI named-query response
-     * @return SO Model info for the vfModule
-     */
-    private SoModelInfo constructVfModuleModelInfo(AaiNqInventoryResponseItem vfModuleItem) {
-        SoModelInfo soModelInfo = new SoModelInfo();
-        soModelInfo.setModelType("vfModule");
-        soModelInfo.setModelInvariantId(vfModuleItem.getVfModule().getModelInvariantId());
-        soModelInfo.setModelCustomizationId(vfModuleItem.getVfModule().getModelCustomizationId());
-
-        for (AaiNqExtraProperty prop : vfModuleItem.getExtraProperties().getExtraProperty()) {
-            if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
-                soModelInfo.setModelName(prop.getPropertyValue());
-            } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
-                soModelInfo.setModelVersion(prop.getPropertyValue());
-            }
-        }
-        return soModelInfo;
-    }
 
     /**
-     * Construct cloudConfiguration for the SO requestDetails.
+     * Construct cloudConfiguration for the SO requestDetails. Overridden for custom query.
      *
      * @param tenantItem tenant item from A&AI named-query response
      * @return SO cloud configuration
      */
-    private SoCloudConfiguration constructCloudConfiguration(AaiNqInventoryResponseItem tenantItem) {
+    private SoCloudConfiguration constructCloudConfigurationCq(Tenant tenantItem, CloudRegion cloudRegionItem) {
         SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration();
-        cloudConfiguration.setTenantId(tenantItem.getTenant().getTenantId());
-        cloudConfiguration.setLcpCloudRegionId(tenantItem.getItems().getInventoryResponseItems().get(0)
-                .getCloudRegion().getCloudRegionId());
+        cloudConfiguration.setTenantId(tenantItem.getTenantId());
+        cloudConfiguration.setLcpCloudRegionId(cloudRegionItem.getCloudRegionId());
         return cloudConfiguration;
     }
 
-    /**
-     * This method is needed to get the serviceInstanceId and vnfInstanceId which is used
-     * in the asyncSORestCall.
-     *
-     * @param requestId the request Id
-     * @param wm the working memory
-     * @param request the request
-     */
-    public static void sendRequest(String requestId, WorkingMemory wm, Object request) {
-        SoManager soManager = new SoManager();
-        soManager.asyncSoRestCall(requestId, wm, lastServiceItemServiceInstanceId, lastVNFItemVnfId,
-                lastVfModuleItemVfModuleInstanceId, (SoRequest) request);
-    }
-
-    /**
-     * Find the base or non base VF module item in an AAI response.
-     * If there is more than one item, then the <i>last</i> item is returned
-     *
-     * @param aaiResponseWrapper the AAI response containing the VF modules
-     * @param baseFlag true if we are searching for the base, false if we are searching
-     *        for the non base
-     * @return the base or non base VF module item or null if the module was not found
-     */
-    private AaiNqInventoryResponseItem findVfModule(AaiNqResponseWrapper aaiResponseWrapper, boolean baseFlag) {
-        List<AaiNqInventoryResponseItem> lst = aaiResponseWrapper.getVfModuleItems(baseFlag);
-        return (lst.isEmpty() ? null : lst.get(lst.size() - 1));
-    }
-
-    /**
-     * Builds the request parameters from the policy payload.
-     *
-     * @param policy the policy
-     * @param request request into which to stick the request parameters
-     */
-    private void buildRequestParameters(Policy policy, SoRequestDetails request) {
-        // assume null until proven otherwise
-        request.setRequestParameters(null);
-        
-        if (policy.getPayload() == null) {
-            return;
-        }
-
-        String json = policy.getPayload().get(REQ_PARAM_NM);
-        if (json == null) {
-            return;
-        }
-
-        request.setRequestParameters(Serialization.gsonPretty.fromJson(json, SoRequestParameters.class));
-    }
-
-    /**
-     * Builds the configuration parameters from the policy payload.
-     *
-     * @param policy the policy
-     * @param request request into which to stick the configuration parameters
-     */
-    private void buildConfigurationParameters(Policy policy, SoRequestDetails request) {
-        // assume null until proven otherwise
-        request.setConfigurationParameters(null);
-        
-        if (policy.getPayload() == null) {
-            return;
-        }
-
-        String json = policy.getPayload().get(CONFIG_PARAM_NM);
-        if (json == null) {
-            return;
-        }
-
-        request.setConfigurationParameters(Serialization.gsonPretty.fromJson(json, CONFIG_TYPE));
-    }
+    // **HERE**
 
-    /**
-     * This method is called to remember the last service instance ID, VNF Item VNF ID and vf module ID.
-     * Note these fields are static, beware for multithreaded deployments
-     *
-     * @param vnfInstanceId update the last VNF instance ID to this value
-     * @param serviceInstanceId update the last service instance ID to this value
-     * @param vfModuleId update the vfModule instance ID to this value
-     */
-    private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId,
-                                            final String vfModuleId) {
-        lastVNFItemVnfId = vnfInstanceId;
-        lastServiceItemServiceInstanceId = serviceInstanceId;
-        lastVfModuleItemVfModuleInstanceId = vfModuleId;
-    }
 }