@Override public Answer createTemplateFromSnapshot(CopyCommand cmd) { Map<String, String> details = cmd.getOptions(); if (details != null && details.get(DiskTO.IQN) != null) { // use the managed-storage approach return createTemplateFromVolumeOrSnapshot(cmd); } return new CopyCmdAnswer("operation not supported"); }
protected Answer backupSnapshotForObjectStore(final CopyCommand cmd) { final DataTO destData = cmd.getDestTO(); final DataStoreTO imageStore = destData.getDataStore(); final DataTO cacheData = cmd.getCacheTO(); if (cacheData == null) { return new CopyCmdAnswer("Failed to copy to object store without cache store"); } final DataStoreTO cacheStore = cacheData.getDataStore(); ((SnapshotObjectTO)destData).setDataStore(cacheStore); final CopyCmdAnswer answer = (CopyCmdAnswer)backupSnapshot(cmd); if (!answer.getResult()) { return answer; } final SnapshotObjectTO snapshotOnCacheStore = (SnapshotObjectTO)answer.getNewData(); snapshotOnCacheStore.setDataStore(cacheStore); ((SnapshotObjectTO)destData).setDataStore(imageStore); final CopyCommand newCpyCmd = new CopyCommand(snapshotOnCacheStore, destData, cmd.getWaitInMillSeconds(), cmd.executeInSequence()); return copyToObjectStore(newCpyCmd); }
if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) { if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) { throw new CloudRuntimeException(copyCmdAnswer.getDetails()); copyCmdAnswer = new CopyCmdAnswer(errMsg);
private void verifyCopyCmdAnswer(CopyCmdAnswer copyCmdAnswer, DataObject dataObject) { if (copyCmdAnswer == null) { throw new CloudRuntimeException("Unable to create a volume from a " + dataObject.getType().toString().toLowerCase() + " (copyCmdAnswer == null)"); } if (copyCmdAnswer.getResult()) { return; } String details = copyCmdAnswer.getDetails(); if (StringUtils.isEmpty(details)) { throw new CloudRuntimeException("Unable to create a volume from a " + dataObject.getType().toString().toLowerCase() + " (no error details specified)"); } throw new CloudRuntimeException(details); }
vmdk = copyCmdAnswer.getNewData().getPath(); uuid = UUID.randomUUID().toString(); if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); copyCmdAnswer = new CopyCmdAnswer(errMsg); } else { copyCmdAnswer = (CopyCmdAnswer)ep.sendMessage(cmd); if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) { if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) { errMsg = copyCmdAnswer.getDetails(); copyCmdAnswer = new CopyCmdAnswer(errMsg);
private CopyCmdAnswer copyImageToVolume(DataObject srcDataObject, VolumeInfo destVolumeInfo, HostVO hostVO) { String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString()); int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue())); CopyCommand copyCommand = new CopyCommand(srcDataObject.getTO(), destVolumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value()); CopyCmdAnswer copyCmdAnswer; try { _volumeService.grantAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); Map<String, String> destDetails = getVolumeDetails(destVolumeInfo); copyCommand.setOptions2(destDetails); copyCmdAnswer = (CopyCmdAnswer)_agentMgr.send(hostVO.getId(), copyCommand); } catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to copy image : "; LOGGER.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } finally { _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); } VolumeObjectTO volumeObjectTO = (VolumeObjectTO)copyCmdAnswer.getNewData(); volumeObjectTO.setFormat(ImageFormat.QCOW2); return copyCmdAnswer; }
if (needCacheStorage && copyCmdAnswer != null && copyCmdAnswer.getResult()) { cacheMgr.deleteCacheObject(cacheData);
protected Void managedCopyBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, ManagedCreateBaseImageContext<VolumeApiResult> context) { CopyCommandResult result = callback.getResult(); VolumeInfo volumeInfo = context.getVolumeInfo(); VolumeApiResult res = new VolumeApiResult(volumeInfo); if (result.isSuccess()) { // volumeInfo.processEvent(Event.OperationSuccessed, result.getAnswer()); VolumeVO volume = volDao.findById(volumeInfo.getId()); CopyCmdAnswer answer = (CopyCmdAnswer)result.getAnswer(); TemplateObjectTO templateObjectTo = (TemplateObjectTO)answer.getNewData(); volume.setPath(templateObjectTo.getPath()); if (templateObjectTo.getFormat() != null) { volume.setFormat(templateObjectTo.getFormat()); } volDao.update(volume.getId(), volume); } else { volumeInfo.processEvent(Event.DestroyRequested); res.setResult(result.getResult()); } AsyncCallFuture<VolumeApiResult> future = context.getFuture(); future.complete(res); return null; }
protected Answer copyFromSwiftToNfs(CopyCommand cmd, DataTO srcData, SwiftTO swiftTO, DataTO destData, NfsTO destImageStore) { final String storagePath = destImageStore.getUrl(); final String destPath = destData.getPath(); try { String downloadPath = determineStorageTemplatePath(storagePath, destPath, _nfsVersion); final File downloadDirectory = _storage.getFile(downloadPath); if (downloadDirectory.exists()) { s_logger.debug("Directory " + downloadPath + " already exists"); } else { if (!downloadDirectory.mkdirs()) { final String errMsg = "Unable to create directory " + downloadPath + " to copy from Swift to cache."; s_logger.error(errMsg); return new CopyCmdAnswer(errMsg); } } File destFile = SwiftUtil.getObject(swiftTO, downloadDirectory, srcData.getPath()); return postProcessing(destFile, downloadPath, destPath, srcData, destData); } catch (Exception e) { s_logger.debug("Failed to copy swift to nfs", e); return new CopyCmdAnswer(e.toString()); } }
if (!answer.getResult()) { return answer; TemplateObjectTO newTemplate = (TemplateObjectTO)answer.getNewData(); newTemplate.setDataStore(srcDataStore); CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence()); if (!answer.getResult()) { return answer; TemplateObjectTO newTemplate = (TemplateObjectTO)answer.getNewData(); newTemplate.setDataStore(srcDataStore); CopyCommand newCpyCmd = new CopyCommand(newTemplate, destData, cmd.getWait(), cmd.executeInSequence()); return new CopyCmdAnswer("Unsupported protocol");
if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) { if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) { errMsg = copyCmdAnswer.getDetails(); copyCmdAnswer = new CopyCmdAnswer(errMsg);
snapshotStoreDao.update(snapshotStore.getId(), snapshotStore); } else if (answer instanceof CopyCmdAnswer) { SnapshotObjectTO snapshotTO = (SnapshotObjectTO)((CopyCmdAnswer)answer).getNewData(); snapshotStore.setInstallPath(snapshotTO.getPath()); if (snapshotTO.getPhysicalSize() != null) {
private void invokeCallback(String errMsg, AsyncCompletionCallback<CopyCommandResult> callback) { CopyCmdAnswer copyCmdAnswer = new CopyCmdAnswer(errMsg); CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer); result.setResult(errMsg); callback.complete(result); }
if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) { if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) { throw new CloudRuntimeException(copyCmdAnswer.getDetails()); copyCmdAnswer = new CopyCmdAnswer(errMsg);
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer; VolumeVO vol = volumeDao.findById(getId()); VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData(); vol.setPath(newVol.getPath()); if (newVol.getSize() != null) { CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer; VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId()); VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData(); volStore.setInstallPath(newVol.getPath()); if (newVol.getSize() != null) {
protected Answer copyFromS3ToNfs(CopyCommand cmd, DataTO srcData, S3TO s3, DataTO destData, NfsTO destImageStore) { final String storagePath = destImageStore.getUrl(); final String destPath = destData.getPath(); try { String downloadPath = determineStorageTemplatePath(storagePath, destPath, _nfsVersion); final File downloadDirectory = _storage.getFile(downloadPath); if (downloadDirectory.exists()) { s_logger.debug("Directory " + downloadPath + " already exists"); } else { if (!downloadDirectory.mkdirs()) { final String errMsg = "Unable to create directory " + downloadPath + " to copy from S3 to cache."; s_logger.error(errMsg); return new CopyCmdAnswer(errMsg); } } File destFile = new File(downloadDirectory, substringAfterLast(srcData.getPath(), S3Utils.SEPARATOR)); S3Utils.getFile(s3, s3.getBucketName(), srcData.getPath(), destFile).waitForCompletion(); return postProcessing(destFile, downloadPath, destPath, srcData, destData); } catch (Exception e) { final String errMsg = format("Failed to download" + "due to $1%s", e.getMessage()); s_logger.error(errMsg, e); return new CopyCmdAnswer(errMsg); } }
if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); copyCmdAnswer = new CopyCmdAnswer(errMsg);
if (answer instanceof CopyCmdAnswer) { CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer; TemplateObjectTO newTemplate = (TemplateObjectTO)cpyAnswer.getNewData(); VMTemplateStoragePoolVO templatePoolRef = templatePoolDao.findByPoolTemplate(getDataStore().getId(), getId()); templatePoolRef.setDownloadPercent(100); if (answer instanceof CopyCmdAnswer) { CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer; TemplateObjectTO newTemplate = (TemplateObjectTO)cpyAnswer.getNewData(); TemplateDataStoreVO templateStoreRef = templateStoreDao.findByStoreTemplate(getDataStore().getId(), getId()); templateStoreRef.setInstallPath(newTemplate.getPath());
srcStorePool = storagePoolMgr.getStoragePoolByURI(srcStore.getUrl() + File.separator + srcSnapshotDir); if (srcStorePool == null) { return new CopyCmdAnswer("Can't get store:" + srcStore.getUrl()); return new CopyCmdAnswer("Can't find src file: " + srcPath); destPath = copyToS3(srcFile, (S3TO)imageStore, destData.getPath()); } else { return new CopyCmdAnswer("Unsupported protocol"); return new CopyCmdAnswer(newSnapshot); } catch (final Exception e) { s_logger.error("failed to upload" + srcPath, e); return new CopyCmdAnswer("failed to upload" + srcPath + e.toString()); } finally { try {
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer; VolumeVO vol = volumeDao.findById(getId()); VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData(); vol.setPath(newVol.getPath()); if (newVol.getSize() != null) { CopyCmdAnswer cpyAnswer = (CopyCmdAnswer)answer; VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId()); VolumeObjectTO newVol = (VolumeObjectTO)cpyAnswer.getNewData(); volStore.setInstallPath(newVol.getPath()); if (newVol.getSize() != null) {