Skip to content

Commit daac0d9

Browse files
committed
fix for cluster arch change
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent f58253c commit daac0d9

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

engine/schema/src/main/java/com/cloud/host/dao/HostDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,7 @@ List<Long> findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(final Long
197197

198198
List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorArchTypes(final Long zoneId);
199199

200+
List<CPU.CPUArch> listDistinctArchTypes(final Long clusterId);
201+
200202
List<HostVO> listByIds(final List<Long> ids);
201203
}

engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,21 @@ public List<Pair<HypervisorType, CPU.CPUArch>> listDistinctHypervisorArchTypes(f
17751775
.collect(Collectors.toList());
17761776
}
17771777

1778+
@Override
1779+
public List<CPU.CPUArch> listDistinctArchTypes(final Long clusterId) {
1780+
GenericSearchBuilder<HostVO, CPU.CPUArch> sb = createSearchBuilder(CPU.CPUArch.class);
1781+
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
1782+
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
1783+
sb.select(null, Func.DISTINCT, sb.entity().getHypervisorType());
1784+
sb.done();
1785+
SearchCriteria<CPU.CPUArch> sc = sb.create();
1786+
if (clusterId != null) {
1787+
sc.setParameters("clusterId", clusterId);
1788+
}
1789+
sc.setParameters("type", Type.Routing);
1790+
return customSearch(sc, null);
1791+
}
1792+
17781793
@Override
17791794
public List<HostVO> listByIds(List<Long> ids) {
17801795
if (CollectionUtils.isEmpty(ids)) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,12 @@ public Cluster updateCluster(UpdateClusterCmd cmd) {
12151215
}
12161216

12171217
if (arch != null) {
1218+
List<CPU.CPUArch> archTypes = _hostDao.listDistinctArchTypes(cluster.getId());
1219+
if (archTypes.stream().anyMatch(a -> !a.equals(arch))) {
1220+
throw new InvalidParameterValueException(String.format(
1221+
"Cluster has host(s) present with arch type(s): %s",
1222+
StringUtils.join(archTypes.stream().map(CPU.CPUArch::getType).toArray())));
1223+
}
12181224
cluster.setArch(arch.getType());
12191225
doUpdate = true;
12201226
}

0 commit comments

Comments
 (0)