diff options
Diffstat (limited to 'models-interactions/model-actors/actor.so/src')
2 files changed, 0 insertions, 362 deletions
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java index 842d0f6a5..b85307547 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java @@ -33,9 +33,6 @@ 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.aai.AaiNqExtraProperty; -import org.onap.policy.aai.AaiNqInventoryResponseItem; -import org.onap.policy.aai.AaiNqResponseWrapper; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; @@ -82,10 +79,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(); @@ -116,79 +109,6 @@ public class SoActorServiceProvider implements Actor { return Collections.emptyList(); } - /** - * 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 - * @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())) { - return null; - } - - // A&AI named query should have been performed by now. If not, return null - if (aaiResponseWrapper == null) { - return null; - } - - AaiNqInventoryResponseItem vnfItem; - AaiNqInventoryResponseItem vnfServiceItem; - AaiNqInventoryResponseItem tenantItem; - - // Extract the items we're interested in from the response - try { - vnfItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems() - .getInventoryResponseItems().get(0); - } catch (Exception e) { - logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper), - e); - return null; - } - - try { - vnfServiceItem = vnfItem.getItems().getInventoryResponseItems().get(0); - } catch (Exception e) { - logger.error("VNF Service Item not found in AAI response {}", - Serialization.gsonPretty.toJson(aaiResponseWrapper), e); - return null; - } - - try { - tenantItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems() - .getInventoryResponseItems().get(1); - } catch (Exception e) { - logger.error(TENANT_NOT_FOUND, - Serialization.gsonPretty.toJson(aaiResponseWrapper), e); - return null; - } - - // Find the index for base vf module and non-base vf module - AaiNqInventoryResponseItem baseItem = findVfModule(aaiResponseWrapper, true); - - SoModelInfo soModelInfo = prepareSoModelInfo(policy); - - // Report the error if either base vf module or non-base vf module is not found - if (baseItem == null || soModelInfo == null) { - logger.error("Either base or non-base vf module is not found from AAI response."); - 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, soModelInfo); - } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) { - return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, policy); - } else { - return null; - } - } - private SoModelInfo prepareSoModelInfo(Policy policy) { if (policy.getTarget() == null || policy.getTarget().getModelCustomizationId() == null @@ -212,139 +132,6 @@ public class SoActorServiceProvider implements Actor { } /** - * Construct SO request to create vf-module. - * - * @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 - */ - private SoRequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy, - AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem, - AaiNqInventoryResponseItem vnfServiceItem, SoModelInfo vfModuleItem) { - 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(constructCloudConfiguration(tenantItem)); - // modelInfo - request.getRequestDetails().setModelInfo(vfModuleItem); - - // requestInfo - request.getRequestDetails().setRequestInfo(constructRequestInfo()); - String vfModuleName = aaiResponseWrapper.genVfModuleName(); - 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.getServiceInstance().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()); - } - } - - // VNF Item - relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getGenericVnf().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()); - } - } - - relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelCustomizationName(vnfItem - .getGenericVnf().getVnfType().substring(vnfItem.getGenericVnf().getVnfType().lastIndexOf('/') + 1)); - relatedInstanceListElement2.getRelatedInstance().getModelInfo() - .setModelCustomizationId(vnfItem.getGenericVnf().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.getGenericVnf().getVnfId(), - vnfServiceItem.getServiceInstance().getServiceInstanceId(), null); - if (logger.isDebugEnabled()) { - logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request)); - } - return request; - } - - /** - * Construct SO request to delete vf-module. - * - * @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 - * @return SO delete vf-module request - */ - private SoRequest constructDeleteRequest(AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem, - AaiNqInventoryResponseItem vnfServiceItem, Policy policy) { - 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(constructCloudConfiguration(tenantItem)); - // 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.getGenericVnf().getVnfId(), - vnfServiceItem.getServiceInstance().getServiceInstanceId(), null); - - if (logger.isDebugEnabled()) { - logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request)); - } - return request; - } - - /** * Construct requestInfo for the SO requestDetails. * * @return SO request information @@ -358,20 +145,6 @@ public class SoActorServiceProvider implements Actor { } /** - * Construct cloudConfiguration for the SO requestDetails. - * - * @param tenantItem tenant item from A&AI named-query response - * @return SO cloud configuration - */ - private SoCloudConfiguration constructCloudConfiguration(AaiNqInventoryResponseItem tenantItem) { - SoCloudConfiguration cloudConfiguration = new SoCloudConfiguration(); - cloudConfiguration.setTenantId(tenantItem.getTenant().getTenantId()); - cloudConfiguration.setLcpCloudRegionId( - tenantItem.getItems().getInventoryResponseItems().get(0).getCloudRegion().getCloudRegionId()); - return cloudConfiguration; - } - - /** * This method is needed to get the serviceInstanceId and vnfInstanceId which is used in the asyncSORestCall. * * @param requestId the request Id @@ -388,18 +161,6 @@ public class SoActorServiceProvider implements Actor { 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. diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java index 175d2fe0c..b46ac52fb 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java @@ -37,8 +37,6 @@ import java.util.UUID; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.onap.policy.aai.AaiCqResponse; -import org.onap.policy.aai.AaiNqResponse; -import org.onap.policy.aai.AaiNqResponseWrapper; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.policy.Policy; @@ -55,113 +53,6 @@ public class SoActorServiceProviderTest { private static final String VF_MODULE_CREATE = "VF Module Create"; private static final String VF_MODULE_DELETE = "VF Module Delete"; - @Test - public void testConstructRequest() throws Exception { - VirtualControlLoopEvent onset = new VirtualControlLoopEvent(); - final ControlLoopOperation operation = new ControlLoopOperation(); - final AaiNqResponseWrapper aaiNqResp = loadAaiResponse(onset, "aai/AaiNqResponse-Full.json"); - - final UUID requestId = UUID.randomUUID(); - onset.setRequestId(requestId); - - Policy policy = new Policy(); - policy.setActor("Dorothy"); - policy.setRecipe("GoToOz"); - - instantiateTarget(policy); - - assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); - - policy.setActor("SO"); - assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); - - policy.setRecipe(VF_MODULE_CREATE); - - // empty policy payload - SoRequest request = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); - assertNotNull(request); - - assertEquals("my_module_3", 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 SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); - 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(SoActorServiceProvider.REQ_PARAM_NM); - request = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); - assertNotNull(request); - assertNull(request.getRequestDetails().getRequestParameters()); - assertNotNull(request.getRequestDetails().getConfigurationParameters()); - - // payload with request, but no config params - policy.setPayload(makePayload()); - policy.getPayload().remove(SoActorServiceProvider.CONFIG_PARAM_NM); - request = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); - assertNotNull(request); - assertNotNull(request.getRequestDetails().getRequestParameters()); - assertNull(request.getRequestDetails().getConfigurationParameters()); - - // null response - assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, null)); - - // response has no base VF module - assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, - loadAaiResponse(onset, "aai/AaiNqResponse-NoBase.json"))); - - policy.setTarget(null); - - // response has no non-base VF modules (other than the "dummy") - assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, - loadAaiResponse(onset, "aai/AaiNqResponse-NoNonBase.json"))); - - instantiateTarget(policy); - policy.setRecipe(VF_MODULE_DELETE); - SoRequest deleteRequest = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); - 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 - aaiNqResp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems() - .remove(1); - assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); - - // null service item - aaiNqResp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0) - .setItems(null); - assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); - - // null response - aaiNqResp.setAaiNqResponse(null); - assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); - } - - private void instantiateTarget(Policy policy) { - - Target target = new Target(); - target.setModelCustomizationId("3e2d67ad-3495-4732-82f6-b0b872791fff"); - target.setModelInvariantId("90b793b5-b8ae-4c36-b10b-4b6372859d3a"); - target.setModelName("SproutScalingVf..scaling_sprout..module-1"); - target.setModelVersion("1"); - target.setModelVersionId("2210154d-e61a-4d7f-8fb9-0face1aee3f8"); - - policy.setTarget(target); - } - private void instantiateTargetCq(Policy policy) { Target target = new Target(); @@ -336,18 +227,4 @@ public class SoActorServiceProviderTest { return Serialization.gsonPretty.toJson(lst); } - /** - * Reads an AAI vserver named-query response from a file. - * - * @param onset the ONSET event - * @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 AaiNqResponseWrapper loadAaiResponse(VirtualControlLoopEvent onset, String fileName) throws IOException { - String resp = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8); - AaiNqResponse aaiNqResponse = Serialization.gsonPretty.fromJson(resp, AaiNqResponse.class); - - return new AaiNqResponseWrapper(onset.getRequestId(), aaiNqResponse); - } } |