summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-07-13 16:06:57 -0400
committerJim Hahn <jrh3@att.com>2020-07-13 16:07:54 -0400
commitc88676ec64c4c870252502bc1cfaa8990c8fd964 (patch)
treed88ec0ac29d5c3066fab025392df4a69256cf288 /models-interactions/model-actors/actor.so
parente4e7d15db6d2f79658e3a5f9e8326ea092afcfab (diff)
Remove legacy actor code from models
Deleted legacy actor code. That includes deleting most of the XxxManager classes. Issue-ID: POLICY-2559 Change-Id: I1ef1b900ca1d23e88da64b2c95a18986feb1b765 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.so')
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java422
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java201
2 files changed, 0 insertions, 623 deletions
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java
index 2b2fddec5..a6619710e 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActor.java
@@ -21,79 +21,13 @@
package org.onap.policy.controlloop.actor.so;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.gson.reflect.TypeToken;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-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.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;
-import org.onap.policy.so.SoModelInfo;
-import org.onap.policy.so.SoOperationType;
-import org.onap.policy.so.SoRelatedInstance;
-import org.onap.policy.so.SoRelatedInstanceListElement;
-import org.onap.policy.so.SoRequest;
-import org.onap.policy.so.SoRequestDetails;
-import org.onap.policy.so.SoRequestInfo;
-import org.onap.policy.so.SoRequestParameters;
-import org.onap.policy.so.util.Serialization;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class SoActor extends HttpActor<HttpPollingActorParams> {
- private static final Logger logger = LoggerFactory.getLogger(SoActor.class);
-
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";
-
- // Strings for recipes
- 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))
- .put(RECIPE_VF_MODULE_DELETE, ImmutableList.of(TARGET_VFC)).build();
-
- // name of request parameters within policy payload
- public static final String REQ_PARAM_NM = "requestParameters";
-
- // name of configuration parameters within policy payload
- public static final String CONFIG_PARAM_NM = "configurationParameters";
-
- // used to decode configuration parameters via gson
- private static final Type CONFIG_TYPE = new TypeToken<List<Map<String, String>>>() {}.getType();
-
- // Static variables required to hold the IDs of the last service item, VNF item and VF Module.
- // Note that in
- // a multithreaded deployment this WILL break
- private static String lastVNFItemVnfId;
- private static String lastServiceItemServiceInstanceId;
- private static String lastVfModuleItemVfModuleInstanceId;
-
- // **HERE**
-
/**
* Constructs the object.
*/
@@ -103,360 +37,4 @@ public class SoActor extends HttpActor<HttpPollingActorParams> {
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 NAME;
- }
-
- @Override
- public List<String> recipes() {
- return ImmutableList.copyOf(recipes);
- }
-
- @Override
- public List<String> recipeTargets(String recipe) {
- return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
- }
-
- @Override
- public List<String> recipePayloads(String recipe) {
- 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;
- }
-
- /**
- * 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 aaiCqResponse response from A&AI custom query
- * @return a SO request conforming to the lcm API using the DMAAP wrapper
- */
- 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 (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;
- }
-
- GenericVnf vnfItem;
- ServiceInstance vnfServiceItem;
- Tenant tenantItem;
- CloudRegion cloudRegionItem;
-
- // Extract the items we're interested in from the response
- try {
- 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(aaiCqResponse), e);
- return null;
- }
-
- try {
- vnfServiceItem = aaiCqResponse.getServiceInstance();
- } catch (Exception e) {
- logger.error("VNF Service Item not found in AAI response {}",
- Serialization.gsonPretty.toJson(aaiCqResponse), e);
- return null;
- }
-
- try {
- tenantItem = aaiCqResponse.getDefaultTenant();
- } catch (Exception e) {
- logger.error(TENANT_NOT_FOUND, Serialization.gsonPretty.toJson(aaiCqResponse), e);
- return null;
- }
-
- 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 constructCreateRequestCq(aaiCqResponse, policy, tenantItem, vnfItem, vnfServiceItem, soModelInfo,
- cloudRegionItem);
- } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
- return constructDeleteRequestCq(tenantItem, vnfItem, vnfServiceItem, policy, cloudRegionItem);
- } else {
- return null;
- }
- }
-
- /**
- * Construct the So request, based on Custom Query response from A&AI.
- *
- * @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 constructCreateRequestCq(AaiCqResponse aaiCqResponse, Policy policy, Tenant tenantItem,
- GenericVnf vnfItem, ServiceInstance vnfServiceItem, SoModelInfo vfModuleItem, CloudRegion cloudRegionItem) {
- SoRequest request = new SoRequest();
- request.setOperationType(SoOperationType.SCALE_OUT);
- //
- //
- // Do NOT send So the requestId, they do not support this field
- //
- request.setRequestDetails(new SoRequestDetails());
- request.getRequestDetails().setRequestParameters(new SoRequestParameters());
- request.getRequestDetails().getRequestParameters().setUserParams(null);
-
- // cloudConfiguration
- request.getRequestDetails().setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem));
- // modelInfo
- request.getRequestDetails().setModelInfo(vfModuleItem);
-
-
- // requestInfo
- request.getRequestDetails().setRequestInfo(constructRequestInfo());
- request.getRequestDetails().getRequestInfo().setInstanceName("vfModuleName");
-
- // relatedInstanceList
- SoRelatedInstanceListElement relatedInstanceListElement1 = new SoRelatedInstanceListElement();
- SoRelatedInstanceListElement relatedInstanceListElement2 = new SoRelatedInstanceListElement();
- relatedInstanceListElement1.setRelatedInstance(new SoRelatedInstance());
- relatedInstanceListElement2.setRelatedInstance(new SoRelatedInstance());
-
- // Service Item
- relatedInstanceListElement1.getRelatedInstance().setInstanceId(vnfServiceItem.getServiceInstanceId());
- relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SoModelInfo());
- relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service");
- relatedInstanceListElement1.getRelatedInstance().getModelInfo()
- .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.getVnfId());
- relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SoModelInfo());
- relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf");
- relatedInstanceListElement2.getRelatedInstance().getModelInfo()
- .setModelInvariantId(vnfItem.getModelInvariantId());
- relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersionId(vnfItem.getModelVersionId());
-
- relatedInstanceListElement2.getRelatedInstance().getModelInfo()
- .setModelName(aaiCqResponse.getModelVerByVersionId(vnfItem.getModelVersionId()).getModelName());
- relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelVersion(
- aaiCqResponse.getModelVerByVersionId(vnfItem.getModelVersionId()).getModelVersion());
-
-
- relatedInstanceListElement2.getRelatedInstance().getModelInfo()
- .setModelCustomizationId(vnfItem.getModelCustomizationId());
-
-
- // Insert the Service Item and VNF Item
- request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1);
- request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2);
-
- // Request Parameters
- buildRequestParameters(policy, request.getRequestDetails());
-
- // Configuration Parameters
- 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.getVnfId(), vnfServiceItem.getServiceInstanceId(), null);
- if (logger.isDebugEnabled()) {
- logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request));
- }
- return request;
- }
-
- /**
- * constructs delete request for So.
- *
- * @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 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());
- request.getRequestDetails().setRelatedInstanceList(null);
- request.getRequestDetails().setConfigurationParameters(null);
-
- // cloudConfiguration
- request.getRequestDetails().setCloudConfiguration(constructCloudConfigurationCq(tenantItem, cloudRegionItem));
- // modelInfo
- 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.getVnfId(), vnfServiceItem.getServiceInstanceId(), null);
-
- if (logger.isDebugEnabled()) {
- logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request));
- }
- return request;
- }
-
-
- /**
- * 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 constructCloudConfigurationCq(Tenant tenantItem, CloudRegion cloudRegionItem) {
- SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration();
- cloudConfiguration.setTenantId(tenantItem.getTenantId());
- cloudConfiguration.setLcpCloudRegionId(cloudRegionItem.getCloudRegionId());
- return cloudConfiguration;
- }
-
- // **HERE**
-
}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java
index 783380855..b42b3f8dd 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorTest.java
@@ -22,52 +22,15 @@
package org.onap.policy.controlloop.actor.so;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.UUID;
import java.util.stream.Collectors;
-import org.apache.commons.io.IOUtils;
import org.junit.Test;
-import org.onap.policy.aai.AaiCqResponse;
-import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actor.test.BasicActor;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.so.SoOperationType;
-import org.onap.policy.so.SoRequest;
-import org.onap.policy.so.SoRequestParameters;
-import org.onap.policy.so.util.Serialization;
public class SoActorTest extends BasicActor {
- private static final String C_VALUE = "cvalue";
- private static final String A_VALUE = "avalue";
- private static final String VF_MODULE_CREATE = "VF Module Create";
- private static final String VF_MODULE_DELETE = "VF Module Delete";
-
- private void instantiateTargetCq(Policy policy) {
-
- Target target = new Target();
- target.setModelCustomizationId("47958575-138f-452a-8c8d-d89b595f8164");
- target.setModelInvariantId("e6130d03-56f1-4b0a-9a1d-e1b2ebc30e0e");
- target.setModelName("VfwclVfwsnkBbefb8ce2bde..base_vfw..module-0");
- target.setModelVersion("1");
- target.setModelVersionId("94b18b1d-cc91-4f43-911a-e6348665f292");
-
- policy.setTarget(target);
- }
-
@Test
public void testConstructor() {
SoActor prov = new SoActor();
@@ -85,168 +48,4 @@ public class SoActorTest extends BasicActor {
// verify that it all plugs into the ActorService
verifyActorService(SoActor.NAME, "service.yaml");
}
-
- @Test
- public void testSendRequest() {
- assertThatCode(() -> SoActor.sendRequest(UUID.randomUUID().toString(), null, null, null, null,
- null)).doesNotThrowAnyException();
- }
-
- @Test
- public void testMethods() {
- SoActor sp = new SoActor();
-
- assertEquals("SO", sp.actor());
- assertEquals(2, sp.recipes().size());
- assertEquals(VF_MODULE_CREATE, sp.recipes().get(0));
- assertEquals(VF_MODULE_DELETE, sp.recipes().get(1));
- assertEquals(0, sp.recipePayloads(VF_MODULE_CREATE).size());
- assertEquals(0, sp.recipeTargets("unknown recipe").size());
- assertEquals(1, sp.recipeTargets(VF_MODULE_CREATE).size());
- }
-
- @Test
- public void testConstructRequestCq() throws Exception {
- VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
- final ControlLoopOperation operation = new ControlLoopOperation();
- final AaiCqResponse aaiCqResp = loadAaiResponseCq("aai/AaiCqResponseFull.json");
- final AaiCqResponse aaiCqRespMissing = loadAaiResponseCq("aai/AaiCqResponseMissing.json");
- final UUID requestId = UUID.randomUUID();
- onset.setRequestId(requestId);
-
- Policy policy = new Policy();
- policy.setActor("Dorothy");
- policy.setRecipe("GoToOz");
-
- instantiateTargetCq(policy);
-
- assertNull(new SoActor().constructRequestCq(onset, operation, policy, aaiCqResp));
-
- policy.setActor("SO");
-
- assertNull(new SoActor().constructRequestCq(onset, operation, policy, aaiCqRespMissing));
-
- policy.setRecipe(VF_MODULE_CREATE);
-
- // empty policy payload
- SoRequest request = new SoActor().constructRequestCq(onset, operation, policy, aaiCqResp);
- assertNotNull(request);
-
- assertEquals("vfModuleName", request.getRequestDetails().getRequestInfo().getInstanceName());
- assertEquals("policy", request.getRequestDetails().getRequestInfo().getRequestorId());
- assertEquals("RegionOne", request.getRequestDetails().getCloudConfiguration().getLcpCloudRegionId());
-
- // non-empty policy payload
- policy.setPayload(makePayload());
- request = new SoActor().constructRequestCq(onset, operation, policy, aaiCqResp);
- assertNotNull(request);
- assertEquals(true, request.getRequestDetails().getRequestParameters().isUsePreload());
- assertEquals(A_VALUE, request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey"));
- assertEquals(1, request.getRequestDetails().getConfigurationParameters().size());
- assertEquals(C_VALUE, request.getRequestDetails().getConfigurationParameters().get(0).get("ckey"));
-
- // payload with config, but no request params
- policy.setPayload(makePayload());
- policy.getPayload().remove(SoActor.REQ_PARAM_NM);
- request = new SoActor().constructRequestCq(onset, operation, policy, aaiCqResp);
- assertNotNull(request);
- assertNull(request.getRequestDetails().getRequestParameters());
- assertNotNull(request.getRequestDetails().getConfigurationParameters());
-
- // payload with request, but no config params
- policy.setPayload(makePayload());
- policy.getPayload().remove(SoActor.CONFIG_PARAM_NM);
- request = new SoActor().constructRequestCq(onset, operation, policy, aaiCqResp);
- assertNotNull(request);
- assertNotNull(request.getRequestDetails().getRequestParameters());
- assertNull(request.getRequestDetails().getConfigurationParameters());
-
- // null response
- assertNull(new SoActor().constructRequestCq(onset, operation, policy, null));
-
- instantiateTargetCq(policy);
- policy.setRecipe(VF_MODULE_DELETE);
- SoRequest deleteRequest = new SoActor().constructRequestCq(onset, operation, policy, aaiCqResp);
- assertNotNull(deleteRequest);
- assertEquals(SoOperationType.DELETE_VF_MODULE, deleteRequest.getOperationType());
-
- /*
- * NOTE: The remaining tests must be done in order
- */
-
- policy.setRecipe(VF_MODULE_CREATE);
-
- // null tenant
- assertNull(new SoActor().constructRequestCq(onset, operation, policy, aaiCqRespMissing));
-
- // null service item
- assertNull(new SoActor().constructRequestCq(onset, operation, policy, aaiCqRespMissing));
-
- assertNull(new SoActor().constructRequestCq(onset, operation, policy, null));
- }
-
- /**
- * Reads an AAI vserver named-query response from a file.
- *
- * @param fileName name of the file containing the JSON response
- * @return output from the AAI vserver named-query
- * @throws IOException if the file cannot be read
- */
- private AaiCqResponse loadAaiResponseCq(String fileName) throws IOException {
- String resp = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8);
- return new AaiCqResponse(resp);
- }
-
-
-
- /**
- * Creates a policy payload containing request & configuration parameters.
- *
- * @return the payload
- */
- private Map<String, String> makePayload() {
- Map<String, String> payload = new TreeMap<>();
-
- payload.put(SoActor.REQ_PARAM_NM, makeReqParams());
- payload.put(SoActor.CONFIG_PARAM_NM, makeConfigParams());
-
- return payload;
- }
-
- /**
- * Creates request parameters.
- *
- * @return request parameters, encoded as JSON
- */
- private String makeReqParams() {
- SoRequestParameters params = new SoRequestParameters();
-
- params.setUsePreload(true);
-
- Map<String, String> map = new TreeMap<>();
- map.put("akey", A_VALUE);
-
- List<Map<String, String>> lst = new LinkedList<>();
- lst.add(map);
-
- params.setUserParams(lst);
-
- return Serialization.gsonPretty.toJson(params);
- }
-
- /**
- * Creates configuration parameters.
- *
- * @return configuration parameters, encoded as JSON
- */
- private String makeConfigParams() {
- Map<String, String> map = new TreeMap<>();
- map.put("ckey", C_VALUE);
-
- List<Map<String, String>> lst = new LinkedList<>();
- lst.add(map);
-
- return Serialization.gsonPretty.toJson(lst);
- }
-
}