This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.20 by this push:
new 603cd84b494 server: fix available hypervisors listing for a zone
(#10738)
603cd84b494 is described below
commit 603cd84b49428c08fae50470c8c69a66468b53fe
Author: Abhishek Kumar <[email protected]>
AuthorDate: Thu Apr 24 09:51:32 2025 +0530
server: fix available hypervisors listing for a zone (#10738)
* server: fix available hypervisors listing for a zone
In the absence of a SYSTEM type template for a zone, listing of
templates can break.
Behaviour was change in #9840 but it would be better to find available
hypervisors using existing hosts.
* fix
Signed-off-by: Abhishek Kumar <[email protected]>
---------
Signed-off-by: Abhishek Kumar <[email protected]>
---
.../java/com/cloud/resource/ResourceManagerImpl.java | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
index 3414ed6651e..1ae214e3c16 100755
--- a/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
@@ -32,7 +32,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
-import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
@@ -60,10 +59,8 @@ import
org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
-
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ObjectUtils;
-
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
@@ -175,6 +172,7 @@ import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
+import com.cloud.utils.StringUtils;
import com.cloud.utils.Ternary;
import com.cloud.utils.UriUtils;
import com.cloud.utils.component.Manager;
@@ -201,7 +199,6 @@ import com.cloud.utils.net.NetUtils;
import com.cloud.utils.ssh.SSHCmdHelper;
import com.cloud.utils.ssh.SshException;
import com.cloud.vm.UserVmManager;
-import com.cloud.utils.StringUtils;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
@@ -3266,12 +3263,16 @@ public class ResourceManagerImpl extends ManagerBase
implements ResourceManager,
@Override
public List<HypervisorType> listAvailHypervisorInZone(final Long zoneId) {
- List<VMTemplateVO> systemVMTemplates =
_templateDao.listAllReadySystemVMTemplates(zoneId);
- final Set<HypervisorType> hypervisors = new HashSet<>();
- for (final VMTemplateVO systemVMTemplate : systemVMTemplates) {
- hypervisors.add(systemVMTemplate.getHypervisorType());
+ final SearchCriteria<String> sc = _hypervisorsInDC.create();
+ if (zoneId != null) {
+ sc.setParameters("dataCenter", zoneId);
}
- return new ArrayList<>(hypervisors);
+ sc.setParameters("type", Host.Type.Routing);
+
+ return _hostDao.customSearch(sc, null).stream()
+ // The search is not able to return list of enums, so getting
+ // list of hypervisors as strings and then converting them to
enum
+ .map(HypervisorType::getType).collect(Collectors.toList());
}
@Override