CLOUDSTACK-4650: change volume state during snapshot only

This commit is contained in:
Edison Su 2013-09-12 16:02:20 -07:00
parent 3420f2d016
commit 9baa45308c
2 changed files with 17 additions and 15 deletions

View File

@ -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;
@ -244,11 +245,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();

View File

@ -1292,22 +1292,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;