Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8FBB9200AE2 for ; Fri, 13 May 2016 06:33:20 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8DC83160A10; Fri, 13 May 2016 04:33:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B0668160939 for ; Fri, 13 May 2016 06:33:19 +0200 (CEST) Received: (qmail 29618 invoked by uid 500); 13 May 2016 04:33:13 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 29516 invoked by uid 99); 13 May 2016 04:33:13 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2016 04:33:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 29107DFBDE; Fri, 13 May 2016 04:33:13 +0000 (UTC) From: mike-tutkowski To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org References: In-Reply-To: Subject: [GitHub] cloudstack pull request: Taking fast and efficient volume snapshot... Content-Type: text/plain Message-Id: <20160513043313.29107DFBDE@git1-us-west.apache.org> Date: Fri, 13 May 2016 04:33:13 +0000 (UTC) archived-at: Fri, 13 May 2016 04:33:20 -0000 Github user mike-tutkowski commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1403#discussion_r63132440 --- Diff: engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java --- @@ -172,78 +258,207 @@ private void validate(SnapshotInfo snapshotInfo) { } } - private Void handleCreateTemplateFromSnapshot(SnapshotInfo snapshotInfo, TemplateInfo templateInfo, AsyncCompletionCallback callback) { + private boolean usingBackendSnapshotFor(SnapshotInfo snapshotInfo) { + String property = getProperty(snapshotInfo.getId(), "takeSnapshot"); + + return Boolean.parseBoolean(property); + } + + 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(); + HostVO hostVO = getHost(snapshotInfo); - 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()); + boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo); + boolean computeClusterSupportsResign = clusterDao.computeWhetherClusterSupportsResigning(hostVO.getClusterId()); - String errMsg = null; - - 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 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 srcDetails = getSnapshotDetails(snapshotInfo); + + copyCommand.setOptions(srcDetails); + + copyCmdAnswer = (CopyCmdAnswer)_agentMgr.send(hostVO.getId(), copyCommand); } - catch (Exception ex) { - s_logger.debug(ex.getMessage(), ex); + catch (AgentUnavailableException | OperationTimedoutException ex) { + throw new CloudRuntimeException("Failed to create template from snapshot : " + ex.getMessage()); } + finally { + try { + _volumeService.revokeAccess(snapshotInfo, hostVO, srcDataStore); + } + catch (Exception ex) { + s_logger.warn("error during revoking access to snapshot: " + 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 create template from snapshot"; + } } - else { - errMsg = "Unable to perform host-side operation"; + + try { + if (StringUtils.isEmpty(errMsg)) { + snapshotInfo.processEvent(Event.OperationSuccessed); + } + else { + snapshotInfo.processEvent(Event.OperationFailed); + } + } + catch (Exception ex) { + s_logger.warn("error while processing snapshot event" + 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 templateInfo source template + * @param volumeInfo destination ROOT volume + * @param callback for async + */ + private void handleCreateVolumeFromTemplateBothOnStorageSystem(TemplateInfo templateInfo, VolumeInfo volumeInfo, AsyncCompletionCallback callback) { + Preconditions.checkArgument(templateInfo != null, "Passing 'null' to templateInfo of handleCreateVolumeFromTemplateBothOnStorageSystem is not supported."); + Preconditions.checkArgument(volumeInfo != null, "Passing 'null' to volumeInfo of handleCreateVolumeFromTemplateBothOnStorageSystem is not supported."); + + CopyCmdAnswer copyCmdAnswer = null; + String errMsg = null; + + 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 = clusterDao.computeWhetherClusterSupportsResigning(hostVO.getClusterId()); + + if (!computeClusterSupportsResign) { + throw new CloudRuntimeException("Unable to locate an applicable host with which to perform a resignature operation"); --- End diff -- Done --- 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---