Skip to content

Commit 431df14

Browse files
shwstpprdhslove
authored andcommitted
server: fix available hypervisors listing for a zone (apache#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 apache#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]>
1 parent 6c8e2cf commit 431df14

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Locale;
3333
import java.util.Map;
3434
import java.util.Random;
35-
import java.util.Set;
3635
import java.util.stream.Collectors;
3736

3837
import javax.inject.Inject;
@@ -60,7 +59,6 @@
6059
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
6160
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
6261
import org.apache.cloudstack.utils.identity.ManagementServerNode;
63-
6462
import org.apache.commons.collections.CollectionUtils;
6563
import org.apache.commons.lang.ObjectUtils;
6664
import org.springframework.stereotype.Component;
@@ -176,6 +174,7 @@
176174
import com.cloud.storage.dao.VolumeDao;
177175
import com.cloud.user.Account;
178176
import com.cloud.user.AccountManager;
177+
import com.cloud.utils.StringUtils;
179178
import com.cloud.utils.Ternary;
180179
import com.cloud.utils.UriUtils;
181180
import com.cloud.utils.component.Manager;
@@ -202,7 +201,6 @@
202201
import com.cloud.utils.ssh.SSHCmdHelper;
203202
import com.cloud.utils.ssh.SshException;
204203
import com.cloud.vm.UserVmManager;
205-
import com.cloud.utils.StringUtils;
206204
import com.cloud.vm.VMInstanceVO;
207205
import com.cloud.vm.VirtualMachine;
208206
import com.cloud.vm.VirtualMachine.State;
@@ -3288,12 +3286,16 @@ public List<HostVO> listAllHostsInAllZonesByType(final Type type) {
32883286

32893287
@Override
32903288
public List<HypervisorType> listAvailHypervisorInZone(final Long zoneId) {
3291-
List<VMTemplateVO> systemVMTemplates = _templateDao.listAllReadySystemVMTemplates(zoneId);
3292-
final Set<HypervisorType> hypervisors = new HashSet<>();
3293-
for (final VMTemplateVO systemVMTemplate : systemVMTemplates) {
3294-
hypervisors.add(systemVMTemplate.getHypervisorType());
3289+
final SearchCriteria<String> sc = _hypervisorsInDC.create();
3290+
if (zoneId != null) {
3291+
sc.setParameters("dataCenter", zoneId);
32953292
}
3296-
return new ArrayList<>(hypervisors);
3293+
sc.setParameters("type", Host.Type.Routing);
3294+
3295+
return _hostDao.customSearch(sc, null).stream()
3296+
// The search is not able to return list of enums, so getting
3297+
// list of hypervisors as strings and then converting them to enum
3298+
.map(HypervisorType::getType).collect(Collectors.toList());
32973299
}
32983300

32993301
@Override

0 commit comments

Comments
 (0)