CLOUDSTACK-6172: Volume is not retaining same uuid when migrating from one storage to another.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/624139d8 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/624139d8 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/624139d8 Branch: refs/heads/acl-item-cidrs Commit: 624139d8ef9ea9462ba81d2d3941ee5ac9467b20 Parents: 88b5761 Author: Sanjay Tripathi <sanjay.tripa...@citrix.com> Authored: Wed Feb 26 14:41:48 2014 +0530 Committer: Sanjay Tripathi <sanjay.tripa...@citrix.com> Committed: Wed Feb 26 14:42:34 2014 +0530 ---------------------------------------------------------------------- .../src/com/cloud/storage/dao/VolumeDao.java | 8 ++++++++ .../com/cloud/storage/dao/VolumeDaoImpl.java | 20 ++++++++++++++++++++ .../storage/volume/VolumeServiceImpl.java | 1 + 3 files changed, 29 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/624139d8/engine/schema/src/com/cloud/storage/dao/VolumeDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java index 8dc0328..da0a5de 100755 --- a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java +++ b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java @@ -105,4 +105,12 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S * @return the scope of the storage pool where the volume is present (ZONE/CLUSTER) */ ScopeType getVolumeStoragePoolScope(long volumeId); + + /*** + * Updates the destVol uuid with srcVol uuid and sets the srcVol uuid as null. + * @param srcVolId + * @param destVolId + * @return returns true if transaction is successful. + */ + boolean updateUuid(long srcVolId, long destVolId); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/624139d8/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java index 5120387..326cba6 100755 --- a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java +++ b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java @@ -580,6 +580,26 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol } @Override + @DB + public boolean updateUuid(long srcVolId, long destVolId) { + TransactionLegacy txn = TransactionLegacy.currentTxn(); + txn.start(); + try { + VolumeVO srcVol = findById(srcVolId); + VolumeVO destVol = findById(destVolId); + String uuid = srcVol.getUuid(); + srcVol.setUuid(null); + destVol.setUuid(uuid); + update(srcVolId, srcVol); + update(destVolId, destVol); + } catch (Exception e) { + throw new CloudRuntimeException("Unable to persist the sequence number for this host"); + } + txn.commit(); + return true; + } + + @Override public ScopeType getVolumeStoragePoolScope(long volumeId) { // finding the storage scope where the volume is present TransactionLegacy txn = TransactionLegacy.currentTxn(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/624139d8/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java ---------------------------------------------------------------------- diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 3e315da..fa0fd95 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -853,6 +853,7 @@ public class VolumeServiceImpl implements VolumeService { } srcVolume.processEvent(Event.OperationSuccessed); destVolume.processEvent(Event.OperationSuccessed, result.getAnswer()); + _volumeDao.updateUuid(srcVolume.getId(), destVolume.getId()); destroyVolume(srcVolume.getId()); srcVolume = volFactory.getVolume(srcVolume.getId()); AsyncCallFuture<VolumeApiResult> destroyFuture = expungeVolumeAsync(srcVolume);