Search in sources :

Example 1 with CopyVolumeAnswer

use of com.cloud.agent.api.storage.CopyVolumeAnswer in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method CopyVolume.

@Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
    boolean toSecondaryStorage = cmd.toSecondaryStorage();
    MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
    if (sec == null) {
        return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
    }
    MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
    if (primaryStorage == null) {
        return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
    }
    MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
    if (volume == null) {
        return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
    }
    String name = UUID.randomUUID().toString();
    if (toSecondaryStorage) {
        MockVolumeVO vol = new MockVolumeVO();
        vol.setName(name);
        vol.setPath(sec.getMountPoint() + name);
        vol.setPoolId(sec.getId());
        vol.setSize(volume.getSize());
        vol.setStatus(Status.DOWNLOADED);
        vol.setType(MockVolumeType.VOLUME);
        vol = _mockVolumeDao.persist(vol);
        return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
    } else {
        MockVolumeVO vol = new MockVolumeVO();
        vol.setName(name);
        vol.setPath(primaryStorage.getMountPoint() + name);
        vol.setPoolId(primaryStorage.getId());
        vol.setSize(volume.getSize());
        vol.setStatus(Status.DOWNLOADED);
        vol.setType(MockVolumeType.VOLUME);
        vol = _mockVolumeDao.persist(vol);
        return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
    }
}
Also used : CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 2 with CopyVolumeAnswer

use of com.cloud.agent.api.storage.CopyVolumeAnswer in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
    boolean copyToSecondary = cmd.toSecondaryStorage();
    String volumePath = cmd.getVolumePath();
    StorageFilerTO pool = cmd.getPool();
    String secondaryStorageUrl = cmd.getSecondaryStorageURL();
    KVMStoragePool secondaryStoragePool = null;
    try {
        KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(pool.getUuid());
        String volumeName = UUID.randomUUID().toString();
        if (copyToSecondary) {
            String destVolumeName = volumeName + ".qcow2";
            KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(cmd.getVolumePath());
            String volumeDestPath = "/volumes/" + cmd.getVolumeId() + File.separator;
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
            secondaryStoragePool.createFolder(volumeDestPath);
            secondaryStoragePool.delete();
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + volumeDestPath);
            _storagePoolMgr.copyPhysicalDisk(volume, destVolumeName, secondaryStoragePool);
            return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
        } else {
            volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
            secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + volumePath);
            KVMPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
            _storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool);
            return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
        }
    } catch (CloudRuntimeException e) {
        return new CopyVolumeAnswer(cmd, false, e.toString(), null, null);
    } finally {
        if (secondaryStoragePool != null) {
            secondaryStoragePool.delete();
        }
    }
}
Also used : KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO)

Example 3 with CopyVolumeAnswer

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

the class StorageSystemDataMotionStrategy method copyManagedVolumeToSecondaryStorage.

private String copyManagedVolumeToSecondaryStorage(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, HostVO hostVO, String errMsg) {
    boolean srcVolumeDetached = srcVolumeInfo.getAttachedVM() == null;
    try {
        StoragePoolVO storagePoolVO = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
        Map<String, String> srcDetails = getVolumeDetails(srcVolumeInfo);
        CopyVolumeCommand copyVolumeCommand = new CopyVolumeCommand(srcVolumeInfo.getId(), destVolumeInfo.getPath(), storagePoolVO, destVolumeInfo.getDataStore().getUri(), true, StorageManager.KvmStorageOfflineMigrationWait.value(), true);
        copyVolumeCommand.setSrcData(srcVolumeInfo.getTO());
        copyVolumeCommand.setSrcDetails(srcDetails);
        handleQualityOfServiceForVolumeMigration(srcVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
        if (srcVolumeDetached) {
            _volumeService.grantAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
        }
        CopyVolumeAnswer copyVolumeAnswer = (CopyVolumeAnswer) agentManager.send(hostVO.getId(), copyVolumeCommand);
        if (copyVolumeAnswer == null || !copyVolumeAnswer.getResult()) {
            if (copyVolumeAnswer != null && StringUtils.isNotEmpty(copyVolumeAnswer.getDetails())) {
                throw new CloudRuntimeException(copyVolumeAnswer.getDetails());
            } else {
                throw new CloudRuntimeException(errMsg);
            }
        }
        return copyVolumeAnswer.getVolumePath();
    } catch (Exception ex) {
        String msg = "Failed to perform volume copy to secondary storage : ";
        LOGGER.warn(msg, ex);
        throw new CloudRuntimeException(msg + ex.getMessage());
    } finally {
        if (srcVolumeDetached) {
            _volumeService.revokeAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
        }
        handleQualityOfServiceForVolumeMigration(srcVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 4 with CopyVolumeAnswer

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

the class MockStorageManagerImpl method CopyVolume.

@Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    boolean toSecondaryStorage = cmd.toSecondaryStorage();
    MockSecStorageVO sec = null;
    MockStoragePoolVO primaryStorage = null;
    try {
        txn.start();
        sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
        if (sec == null) {
            return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing secondary at " + cmd.getSecondaryStorageURL(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
        if (primaryStorage == null) {
            return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing primary at " + cmd.getPool(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    MockVolumeVO volume = null;
    txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
        if (volume == null) {
            return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing volume at " + cmd.getVolumePath(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    String name = UUID.randomUUID().toString();
    if (toSecondaryStorage) {
        MockVolumeVO vol = new MockVolumeVO();
        vol.setName(name);
        vol.setPath(sec.getMountPoint() + name);
        vol.setPoolId(sec.getId());
        vol.setSize(volume.getSize());
        vol.setStatus(Status.DOWNLOADED);
        vol.setType(MockVolumeType.VOLUME);
        txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            vol = _mockVolumeDao.persist(vol);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume " + vol.getName(), ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
        return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
    } else {
        MockVolumeVO vol = new MockVolumeVO();
        vol.setName(name);
        vol.setPath(primaryStorage.getMountPoint() + name);
        vol.setPoolId(primaryStorage.getId());
        vol.setSize(volume.getSize());
        vol.setStatus(Status.DOWNLOADED);
        vol.setType(MockVolumeType.VOLUME);
        txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            vol = _mockVolumeDao.persist(vol);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume " + vol.getName(), ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
        return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 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