Use cloud configuration from Vnf 39/126539/7
authorkuldipr <kuldip.rai@amdocs.com>
Mon, 10 Jan 2022 15:31:33 +0000 (10:31 -0500)
committerkuldipr <kuldip.rai@amdocs.com>
Thu, 27 Jan 2022 19:31:29 +0000 (14:31 -0500)
Vnfs can be part of different clouds and thus cloud configuration
is fetched from vnf itself and passed along the flow to create vnf
in the correct region.

Issue-ID: SO-3423
Change-Id: I1a91486a0bbc6a13aaa292905caeb0c72c4b4885
Signed-off-by: kuldipr <kuldip.rai@amdocs.com>
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java

index d39da5e..a808393 100644 (file)
@@ -1584,9 +1584,10 @@ public class BBInputSetup implements JavaDelegate {
         Vnfs vnfs = null;
         VfModules vfModules = null;
         Networks networks = null;
+
         CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
-        CloudRegion cloudRegion = getCloudRegionFromMacroRequest(cloudConfiguration, resources);
-        gBB.setCloudRegion(cloudRegion);
+        CloudRegion cloudRegion = setCloudConfiguration(gBB, cloudConfiguration);
+
         BBInputSetupParameter parameter =
                 new BBInputSetupParameter.Builder().setRequestId(executeBB.getRequestId()).setService(service)
                         .setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).build();
@@ -1599,6 +1600,11 @@ public class BBInputSetup implements JavaDelegate {
                 vnfs = findVnfsByKey(key, resources);
             }
 
+            // Vnf level cloud configuration takes precedence over service level cloud configuration.
+            if (vnfs.getCloudConfiguration() != null) {
+                setCloudConfiguration(gBB, vnfs.getCloudConfiguration());
+            }
+
             String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
             // This stores the vnf id in request db to be retrieved later when
             // working on a vf module or volume group
@@ -1635,6 +1641,21 @@ public class BBInputSetup implements JavaDelegate {
                 vfModules = getVfModulesByKey(key, resources);
             }
 
+            String vfModulesName = vfModules.getInstanceName();
+            String vfModulesModelCustId = vfModules.getModelInfo().getModelCustomizationId();
+            // Get the Vnf associated with vfModule
+            Optional<org.onap.so.serviceinstancebeans.Vnfs> parentVnf = resources.getVnfs().stream()
+                    .filter(aVnf -> aVnf.getCloudConfiguration() != null)
+                    .filter(aVnf -> aVnf.getVfModules().stream()
+                            .anyMatch(aVfModules -> aVfModules.getInstanceName().equals(vfModulesName) && aVfModules
+                                    .getModelInfo().getModelCustomizationId().equals(vfModulesModelCustId)))
+                    .findAny();
+
+            // Get the cloud configuration from this Vnf
+            if (parentVnf.isPresent()) {
+                cloudRegion = setCloudConfiguration(gBB, parentVnf.get().getCloudConfiguration());
+            }
+
             lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, getVnfId(executeBB, lookupKeyMap));
 
             parameter.setModelInfo(vfModules.getModelInfo());
