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());
}
}
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();
}
}
}
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);
}
}
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());
}
}
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());
}
}
}
Aggregations