Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface ClusterDao extends GenericDao<ClusterVO, Long> {

List<HypervisorType> getAvailableHypervisorInZone(Long zoneId);

List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorsArchAcrossClusters(Long zoneId);
List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorsAndArchExcludingExternalType(Long zoneId);

List<ClusterVO> listByDcHyType(long dcId, String hyType);

Expand Down
12 changes: 11 additions & 1 deletion engine/schema/src/main/java/com/cloud/dc/dao/ClusterDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,26 @@ public List<HypervisorType> getAvailableHypervisorInZone(Long zoneId) {
.collect(Collectors.toList());
}

/**
* Returns distinct (HypervisorType, CPUArch) pairs from clusters in the given zone,
* excluding clusters with {@link HypervisorType#External}.
*
* @param zoneId the zone ID to filter by, or {@code null} to include all zones
* @return list of unique hypervisor type and CPU architecture pairs
*/
@Override
public List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorsArchAcrossClusters(Long zoneId) {
public List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorsAndArchExcludingExternalType(Long zoneId) {
SearchBuilder<ClusterVO> sb = createSearchBuilder();
sb.select(null, Func.DISTINCT_PAIR, sb.entity().getHypervisorType(), sb.entity().getArch());
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.NEQ);
sb.done();
SearchCriteria<ClusterVO> sc = sb.create();
if (zoneId != null) {
sc.setParameters("zoneId", zoneId);
}
sc.setParameters("hypervisorType", HypervisorType.External);

final List<ClusterVO> clusters = search(sc, null);
return clusters.stream()
.map(c -> new Pair<>(c.getHypervisorType(), c.getArch()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ protected void registerTemplatesForZone(long zoneId, String filePath) {
String nfsVersion = getNfsVersion(storeUrlAndId.second());
mountStore(storeUrlAndId.first(), filePath, nfsVersion);
List<Pair<Hypervisor.HypervisorType, CPU.CPUArch>> hypervisorArchList =
clusterDao.listDistinctHypervisorsArchAcrossClusters(zoneId);
clusterDao.listDistinctHypervisorsAndArchExcludingExternalType(zoneId);
for (Pair<Hypervisor.HypervisorType, CPU.CPUArch> hypervisorArch : hypervisorArchList) {
Hypervisor.HypervisorType hypervisorType = hypervisorArch.first();
MetadataTemplateDetails templateDetails = getMetadataTemplateDetails(hypervisorType,
Expand Down Expand Up @@ -1065,7 +1065,7 @@ public void updateSystemVmTemplates(final Connection conn) {
public void doInTransactionWithoutResult(final TransactionStatus status) {
List<Pair<Hypervisor.HypervisorType, CPU.CPUArch>> hypervisorsInUse;
try {
hypervisorsInUse = clusterDao.listDistinctHypervisorsArchAcrossClusters(null);
hypervisorsInUse = clusterDao.listDistinctHypervisorsAndArchExcludingExternalType(null);
} catch (final Exception e) {
throw new CloudRuntimeException("Exception while getting hypervisor types from clusters", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void listDistinctHypervisorsArchAcrossClusters_WithZone() {
when(cluster2.getArch()).thenReturn(CPU.CPUArch.arm64);
List<ClusterVO> dummyHosts = Arrays.asList(cluster1, cluster2);
doReturn(dummyHosts).when(clusterDao).search(any(SearchCriteria.class), isNull());
List<Pair<Hypervisor.HypervisorType, CPU.CPUArch>> result = clusterDao.listDistinctHypervisorsArchAcrossClusters(zoneId);
List<Pair<Hypervisor.HypervisorType, CPU.CPUArch>> result = clusterDao.listDistinctHypervisorsAndArchExcludingExternalType(zoneId);
assertNotNull(result);
assertEquals(2, result.size());
assertEquals(Hypervisor.HypervisorType.XenServer, result.get(0).first());
Expand All @@ -109,7 +109,7 @@ public void listDistinctHypervisorsArchAcrossClusters_WithoutZone() {
when(cluster.getArch()).thenReturn(CPU.CPUArch.amd64);
List<ClusterVO> dummyHosts = Collections.singletonList(cluster);
doReturn(dummyHosts).when(clusterDao).search(any(SearchCriteria.class), isNull());
List<Pair<Hypervisor.HypervisorType, CPU.CPUArch>> result = clusterDao.listDistinctHypervisorsArchAcrossClusters(zoneId);
List<Pair<Hypervisor.HypervisorType, CPU.CPUArch>> result = clusterDao.listDistinctHypervisorsAndArchExcludingExternalType(zoneId);
assertNotNull(result);
assertEquals(1, result.size());
assertEquals(Hypervisor.HypervisorType.VMware, result.get(0).first());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void testRegisterTemplatesForZone() {
Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.KVM;
CPU.CPUArch arch = CPU.CPUArch.getDefault();
hypervisorArchList.add(new Pair<>(hypervisorType, arch));
doReturn(hypervisorArchList).when(clusterDao).listDistinctHypervisorsArchAcrossClusters(zoneId);
doReturn(hypervisorArchList).when(clusterDao).listDistinctHypervisorsAndArchExcludingExternalType(zoneId);
SystemVmTemplateRegistration.MetadataTemplateDetails details =
Mockito.mock(SystemVmTemplateRegistration.MetadataTemplateDetails.class);
String name = "existing";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4029,7 +4029,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
DataStoreRole.Image, store.getId());
if (CollectionUtils.isEmpty(stores)) {
List<Pair<HypervisorType, CPU.CPUArch>> hypervisorTypes =
_clusterDao.listDistinctHypervisorsArchAcrossClusters(zoneId);
_clusterDao.listDistinctHypervisorsAndArchExcludingExternalType(zoneId);
TransactionLegacy txn = TransactionLegacy.open("AutomaticTemplateRegister");
SystemVmTemplateRegistration systemVmTemplateRegistration = new SystemVmTemplateRegistration();
String filePath = null;
Expand Down
Loading