use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method performCopyOfVdi.
/**
* Copies data from secondary storage to a primary volume
* @param volumeInfo The primary volume
* @param snapshotInfo destination of the copy
* @param hostVO the host used to copy the data
* @return result of the copy
*/
private CopyCmdAnswer performCopyOfVdi(VolumeInfo volumeInfo, SnapshotInfo snapshotInfo, HostVO hostVO) {
Snapshot.LocationType locationType = snapshotInfo.getLocationType();
String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
DataObject srcData = snapshotInfo;
CopyCmdAnswer copyCmdAnswer = null;
DataObject cacheData = null;
boolean needCacheStorage = needCacheStorage(snapshotInfo, volumeInfo);
if (needCacheStorage) {
cacheData = cacheSnapshotChain(snapshotInfo, new ZoneScope(volumeInfo.getDataCenterId()));
srcData = cacheData;
}
CopyCommand copyCommand = new CopyCommand(srcData.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
try {
if (Snapshot.LocationType.PRIMARY.equals(locationType)) {
_volumeService.grantAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
Map<String, String> srcDetails = getSnapshotDetails(snapshotInfo);
copyCommand.setOptions(srcDetails);
}
_volumeService.grantAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
Map<String, String> destDetails = getVolumeDetails(volumeInfo);
copyCommand.setOptions2(destDetails);
copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
} catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) {
String msg = "Failed to perform VDI copy : ";
LOGGER.warn(msg, ex);
throw new CloudRuntimeException(msg + ex.getMessage());
} finally {
if (Snapshot.LocationType.PRIMARY.equals(locationType)) {
_volumeService.revokeAccess(snapshotInfo, hostVO, snapshotInfo.getDataStore());
}
_volumeService.revokeAccess(volumeInfo, hostVO, volumeInfo.getDataStore());
if (needCacheStorage && copyCmdAnswer != null && copyCmdAnswer.getResult()) {
cacheMgr.deleteCacheObject(cacheData);
}
}
return copyCmdAnswer;
}
use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class AncientDataMotionStrategy method cloneVolume.
protected Answer cloneVolume(DataObject template, DataObject volume) {
CopyCommand cmd = new CopyCommand(template.getTO(), addFullCloneFlagOnVMwareDest(volume.getTO()), 0, VirtualMachineManager.ExecuteInSequence.value());
try {
EndPoint ep = selector.select(volume.getDataStore());
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
return answer;
} catch (Exception e) {
s_logger.debug("Failed to send to storage pool", e);
throw new CloudRuntimeException("Failed to send to storage pool", e);
}
}
use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class AncientDataMotionStrategy method copySnapshot.
protected Answer copySnapshot(DataObject srcData, DataObject destData) {
String value = configDao.getValue(Config.BackupSnapshotWait.toString());
int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
DataObject cacheData = null;
SnapshotInfo snapshotInfo = (SnapshotInfo) srcData;
Object payload = snapshotInfo.getPayload();
Boolean fullSnapshot = true;
if (payload != null) {
fullSnapshot = (Boolean) payload;
}
Map<String, String> options = new HashMap<String, String>();
options.put("fullSnapshot", fullSnapshot.toString());
Answer answer = null;
try {
if (needCacheStorage(srcData, destData)) {
Scope selectedScope = pickCacheScopeForCopy(srcData, destData);
cacheData = cacheMgr.getCacheObject(srcData, selectedScope);
CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
cmd.setCacheTO(cacheData.getTO());
cmd.setOptions(options);
EndPoint ep = selector.select(srcData, destData);
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
} else {
addFullCloneFlagOnVMwareDest(destData.getTO());
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
cmd.setOptions(options);
EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT);
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
}
// clean up cache entry
if (cacheData != null) {
cacheMgr.deleteCacheObject(cacheData);
}
return answer;
} catch (Exception e) {
s_logger.debug("copy snasphot failed: " + e.toString());
if (cacheData != null) {
cacheMgr.deleteCacheObject(cacheData);
}
throw new CloudRuntimeException(e.toString());
}
}
use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class AncientDataMotionStrategy method createTemplateFromSnapshot.
@DB
protected Answer createTemplateFromSnapshot(DataObject srcData, DataObject destData) {
String value = configDao.getValue(Config.CreatePrivateTemplateFromSnapshotWait.toString());
int _createprivatetemplatefromsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreatePrivateTemplateFromSnapshotWait.getDefaultValue()));
boolean needCache = false;
if (needCacheStorage(srcData, destData)) {
needCache = true;
SnapshotInfo snapshot = (SnapshotInfo) srcData;
srcData = cacheSnapshotChain(snapshot, snapshot.getDataStore().getScope());
}
EndPoint ep = null;
if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
ep = selector.select(destData);
} else {
ep = selector.select(srcData, destData);
}
CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _createprivatetemplatefromsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(cmd, false, errMsg);
} else {
answer = ep.sendMessage(cmd);
}
// clean up snapshot copied to staging
if (needCache && srcData != null) {
// reduce ref count, but keep it there on cache which is converted from previous secondary storage
cacheMgr.releaseCacheObject(srcData);
}
return answer;
}
use of org.apache.cloudstack.storage.command.CopyCommand in project cloudstack by apache.
the class Ovm3StorageProcessorTest method copyCommandTemplateToTemplateTest.
/**
* Copy template from secondary to primary template
*
* @throws ConfigurationException
*/
@Test
public void copyCommandTemplateToTemplateTest() throws ConfigurationException {
con = prepare();
con.setMethodResponse("storage_plugin_mount", results.simpleResponseWrapWrapper(storageplugin.getNfsFileSystemInfo()));
/*
* because the template requires a reference to the name for the uuid...
* -sigh-
*/
String templateid = ovmObject.newUuid();
String targetid = ovmObject.newUuid();
String templatedir = "template/tmpl/1/11" + templateid + ".raw";
String storeUrl = "nfs://" + linux.getRemoteHost() + "/" + linux.getRemoteDir();
TemplateObjectTO src = template(templateid, linux.getRepoId(), storeUrl, templatedir);
TemplateObjectTO dest = template(targetid, linux.getRepoId(), linux.getRepoId(), linux.getTemplatesDir());
CopyCommand copy = new CopyCommand(src, dest, 0, true);
CopyCmdAnswer ra = (CopyCmdAnswer) hypervisor.executeRequest(copy);
TemplateObjectTO vol = (TemplateObjectTO) ra.getNewData();
results.basicStringTest(vol.getUuid(), targetid);
results.basicStringTest(vol.getPath(), targetid);
results.basicBooleanTest(ra.getResult());
}
Aggregations