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


##########
framework/extensions/src/main/java/org/apache/cloudstack/framework/extensions/manager/ExtensionsManagerImpl.java:
##########
@@ -1765,4 +2433,101 @@ protected void runInContext() {
             }
         }
     }
+
+    @Override
+    public String getExtensionScriptPath(Extension extension) {
+        if (extension == null) {
+            return null;
+        }
+        return 
externalProvisioner.getExtensionPath(extension.getRelativePath());
+    }
+
+    @Override
+    public Extension getExtensionForPhysicalNetworkAndProvider(long 
physicalNetworkId, String providerName) {
+        if (StringUtils.isBlank(providerName)) {
+            return null;
+        }
+        List<ExtensionResourceMapVO> maps = 
extensionResourceMapDao.listByResourceIdAndType(
+                physicalNetworkId, 
ExtensionResourceMap.ResourceType.PhysicalNetwork);
+        if (maps == null || maps.isEmpty()) {
+            return null;
+        }
+        for (ExtensionResourceMapVO map : maps) {
+            ExtensionVO ext = extensionDao.findById(map.getExtensionId());
+            if (ext != null && providerName.equalsIgnoreCase(ext.getName())) {
+                return ext;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public Map<String, String> 
getAllResourceMapDetailsForExtensionOnPhysicalNetwork(long physicalNetworkId, 
long extensionId) {
+        List<ExtensionResourceMapVO> maps = 
extensionResourceMapDao.listByResourceIdAndType(
+                physicalNetworkId, 
ExtensionResourceMap.ResourceType.PhysicalNetwork);
+        if (maps == null || maps.isEmpty()) {
+            return new HashMap<>();
+        }
+        for (ExtensionResourceMapVO map : maps) {
+            if (map.getExtensionId() == extensionId) {
+                Map<String, String> details = 
extensionResourceMapDetailsDao.listDetailsKeyPairs(map.getId());
+                return details != null ? details : new HashMap<>();
+            }
+        }
+        return new HashMap<>();
+    }
+
+    @Override
+    public boolean isNetworkExtensionProvider(String providerName) {
+        if (StringUtils.isBlank(providerName)) {
+            return false;
+        }
+        List<ExtensionVO> networkOrchExtensions = 
extensionDao.listByType(Extension.Type.NetworkOrchestrator);
+        if (networkOrchExtensions == null || networkOrchExtensions.isEmpty()) {
+            return false;
+        }
+        return networkOrchExtensions.stream()
+                .anyMatch(ext -> providerName.equalsIgnoreCase(ext.getName()));
+    }
+
+    @Override
+    public List<Extension> listExtensionsByType(Extension.Type type) {
+        if (type == null) {
+            return new ArrayList<>();
+        }
+        List<ExtensionVO> extensions = extensionDao.listByType(type);
+        if (extensions == null || extensions.isEmpty()) {
+            return new ArrayList<>();
+        }
+        return new ArrayList<>(extensions);
+    }
+
+    @Override
+    public Map<Service, Map<Capability, String>> 
getNetworkCapabilitiesForProvider(Long physicalNetworkId,
+            String providerName) {
+        if (StringUtils.isBlank(providerName)) {
+            return new HashMap<>();
+        }
+        Extension extension = null;
+        if (physicalNetworkId != null) {
+            extension = 
getExtensionForPhysicalNetworkAndProvider(physicalNetworkId, providerName);
+        }
+        if (extension == null) {
+            // Search across all physical networks
+            List<ExtensionVO> networkOrchExtensions = 
extensionDao.listByType(Extension.Type.NetworkOrchestrator);
+            if (networkOrchExtensions != null) {
+                for (ExtensionVO ext : networkOrchExtensions) {
+                    if (providerName.equalsIgnoreCase(ext.getName())) {
+                        extension = ext;
+                        break;
+                    }
+                }

Review Comment:
   :+1: 



-- 
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