CLOUDSTACK-4572: findHostsForMigration API does not return correct host list
Changes: Expected behavior: The api should return the list of suitable/unsuitable hosts Added fix that creates a deep copy of the the variable allHosts and prevents faulty host list return. (cherry picked from commit 6354604eedff0c5f4ddef4940ce02df80adb656c) Signed-off-by: animesh <anim...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/eb85ff6f Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/eb85ff6f Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/eb85ff6f Branch: refs/heads/4.2 Commit: eb85ff6f3bf783700f26ccac640024394a9360a5 Parents: 92f2360 Author: Saksham Srivastava <saksham.srivast...@citrix.com> Authored: Fri Aug 30 12:30:41 2013 -0700 Committer: animesh <anim...@apache.org> Committed: Tue Sep 3 16:25:49 2013 -0700 ---------------------------------------------------------------------- server/src/com/cloud/server/ManagementServerImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb85ff6f/server/src/com/cloud/server/ManagementServerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 3341c05..8437c99 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -1161,8 +1161,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe null, null, null); } - Pair<List<? extends Host>, Integer> otherHosts = new Pair<List <? extends Host>, Integer>(allHosts, - new Integer(allHosts.size())); + //'otherHosts' must use the current value of allHosts as allHosts may get modified later in the allocator + List<HostVO> allHostsCpy = new ArrayList<HostVO>(allHosts); + Pair<List<? extends Host>, Integer> otherHosts = new Pair<List <? extends Host>, Integer>(allHostsCpy, + new Integer(allHostsCpy.size())); List<Host> suitableHosts = new ArrayList<Host>(); ExcludeList excludes = new ExcludeList(); excludes.addHost(srcHostId);