diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java index de98f55be6f..26a631bc468 100644 --- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java +++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java @@ -177,6 +177,13 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } private Void handleCreateTemplateFromSnapshot(SnapshotInfo snapshotInfo, TemplateInfo templateInfo, AsyncCompletionCallback callback) { + try { + snapshotInfo.processEvent(Event.CopyingRequested); + } + catch (Exception ex) { + throw new CloudRuntimeException("This snapshot is not currently in a state where it can be used to create a template."); + } + HostVO hostVO = getHost(snapshotInfo.getDataStore().getId()); DataStore srcDataStore = snapshotInfo.getDataStore(); @@ -184,6 +191,8 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue())); CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), templateInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value()); + String errMsg = null; + CopyCmdAnswer copyCmdAnswer = null; try { @@ -205,16 +214,26 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { catch (Exception ex) { s_logger.debug(ex.getMessage(), ex); } - } - String errMsg = null; - - if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) { - if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) { - errMsg = copyCmdAnswer.getDetails(); + if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) { + if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) { + errMsg = copyCmdAnswer.getDetails(); + } + else { + errMsg = "Unable to perform host-side operation"; + } } - else { - errMsg = "Unable to perform host-side operation"; + + try { + if (errMsg == null) { + snapshotInfo.processEvent(Event.OperationSuccessed); + } + else { + snapshotInfo.processEvent(Event.OperationFailed); + } + } + catch (Exception ex) { + s_logger.debug(ex.getMessage(), ex); } }