mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Handle CopyCmdAnswer in VolumeObject.processEvent for image and
imageCache, and fix a bug in selecting endpoint.
This commit is contained in:
parent
383be568b3
commit
f23f341922
@ -140,6 +140,9 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
protected Answer copyObject(DataObject srcData, DataObject destData) {
|
||||
String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
|
||||
int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
|
||||
Answer answer = null;
|
||||
DataObject cacheData = null;
|
||||
try {
|
||||
if (needCacheStorage(srcData, destData)) {
|
||||
// need to copy it to image cache store
|
||||
Scope destScope = destData.getDataStore().getScope();
|
||||
@ -150,18 +153,31 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
HostScope hostScope = (HostScope) destScope;
|
||||
destScope = new ZoneScope(hostScope.getZoneId());
|
||||
}
|
||||
DataObject cacheData = cacheMgr.createCacheObject(srcData, destScope);
|
||||
cacheData = cacheMgr.createCacheObject(srcData, destScope);
|
||||
CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _primaryStorageDownloadWait);
|
||||
EndPoint ep = selector.select(cacheData, destData);
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
return answer;
|
||||
answer = ep.sendMessage(cmd);
|
||||
} else {
|
||||
// handle copy it to/from cache store
|
||||
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait);
|
||||
EndPoint ep = selector.select(srcData, destData);
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
return answer;
|
||||
answer = ep.sendMessage(cmd);
|
||||
}
|
||||
// clean up cache entry in case of failure
|
||||
if (answer == null || !answer.getResult()) {
|
||||
if (cacheData != null) {
|
||||
cacheMgr.deleteCacheObject(cacheData);
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("copy object failed: " + e.toString());
|
||||
if (cacheData != null) {
|
||||
cacheMgr.deleteCacheObject(cacheData);
|
||||
}
|
||||
throw new CloudRuntimeException(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected DataObject cacheSnapshotChain(SnapshotInfo snapshot) {
|
||||
@ -306,6 +322,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
|
||||
|
||||
DataObject cacheData = null;
|
||||
Answer answer = null;
|
||||
try {
|
||||
if (needCacheStorage(srcData, destData)) {
|
||||
cacheData = cacheMgr.getCacheObject(srcData, destData.getDataStore().getScope());
|
||||
@ -313,14 +330,19 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
|
||||
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
|
||||
cmd.setCacheTO(cacheData.getTO());
|
||||
EndPoint ep = selector.select(srcData, destData);
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
return answer;
|
||||
answer = ep.sendMessage(cmd);
|
||||
} else {
|
||||
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
|
||||
EndPoint ep = selector.select(srcData, destData);
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
return answer;
|
||||
answer = ep.sendMessage(cmd);
|
||||
}
|
||||
// clean up cache entry in case of failure
|
||||
if (answer == null || !answer.getResult()) {
|
||||
if (cacheData != null) {
|
||||
cacheMgr.deleteCacheObject(cacheData);
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("copy snasphot failed: " + e.toString());
|
||||
if (cacheData != null) {
|
||||
|
||||
@ -77,7 +77,8 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
||||
protected boolean moveBetweenCacheAndImage(DataStore srcStore, DataStore destStore) {
|
||||
DataStoreRole srcRole = srcStore.getRole();
|
||||
DataStoreRole destRole = destStore.getRole();
|
||||
if (srcRole == DataStoreRole.Image && destRole == DataStoreRole.ImageCache) {
|
||||
if (srcRole == DataStoreRole.Image && destRole == DataStoreRole.ImageCache ||
|
||||
srcRole == DataStoreRole.ImageCache && destRole == DataStoreRole.Image) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@ -403,13 +403,21 @@ public class VolumeObject implements VolumeInfo {
|
||||
vol.setPoolId(this.getDataStore().getId());
|
||||
volumeDao.update(vol.getId(), vol);
|
||||
}
|
||||
} else if (this.dataStore.getRole() == DataStoreRole.Image) {
|
||||
} else {
|
||||
// image store or imageCache store
|
||||
if (answer instanceof DownloadAnswer) {
|
||||
DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
|
||||
VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
|
||||
volStore.setInstallPath(dwdAnswer.getInstallPath());
|
||||
volStore.setChecksum(dwdAnswer.getCheckSum());
|
||||
this.volumeStoreDao.update(volStore.getId(), volStore);
|
||||
} else if (answer instanceof CopyCmdAnswer ){
|
||||
CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
|
||||
VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(), this.getId());
|
||||
VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
|
||||
volStore.setInstallPath(newVol.getPath());
|
||||
volStore.setSize(newVol.getSize());
|
||||
this.volumeStoreDao.update(volStore.getId(), volStore);
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException ex) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user