From d1c08609218f475aa3210b761b1ccf86e1476f2f Mon Sep 17 00:00:00 2001 From: Edison Su Date: Mon, 12 Aug 2013 16:17:29 -0700 Subject: [PATCH] CLOUDSTACK-4222: use new volume object in case of migrate volume --- .../com/cloud/storage/VolumeApiService.java | 1 + .../command/user/volume/MigrateVolumeCmd.java | 1 + .../src/com/cloud/storage/VolumeManager.java | 4 +-- .../com/cloud/storage/VolumeManagerImpl.java | 29 ++++++++++--------- .../cloud/vm/VirtualMachineManagerImpl.java | 4 +++ 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/api/src/com/cloud/storage/VolumeApiService.java b/api/src/com/cloud/storage/VolumeApiService.java index 95f962df374..0194c817cac 100644 --- a/api/src/com/cloud/storage/VolumeApiService.java +++ b/api/src/com/cloud/storage/VolumeApiService.java @@ -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; diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java index 40e6123d0ec..61863976930 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java @@ -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); diff --git a/server/src/com/cloud/storage/VolumeManager.java b/server/src/com/cloud/storage/VolumeManager.java index c8adaebe764..d022c4a5f7b 100644 --- a/server/src/com/cloud/storage/VolumeManager.java +++ b/server/src/com/cloud/storage/VolumeManager.java @@ -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 vm, - StoragePool destPool); + StoragePool destPool) throws StorageUnavailableException; void prepareForMigration( VirtualMachineProfile vm, diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index e0997487a34..8d2eb565355 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -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 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 vm, - StoragePool destPool) { + StoragePool destPool) throws StorageUnavailableException { List vols = _volsDao.findUsableVolumesForInstance(vm.getId()); List volumesNeedToMigrate = new ArrayList(); @@ -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 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 vols = _volsDao.findCreatedByInstance(vmId); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 6a48e9fb584..6691b40e6af 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -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);