Github user jburwell commented on a diff in the pull request:
https://github.com/apache/cloudstack/pull/1403#discussion_r59076160
--- Diff:
engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java
---
@@ -172,78 +232,211 @@ private void validate(SnapshotInfo snapshotInfo) {
}
}
- private Void handleCreateTemplateFromSnapshot(SnapshotInfo
snapshotInfo, TemplateInfo templateInfo,
AsyncCompletionCallback<CopyCommandResult> callback) {
+ private boolean usingBackendSnapshotFor(SnapshotInfo snapshotInfo) {
+ String property = getProperty(snapshotInfo.getId(),
"takeSnapshot");
+
+ return Boolean.parseBoolean(property);
+ }
+
+ private void handleCreateTemplateFromSnapshot(SnapshotInfo
snapshotInfo, TemplateInfo templateInfo,
AsyncCompletionCallback<CopyCommandResult> 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();
-
- String value =
_configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
- int primaryStorageDownloadWait = NumbersUtil.parseInt(value,
Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
- CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(),
templateInfo.getTO(), primaryStorageDownloadWait,
VirtualMachineManager.ExecuteInSequence.value());
+ HostVO hostVO = getHost(snapshotInfo);
- String errMsg = null;
+ boolean usingBackendSnapshot =
usingBackendSnapshotFor(snapshotInfo);
+ boolean computeClusterSupportsResign =
computeClusterSupportsResign(hostVO.getClusterId());
- CopyCmdAnswer copyCmdAnswer = null;
+ if (usingBackendSnapshot && !computeClusterSupportsResign) {
+ throw new CloudRuntimeException("Unable to locate an
applicable host with which to perform a resignature operation");
+ }
try {
- _volumeService.grantAccess(snapshotInfo, hostVO, srcDataStore);
+ if (usingBackendSnapshot) {
+ createVolumeFromSnapshot(hostVO, snapshotInfo, true);
+ }
- Map<String, String> srcDetails =
getSnapshotDetails(_storagePoolDao.findById(srcDataStore.getId()),
snapshotInfo);
+ DataStore srcDataStore = snapshotInfo.getDataStore();
- copyCommand.setOptions(srcDetails);
+ String value =
_configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
+ 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;
- copyCmdAnswer = (CopyCmdAnswer)_agentMgr.send(hostVO.getId(),
copyCommand);
- }
- catch (Exception ex) {
- throw new CloudRuntimeException(ex.getMessage());
- }
- finally {
try {
- _volumeService.revokeAccess(snapshotInfo, hostVO,
srcDataStore);
+ // If we are using a back-end snapshot, then we should
still have access to it from the hosts in the cluster that hostVO is in
+ // (because we passed in true as the third parameter to
createVolumeFromSnapshot above).
+ if (usingBackendSnapshot == false) {
+ _volumeService.grantAccess(snapshotInfo, hostVO,
srcDataStore);
+ }
+
+ Map<String, String> srcDetails =
getSnapshotDetails(snapshotInfo);
+
+ copyCommand.setOptions(srcDetails);
+
+ copyCmdAnswer =
(CopyCmdAnswer)_agentMgr.send(hostVO.getId(), copyCommand);
}
catch (Exception ex) {
- s_logger.debug(ex.getMessage(), ex);
+ throw new CloudRuntimeException(ex.getMessage());
}
+ finally {
+ try {
+ _volumeService.revokeAccess(snapshotInfo, hostVO,
srcDataStore);
+ }
+ catch (Exception ex) {
+ s_logger.debug(ex.getMessage(), ex);
+ }
- 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 &&
!StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
+ 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);
}
}
- try {
- if (errMsg == null) {
- snapshotInfo.processEvent(Event.OperationSuccessed);
+ CopyCommandResult result = new CopyCommandResult(null,
copyCmdAnswer);
+
+ result.setResult(errMsg);
+
+ callback.complete(result);
+ }
+ finally {
+ if (usingBackendSnapshot) {
+ deleteVolumeFromSnapshot(snapshotInfo);
+ }
+ }
+ }
+
+ /**
+ * Clones a template present on the storage to a new volume and
resignatures it.
+ *
+ * @param srcData source template
+ * @param destData destination ROOT volume
+ * @param callback for async
+ */
+ private void
handleCreateVolumeFromTemplateBothOnStorageSystem(DataObject srcData,
DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
+ CopyCmdAnswer copyCmdAnswer = null;
+ String errMsg = null;
+
+ TemplateInfo templateInfo = (TemplateInfo)srcData;
+ VolumeInfo volumeInfo = (VolumeInfo)destData;
+
+ HostVO hostVO = getHost(volumeInfo.getDataCenterId(), true);
+
+ if (hostVO == null) {
+ throw new CloudRuntimeException("Unable to locate a host
capable of resigning in the zone with the following ID: " +
volumeInfo.getDataCenterId());
+ }
+
+ boolean computeClusterSupportsResign =
computeClusterSupportsResign(hostVO.getClusterId());
+
+ if (!computeClusterSupportsResign) {
+ throw new CloudRuntimeException("Unable to locate an
applicable host with which to perform a resignature operation");
+ }
+
+ try {
+ VolumeDetailVO volumeDetail = new
VolumeDetailVO(volumeInfo.getId(),
+ "cloneOfTemplate",
+ String.valueOf(templateInfo.getId()),
+ false);
+
+ volumeDetail = _volumeDetailsDao.persist(volumeDetail);
+
+ AsyncCallFuture<VolumeApiResult> future =
_volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
+ VolumeApiResult result = future.get();
+
+ if (volumeDetail != null) {
+ _volumeDetailsDao.remove(volumeDetail.getId());
+ }
+
+ if (result.isFailed()) {
+ s_logger.debug("Failed to create a volume: " +
result.getResult());
+
+ throw new CloudRuntimeException(result.getResult());
+ }
+
+ volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(),
volumeInfo.getDataStore());
+
+ volumeInfo.processEvent(Event.MigrationRequested);
+
+ volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(),
volumeInfo.getDataStore());
+
+ copyCmdAnswer = performResignature(volumeInfo, hostVO);
+
+ if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
+ if (copyCmdAnswer != null &&
!StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
+ throw new
CloudRuntimeException(copyCmdAnswer.getDetails());
}
else {
- snapshotInfo.processEvent(Event.OperationFailed);
+ throw new CloudRuntimeException("Unable to perform
host-side operation");
}
}
- catch (Exception ex) {
- s_logger.debug(ex.getMessage(), ex);
+ } catch (Exception ex) {
--- End diff --
What are all checked and unchecked exceptions being caught?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---