allow deleteL3Network logic to be overridden 77/116877/1
authorBenjamin, Max <max.benjamin@att.com>
Thu, 14 Jan 2021 15:22:44 +0000 (10:22 -0500)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Thu, 14 Jan 2021 15:22:45 +0000 (10:22 -0500)
allow deleteL3Network logic to be overridden
created public method for heatbridge client to allow
custom implementation

Issue-ID: SO-3482
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Icc5f3e649629a29dedbcbe2dda7f5a5d70978a59

adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventory.java
adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/inventory/DeleteAAIInventory.java
adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java

index 14d0b0a..0dd7635 100644 (file)
@@ -70,9 +70,7 @@ public class CreateAAIInventory {
 
         List<String> oobMgtNetNames = new ArrayList<>();
 
-        HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity,
-                cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(),
-                cloudInformation.getTenantId(), cloudInformation.getNodeType());
+        HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation);
 
         heatBridgeClient.authenticate();
 
@@ -128,6 +126,12 @@ public class CreateAAIInventory {
         heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
     }
 
+    public HeatBridgeApi createClient(AAIResourcesClient client, CloudSite cloudSite, CloudIdentity cloudIdentity,
+            CloudInformation cloudInformation) {
+        return new HeatBridgeImpl(client, cloudIdentity, cloudInformation.getOwner(), cloudInformation.getRegionId(),
+                cloudSite.getRegionId(), cloudInformation.getTenantId(), cloudInformation.getNodeType());
+    }
+
     protected AAIResourcesClient getAaiClient() {
         if (aaiClient == null)
             return new AAIResourcesClient();
index f904788..f9bbf4a 100644 (file)
@@ -59,13 +59,17 @@ public class DeleteAAIInventory {
             return;
         }
         CloudIdentity cloudIdentity = cloudSite.getIdentityService();
-        HeatBridgeApi heatBridgeClient = new HeatBridgeImpl(new AAIResourcesClient(), cloudIdentity,
-                cloudInformation.getOwner(), cloudInformation.getRegionId(), cloudSite.getRegionId(),
-                cloudInformation.getTenantId(), cloudInformation.getNodeType());
+        HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation);
         heatBridgeClient.authenticate();
         heatBridgeClient.deleteVfModuleData(cloudInformation.getVnfId(), cloudInformation.getVfModuleId());
     }
 
+    public HeatBridgeApi createClient(AAIResourcesClient client, CloudSite cloudSite, CloudIdentity cloudIdentity,
+            CloudInformation cloudInformation) {
+        return new HeatBridgeImpl(client, cloudIdentity, cloudInformation.getOwner(), cloudInformation.getRegionId(),
+                cloudSite.getRegionId(), cloudInformation.getTenantId(), cloudInformation.getNodeType());
+    }
+
     protected AAIResourcesClient getAaiClient() {
         if (aaiClient == null)
             return new AAIResourcesClient();
index 9b20139..0512912 100644 (file)
@@ -61,9 +61,8 @@ import org.onap.aai.domain.yang.Pserver;
 import org.onap.aai.domain.yang.Relationship;
 import org.onap.aai.domain.yang.RelationshipList;
 import org.onap.aai.domain.yang.SriovPf;
-import org.onap.aai.domain.yang.Subnets;
 import org.onap.aai.domain.yang.SriovVf;
-import org.onap.aai.domain.yang.VfModule;
+import org.onap.aai.domain.yang.Subnets;
 import org.onap.aai.domain.yang.Vlan;
 import org.onap.aai.domain.yang.Vserver;
 import org.onap.aaiclient.client.aai.AAIDSLQueryClient;
@@ -734,27 +733,15 @@ public class HeatBridgeImpl implements HeatBridgeApi {
         Objects.requireNonNull(vnfId, "Null vnf-id!");
         Objects.requireNonNull(vfModuleId, "Null vf-module-id!");
         try {
-            Optional<VfModule> vfModule = resourcesClient.get(AAIUriFactory
+            AAIResultWrapper vfModule = resourcesClient.get(AAIUriFactory
                     .createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId))
-                    .depth(Depth.ONE), NotFoundException.class).asBean(VfModule.class);
+                    .depth(Depth.ONE), NotFoundException.class);
 
-            AAIResultWrapper resultWrapper = new AAIResultWrapper(vfModule.get());
-            Optional<Relationships> relationships = resultWrapper.getRelationships();
+            Optional<Relationships> relationships = vfModule.getRelationships();
             logger.debug("VfModule contains relationships in AAI: {}", relationships.isPresent());
             if (relationships.isPresent()) {
 
-                List<AAIResourceUri> l3NetworkUris = relationships.get().getRelatedUris(Types.L3_NETWORK);
-                logger.debug("L3Network contains {} relationships in AAI", l3NetworkUris.size());
-
-                if (!l3NetworkUris.isEmpty()) {
-                    for (AAIResourceUri l3NetworkUri : l3NetworkUris) {
-                        if (env.getProperty("heatBridgeDryrun", Boolean.class, true)) {
-                            logger.debug("Would delete L3Network: {}", l3NetworkUri.build().toString());
-                        } else {
-                            resourcesClient.delete(l3NetworkUri);
-                        }
-                    }
-                }
+                deleteL3Networks(relationships.get());
 
                 List<AAIResourceUri> vserverUris = relationships.get().getRelatedUris(Types.VSERVER);
                 logger.debug("VServer contains {} relationships in AAI", vserverUris.size());
@@ -782,6 +769,21 @@ public class HeatBridgeImpl implements HeatBridgeApi {
         }
     }
 
+    protected void deleteL3Networks(Relationships relationships) {
+        List<AAIResourceUri> l3NetworkUris = relationships.getRelatedUris(Types.L3_NETWORK);
+        logger.debug("L3Network contains {} relationships in AAI", l3NetworkUris.size());
+
+        if (!l3NetworkUris.isEmpty()) {
+            for (AAIResourceUri l3NetworkUri : l3NetworkUris) {
+                if (env.getProperty("heatBridgeDryrun", Boolean.class, true)) {
+                    logger.debug("Would delete L3Network: {}", l3NetworkUri.build().toString());
+                } else {
+                    resourcesClient.delete(l3NetworkUri);
+                }
+            }
+        }
+    }
+
     private void createTransactionToDeleteSriovPfFromPserver(List<AAIResourceUri> vserverUris) {
         Map<String, List<String>> pserverToPciIdMap = getPserverToPciIdMap(vserverUris);
         for (Map.Entry<String, List<String>> entry : pserverToPciIdMap.entrySet()) {