Search in sources :

Example 11 with CopyVolumeAnswer

use of com.cloud.agent.api.storage.CopyVolumeAnswer in project cosmic by MissionCriticalCloud.

the class LibvirtCopyVolumeCommandWrapper method execute.

@Override
public Answer execute(final CopyVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final boolean copyToSecondary = command.toSecondaryStorage();
    String volumePath = command.getVolumePath();
    final StorageFilerTO pool = command.getPool();
    final String secondaryStorageUrl = command.getSecondaryStorageURL();
    KvmStoragePool secondaryStoragePool = null;
    KvmStoragePool primaryPool = null;
    final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    try {
        try {
            primaryPool = storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid());
        } catch (final CloudRuntimeException e) {
            if (e.getMessage().contains("not found")) {
                primaryPool = storagePoolMgr.createStoragePool(pool.getUuid(), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUserInfo(), pool.getType());
            } else {
                return new CopyVolumeAnswer(command, false, e.getMessage(), null, null);
            }
        }
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        final String volumeName = libvirtUtilitiesHelper.generateUuidName();
        if (copyToSecondary) {
            final String destVolumeName = volumeName + ".qcow2";
            final KvmPhysicalDisk volume = primaryPool.getPhysicalDisk(command.getVolumePath());
            final String volumeDestPath = "/volumes/" + command.getVolumeId() + File.separator;
            secondaryStoragePool = storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl);
            secondaryStoragePool.createFolder(volumeDestPath);
            storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
            secondaryStoragePool = storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + volumeDestPath);
            storagePoolMgr.copyPhysicalDisk(volume, destVolumeName, secondaryStoragePool, 0);
            return new CopyVolumeAnswer(command, true, null, null, volumeName);
        } else {
            volumePath = "/volumes/" + command.getVolumeId() + File.separator;
            secondaryStoragePool = storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl + volumePath);
            final KvmPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(command.getVolumePath() + ".qcow2");
            storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool, 0);
            return new CopyVolumeAnswer(command, true, null, null, volumeName);
        }
    } catch (final CloudRuntimeException e) {
        return new CopyVolumeAnswer(command, false, e.toString(), null, null);
    } finally {
        if (secondaryStoragePool != null) {
            storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        }
    }
}
Also used : KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KvmStoragePoolManager(com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) KvmPhysicalDisk(com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO)

Aggregations

CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)4 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)2 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)2 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)2 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)2 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)2 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)2 MockVolumeVO (com.cloud.simulator.MockVolumeVO)2 URISyntaxException (java.net.URISyntaxException)2 ConfigurationException (javax.naming.ConfigurationException)2 CopyVolumeCommand (com.cloud.agent.api.storage.CopyVolumeCommand)1 KVMPhysicalDisk (com.cloud.agent.storage.KVMPhysicalDisk)1 KVMStoragePool (com.cloud.agent.storage.KVMStoragePool)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 KvmPhysicalDisk (com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk)1 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager)1