CLOUDSTACK-4222: use new volume object in case of migrate volume

This commit is contained in:
Edison Su 2013-08-12 16:17:29 -07:00
parent 02921b5d7c
commit d1c0860921
5 changed files with 24 additions and 15 deletions

View File

@ -20,6 +20,7 @@ package com.cloud.storage;
import java.net.URISyntaxException;
import com.cloud.exception.StorageUnavailableException;
import org.apache.cloudstack.api.command.user.volume.*;
import com.cloud.exception.ConcurrentOperationException;

View File

@ -99,6 +99,7 @@ public class MigrateVolumeCmd extends BaseAsyncCmd {
@Override
public void execute(){
Volume result;
result = _volumeService.migrateVolume(this);
if (result != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(result);

View File

@ -47,7 +47,7 @@ import com.cloud.vm.VirtualMachineProfile;
public interface VolumeManager extends VolumeApiService {
VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId,
Long destPoolClusterId, HypervisorType dataDiskHyperType)
throws ConcurrentOperationException;
throws ConcurrentOperationException, StorageUnavailableException;
@Override
VolumeVO uploadVolume(UploadVolumeCmd cmd)
@ -97,7 +97,7 @@ public interface VolumeManager extends VolumeApiService {
boolean storageMigration(
VirtualMachineProfile<? extends VirtualMachine> vm,
StoragePool destPool);
StoragePool destPool) throws StorageUnavailableException;
void prepareForMigration(
VirtualMachineProfile<? extends VirtualMachine> vm,

View File

@ -340,7 +340,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
public VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId,
Long destPoolPodId, Long destPoolClusterId,
HypervisorType dataDiskHyperType)
throws ConcurrentOperationException {
throws ConcurrentOperationException, StorageUnavailableException {
// Find a destination storage pool with the specified criteria
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume
@ -1892,6 +1892,9 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
} catch (ConcurrentOperationException e) {
s_logger.debug("move volume failed", e);
throw new CloudRuntimeException("move volume failed", e);
} catch (StorageUnavailableException e) {
s_logger.debug("move volume failed", e);
throw new CloudRuntimeException("move volume failed", e);
}
}
}
@ -2157,7 +2160,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
@DB
@Override
public Volume migrateVolume(MigrateVolumeCmd cmd) {
public Volume migrateVolume(MigrateVolumeCmd cmd){
Long volumeId = cmd.getVolumeId();
Long storagePoolId = cmd.getStoragePoolId();
@ -2221,28 +2224,32 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
if (liveMigrateVolume) {
newVol = liveMigrateVolume(vol, destPool);
} else {
newVol = migrateVolume(vol, destPool);
try {
newVol = migrateVolume(vol, destPool);
} catch(StorageUnavailableException e) {
s_logger.debug("Failed to migrate volume: ", e);
}
}
return newVol;
}
@DB
protected Volume migrateVolume(Volume volume, StoragePool destPool) {
protected Volume migrateVolume(Volume volume, StoragePool destPool) throws StorageUnavailableException {
VolumeInfo vol = volFactory.getVolume(volume.getId());
AsyncCallFuture<VolumeApiResult> future = volService.copyVolume(vol, (DataStore)destPool);
try {
VolumeApiResult result = future.get();
if (result.isFailed()) {
s_logger.error("migrate volume failed:" + result.getResult());
return null;
throw new StorageUnavailableException("migrate volume failed: " + result.getResult(), destPool.getId());
}
return result.getVolume();
} catch (InterruptedException e) {
s_logger.debug("migrate volume failed", e);
return null;
throw new StorageUnavailableException("migrate vlume failed:" + e.toString(), destPool.getId());
} catch (ExecutionException e) {
s_logger.debug("migrate volume failed", e);
return null;
throw new StorageUnavailableException("migrate vlume failed:" + e.toString(), destPool.getId());
}
}
@ -2309,7 +2316,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
@Override
public boolean storageMigration(
VirtualMachineProfile<? extends VirtualMachine> vm,
StoragePool destPool) {
StoragePool destPool) throws StorageUnavailableException {
List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId());
List<Volume> volumesNeedToMigrate = new ArrayList<Volume>();
@ -2570,8 +2577,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
vol = task.volume;
} else if (task.type == VolumeTaskType.MIGRATE) {
pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
migrateVolume(task.volume, pool);
vol = task.volume;
vol = migrateVolume(task.volume, pool);
} else if (task.type == VolumeTaskType.RECREATE) {
Pair<VolumeVO, DataStore> result = recreateVolume(task.volume, vm, dest);
pool = (StoragePool)dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
@ -2618,9 +2624,6 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager {
return _volStateMachine.transitTo(vol, event, null, _volsDao);
}
@Override
public boolean canVmRestartOnAnotherServer(long vmId) {
List<VolumeVO> vols = _volsDao.findCreatedByInstance(vmId);

View File

@ -37,6 +37,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.dc.dao.VlanDao;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.network.dao.IPAddressDao;
import org.apache.log4j.Logger;
@ -1419,6 +1420,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
} catch (InsufficientCapacityException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} catch (StorageUnavailableException e) {
s_logger.debug("Failed to migration: " + e.toString());
throw new CloudRuntimeException("Failed to migration: " + e.toString());
} finally {
try {
stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);