@Test public void testCopyVolumeFromImageCacheToPrimary() throws Exception { }
@Override public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final DataStoreTO srcStore = srcData.getDataStore(); final DataStoreTO destStore = destData.getDataStore(); final VolumeObjectTO srcVol = (VolumeObjectTO) srcData; final ImageFormat srcFormat = srcVol.getFormat(); final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore; if (!(srcStore instanceof NfsTO)) { return new CopyCmdAnswer("can only handle nfs storage"); } final NfsTO nfsStore = (NfsTO) srcStore; final String srcVolumePath = srcData.getPath(); final String secondaryStorageUrl = nfsStore.getUrl(); KvmStoragePool secondaryStoragePool = null; KvmStoragePool primaryPool; try { try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); } catch (final CloudRuntimeException e) { if (e.getMessage().contains("not found")) { primaryPool = this.storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType()); } else { return new CopyCmdAnswer(e.getMessage()); } } final String volumeName = UUID.randomUUID().toString(); final int index = srcVolumePath.lastIndexOf(File.separator); final String volumeDir = srcVolumePath.substring(0, index); String srcVolumeName = srcVolumePath.substring(index + 1); secondaryStoragePool = this.storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + File.separator + volumeDir); if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) { srcVolumeName = srcVolumeName + ".qcow2"; } final KvmPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName); volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString())); final KvmPhysicalDisk newDisk = this.storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool, cmd.getWaitInMillSeconds()); final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase())); newVol.setPath(volumeName); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to ccopyVolumeFromImageCacheToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { if (secondaryStoragePool != null) { this.storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid()); } } }
KvmStorageProcessor implements StorageProcessor { @Override public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final DataStoreTO srcStore = srcData.getDataStore(); final DataStoreTO destStore = destData.getDataStore(); final VolumeObjectTO srcVol = (VolumeObjectTO) srcData; final ImageFormat srcFormat = srcVol.getFormat(); final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore; if (!(srcStore instanceof NfsTO)) { return new CopyCmdAnswer("can only handle nfs storage"); } final NfsTO nfsStore = (NfsTO) srcStore; final String srcVolumePath = srcData.getPath(); final String secondaryStorageUrl = nfsStore.getUrl(); KvmStoragePool secondaryStoragePool = null; KvmStoragePool primaryPool; try { try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); } catch (final CloudRuntimeException e) { if (e.getMessage().contains("not found")) { primaryPool = this.storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType()); } else { return new CopyCmdAnswer(e.getMessage()); } } final String volumeName = UUID.randomUUID().toString(); final int index = srcVolumePath.lastIndexOf(File.separator); final String volumeDir = srcVolumePath.substring(0, index); String srcVolumeName = srcVolumePath.substring(index + 1); secondaryStoragePool = this.storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + File.separator + volumeDir); if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) { srcVolumeName = srcVolumeName + ".qcow2"; } final KvmPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName); volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString())); final KvmPhysicalDisk newDisk = this.storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool, cmd.getWaitInMillSeconds()); final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase())); newVol.setPath(volumeName); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to ccopyVolumeFromImageCacheToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { if (secondaryStoragePool != null) { this.storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid()); } } } }
KvmStorageProcessor implements StorageProcessor { @Override public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final DataStoreTO srcStore = srcData.getDataStore(); final DataStoreTO destStore = destData.getDataStore(); final VolumeObjectTO srcVol = (VolumeObjectTO) srcData; final ImageFormat srcFormat = srcVol.getFormat(); final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore; if (!(srcStore instanceof NfsTO)) { return new CopyCmdAnswer("can only handle nfs storage"); } final NfsTO nfsStore = (NfsTO) srcStore; final String srcVolumePath = srcData.getPath(); final String secondaryStorageUrl = nfsStore.getUrl(); KvmStoragePool secondaryStoragePool = null; KvmStoragePool primaryPool; try { try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); } catch (final CloudRuntimeException e) { if (e.getMessage().contains("not found")) { primaryPool = this.storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType()); } else { return new CopyCmdAnswer(e.getMessage()); } } final String volumeName = UUID.randomUUID().toString(); final int index = srcVolumePath.lastIndexOf(File.separator); final String volumeDir = srcVolumePath.substring(0, index); String srcVolumeName = srcVolumePath.substring(index + 1); secondaryStoragePool = this.storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + File.separator + volumeDir); if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) { srcVolumeName = srcVolumeName + ".qcow2"; } final KvmPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName); volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString())); final KvmPhysicalDisk newDisk = this.storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool, cmd.getWaitInMillSeconds()); final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase())); newVol.setPath(volumeName); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to ccopyVolumeFromImageCacheToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { if (secondaryStoragePool != null) { this.storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid()); } } } KvmStorageProcessor(final KvmStoragePoolManager storagePoolMgr, final LibvirtComputingResource resource); }
KvmStorageProcessor implements StorageProcessor { @Override public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final DataStoreTO srcStore = srcData.getDataStore(); final DataStoreTO destStore = destData.getDataStore(); final VolumeObjectTO srcVol = (VolumeObjectTO) srcData; final ImageFormat srcFormat = srcVol.getFormat(); final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore; if (!(srcStore instanceof NfsTO)) { return new CopyCmdAnswer("can only handle nfs storage"); } final NfsTO nfsStore = (NfsTO) srcStore; final String srcVolumePath = srcData.getPath(); final String secondaryStorageUrl = nfsStore.getUrl(); KvmStoragePool secondaryStoragePool = null; KvmStoragePool primaryPool; try { try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); } catch (final CloudRuntimeException e) { if (e.getMessage().contains("not found")) { primaryPool = this.storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType()); } else { return new CopyCmdAnswer(e.getMessage()); } } final String volumeName = UUID.randomUUID().toString(); final int index = srcVolumePath.lastIndexOf(File.separator); final String volumeDir = srcVolumePath.substring(0, index); String srcVolumeName = srcVolumePath.substring(index + 1); secondaryStoragePool = this.storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + File.separator + volumeDir); if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) { srcVolumeName = srcVolumeName + ".qcow2"; } final KvmPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName); volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString())); final KvmPhysicalDisk newDisk = this.storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool, cmd.getWaitInMillSeconds()); final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase())); newVol.setPath(volumeName); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to ccopyVolumeFromImageCacheToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { if (secondaryStoragePool != null) { this.storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid()); } } } KvmStorageProcessor(final KvmStoragePoolManager storagePoolMgr, final LibvirtComputingResource resource); boolean configure(final String name, final Map<String, Object> params); @Override Answer copyTemplateToPrimaryStorage(final CopyCommand cmd); @Override Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd); @Override Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd); @Override Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd); @Override Answer createTemplateFromVolume(final CopyCommand cmd); @Override Answer createTemplateFromSnapshot(final CopyCommand cmd); @Override Answer backupSnapshot(final CopyCommand cmd); @Override Answer attachIso(final AttachCommand cmd); @Override Answer attachVolume(final AttachCommand cmd); @Override Answer dettachIso(final DettachCommand cmd); @Override Answer dettachVolume(final DettachCommand cmd); @Override Answer createVolume(final CreateObjectCommand cmd); @Override Answer createSnapshot(final CreateObjectCommand cmd); @Override Answer deleteVolume(final DeleteCommand cmd); @Override Answer createVolumeFromSnapshot(final CopyCommand cmd); @Override Answer deleteSnapshot(final DeleteCommand cmd); @Override Answer introduceObject(final IntroduceObjectCommand cmd); @Override Answer forgetObject(final ForgetObjectCommand cmd); @Override SnapshotAndCopyAnswer snapshotAndCopy(final SnapshotAndCopyCommand cmd); }
KvmStorageProcessor implements StorageProcessor { @Override public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) { final DataTO srcData = cmd.getSrcTO(); final DataTO destData = cmd.getDestTO(); final DataStoreTO srcStore = srcData.getDataStore(); final DataStoreTO destStore = destData.getDataStore(); final VolumeObjectTO srcVol = (VolumeObjectTO) srcData; final ImageFormat srcFormat = srcVol.getFormat(); final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destStore; if (!(srcStore instanceof NfsTO)) { return new CopyCmdAnswer("can only handle nfs storage"); } final NfsTO nfsStore = (NfsTO) srcStore; final String srcVolumePath = srcData.getPath(); final String secondaryStorageUrl = nfsStore.getUrl(); KvmStoragePool secondaryStoragePool = null; KvmStoragePool primaryPool; try { try { primaryPool = this.storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); } catch (final CloudRuntimeException e) { if (e.getMessage().contains("not found")) { primaryPool = this.storagePoolMgr.createStoragePool(primaryStore.getUuid(), primaryStore.getHost(), primaryStore.getPort(), primaryStore.getPath(), null, primaryStore.getPoolType()); } else { return new CopyCmdAnswer(e.getMessage()); } } final String volumeName = UUID.randomUUID().toString(); final int index = srcVolumePath.lastIndexOf(File.separator); final String volumeDir = srcVolumePath.substring(0, index); String srcVolumeName = srcVolumePath.substring(index + 1); secondaryStoragePool = this.storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + File.separator + volumeDir); if (!srcVolumeName.endsWith(".qcow2") && srcFormat == ImageFormat.QCOW2) { srcVolumeName = srcVolumeName + ".qcow2"; } final KvmPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName); volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString())); final KvmPhysicalDisk newDisk = this.storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool, cmd.getWaitInMillSeconds()); final VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase())); newVol.setPath(volumeName); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { this.logger.debug("Failed to ccopyVolumeFromImageCacheToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { if (secondaryStoragePool != null) { this.storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid()); } } } KvmStorageProcessor(final KvmStoragePoolManager storagePoolMgr, final LibvirtComputingResource resource); boolean configure(final String name, final Map<String, Object> params); @Override Answer copyTemplateToPrimaryStorage(final CopyCommand cmd); @Override Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd); @Override Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd); @Override Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd); @Override Answer createTemplateFromVolume(final CopyCommand cmd); @Override Answer createTemplateFromSnapshot(final CopyCommand cmd); @Override Answer backupSnapshot(final CopyCommand cmd); @Override Answer attachIso(final AttachCommand cmd); @Override Answer attachVolume(final AttachCommand cmd); @Override Answer dettachIso(final DettachCommand cmd); @Override Answer dettachVolume(final DettachCommand cmd); @Override Answer createVolume(final CreateObjectCommand cmd); @Override Answer createSnapshot(final CreateObjectCommand cmd); @Override Answer deleteVolume(final DeleteCommand cmd); @Override Answer createVolumeFromSnapshot(final CopyCommand cmd); @Override Answer deleteSnapshot(final DeleteCommand cmd); @Override Answer introduceObject(final IntroduceObjectCommand cmd); @Override Answer forgetObject(final ForgetObjectCommand cmd); @Override SnapshotAndCopyAnswer snapshotAndCopy(final SnapshotAndCopyCommand cmd);  }