use of org.apache.cloudstack.engine.subsystem.api.storage.DataObject in project cloudstack by apache.
the class AncientDataMotionStrategy method copyObject.
protected Answer copyObject(DataObject srcData, DataObject destData, Host destHost) {
String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
Answer answer = null;
DataObject cacheData = null;
DataObject srcForCopy = srcData;
try {
if (needCacheStorage(srcData, destData)) {
Scope destScope = pickCacheScopeForCopy(srcData, destData);
srcForCopy = cacheData = cacheMgr.createCacheObject(srcData, destScope);
}
CopyCommand cmd = new CopyCommand(srcForCopy.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcForCopy, 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);
}
if (cacheData != null) {
final Long cacheId = cacheData.getId();
final String cacheType = cacheData.getType().toString();
final String cacheUuid = cacheData.getUuid().toString();
if (srcData.getType() == DataObjectType.VOLUME && (destData.getType() == DataObjectType.VOLUME || destData.getType() == DataObjectType.TEMPLATE)) {
// volume transfer from primary to secondary. Volume transfer between primary pools are already handled by copyVolumeBetweenPools
// Delete cache in order to certainly transfer a latest image.
s_logger.debug("Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
cacheMgr.deleteCacheObject(srcForCopy);
} else {
// for template, we want to leave it on cache for performance reason
if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) {
// cache object created by this copy, not already there
s_logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + " Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
cacheMgr.deleteCacheObject(srcForCopy);
} else {
s_logger.debug("Decrease reference count of " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
cacheMgr.releaseCacheObject(srcForCopy);
}
}
}
return answer;
} catch (Exception e) {
s_logger.debug("copy object failed: ", e);
if (cacheData != null) {
cacheMgr.deleteCacheObject(cacheData);
}
throw new CloudRuntimeException(e.toString());
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataObject in project cloudstack by apache.
the class AncientDataMotionStrategy method copyVolumeFromSnapshot.
protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) {
SnapshotInfo snapshot = (SnapshotInfo) snapObj;
StoragePool pool = (StoragePool) volObj.getDataStore();
String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
DataStore store = snapObj.getDataStore();
DataStoreTO storTO = store.getTO();
DataObject srcData = snapObj;
try {
if (!(storTO instanceof NfsTO)) {
// cache snapshot to zone-wide staging store for the volume to be created
srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));
}
String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
EndPoint ep = null;
if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
ep = selector.select(volObj);
} else {
ep = selector.select(srcData, volObj);
}
CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneFlagOnVMwareDest(volObj.getTO()), _createVolumeFromSnapshotWait, 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);
}
return answer;
} catch (Exception e) {
s_logger.error(basicErrMsg, e);
throw new CloudRuntimeException(basicErrMsg);
} finally {
if (!(storTO instanceof NfsTO)) {
// still keep snapshot on cache which may be migrated from previous secondary storage
releaseSnapshotCacheChain((SnapshotInfo) srcData);
}
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataObject in project cloudstack by apache.
the class TemplateServiceImpl method copyTemplate.
@Override
public AsyncCallFuture<TemplateApiResult> copyTemplate(TemplateInfo srcTemplate, DataStore destStore) {
// Need to understand what is the background to use two different urls for copy and extract.
if (srcTemplate.getFormat() == ImageFormat.OVA) {
ImageStoreEntity tmpltStore = (ImageStoreEntity) srcTemplate.getDataStore();
tmpltStore.createEntityExtractUrl(srcTemplate.getInstallPath(), srcTemplate.getFormat(), srcTemplate);
}
// generate a URL from source template ssvm to download to destination data store
String url = generateCopyUrl(srcTemplate);
if (url == null) {
s_logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + ", no secondary storage vm in running state in source zone");
throw new CloudRuntimeException("No secondary VM in running state in source template zone ");
}
TemplateObject tmplForCopy = (TemplateObject) _templateFactory.getTemplate(srcTemplate, destStore);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting source template url to " + url);
}
tmplForCopy.setUrl(url);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Mark template_store_ref entry as Creating");
}
AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
DataObject templateOnStore = destStore.create(tmplForCopy);
templateOnStore.processEvent(Event.CreateOnlyRequested);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Invoke datastore driver createAsync to create template on destination store");
}
try {
TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<TemplateApiResult>(null, (TemplateObject) templateOnStore, future);
AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context);
destStore.getDriver().createAsync(destStore, templateOnStore, caller);
} catch (CloudRuntimeException ex) {
// clean up already persisted template_store_ref entry in case of createTemplateCallback is never called
TemplateDataStoreVO templateStoreVO = _vmTemplateStoreDao.findByStoreTemplate(destStore.getId(), srcTemplate.getId());
if (templateStoreVO != null) {
TemplateInfo tmplObj = _templateFactory.getTemplate(srcTemplate, destStore);
tmplObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
}
TemplateApiResult res = new TemplateApiResult((TemplateObject) templateOnStore);
res.setResult(ex.getMessage());
future.complete(res);
}
return future;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataObject in project cloudstack by apache.
the class AncientDataMotionStrategy method copyVolumeBetweenPools.
protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) {
String value = configDao.getValue(Config.CopyVolumeWait.key());
int _copyvolumewait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
Scope destScope = getZoneScope(destData.getDataStore().getScope());
DataStore cacheStore = cacheMgr.getCacheStorage(destScope);
if (cacheStore == null) {
// need to find a nfs or cifs image store, assuming that can't copy volume
// directly to s3
ImageStoreEntity imageStore = (ImageStoreEntity) dataStoreMgr.getImageStore(destScope.getScopeId());
if (!imageStore.getProtocol().equalsIgnoreCase("nfs") && !imageStore.getProtocol().equalsIgnoreCase("cifs")) {
s_logger.debug("can't find a nfs (or cifs) image store to satisfy the need for a staging store");
return null;
}
DataObject objOnImageStore = imageStore.create(srcData);
objOnImageStore.processEvent(Event.CreateOnlyRequested);
Answer answer = copyObject(srcData, objOnImageStore);
if (answer == null || !answer.getResult()) {
if (answer != null) {
s_logger.debug("copy to image store failed: " + answer.getDetails());
}
objOnImageStore.processEvent(Event.OperationFailed);
imageStore.delete(objOnImageStore);
return answer;
}
objOnImageStore.processEvent(Event.OperationSuccessed, answer);
objOnImageStore.processEvent(Event.CopyingRequested);
CopyCommand cmd = new CopyCommand(objOnImageStore.getTO(), addFullCloneFlagOnVMwareDest(destData.getTO()), _copyvolumewait, VirtualMachineManager.ExecuteInSequence.value());
EndPoint ep = selector.select(objOnImageStore, 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);
}
if (answer == null || !answer.getResult()) {
if (answer != null) {
s_logger.debug("copy to primary store failed: " + answer.getDetails());
}
objOnImageStore.processEvent(Event.OperationFailed);
imageStore.delete(objOnImageStore);
return answer;
}
objOnImageStore.processEvent(Event.OperationSuccessed);
imageStore.delete(objOnImageStore);
return answer;
} else {
DataObject cacheData = cacheMgr.createCacheObject(srcData, destScope);
CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _copyvolumewait, VirtualMachineManager.ExecuteInSequence.value());
EndPoint ep = selector.select(cacheData, destData);
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);
}
// delete volume on cache store
if (cacheData != null) {
cacheMgr.deleteCacheObject(cacheData);
}
return answer;
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataObject in project cloudstack by apache.
the class AncientDataMotionStrategy method cacheSnapshotChain.
protected DataObject cacheSnapshotChain(SnapshotInfo snapshot, Scope scope) {
DataObject leafData = null;
DataStore store = cacheMgr.getCacheStorage(snapshot, scope);
while (snapshot != null) {
DataObject cacheData = cacheMgr.createCacheObject(snapshot, store);
if (leafData == null) {
leafData = cacheData;
}
snapshot = snapshot.getParent();
}
return leafData;
}
Aggregations