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