From c58f15d86785a201ad42a19c0bfa94eefd2d293e Mon Sep 17 00:00:00 2001 From: Edison Su Date: Tue, 13 Aug 2013 15:01:15 -0700 Subject: [PATCH] CLOUDSTACK-4222: use new volume object in case of migrate volume --- api/src/com/cloud/storage/VolumeApiService.java | 1 + .../api/command/user/volume/MigrateVolumeCmd.java | 1 + .../service/VolumeOrchestrationService.java | 6 +++--- .../engine/orchestration/VolumeOrchestrator.java | 11 +++++------ .../src/com/cloud/vm/VirtualMachineManagerImpl.java | 4 ++++ 5 files changed, 14 insertions(+), 9 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/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java b/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java index 5ba9fafd6e8..4e4a1917db6 100644 --- a/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java +++ b/engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java @@ -51,7 +51,7 @@ import com.cloud.vm.VirtualMachineProfile; * to provision volumes. */ public interface VolumeOrchestrationService { - VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType) throws ConcurrentOperationException; + VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType) throws ConcurrentOperationException, StorageUnavailableException; Volume allocateDuplicateVolume(Volume oldVol, Long templateId); @@ -61,7 +61,7 @@ public interface VolumeOrchestrationService { String getVmNameOnVolume(Volume volume); - Volume migrateVolume(Volume volume, StoragePool destPool); + Volume migrateVolume(Volume volume, StoragePool destPool) throws StorageUnavailableException; void destroyVolume(Volume volume); @@ -75,7 +75,7 @@ public interface VolumeOrchestrationService { void migrateVolumes(VirtualMachine vm, VirtualMachineTO vmTo, Host srcHost, Host destHost, Map volumeToPool); - boolean storageMigration(VirtualMachineProfile vm, StoragePool destPool); + boolean storageMigration(VirtualMachineProfile vm, StoragePool destPool) throws StorageUnavailableException; void prepareForMigration(VirtualMachineProfile vm, DeployDestination dest); diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index d82bc79bbce..9a262e781e4 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -158,7 +158,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati @Override 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 DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId()); @@ -754,14 +754,14 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati @Override @DB - public Volume migrateVolume(Volume volume, StoragePool destPool) { + public 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) { @@ -830,7 +830,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } @Override - public boolean storageMigration(VirtualMachineProfile vm, StoragePool destPool) { + public boolean storageMigration(VirtualMachineProfile vm, StoragePool destPool) throws StorageUnavailableException { List vols = _volsDao.findUsableVolumesForInstance(vm.getId()); List volumesNeedToMigrate = new ArrayList(); @@ -1047,8 +1047,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati 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); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index dc216df1532..c1146e1d0b6 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -35,6 +35,7 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.exception.StorageUnavailableException; import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -1385,6 +1386,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);