From feb3f66334092f8d28cdba41450d0a11970319de Mon Sep 17 00:00:00 2001 From: "Kalkere Ramesh, Sharan (sk720x)" Date: Thu, 6 Dec 2018 14:11:29 -0500 Subject: creating relationships vnf and tenant Change-Id: I515fc40c7924c2fdb3f0bc4dd3a620eb0a3bf948 Issue-ID: SO-1284 Signed-off-by: Kalkere Ramesh, Sharan (sk720x) --- .../servicedecomposition/tasks/BBInputSetup.java | 15 ++- .../tasks/CloudInfoFromAAI.java | 93 ++++++++++++++ .../tasks/BBInputSetupTest.java | 3 +- .../tasks/CloudInfoFromAAITest.java | 142 +++++++++++++++++++++ .../subprocess/BuildingBlock/AssignVnfBB.bpmn | 63 ++++++--- .../bpmn/subprocess/AssignVnfBBTest.java | 2 +- .../infrastructure/aai/tasks/AAICreateTasks.java | 28 ++++ .../so/client/orchestration/AAIVnfResources.java | 14 ++ .../aai/tasks/AAICreateTasksTest.java | 16 +++ .../client/orchestration/AAIVnfResourcesTest.java | 22 ++++ 10 files changed, 378 insertions(+), 20 deletions(-) create mode 100644 bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAI.java create mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAITest.java (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 7edf39df14..c0f1c48b76 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -90,6 +90,7 @@ import org.onap.so.serviceinstancebeans.Vnfs; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -112,6 +113,9 @@ public class BBInputSetup implements JavaDelegate { @Autowired private BBInputSetupMapperLayer mapperLayer; + + @Autowired + private CloudInfoFromAAI bbInputSetupHelper; @Autowired private ExceptionBuilder exceptionUtil; @@ -981,11 +985,18 @@ public class BBInputSetup implements JavaDelegate { Map lookupKeyMap, String bbName, GeneralBuildingBlock gBB, Service service, String requestAction, CloudConfiguration cloudConfiguration) throws Exception { ServiceInstance serviceInstance = gBB.getServiceInstance(); + CloudRegion cloudRegion = null; + if(cloudConfiguration == null) { + Optional cloudRegionOp = bbInputSetupHelper.getCloudInfoFromAAI(serviceInstance); + if(cloudRegionOp.isPresent()) { + cloudRegion = cloudRegionOp.get(); + } + } if (cloudConfiguration != null && requestAction.equalsIgnoreCase("deleteInstance")) { org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration); - CloudRegion cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion); - gBB.setCloudRegion(cloudRegion); + cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion); } + gBB.setCloudRegion(cloudRegion); if (bbName.contains(VNF)) { for (GenericVnf genericVnf : serviceInstance.getVnfs()) { if (lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID) != null diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAI.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAI.java new file mode 100644 index 0000000000..37088022bc --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAI.java @@ -0,0 +1,93 @@ +package org.onap.so.bpmn.servicedecomposition.tasks; + +import java.util.List; +import java.util.Optional; + +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.core.JsonProcessingException; + +@Component +public class CloudInfoFromAAI { + + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CloudInfoFromAAI.class); + @Autowired + private BBInputSetupUtils bbInputSetupUtils; + + public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { + this.bbInputSetupUtils = bbInputSetupUtils; + } + + protected Optional getCloudInfoFromAAI(ServiceInstance serviceInstance) throws JsonProcessingException { + Optional relationshipsOp = Optional.empty(); + if(!serviceInstance.getVnfs().isEmpty()) { + GenericVnf vnf = serviceInstance.getVnfs().get(0); + org.onap.aai.domain.yang.GenericVnf aaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnf.getVnfId()); + AAIResultWrapper vnfWrapper = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVnf)); + relationshipsOp = getRelationshipsFromWrapper(vnfWrapper); + } else if(!serviceInstance.getNetworks().isEmpty()) { + L3Network network = serviceInstance.getNetworks().get(0); + org.onap.aai.domain.yang.L3Network aaiL3Network = bbInputSetupUtils.getAAIL3Network(network.getNetworkId()); + AAIResultWrapper networkWrapper = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiL3Network)); + relationshipsOp = getRelationshipsFromWrapper(networkWrapper); + } else { + msoLogger.debug("BBInputSetup could not find a cloud region or tenant, since there are no resources under the SI."); + return Optional.empty(); + } + if (relationshipsOp.isPresent()) { + return getRelatedCloudRegionAndTenant(relationshipsOp.get()); + } else { + msoLogger.debug("BBInputSetup could not find a cloud region or tenant"); + return Optional.empty(); + } + } + + protected Optional getRelationshipsFromWrapper(AAIResultWrapper wrapper) { + Optional relationshipsOp; + relationshipsOp = wrapper.getRelationships(); + if(relationshipsOp.isPresent()) { + return relationshipsOp; + } + return Optional.empty(); + } + + protected Optional getRelatedCloudRegionAndTenant(Relationships relationships) { + CloudRegion cloudRegion = new CloudRegion(); + List cloudRegions = relationships.getByType(AAIObjectType.CLOUD_REGION); + List tenants = relationships.getByType(AAIObjectType.TENANT); + if(!cloudRegions.isEmpty()) { + AAIResultWrapper cloudRegionWrapper = cloudRegions.get(0); + Optional aaiCloudRegionOp = cloudRegionWrapper + .asBean(org.onap.aai.domain.yang.CloudRegion.class); + if(aaiCloudRegionOp.isPresent()) { + org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = aaiCloudRegionOp.get(); + cloudRegion.setCloudOwner(aaiCloudRegion.getCloudOwner()); + cloudRegion.setCloudRegionVersion(aaiCloudRegion.getCloudRegionVersion()); + cloudRegion.setLcpCloudRegionId(aaiCloudRegion.getCloudRegionId()); + cloudRegion.setComplex(aaiCloudRegion.getComplexName()); + } + } + if(!tenants.isEmpty()) { + AAIResultWrapper tenantWrapper = tenants.get(0); + Optional aaiTenantOp = tenantWrapper + .asBean(org.onap.aai.domain.yang.Tenant.class); + if(aaiTenantOp.isPresent()) { + org.onap.aai.domain.yang.Tenant aaiTenant = aaiTenantOp.get(); + cloudRegion.setTenantId(aaiTenant.getTenantId()); + } + } + return Optional.of(cloudRegion); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java index b36d6d43f8..8399fe15a3 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java @@ -84,6 +84,7 @@ import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; import org.onap.so.client.aai.AAICommonObjectMapperProvider; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.constants.Defaults; @@ -137,7 +138,7 @@ public class BBInputSetupTest { SPY_bbInputSetup.setBbInputSetupUtils(SPY_bbInputSetupUtils); SPY_bbInputSetup.setMapperLayer(bbInputSetupMapperLayer); } - + @Test public void testGetAlaCarteServiceInstance() throws Exception { ServiceInstance expected = mapper.readValue( diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAITest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAITest.java new file mode 100644 index 0000000000..ccaa97b735 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/CloudInfoFromAAITest.java @@ -0,0 +1,142 @@ +package org.onap.so.bpmn.servicedecomposition.tasks; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doReturn; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAICommonObjectMapperProvider; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(MockitoJUnitRunner.class) +public class CloudInfoFromAAITest { + + private static final String RESOURCE_PATH = "src/test/resources/__files/ExecuteBuildingBlock/"; + + @Spy + private CloudInfoFromAAI SPY_CloudInfoFromAAI = new CloudInfoFromAAI(); + + protected ObjectMapper mapper = new ObjectMapper(); + + @Mock + private BBInputSetupUtils SPY_bbInputSetupUtils; + + @Before + public void setup(){ + SPY_CloudInfoFromAAI.setBbInputSetupUtils(SPY_bbInputSetupUtils); + } + + @Test + public void testGetCloudInfoFromAAI() throws JsonParseException, JsonMappingException, IOException { + //Test vnfs + ServiceInstance serviceInstance = mapper.readValue( + new File(RESOURCE_PATH + "ServiceInstance_getServiceInstanceNOAAIExpected.json"), + ServiceInstance.class); + CloudRegion expected = new CloudRegion(); + GenericVnf vnf = new GenericVnf(); + String vnfId = "vnfId"; + vnf.setVnfId(vnfId); + serviceInstance.getVnfs().add(vnf); + org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); + aaiVnf.setVnfId(vnfId); + Relationships relationships = Mockito.mock(Relationships.class); + Optional relationshipsOp= Optional.of(relationships); + doReturn(aaiVnf).when(SPY_bbInputSetupUtils).getAAIGenericVnf(vnf.getVnfId()); + doReturn(relationshipsOp).when(SPY_CloudInfoFromAAI).getRelationshipsFromWrapper(isA(AAIResultWrapper.class)); + doReturn(Optional.of(expected)).when(SPY_CloudInfoFromAAI).getRelatedCloudRegionAndTenant(relationships); + Optional actual = SPY_CloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance); + assertThat(actual.get(), sameBeanAs(expected)); + + //Test networks + serviceInstance = mapper.readValue( + new File(RESOURCE_PATH + "ServiceInstance_getServiceInstanceNOAAIExpected.json"), + ServiceInstance.class); + L3Network l3Network = new L3Network(); + String networkId = "networkId"; + l3Network.setNetworkId(networkId); + serviceInstance.getNetworks().add(l3Network); + org.onap.aai.domain.yang.L3Network aaiL3Network = new org.onap.aai.domain.yang.L3Network(); + aaiL3Network.setNetworkId(networkId); + doReturn(aaiL3Network).when(SPY_bbInputSetupUtils).getAAIL3Network(l3Network.getNetworkId()); + actual = SPY_CloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance); + assertThat(actual.get(), sameBeanAs(expected)); + + //Test no relationships + + doReturn(Optional.empty()).when(SPY_CloudInfoFromAAI).getRelationshipsFromWrapper(isA(AAIResultWrapper.class)); + actual = SPY_CloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance); + assertEquals(actual, Optional.empty()); + + //Test null + serviceInstance = mapper.readValue( + new File(RESOURCE_PATH + "ServiceInstance_getServiceInstanceNOAAIExpected.json"), + ServiceInstance.class); + actual = SPY_CloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance); + assertEquals(actual, Optional.empty()); + } + + @Test + public void testGetRelatedCloudRegionAndTenant() throws JsonProcessingException { + String cloudOwner = "cloudOwner"; + String cloudRegionId = "cloudRegionId"; + String cloudRegionVersion = "cloudRegionVersion"; + String cloudRegionComplexName = "cloudRegionComplexName"; + String tenantId = "tenantId"; + CloudRegion expected = new CloudRegion(); + expected.setCloudOwner(cloudOwner); + expected.setCloudRegionVersion(cloudRegionVersion); + expected.setComplex(cloudRegionComplexName); + expected.setLcpCloudRegionId(cloudRegionId); + expected.setTenantId(tenantId); + + Relationships relationships = Mockito.mock(Relationships.class); + List cloudRegions = new ArrayList<>(); + org.onap.aai.domain.yang.CloudRegion cloudRegion = new org.onap.aai.domain.yang.CloudRegion(); + cloudRegion.setCloudOwner(cloudOwner); + cloudRegion.setCloudRegionId(cloudRegionId); + cloudRegion.setCloudRegionVersion(cloudRegionVersion); + cloudRegion.setComplexName(cloudRegionComplexName); + AAIResultWrapper cloudRegionWrapper = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(cloudRegion)); + cloudRegions.add(cloudRegionWrapper); + + doReturn(cloudRegions).when(relationships).getByType(AAIObjectType.CLOUD_REGION); + List tenants = new ArrayList<>(); + org.onap.aai.domain.yang.Tenant tenant = new org.onap.aai.domain.yang.Tenant(); + tenant.setTenantId(tenantId); + AAIResultWrapper tenantWrapper = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(tenant)); + tenants.add(tenantWrapper); + doReturn(tenants).when(relationships).getByType(AAIObjectType.TENANT); + + Optional actual = SPY_CloudInfoFromAAI.getRelatedCloudRegionAndTenant(relationships); + + assertThat(actual.get(), sameBeanAs(expected)); + } +} diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignVnfBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignVnfBB.bpmn index 0a067483ff..f4db92ba5c 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignVnfBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/AssignVnfBB.bpmn @@ -13,7 +13,7 @@ SequenceFlow_0zaz9o2 - SequenceFlow_1jwsja5 + SequenceFlow_0qj7zcn @@ -25,7 +25,6 @@ SequenceFlow_1lppa2m SequenceFlow_1nle8kc - @@ -45,7 +44,7 @@ - SequenceFlow_1jwsja5 + SequenceFlow_18ixm0j SequenceFlow_169g0ir @@ -73,6 +72,17 @@ SequenceFlow_0v8d14a SequenceFlow_1samncw + + SequenceFlow_0qj7zcn + SequenceFlow_0nsg48b + + + + SequenceFlow_0nsg48b + SequenceFlow_18ixm0j + + + @@ -89,9 +99,9 @@ - + - + @@ -104,13 +114,13 @@ - + - - + + - + @@ -126,13 +136,6 @@ - - - - - - - @@ -222,6 +225,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -249,3 +279,4 @@ + diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/AssignVnfBBTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/AssignVnfBBTest.java index f675440ead..f4258f46b8 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/AssignVnfBBTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/AssignVnfBBTest.java @@ -38,7 +38,7 @@ public class AssignVnfBBTest extends BaseBPMNTest { mockSubprocess("SDNCHandler", "My Mock Process Name", "GenericStub"); ProcessInstance pi = runtimeService.startProcessInstanceByKey("AssignVnfBB", variables); assertThat(pi).isNotNull(); - assertThat(pi).isStarted().hasPassedInOrder("Start_AssignVnfBB", "Task_CreateVnf", "Task_createPlatform", "Task_createLineOfBusiness", "Task_createInstanceGroups", + assertThat(pi).isStarted().hasPassedInOrder("Start_AssignVnfBB", "Task_CreateVnf", "ServiceTask_ConnectVnfToCloudRegion", "ServiceTask_ConnectVnfToTenant", "Task_createPlatform", "Task_createLineOfBusiness", "Task_createInstanceGroups", "Task_callHoming", "Task_SDNCAdapterVnfTopologyAssign","CallActivity_sdncAssign", "Task_UpdateVnfOrchestrationStatusAssigned", "End_AssignVnfBB"); assertThat(pi).isEnded(); 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 887c51e179..54ee26d0ad 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 @@ -349,6 +349,34 @@ public class AAICreateTasks { } } + /** + * BPMN access method to establish relationships in AAI + * @param execution + * @throws Exception + */ + public void connectVnfToCloudRegion(BuildingBlockExecution execution) { + try { + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + aaiVnfResources.connectVnfToCloudRegion(vnf, execution.getGeneralBuildingBlock().getCloudRegion()); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + /** + * BPMN access method to establish relationships in AAI + * @param execution + * @throws Exception + */ + public void connectVnfToTenant(BuildingBlockExecution execution) { + try { + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + aaiVnfResources.connectVnfToTenant(vnf, execution.getGeneralBuildingBlock().getCloudRegion()); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + /** * BPMN access method to establish relationships in AAI * @param execution diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java index 19025b4b9f..6717c1c6bc 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java @@ -110,4 +110,18 @@ public class AAIVnfResources { .orElse(new org.onap.aai.domain.yang.GenericVnf()); return vnf.isInMaint(); } + + public void connectVnfToCloudRegion(GenericVnf vnf, CloudRegion cloudRegion) { + AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, + cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()); + AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()); + injectionHelper.getAaiClient().connect(cloudRegionURI, vnfURI); + } + + public void connectVnfToTenant(GenericVnf vnf, CloudRegion cloudRegion) { + AAIResourceUri tenantURI = AAIUriFactory.createResourceUri(AAIObjectType.TENANT, + cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), cloudRegion.getTenantId()); + AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()); + injectionHelper.getAaiClient().connect(tenantURI, vnfURI); + } } 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 44b56662ba..b2e46f6130 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 @@ -417,4 +417,20 @@ public class AAICreateTasksTest extends BaseTaskTest{ aaiCreateTasks.createConfiguration(execution); verify(aaiConfigurationResources, times(1)).createConfiguration(configuration); } + + @Test + public void connectVnfToCloudRegionTest() throws Exception { + gBBInput = execution.getGeneralBuildingBlock(); + doNothing().when(aaiVnfResources).connectVnfToCloudRegion(genericVnf, gBBInput.getCloudRegion()); + aaiCreateTasks.connectVnfToCloudRegion(execution); + verify(aaiVnfResources, times(1)).connectVnfToCloudRegion(genericVnf, gBBInput.getCloudRegion()); + } + + @Test + public void connectVnfTenantTest() throws Exception { + gBBInput = execution.getGeneralBuildingBlock(); + doNothing().when(aaiVnfResources).connectVnfToTenant(genericVnf, gBBInput.getCloudRegion()); + aaiCreateTasks.connectVnfToTenant(execution); + verify(aaiVnfResources, times(1)).connectVnfToTenant(genericVnf, gBBInput.getCloudRegion()); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java index fcd6c30220..9894a08968 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java @@ -40,12 +40,15 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.common.InjectionHelper; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; import org.onap.so.db.catalog.beans.OrchestrationStatus; @@ -55,6 +58,9 @@ public class AAIVnfResourcesTest extends TestDataSetup { private GenericVnf genericVnf; private ServiceInstance serviceInstance; + + private CloudRegion cloudRegion; + @Mock protected AAIResourcesClient MOCK_aaiResourcesClient; @@ -71,6 +77,7 @@ public class AAIVnfResourcesTest extends TestDataSetup { public void before() { serviceInstance = buildServiceInstance(); genericVnf = buildGenericVnf(); + cloudRegion = buildCloudRegion(); doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); } @@ -159,4 +166,19 @@ public class AAIVnfResourcesTest extends TestDataSetup { verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); assertEquals(inMaintFlag, true); } + + @Test + public void connectVnfToTenantTest() throws Exception { + aaiVnfResources.connectVnfToTenant(genericVnf, cloudRegion); + verify(MOCK_aaiResourcesClient, times(1)).connect(eq(AAIUriFactory.createResourceUri(AAIObjectType.TENANT, + cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), cloudRegion.getTenantId())), + eq(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVnf.getVnfId()))); + } + + @Test + public void connectVnfToCloudRegionTest() throws Exception { + aaiVnfResources.connectVnfToCloudRegion(genericVnf, cloudRegion); + verify(MOCK_aaiResourcesClient, times(1)).connect(eq(AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, + cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId())), eq(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVnf.getVnfId()))); + } } -- cgit 1.2.3-korg