mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-6830: Fixed during VM migration, volumes on zone wide primary store
requires storage migration resulting in failure of VM migration. This also improves the hostsformigration api. Firstly we were trying to list all hosts and then finding suitable storage pools for all volumes and then we were checking whether vm migration requires storage migration to that host. Now the process is updated. We are checking for only those volumes which are not in zone wide primary store. We are verifying by comparing volumes->poolid->clusterid to host clusterid. If it uses local or clusterids are different then verifying whether host has suitable storage pools for the volume of the vm to be migrated too.
This commit is contained in:
parent
918c320438
commit
450d890942
|
|
@ -41,6 +41,8 @@ import javax.ejb.Local;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||
|
|
@ -69,7 +71,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
|||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
import org.apache.cloudstack.utils.identity.ManagementServerNode;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.Listener;
|
||||
|
|
@ -160,6 +161,7 @@ import com.cloud.resource.ResourceManager;
|
|||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.ScopeType;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.Volume;
|
||||
|
|
@ -1827,8 +1829,16 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||
}
|
||||
|
||||
if (fromHost.getClusterId().longValue() != dest.getCluster().getId()) {
|
||||
s_logger.info("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId());
|
||||
throw new CloudRuntimeException("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId());
|
||||
List<VolumeVO> volumes = _volsDao.findCreatedByInstance(vm.getId());
|
||||
for (VolumeVO volume : volumes) {
|
||||
if (!(_storagePoolDao.findById(volume.getPoolId())).getScope().equals(ScopeType.ZONE)) {
|
||||
s_logger.info("Source and destination host are not in same cluster and all volumes are not on zone wide primary store, unable to migrate to host: "
|
||||
+ dest.getHost().getId());
|
||||
throw new CloudRuntimeException(
|
||||
"Source and destination host are not in same cluster and all volumes are not on zone wide primary store, unable to migrate to host: "
|
||||
+ dest.getHost().getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VirtualMachineGuru vmGuru = getVmGuru(vm);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import java.lang.reflect.Field;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
|
|
@ -38,6 +37,9 @@ import javax.crypto.spec.SecretKeySpec;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
|
|
@ -507,8 +509,6 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
|||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.utils.identity.ManagementServerNode;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.GetVncPortAnswer;
|
||||
|
|
@ -1171,29 +1171,28 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
List<HostVO> allHosts = null;
|
||||
Map<Host, Boolean> requiresStorageMotion = new HashMap<Host, Boolean>();
|
||||
DataCenterDeployment plan = null;
|
||||
boolean zoneWideStoragePool = false;
|
||||
|
||||
if (canMigrateWithStorage) {
|
||||
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), null, null, null, null, null, null, srcHost.getHypervisorType(),
|
||||
srcHost.getHypervisorVersion());
|
||||
allHostsPair = searchForServers(startIndex, pageSize, null, hostType, null, srcHost.getDataCenterId(), null, null, null, null, null, null,
|
||||
srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
|
||||
allHosts = allHostsPair.first();
|
||||
allHosts.remove(srcHost);
|
||||
|
||||
// Check if the host has storage pools for all the volumes of the vm to be migrated.
|
||||
for (Iterator<HostVO> iterator = allHosts.iterator(); iterator.hasNext();) {
|
||||
Host host = iterator.next();
|
||||
Map<Volume, List<StoragePool>> volumePools = findSuitablePoolsForVolumes(vmProfile, host);
|
||||
if (volumePools.isEmpty()) {
|
||||
iterator.remove();
|
||||
} else {
|
||||
if (srcHost.getHypervisorType() == HypervisorType.VMware || srcHost.getHypervisorType() == HypervisorType.KVM) {
|
||||
zoneWideStoragePool = checkForZoneWideStoragePool(volumePools);
|
||||
}
|
||||
if ((!host.getClusterId().equals(srcHost.getClusterId()) || usesLocal) && !zoneWideStoragePool) {
|
||||
requiresStorageMotion.put(host, true);
|
||||
for (VolumeVO volume : volumes) {
|
||||
Long volClusterId = _poolDao.findById(volume.getPoolId()).getClusterId();
|
||||
// only check for volume which are not in zone wide primary store, as only those may require storage motion
|
||||
if (volClusterId != null) {
|
||||
for (Iterator<HostVO> iterator = allHosts.iterator(); iterator.hasNext();) {
|
||||
Host host = iterator.next();
|
||||
if (!host.getClusterId().equals(volClusterId) || usesLocal) {
|
||||
if (hasSuitablePoolsForVolume(volume, host, vmProfile)) {
|
||||
requiresStorageMotion.put(host, true);
|
||||
} else {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plan = new DataCenterDeployment(srcHost.getDataCenterId(), null, null, null, null, null);
|
||||
} else {
|
||||
Long cluster = srcHost.getClusterId();
|
||||
|
|
@ -1244,50 +1243,20 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||
return new Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>>(otherHosts, suitableHosts, requiresStorageMotion);
|
||||
}
|
||||
|
||||
private boolean checkForZoneWideStoragePool(Map<Volume, List<StoragePool>> volumePools) {
|
||||
boolean zoneWideStoragePool = false;
|
||||
Collection<List<StoragePool>> pools = volumePools.values();
|
||||
List<StoragePool> aggregatePoolList = new ArrayList<StoragePool>();
|
||||
for (Iterator<List<StoragePool>> volumePoolsIter = pools.iterator(); volumePoolsIter.hasNext();) {
|
||||
aggregatePoolList.addAll(volumePoolsIter.next());
|
||||
}
|
||||
for (StoragePool pool : aggregatePoolList) {
|
||||
if (null == pool.getClusterId()) {
|
||||
zoneWideStoragePool = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return zoneWideStoragePool;
|
||||
}
|
||||
private boolean hasSuitablePoolsForVolume(VolumeVO volume, Host host, VirtualMachineProfile vmProfile) {
|
||||
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
|
||||
DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
|
||||
DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null);
|
||||
ExcludeList avoid = new ExcludeList();
|
||||
|
||||
private Map<Volume, List<StoragePool>> findSuitablePoolsForVolumes(VirtualMachineProfile vmProfile, Host host) {
|
||||
List<VolumeVO> volumes = _volumeDao.findCreatedByInstance(vmProfile.getId());
|
||||
Map<Volume, List<StoragePool>> suitableVolumeStoragePools = new HashMap<Volume, List<StoragePool>>();
|
||||
|
||||
// For each volume find list of suitable storage pools by calling the allocators
|
||||
for (VolumeVO volume : volumes) {
|
||||
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
|
||||
DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
|
||||
DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null);
|
||||
ExcludeList avoid = new ExcludeList();
|
||||
|
||||
boolean foundPools = false;
|
||||
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
|
||||
List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL);
|
||||
if (poolList != null && !poolList.isEmpty()) {
|
||||
suitableVolumeStoragePools.put(volume, poolList);
|
||||
foundPools = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundPools) {
|
||||
suitableVolumeStoragePools.clear();
|
||||
break;
|
||||
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
|
||||
List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, 1);
|
||||
if (poolList != null && !poolList.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return suitableVolumeStoragePools;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue