2323import java .security .SecureRandom ;
2424import java .util .ArrayList ;
2525import java .util .Calendar ;
26+ import java .util .Collection ;
2627import java .util .Comparator ;
2728import java .util .Date ;
2829import java .util .HashMap ;
148149import org .apache .cloudstack .api .command .admin .storage .CancelPrimaryStorageMaintenanceCmd ;
149150import org .apache .cloudstack .api .command .admin .storage .CreateSecondaryStagingStoreCmd ;
150151import org .apache .cloudstack .api .command .admin .storage .CreateStoragePoolCmd ;
151- import org .apache .cloudstack .api .command .admin .storage .DeleteSecondaryStagingStoreCmd ;
152152import org .apache .cloudstack .api .command .admin .storage .DeleteImageStoreCmd ;
153153import org .apache .cloudstack .api .command .admin .storage .DeletePoolCmd ;
154+ import org .apache .cloudstack .api .command .admin .storage .DeleteSecondaryStagingStoreCmd ;
154155import org .apache .cloudstack .api .command .admin .storage .FindStoragePoolsForMigrationCmd ;
155- import org .apache .cloudstack .api .command .admin .storage .ListSecondaryStagingStoresCmd ;
156156import org .apache .cloudstack .api .command .admin .storage .ListImageStoresCmd ;
157157import org .apache .cloudstack .api .command .admin .storage .ListS3sCmd ;
158+ import org .apache .cloudstack .api .command .admin .storage .ListSecondaryStagingStoresCmd ;
158159import org .apache .cloudstack .api .command .admin .storage .ListStoragePoolsCmd ;
159160import org .apache .cloudstack .api .command .admin .storage .ListStorageProvidersCmd ;
160161import org .apache .cloudstack .api .command .admin .storage .PreparePrimaryStorageForMaintenanceCmd ;
@@ -1094,6 +1095,7 @@ public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
10941095 List <HostVO > allHosts = null ;
10951096 Map <Host , Boolean > requiresStorageMotion = new HashMap <Host , Boolean >();
10961097 DataCenterDeployment plan = null ;
1098+ boolean zoneWideStoragePool = false ;
10971099 if (canMigrateWithStorage ) {
10981100 allHostsPair = searchForServers (startIndex , pageSize , null , hostType , null , srcHost .getDataCenterId (), null ,
10991101 null , null , null , null , null , srcHost .getHypervisorType (), srcHost .getHypervisorVersion ());
@@ -1107,7 +1109,10 @@ public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
11071109 if (volumePools .isEmpty ()) {
11081110 iterator .remove ();
11091111 } else {
1110- if (!host .getClusterId ().equals (srcHost .getClusterId ()) || usesLocal ) {
1112+ if (srcHost .getHypervisorType () == HypervisorType .VMware || srcHost .getHypervisorType () == HypervisorType .KVM ) {
1113+ zoneWideStoragePool = checkForZoneWideStoragePool (volumePools );
1114+ }
1115+ if ((!host .getClusterId ().equals (srcHost .getClusterId ()) || usesLocal ) && !zoneWideStoragePool ) {
11111116 requiresStorageMotion .put (host , true );
11121117 }
11131118 }
@@ -1169,6 +1174,22 @@ public Pair<List<? extends Host>, Integer> searchForServers(ListHostsCmd cmd) {
11691174 suitableHosts , requiresStorageMotion );
11701175 }
11711176
1177+ private boolean checkForZoneWideStoragePool (Map <Volume , List <StoragePool >> volumePools ) {
1178+ boolean zoneWideStoragePool = false ;
1179+ Collection <List <StoragePool >> pools = volumePools .values ();
1180+ List <StoragePool > aggregatePoolList = new ArrayList <StoragePool >();
1181+ for (Iterator <List <StoragePool >> volumePoolsIter = pools .iterator (); volumePoolsIter .hasNext ();) {
1182+ aggregatePoolList .addAll (volumePoolsIter .next ());
1183+ }
1184+ for (StoragePool pool : aggregatePoolList ) {
1185+ if (null == pool .getClusterId ()) {
1186+ zoneWideStoragePool = true ;
1187+ break ;
1188+ }
1189+ }
1190+ return zoneWideStoragePool ;
1191+ }
1192+
11721193 private Map <Volume , List <StoragePool >> findSuitablePoolsForVolumes (VirtualMachineProfile vmProfile ,
11731194 Host host ) {
11741195 List <VolumeVO > volumes = _volumeDao .findCreatedByInstance (vmProfile .getId ());
0 commit comments