Skip to content

Commit 5af702d

Browse files
committed
CLOUDSTACK-2737: findHostsForMigration is resulting in an exception when there are no suitable tagged storage pools. Instead of a foreach made changes to use a iterator in the loop to avoid ConcurrentModificationException as the host list is being updated inside the loop.
1 parent 0a9b9f7 commit 5af702d

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Date;
3131
import java.util.HashMap;
3232
import java.util.HashSet;
33+
import java.util.Iterator;
3334
import java.util.List;
3435
import java.util.Map;
3536
import java.util.Set;
@@ -373,15 +374,6 @@
373374
import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd;
374375
import org.apache.cloudstack.api.command.user.vmsnapshot.RevertToVMSnapshotCmd;
375376
import org.apache.cloudstack.api.command.user.volume.*;
376-
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
377-
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
378-
import org.apache.cloudstack.api.command.user.volume.DeleteVolumeCmd;
379-
import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
380-
import org.apache.cloudstack.api.command.user.volume.ExtractVolumeCmd;
381-
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
382-
import org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd;
383-
import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
384-
import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
385377
import org.apache.cloudstack.api.command.user.vpc.CreateStaticRouteCmd;
386378
import org.apache.cloudstack.api.command.user.vpc.CreateVPCCmd;
387379
import org.apache.cloudstack.api.command.user.vpc.DeleteStaticRouteCmd;
@@ -1184,10 +1176,11 @@ public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
11841176
allHosts.remove(srcHost);
11851177

11861178
// Check if the host has storage pools for all the volumes of the vm to be migrated.
1187-
for (Host host : allHosts) {
1179+
for (Iterator<HostVO> iterator = allHosts.iterator(); iterator.hasNext();) {
1180+
Host host = iterator.next();
11881181
Map<Volume, List<StoragePool>> volumePools = findSuitablePoolsForVolumes(vmProfile, host);
11891182
if (volumePools.isEmpty()) {
1190-
allHosts.remove(host);
1183+
iterator.remove();
11911184
} else {
11921185
if (!host.getClusterId().equals(srcHost.getClusterId()) || usesLocal) {
11931186
requiresStorageMotion.put(host, true);

0 commit comments

Comments
 (0)