diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-04-09 08:24:14 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2019-04-09 08:24:21 -0400 |
commit | 7e63a8833ae226738d858a3ff1aaf715f9b51d6b (patch) | |
tree | 96efb370cffa1db2c3482b5a9991df043a3eb8ac /models-interactions/model-actors/actor.so | |
parent | c54b9408a10c0060e35be2ee0b5bac6a24e9153a (diff) |
Parse new model ids from operational policy
Companion review to https://gerrit.onap.org/r/#/c/84235/
Copies the required changes into policy/models.
Issue-ID: POLICY-1545
Change-Id: I43fec36f60b5409d9e3df9d925de06209c81fd01
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.so')
2 files changed, 53 insertions, 35 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 2a14bb19a..6d8fa4bd2 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 @@ -164,10 +164,11 @@ public class SoActorServiceProvider implements Actor { // Find the index for base vf module and non-base vf module AaiNqInventoryResponseItem baseItem = findVfModule(aaiResponseWrapper, true); - AaiNqInventoryResponseItem vfModuleItem = findVfModule(aaiResponseWrapper, false); + + SoModelInfo soModelInfo = prepareSoModelInfo(policy); // Report the error if either base vf module or non-base vf module is not found - if (baseItem == null || vfModuleItem == null) { + if (baseItem == null || soModelInfo == null) { logger.error("Either base or non-base vf module is not found from AAI response."); return null; } @@ -175,9 +176,31 @@ public class SoActorServiceProvider implements Actor { // Construct SO Request for a policy's recipe if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) { return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem, - vfModuleItem); + soModelInfo); } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) { - return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, vfModuleItem); + return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, soModelInfo, policy); + } else { + return null; + } + } + + private SoModelInfo prepareSoModelInfo(Policy policy) { + + SoModelInfo soModelInfo = new SoModelInfo(); + if ((policy.getTarget() != null + && (policy.getTarget().getModelCustomizationId() != null)) + && (policy.getTarget().getModelInvariantId() != null) + && (policy.getTarget().getModelName() != null) + && (policy.getTarget().getModelVersion() != null) + && (policy.getTarget().getModelVersionId() != null)) { + + 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()); + + return soModelInfo; } else { return null; } @@ -197,7 +220,7 @@ public class SoActorServiceProvider implements Actor { private SoRequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy, AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem, AaiNqInventoryResponseItem vnfServiceItem, - AaiNqInventoryResponseItem vfModuleItem) { + SoModelInfo vfModuleItem) { SoRequest request = new SoRequest(); request.setOperationType(SoOperationType.SCALE_OUT); // @@ -211,8 +234,7 @@ public class SoActorServiceProvider implements Actor { // cloudConfiguration request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem)); // modelInfo - request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem)); - request.getRequestDetails().getModelInfo().setModelVersionId(vfModuleItem.getVfModule().getModelVersionId()); + request.getRequestDetails().setModelInfo(vfModuleItem); // requestInfo request.getRequestDetails().setRequestInfo(constructRequestInfo()); @@ -296,7 +318,7 @@ public class SoActorServiceProvider implements Actor { * @return SO delete vf-module request */ private SoRequest constructDeleteRequest(AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem - vnfItem, AaiNqInventoryResponseItem vnfServiceItem, AaiNqInventoryResponseItem vfModuleItem) { + vnfItem, AaiNqInventoryResponseItem vnfServiceItem, SoModelInfo vfModuleItem, Policy policy) { SoRequest request = new SoRequest(); request.setOperationType(SoOperationType.DELETE_VF_MODULE); request.setRequestDetails(new SoRequestDetails()); @@ -306,12 +328,12 @@ public class SoActorServiceProvider implements Actor { // cloudConfiguration request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem)); // 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()); + .getServiceInstanceId(), null); if (logger.isDebugEnabled()) { logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request)); @@ -333,28 +355,6 @@ public class SoActorServiceProvider implements Actor { } /** - * 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. * * @param tenantItem tenant item from A&AI named-query response 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 a7bdf1a76..8b4bcf20a 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 @@ -42,6 +42,7 @@ 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; +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; @@ -64,7 +65,9 @@ public class SoActorServiceProviderTest { Policy policy = new Policy(); policy.setActor("Dorothy"); policy.setRecipe("GoToOz"); - + + instantiateTarget(policy); + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); policy.setActor("SO"); @@ -88,7 +91,7 @@ public class SoActorServiceProviderTest { assertEquals("avalue", request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey")); assertEquals(1, request.getRequestDetails().getConfigurationParameters().size()); assertEquals("cvalue", request.getRequestDetails().getConfigurationParameters().get(0).get("ckey")); - + // payload with config, but no request params policy.setPayload(makePayload()); policy.getPayload().remove(SoActorServiceProvider.REQ_PARAM_NM); @@ -96,7 +99,7 @@ public class SoActorServiceProviderTest { 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); @@ -112,10 +115,13 @@ public class SoActorServiceProviderTest { 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); @@ -142,6 +148,18 @@ public class SoActorServiceProviderTest { 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); + } + @Test public void testSendRequest() { try { |