Updated Branches: refs/heads/4.2-forward 4c1a20fe6 -> 52a45ce56
CLOUDSTACK-4650: change volume state during snapshot only Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/52a45ce5 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/52a45ce5 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/52a45ce5 Branch: refs/heads/4.2-forward Commit: 52a45ce56e4607cda8bf365b7f6a8d26535f5163 Parents: 4c1a20f Author: Edison Su <[email protected]> Authored: Thu Sep 12 16:02:20 2013 -0700 Committer: Edison Su <[email protected]> Committed: Thu Sep 12 16:02:40 2013 -0700 ---------------------------------------------------------------------- .../snapshot/XenserverSnapshotStrategy.java | 21 ++++++++++++++++---- .../storage/volume/VolumeServiceImpl.java | 11 ---------- 2 files changed, 17 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/52a45ce5/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java ---------------------------------------------------------------------- diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java index 93d6a3c..a58abab 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.storage.snapshot; import javax.inject.Inject; +import com.cloud.storage.Volume; import com.cloud.utils.db.DB; import org.apache.cloudstack.engine.subsystem.api.storage.*; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; @@ -253,11 +254,23 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase { } try { - SnapshotResult result = snapshotSvr.takeSnapshot(snapshot); - if (result.isFailed()) { - s_logger.debug("Failed to take snapshot: " + result.getResult()); - throw new CloudRuntimeException(result.getResult()); + VolumeInfo volumeInfo = snapshot.getBaseVolume(); + volumeInfo.stateTransit(Volume.Event.SnapshotRequested); + SnapshotResult result = null; + try { + result = snapshotSvr.takeSnapshot(snapshot); + if (result.isFailed()) { + s_logger.debug("Failed to take snapshot: " + result.getResult()); + throw new CloudRuntimeException(result.getResult()); + } + } finally { + if (result != null && result.isSuccess()) { + volumeInfo.stateTransit(Volume.Event.OperationSucceeded); + } else { + volumeInfo.stateTransit(Volume.Event.OperationFailed); + } } + snapshot = result.getSnashot(); DataStore primaryStore = snapshot.getDataStore(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/52a45ce5/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 2c592b2..c93dcee 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 @@ -1297,22 +1297,11 @@ public class VolumeServiceImpl implements VolumeService { @Override public SnapshotInfo takeSnapshot(VolumeInfo volume) { - VolumeObject vol = (VolumeObject) volume; - boolean result = vol.stateTransit(Volume.Event.SnapshotRequested); - if (!result) { - s_logger.debug("Failed to transit state"); - } SnapshotInfo snapshot = null; try { snapshot = snapshotMgr.takeSnapshot(volume); } catch (Exception e) { s_logger.debug("Take snapshot: " + volume.getId() + " failed", e); - } finally { - if (snapshot != null) { - vol.stateTransit(Volume.Event.OperationSucceeded); - } else { - vol.stateTransit(Volume.Event.OperationFailed); - } } return snapshot;
