weizhouapache commented on code in PR #13032:
URL: https://github.com/apache/cloudstack/pull/13032#discussion_r3334383153


##########
framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImpl.java:
##########
@@ -965,6 +1403,55 @@ public void unregisterExtensionWithCluster(Cluster 
cluster, Long extensionId) {
         }
     }
 
+    protected void unregisterExtensionWithPhysicalNetwork(String resourceId, 
Long extensionId) {
+        PhysicalNetworkVO physicalNetwork = 
physicalNetworkDao.findByUuid(resourceId);
+        if (physicalNetwork == null) {
+            try {
+                physicalNetwork = 
physicalNetworkDao.findById(Long.parseLong(resourceId));
+            } catch (NumberFormatException ignored) {
+            }
+        }
+        if (physicalNetwork == null) {
+            throw new InvalidParameterValueException("Invalid physical network 
ID specified");
+        }
+        // Find the specific map entry for this extension+physical-network 
combination
+        List<ExtensionResourceMapVO> existingList = 
extensionResourceMapDao.listByResourceIdAndType(
+                physicalNetwork.getId(), 
ExtensionResourceMap.ResourceType.PhysicalNetwork);
+        if (existingList == null || existingList.isEmpty()) {
+            return;
+        }
+        final long physNetId = physicalNetwork.getId();
+        for (ExtensionResourceMapVO existing : existingList) {
+            if (extensionId == null || existing.getExtensionId() == 
extensionId) {
+                ExtensionVO ext = 
extensionDao.findById(existing.getExtensionId());
+                if (ext != null) {
+                    List<NetworkVO> networksUsingProvider = 
networkDao.listByPhysicalNetworkAndProvider(
+                            physNetId, ext.getName());
+                    if (CollectionUtils.isNotEmpty(networksUsingProvider)) {
+                        throw new CloudRuntimeException(String.format(
+                                "Cannot unregister extension '%s' from 
physical network %s. "
+                                        + "Provider is used by %d existing 
network service(s)",
+                                ext.getName(), physNetId, 
networksUsingProvider.size()));

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to