From d231a18148d7bf7f10afd3b72f4be0e0b9a3bb0e Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Fri, 1 Feb 2019 18:35:25 -0500 Subject: auto generated vf module index param added test for when this is the first vfmodule added unit test no longer tests already created vnf refactored test to be more clear about uuid grouping Added javadoc for getLowestUnusedVfModIndex method. Increment index by vf module model invariant uuid Fix unnecessary whitespace delta for GenericVnf file Fix GenericVnf and modify junit for setting vfmodules Change-Id: Iacd31c5bf73c971c0b3c06e790d4c5193c3c9860 Issue-ID: SO-1458 Signed-off-by: Benjamin, Max (mb388a) --- .../infrastructure/aai/tasks/AAICreateTasks.java | 47 +++++++++++- .../onap/so/bpmn/common/data/TestDataSetup.java | 10 ++- .../aai/tasks/AAICreateTasksTest.java | 85 +++++++++++++++++++++- 3 files changed, 134 insertions(+), 8 deletions(-) diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java index 4a3cb01b74..55e74339a4 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java @@ -21,12 +21,11 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; +import java.util.Set; +import java.util.TreeSet; import org.camunda.bpm.engine.delegate.BpmnError; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.core.UrnPropertiesReader; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; @@ -53,7 +52,6 @@ import org.onap.so.client.orchestration.AAIVfModuleResources; import org.onap.so.client.orchestration.AAIVnfResources; import org.onap.so.client.orchestration.AAIVolumeGroupResources; import org.onap.so.client.orchestration.AAIVpnBindingResources; -import org.onap.so.db.catalog.beans.OrchestrationStatus; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; @@ -233,6 +231,11 @@ public class AAICreateTasks { try { GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID, execution.getLookupMap().get(ResourceKey.VF_MODULE_ID)); + int moduleIndex = 0; + if (vfModule.getModelInfoVfModule() != null && !Boolean.TRUE.equals(vfModule.getModelInfoVfModule().getIsBaseBoolean())) { + moduleIndex = this.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, vfModule); + } + vfModule.setModuleIndex(moduleIndex); aaiVfModuleResources.createVfModule(vfModule, vnf); } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); @@ -432,4 +435,40 @@ public class AAICreateTasks { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } + /** + * Groups existing vf modules by the model uuid of our new vf module and returns the lowest unused index + * + * if we have a module type A, and there are 3 instances of those, + * and then module type B has 2 instances, if we are adding a new module type A, + * the vf-module-index should be 3 assuming contiguous indices (not 5, or 2) + * + */ + protected int getLowestUnusedVfModuleIndexFromAAIVnfResponse(GenericVnf genericVnf, VfModule newVfModule) { + + String newVfModuleModelInvariantUUID = null; + if (newVfModule.getModelInfoVfModule() != null) { + newVfModuleModelInvariantUUID = newVfModule.getModelInfoVfModule().getModelInvariantUUID(); + } + + + if (genericVnf != null && genericVnf.getVfModules() != null && !genericVnf.getVfModules().isEmpty()) { + Set moduleIndices = new TreeSet<>(); + for (VfModule vfModule : genericVnf.getVfModules()) { + if (vfModule.getModelInfoVfModule() != null) { + if (vfModule.getModelInfoVfModule().getModelInvariantUUID().equals(newVfModuleModelInvariantUUID)) { + moduleIndices.add(vfModule.getModuleIndex()); + } + } + } + Object[] array = moduleIndices.toArray(); + for (int i=0; i < array.length; i++) { + if ((int) array[i] != i) { + return i; + } + } + return array.length; + } else { + return 0; + } + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java index df1f0adcea..7375f09240 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/data/TestDataSetup.java @@ -516,7 +516,7 @@ public class TestDataSetup{ VfModule vfModule = new VfModule(); vfModule.setVfModuleId("testVfModuleId" + vfModuleCounter); vfModule.setVfModuleName("testVfModuleName" + vfModuleCounter); - + vfModule.setModuleIndex(0); ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule(); modelInfoVfModule.setModelInvariantUUID("testModelInvariantUUID" + vfModuleCounter); modelInfoVfModule.setModelVersion("testModelVersion" + vfModuleCounter); @@ -529,6 +529,10 @@ public class TestDataSetup{ } public VfModule setVfModule() { + return setVfModule(true); + } + + public VfModule setVfModule(boolean addToGenericVnf) { VfModule vfModule = buildVfModule(); GenericVnf genericVnf = null; @@ -539,7 +543,9 @@ public class TestDataSetup{ genericVnf = setGenericVnf(); } - genericVnf.getVfModules().add(vfModule); + if (addToGenericVnf) { + genericVnf.getVfModules().add(vfModule); + } lookupKeyMap.put(ResourceKey.VF_MODULE_ID, vfModule.getVfModuleId()); return vfModule; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java index da7e727488..8e261cfa8e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java @@ -19,6 +19,7 @@ */ package org.onap.so.bpmn.infrastructure.aai.tasks; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; @@ -47,6 +48,8 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.db.catalog.beans.OrchestrationStatus; @@ -268,9 +271,17 @@ public class AAICreateTasksTest extends BaseTaskTest{ @Test public void createVfModuleTest() throws Exception { - doNothing().when(aaiVfModuleResources).createVfModule(vfModule, genericVnf); + + VfModule newVfModule = setVfModule(false); + newVfModule.setModuleIndex(null); + newVfModule.getModelInfoVfModule().setModelInvariantUUID("testModelInvariantUUID1"); + doNothing().when(aaiVfModuleResources).createVfModule(newVfModule, genericVnf); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(newVfModule); + + assertEquals(null, newVfModule.getModuleIndex()); aaiCreateTasks.createVfModule(execution); - verify(aaiVfModuleResources, times(1)).createVfModule(vfModule, genericVnf); + assertEquals(1, newVfModule.getModuleIndex().intValue()); + verify(aaiVfModuleResources, times(1)).createVfModule(newVfModule, genericVnf); } @Test @@ -445,4 +456,74 @@ public class AAICreateTasksTest extends BaseTaskTest{ aaiCreateTasks.connectVnfToTenant(execution); verify(aaiVnfResources, times(1)).connectVnfToTenant(genericVnf, gBBInput.getCloudRegion()); } + @Test + public void createVfModuleGetLowestIndexTest() throws Exception { + GenericVnf vnf = new GenericVnf(); + ModelInfoGenericVnf vnfInfo = new ModelInfoGenericVnf(); + vnf.setModelInfoGenericVnf(vnfInfo); + vnfInfo.setModelInvariantUuid("my-uuid"); + + ModelInfoVfModule infoA = new ModelInfoVfModule(); + infoA.setIsBaseBoolean(false); + infoA.setModelInvariantUUID("A"); + + ModelInfoVfModule infoB = new ModelInfoVfModule(); + infoB.setIsBaseBoolean(false); + infoB.setModelInvariantUUID("B"); + + ModelInfoVfModule infoC = new ModelInfoVfModule(); + infoB.setIsBaseBoolean(false); + infoB.setModelInvariantUUID("C"); + + VfModule newVfModuleA = new VfModule(); + VfModule newVfModuleB = new VfModule(); + VfModule newVfModuleC = new VfModule(); + + VfModule vfModule = new VfModule(); + vnf.getVfModules().add(vfModule); + + VfModule vfModule2 = new VfModule(); + vnf.getVfModules().add(vfModule2); + + VfModule vfModule3 = new VfModule(); + vnf.getVfModules().add(vfModule3); + + VfModule vfModule4 = new VfModule(); + vnf.getVfModules().add(vfModule4); + + VfModule vfModule5 = new VfModule(); + vnf.getVfModules().add(vfModule5); + + //A + newVfModuleA.setModelInfoVfModule(infoA); + vfModule.setModelInfoVfModule(infoA); + vfModule2.setModelInfoVfModule(infoA); + vfModule3.setModelInfoVfModule(infoA); + + //B + newVfModuleB.setModelInfoVfModule(infoB); + vfModule4.setModelInfoVfModule(infoB); + vfModule5.setModelInfoVfModule(infoB); + + //C + newVfModuleC.setModelInfoVfModule(infoC); + + + //A + vfModule.setModuleIndex(2); + vfModule2.setModuleIndex(0); + vfModule3.setModuleIndex(3); + + //B + vfModule4.setModuleIndex(0); + vfModule5.setModuleIndex(1); + + assertEquals(aaiCreateTasks.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, newVfModuleA), 1); + + assertEquals(aaiCreateTasks.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, newVfModuleB), 2); + + assertEquals(aaiCreateTasks.getLowestUnusedVfModuleIndexFromAAIVnfResponse(vnf, newVfModuleC), 0); + + + } } -- cgit 1.2.3-korg