From 5671fed30c9bcc74f0884893538e4aacabbc1b2f Mon Sep 17 00:00:00 2001 From: "Gamboa, Gilbert" Date: Wed, 11 Dec 2019 13:35:47 -0500 Subject: Need to globally check object name duplicates in Need to globally check object name duplicates in AAI for vf-module, volumegroup and configuration. Issue-ID: SO-2563 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I88a89a4a3ba02d5d9d586593d259580bf4546c96 --- .../tasks/BBInputSetupUtils.java | 18 ++++++++ .../tasks/BBInputSetupUtilsTest.java | 31 +++++++++++++ .../workflow/tasks/WorkflowAction.java | 13 +++++- .../workflow/tasks/WorkflowActionTest.java | 52 ++++++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java index fcac86b251..31275f7143 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java @@ -587,6 +587,24 @@ public class BBInputSetupUtils { return aaiRC.exists(l3networkUri); } + public boolean existsAAIVfModuleGloballyByName(String vfModuleName) { + AAIResourceUri vfModuleUri = + AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE).queryParam("vf-module-name", vfModuleName); + return injectionHelper.getAaiClient().exists(vfModuleUri); + } + + public boolean existsAAIConfigurationGloballyByName(String configurationName) { + AAIResourceUri configUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION) + .queryParam("configuration-name", configurationName); + return injectionHelper.getAaiClient().exists(configUri); + } + + public boolean existsAAIVolumeGroupGloballyByName(String volumeGroupName) { + AAIResourceUri volumeGroupUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP) + .queryParam("volume-group-name", volumeGroupName); + return injectionHelper.getAaiClient().exists(volumeGroupUri); + } + public GenericVnfs getAAIVnfsGloballyByName(String vnfName) { return injectionHelper.getAaiClient() diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java index 7780837714..53d167e4af 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java @@ -878,4 +878,35 @@ public class BBInputSetupUtilsTest { assertEquals(actual.get().getConfigurationId(), expected.get().getConfiguration().get(0).getConfigurationId()); } + @Test + public void existsAAIVfModuleGloballyByNameTest() throws Exception { + AAIResourceUri expectedUri = + AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE).queryParam("vf-module-name", "testVfModule"); + bbInputSetupUtils.existsAAIVfModuleGloballyByName("testVfModule"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); + } + + @Test + public void existsAAIConfigurationGloballyByNameTest() throws Exception { + AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION) + .queryParam("configuration-name", "testConfig"); + bbInputSetupUtils.existsAAIConfigurationGloballyByName("testConfig"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); + } + + @Test + public void existsAAINetworksGloballyByNameTest() throws Exception { + AAIResourceUri expectedUri = + AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", "testNetwork"); + bbInputSetupUtils.existsAAINetworksGloballyByName("testNetwork"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); + } + + @Test + public void existsAAIVolumeGroupGloballyByNameTest() throws Exception { + AAIResourceUri expectedUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP) + .queryParam("volume-group-name", "testVoumeGroup"); + bbInputSetupUtils.existsAAIVolumeGroupGloballyByName("testVoumeGroup"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 58bf17f08b..5cab676469 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -1268,12 +1268,15 @@ public class WorkflowAction { } } } + if (bbInputSetupUtils.existsAAIVfModuleGloballyByName(instanceName)) { + throw new DuplicateNameException("vfModule", instanceName); + } } else if ("VOLUMEGROUP".equalsIgnoreCase(type.toString())) { GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(workflowResourceIds.getVnfId()); Optional volumeGroup = bbInputSetupUtils .getRelatedVolumeGroupByNameFromVnf(workflowResourceIds.getVnfId(), instanceName); if (volumeGroup.isPresent()) { - if (vnf.getModelCustomizationId() + if (volumeGroup.get().getVfModuleModelCustomizationId() .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { return volumeGroup.get().getVolumeGroupId(); } else { @@ -1286,7 +1289,7 @@ public class WorkflowAction { bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnf.getVnfId(), vfModule.getVfModuleId(), instanceName); if (volumeGroupFromVfModule.isPresent()) { - if (vnf.getModelCustomizationId() + if (volumeGroupFromVfModule.get().getVfModuleModelCustomizationId() .equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) { return volumeGroupFromVfModule.get().getVolumeGroupId(); } else { @@ -1297,6 +1300,9 @@ public class WorkflowAction { } } } + if (bbInputSetupUtils.existsAAIVolumeGroupGloballyByName(instanceName)) { + throw new DuplicateNameException("volumeGroup", instanceName); + } } else if ("CONFIGURATION".equalsIgnoreCase(type.toString())) { Optional configuration = bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance( @@ -1311,6 +1317,9 @@ public class WorkflowAction { configuration.get().getConfigurationId())); } } + if (bbInputSetupUtils.existsAAIConfigurationGloballyByName(instanceName)) { + throw new DuplicateNameException("configuration", instanceName); + } } return generatedResourceId; } catch (DuplicateNameException dne) { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 6c959703e4..a894706357 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -1702,7 +1702,24 @@ public class WorkflowActionTest extends BaseTaskTest { "vfModule with name (vFModName222), same parent and different customization id (1234567) already exists. The name must be unique.")); workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName222", reqDetails, workflowResourceIds); + } + @Test + public void validateVfModuleResourceIdInAAINotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setVnfId("id111"); + + GenericVnf vnf1 = new GenericVnf(); + workflowResourceIds.setVnfId("id111"); + when(bbSetupUtils.getAAIGenericVnf("id111")).thenReturn(vnf1); + + when(bbSetupUtils.existsAAIVfModuleGloballyByName("vFModName333")).thenReturn(true); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("vfModule with name vFModName333 already exists. The name must be unique.")); + workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VFMODULE, "vFModName333", reqDetails, + workflowResourceIds); } @Test @@ -1725,6 +1742,7 @@ public class WorkflowActionTest extends BaseTaskTest { VolumeGroup volumeGroup = new VolumeGroup(); volumeGroup.setVolumeGroupId("id123"); volumeGroup.setVolumeGroupName("name123"); + volumeGroup.setVfModuleModelCustomizationId("1234567"); workflowResourceIds.setVnfId("id123"); Optional opVolumeGroup = Optional.of(volumeGroup); @@ -1746,6 +1764,24 @@ public class WorkflowActionTest extends BaseTaskTest { assertEquals("generatedId123", id2); } + @Test + public void validateVolumeGroupResourceIdInAAINotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setVnfId("id123"); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("id123"); + when(bbSetupUtils.getAAIGenericVnf("id123")).thenReturn(vnf); + when(bbSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "testVolumeGroup")).thenReturn(Optional.empty()); + + when(bbSetupUtils.existsAAIVolumeGroupGloballyByName("testVolumeGroup")).thenReturn(true); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("volumeGroup with name testVolumeGroup already exists. The name must be unique.")); + workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.VOLUMEGROUP, "testVolumeGroup", + reqDetails, workflowResourceIds); + } + @Test public void validateConfigurationResourceIdInAAITest() throws Exception { RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); @@ -1788,6 +1824,22 @@ public class WorkflowActionTest extends BaseTaskTest { workflowResourceIds); } + @Test + public void validateConfigurationResourceIdInAAINotGloballyUniqueTest() throws Exception { + RequestDetails reqDetails = setupRequestDetails("id123", "subServiceType123", "1234567"); + WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); + workflowResourceIds.setServiceInstanceId("siId123"); + + when(bbSetupUtils.getRelatedConfigurationByNameFromServiceInstance("siId123", "testConfig")) + .thenReturn(Optional.empty()); + when(bbSetupUtils.existsAAIConfigurationGloballyByName("testConfig")).thenReturn(true); + this.expectedException.expect(DuplicateNameException.class); + this.expectedException.expectMessage( + containsString("configuration with name testConfig already exists. The name must be unique.")); + workflowAction.validateResourceIdInAAI("generatedId123", WorkflowType.CONFIGURATION, "testConfig", reqDetails, + workflowResourceIds); + } + @Test public void validateServiceInstanceResourceIdInAAITest() throws Exception { WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); -- cgit 1.2.3-korg