Skip to content
Merged
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
30 changes: 18 additions & 12 deletions server/src/main/java/com/cloud/server/ManagementServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1172,8 +1172,8 @@ public Pair<List<? extends Host>, Integer> searchForServers(final ListHostsCmd c
final Object resourceState = cmd.getResourceState();
final Object haHosts = cmd.getHaHost();

final Pair<List<HostVO>, Integer> result = searchForServers(cmd.getStartIndex(), cmd.getPageSizeVal(), name, type, state, zoneId, pod, cluster, id, keyword, resourceState, haHosts, null,
null);
final Pair<List<HostVO>, Integer> result = searchForServers(cmd.getStartIndex(), cmd.getPageSizeVal(), name, type, state, zoneId, pod,
cluster, id, keyword, resourceState, haHosts, null, null);
return new Pair<List<? extends Host>, Integer>(result.first(), result.second());
}

Expand Down Expand Up @@ -1275,19 +1275,20 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho
final Type hostType = srcHost.getType();
Pair<List<HostVO>, Integer> allHostsPair = null;
List<HostVO> allHosts = null;
List<HostVO> hostsForMigrationWithStorage = null;
final Map<Host, Boolean> requiresStorageMotion = new HashMap<Host, Boolean>();
DataCenterDeployment plan = null;
if (canMigrateWithStorage) {
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), null, null, null, keyword, null, null, srcHost.getHypervisorType(),
srcHost.getHypervisorVersion());
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), null, null, null, keyword,
null, null, srcHost.getHypervisorType(), srcHost.getHypervisorVersion(), srcHost.getId());
allHosts = allHostsPair.first();
allHosts.remove(srcHost);
hostsForMigrationWithStorage = new ArrayList<>(allHosts);

for (final VolumeVO volume : volumes) {
StoragePool storagePool = _poolDao.findById(volume.getPoolId());
Long volClusterId = storagePool.getClusterId();

for (Iterator<HostVO> iterator = allHosts.iterator(); iterator.hasNext();) {
for (Iterator<HostVO> iterator = hostsForMigrationWithStorage.iterator(); iterator.hasNext();) {
final Host host = iterator.next();

if (volClusterId != null) {
Expand Down Expand Up @@ -1326,10 +1327,9 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho
if (s_logger.isDebugEnabled()) {
s_logger.debug("Searching for all hosts in cluster " + cluster + " for migrating VM " + vm);
}
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, keyword, null, null, null, null);
// Filter out the current host.
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, null, null, cluster, null, keyword, null, null, null,
null, srcHost.getId());
allHosts = allHostsPair.first();
allHosts.remove(srcHost);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidjumani didn't see any change with respect to hosts count, does these changes fix the count issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does since I've added an excludes param in the searchForServers method and passing the source host ID to it. This excludes the source host in the query, as well as ensures that the allHosts list is never altered. So the count remains consistant but unsuitable hosts are marked accordingly

plan = new DataCenterDeployment(srcHost.getDataCenterId(), srcHost.getPodId(), srcHost.getClusterId(), null, null, null);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidjumani can you check if otherHosts here is not required as there is no change in the allHosts & its count, which you can return as it is (as a List), instead of Pair (with count). You can use use the allHosts count wherever applicable.

Copy link
Contributor Author

@davidjumani davidjumani Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed here since the data type is different Pair<List<HostVO>, Integer> vs Pair<List<? extends Host>, Integer>. Also the allHostsPair contains the total count of servers whereas the allHosts lists contains only those in the specified page / pagesize

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for confirming that @davidjumani

Expand Down Expand Up @@ -1358,7 +1358,7 @@ public Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Ho

for (final HostAllocator allocator : hostAllocators) {
if (canMigrateWithStorage) {
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, excludes, allHosts, HostAllocator.RETURN_UPTO_ALL, false);
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, excludes, hostsForMigrationWithStorage, HostAllocator.RETURN_UPTO_ALL, false);
} else {
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, excludes, HostAllocator.RETURN_UPTO_ALL, false);
}
Expand Down Expand Up @@ -1550,12 +1550,14 @@ private List<StoragePool> findAllSuitableStoragePoolsForVm(final VolumeVO volume
return suitablePools;
}

private Pair<List<HostVO>, Integer> searchForServers(final Long startIndex, final Long pageSize, final Object name, final Object type, final Object state, final Object zone, final Object pod,
final Object cluster, final Object id, final Object keyword, final Object resourceState, final Object haHosts, final Object hypervisorType, final Object hypervisorVersion) {
private Pair<List<HostVO>, Integer> searchForServers(final Long startIndex, final Long pageSize, final Object name, final Object type,
final Object state, final Object zone, final Object pod, final Object cluster, final Object id, final Object keyword,
final Object resourceState, final Object haHosts, final Object hypervisorType, final Object hypervisorVersion, final Object... excludes) {
final Filter searchFilter = new Filter(HostVO.class, "id", Boolean.TRUE, startIndex, pageSize);

final SearchBuilder<HostVO> sb = _hostDao.createSearchBuilder();
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("idsNotIn", sb.entity().getId(), SearchCriteria.Op.NOTIN);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.LIKE);
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
Expand Down Expand Up @@ -1596,6 +1598,10 @@ private Pair<List<HostVO>, Integer> searchForServers(final Long startIndex, fina
sc.setParameters("id", id);
}

if (excludes != null && excludes.length > 0) {
sc.setParameters("idsNotIn", excludes);
}

if (name != null) {
sc.setParameters("name", "%" + name + "%");
}
Expand Down