@@ -1665,6 +1686,16 @@ public class BBInputSetup implements JavaDelegate {
             networks = findNetworksByKey(key, resources);
             String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
             if (networks != null) {
+                // If service level cloud configuration is not provided then get it from networks.
+                if (cloudConfiguration == null) {
+                    Optional<org.onap.so.serviceinstancebeans.Networks> netWithCloudConfig = resources.getNetworks()
+                            .stream().filter(aNetwork -> aNetwork.getCloudConfiguration() != null).findAny();
+                    if (netWithCloudConfig.isPresent()) {
+                        setCloudConfiguration(gBB, netWithCloudConfig.get().getCloudConfiguration());
+                    } else {
+                        logger.debug("Could not find any cloud configuration for this request.");
+                    }
+                }
                 parameter.setInstanceName(networks.getInstanceName());
                 parameter.setModelInfo(networks.getModelInfo());
                 parameter.setInstanceParams(networks.getInstanceParams());
@@ -1690,6 +1721,24 @@ public class BBInputSetup implements JavaDelegate {
         return gBB;
     }
 
+    /**
+     * setCloudConfiguration - set cloud info on a building block.
+     * 
+     * @param gBB
+     * @param cloudConfiguration
+     * @return CloudRegion
+     * @throws Exception
+     */
+    private CloudRegion setCloudConfiguration(GeneralBuildingBlock gBB, CloudConfiguration cloudConfiguration)
+            throws Exception {
+        org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration);
+        Tenant tenant = getTenant(cloudConfiguration, aaiCloudRegion);
+        gBB.setTenant(tenant);
+        CloudRegion cloudRegion = mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion);
+        gBB.setCloudRegion(cloudRegion);
+        return cloudRegion;
+    }
+
     protected Networks findNetworksByKey(String key, Resources resources) {
         for (Networks networks : resources.getNetworks()) {
             if (networks.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) {
@@ -1740,39 +1789,6 @@ public class BBInputSetup implements JavaDelegate {
         throw new ResourceNotFoundException("Could not find vnf with key: " + key + " in userparams");
     }
 
-    protected CloudRegion getCloudRegionFromMacroRequest(CloudConfiguration cloudConfiguration, Resources resources) {
-        if (cloudConfiguration == null) {
-            for (Vnfs vnfs : resources.getVnfs()) {
-                if (cloudConfiguration == null) {
-                    cloudConfiguration = vnfs.getCloudConfiguration();
-                } else {
-                    break;
-                }
-                for (VfModules vfModules : vnfs.getVfModules()) {
-                    if (cloudConfiguration == null) {
-                        cloudConfiguration = vfModules.getCloudConfiguration();
-                    } else {
-                        break;
-                    }
-                }
-            }
-            for (Networks networks : resources.getNetworks()) {
-                if (cloudConfiguration == null) {
-                    cloudConfiguration = networks.getCloudConfiguration();
-                } else {
-                    break;
-                }
-            }
-        }
-        if (cloudConfiguration != null) {
-            org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfiguration);
-            return mapperLayer.mapCloudRegion(cloudConfiguration, aaiCloudRegion);
-        } else {
-            logger.debug("Could not find any cloud configuration for this request.");
-            return null;
-        }
-    }
-
     protected String getVnfId(ExecuteBuildingBlock executeBB, Map<ResourceKey, String> lookupKeyMap) {
         String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
         if (vnfId == null) {
index b561055..d405cff 100644 (file)
@@ -2281,45 +2281,6 @@ public class BBInputSetupTest {
         assertThat(actual, sameBeanAs(expected));
     }
 
-    @Test
-    public void testgetGBBMacroCloudConfiguration() throws Exception {
-        org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue(
-                new File(RESOURCE_PATH + "ServiceMacroVfModules.json"), org.onap.so.serviceinstancebeans.Service.class);
-        CloudConfiguration cloudConfig = null;
-        org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = new org.onap.aai.domain.yang.CloudRegion();
-        aaiCloudRegion.setCloudOwner("test-owner-name");
-        Resources resources = serviceMacro.getResources();
-        doReturn(aaiCloudRegion).when(SPY_bbInputSetupUtils).getCloudRegion(any(CloudConfiguration.class));
-        CloudRegion expected = new CloudRegion();
-        expected.setLcpCloudRegionId("mdt1");
-        expected.setCloudOwner("test-owner-name");
-        expected.setTenantId("88a6ca3ee0394ade9403f075db23167e");
-
-        CloudRegion actual = SPY_bbInputSetup.getCloudRegionFromMacroRequest(cloudConfig, resources);
-        assertThat(actual, sameBeanAs(expected));
-
-        serviceMacro = mapper.readValue(new File(RESOURCE_PATH + "ServiceMacroVnfs.json"),
-                org.onap.so.serviceinstancebeans.Service.class);
-        resources = serviceMacro.getResources();
-
-        actual = SPY_bbInputSetup.getCloudRegionFromMacroRequest(cloudConfig, resources);
-        assertThat(actual, sameBeanAs(expected));
-
-        serviceMacro = mapper.readValue(new File(RESOURCE_PATH + "ServiceMacroNetworks.json"),
-                org.onap.so.serviceinstancebeans.Service.class);
-        resources = serviceMacro.getResources();
-
-        actual = SPY_bbInputSetup.getCloudRegionFromMacroRequest(cloudConfig, resources);
-        assertThat(actual, sameBeanAs(expected));
-
-        serviceMacro = mapper.readValue(new File(RESOURCE_PATH + "ServiceMacroNoCloudConfig.json"),
-                org.onap.so.serviceinstancebeans.Service.class);
-        resources = serviceMacro.getResources();
-
-        actual = SPY_bbInputSetup.getCloudRegionFromMacroRequest(cloudConfig, resources);
-        assertNull(actual);
-    }
-
     @Test
     public void testgetGBBMacroWithEmptyUserParams() throws Exception {
         String resourceId = "123";