Search in sources :

Example 6 with CopyVolumeAnswer

use of com.cloud.agent.api.storage.CopyVolumeAnswer in project cloudstack by apache.

the class LibvirtCopyVolumeCommandWrapper method handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails.

private Answer handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails(CopyVolumeCommand command, LibvirtComputingResource libvirtComputingResource) {
    KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    PrimaryDataStoreTO srcPrimaryDataStore = null;
    KVMStoragePool secondaryStoragePool = null;
    Map<String, String> srcDetails = command.getSrcDetails();
    String srcPath = srcDetails.get(DiskTO.IQN);
    if (srcPath == null) {
        return new CopyVolumeAnswer(command, false, "No IQN was specified", null, null);
    }
    try {
        LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        String destVolumeName = libvirtUtilitiesHelper.generateUUIDName() + ".qcow2";
        String destVolumePath = command.getVolumePath() + File.separator;
        String secondaryStorageUrl = command.getSecondaryStorageURL();
        secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
        secondaryStoragePool.createFolder(File.separator + destVolumePath);
        storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + File.separator + destVolumePath);
        VolumeObjectTO srcVolumeObjectTO = (VolumeObjectTO) command.getSrcData();
        srcPrimaryDataStore = (PrimaryDataStoreTO) srcVolumeObjectTO.getDataStore();
        storagePoolMgr.connectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath, srcDetails);
        KVMPhysicalDisk srcPhysicalDisk = storagePoolMgr.getPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
        storagePoolMgr.copyPhysicalDisk(srcPhysicalDisk, destVolumeName, secondaryStoragePool, command.getWait() * 1000);
        return new CopyVolumeAnswer(command, true, null, null, destVolumePath + destVolumeName);
    } catch (final CloudRuntimeException e) {
        return new CopyVolumeAnswer(command, false, e.toString(), null, null);
    } finally {
        try {
            if (srcPrimaryDataStore != null) {
                storagePoolMgr.disconnectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
            }
        } catch (Exception e) {
            LOGGER.warn("Unable to disconnect from the source device.", e);
        }
        if (secondaryStoragePool != null) {
            storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
        }
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 7 with CopyVolumeAnswer

use of com.cloud.agent.api.storage.CopyVolumeAnswer in project cloudstack by apache.

the class LibvirtCopyVolumeCommandWrapper method execute.

@Override
public Answer execute(final CopyVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) {
    /**
     * This method is only used for copying files from Primary Storage TO
     * Secondary Storage
     *
     * It COULD also do it the other way around, but the code in the
     * ManagementServerImpl shows that it always sets copyToSecondary to
     * true
     */
    Map<String, String> srcDetails = command.getSrcDetails();
    if (srcDetails != null) {
        return handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails(command, libvirtComputingResource);
    }
    final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    final boolean copyToSecondary = command.toSecondaryStorage();
    final StorageFilerTO pool = command.getPool();
    final String secondaryStorageUrl = command.getSecondaryStorageURL();
    KVMStoragePool secondaryStoragePool = null;
    String volumePath;
    KVMStoragePool primaryPool;
    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 : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO)

Example 8 with CopyVolumeAnswer

use of com.cloud.agent.api.storage.CopyVolumeAnswer in project cloudstack by apache.

the class OvmResourceBase method execute.

protected CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
    String volumePath = cmd.getVolumePath();
    String secondaryStorageURL = cmd.getSecondaryStorageURL();
    int wait = cmd.getWait();
    if (wait == 0) {
        wait = 7200;
    }
    try {
        URI uri = new URI(secondaryStorageURL);
        String secStorageMountPath = uri.getHost() + ":" + uri.getPath();
        String volumeFolderOnSecStorage = "volumes/" + String.valueOf(cmd.getVolumeId());
        String storagePoolUuid = cmd.getPool().getUuid();
        Boolean toSec = cmd.toSecondaryStorage();
        String res = OvmStoragePool.copyVolume(_conn, secStorageMountPath, volumeFolderOnSecStorage, volumePath, storagePoolUuid, toSec, wait);
        return new CopyVolumeAnswer(cmd, true, null, null, res);
    } catch (Exception e) {
        s_logger.debug("Copy volume failed", e);
        return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null);
    }
}
Also used : CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) URI(java.net.URI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException)

Example 9 with CopyVolumeAnswer

use of com.cloud.agent.api.storage.CopyVolumeAnswer in project cloudstack by apache.

the class Ovm3StorageProcessor method execute.

/*
     * CopyVolumeCommand gets the storage_pool should use that for
     * bumper bowling.
     */
public CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    String volumePath = cmd.getVolumePath();
    /* is a repository */
    String secondaryStorageURL = cmd.getSecondaryStorageURL();
    int wait = cmd.getWait();
    if (wait == 0) {
        wait = 7200;
    }
    try {
        Linux host = new Linux(c);
        /* to secondary storage */
        if (cmd.toSecondaryStorage()) {
            LOGGER.debug("Copy to  secondary storage " + volumePath + " to " + secondaryStorageURL);
            host.copyFile(volumePath, secondaryStorageURL);
        /* from secondary storage */
        } else {
            LOGGER.debug("Copy from secondary storage " + secondaryStorageURL + " to " + volumePath);
            host.copyFile(secondaryStorageURL, volumePath);
        }
        /* check the truth of this */
        return new CopyVolumeAnswer(cmd, true, null, null, null);
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("Copy volume failed", e);
        return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null);
    }
}
Also used : Linux(com.cloud.hypervisor.ovm3.objects.Linux) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer)

Example 10 with CopyVolumeAnswer

use of com.cloud.agent.api.storage.CopyVolumeAnswer in project cloudstack by apache.

the class VmwareStorageManagerImpl method execute.

@Override
public Answer execute(VmwareHostService hostService, CopyVolumeCommand cmd) {
    Long volumeId = cmd.getVolumeId();
    String volumePath = cmd.getVolumePath();
    String secondaryStorageURL = cmd.getSecondaryStorageURL();
    String vmName = cmd.getVmName();
    VmwareContext context = hostService.getServiceContext(cmd);
    try {
        VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
        Pair<String, String> result;
        if (cmd.toSecondaryStorage()) {
            result = copyVolumeToSecStorage(hostService, hyperHost, cmd, vmName, volumeId, cmd.getPool().getUuid(), volumePath, secondaryStorageURL, hostService.getWorkerName(context, cmd, 0, null), cmd.getNfsVersion());
        } else {
            StorageFilerTO poolTO = cmd.getPool();
            ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, poolTO.getUuid());
            if (morDatastore == null) {
                morDatastore = hyperHost.mountDatastore(false, poolTO.getHost(), 0, poolTO.getPath(), poolTO.getUuid().replace("-", ""), true);
                if (morDatastore == null) {
                    throw new Exception("Unable to mount storage pool on host. storeUrl: " + poolTO.getHost() + ":/" + poolTO.getPath());
                }
            }
            result = copyVolumeFromSecStorage(hyperHost, volumeId, new DatastoreMO(context, morDatastore), secondaryStorageURL, volumePath, cmd.getNfsVersion());
            deleteVolumeDirOnSecondaryStorage(volumeId, secondaryStorageURL, cmd.getNfsVersion());
        }
        return new CopyVolumeAnswer(cmd, true, null, result.first(), result.second());
    } catch (Throwable e) {
        return new CopyVolumeAnswer(cmd, false, hostService.createLogMessageException(e, cmd), null, null);
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

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