bug 12113: DeployVm: when template download from Secondary to Primary storage fails try a couple of times first and then fail.

Reviewed by : Kishan.
This commit is contained in:
Nitin Mehta 2011-12-21 11:33:30 +05:30
parent 744e10bf01
commit b675a01741
1 changed files with 28 additions and 30 deletions

View File

@ -622,12 +622,8 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
List<StoragePoolHostVO> vos = _poolHostDao.listByHostStatus(poolId, com.cloud.host.Status.Up);
if (vos == null || vos.isEmpty()){
if (s_logger.isDebugEnabled()) {
s_logger.debug("Cannot download " + templateId + " to poolId " + poolId + " since there is no host in the Up state connected to this pool");
}
}
Collections.shuffle(vos); // Shuffling so we don't pick the same host in the vm deployment retries
StoragePoolHostVO vo = vos.get(0);
throw new CloudRuntimeException("Cannot download " + templateId + " to poolId " + poolId + " since there is no host in the Up state connected to this pool");
}
templateStoragePoolRef = _tmpltPoolDao.acquireInLockTable(templateStoragePoolRefId, _storagePoolMaxWaitSeconds);
if (templateStoragePoolRef == null) {
@ -647,31 +643,33 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
// TODO temporary hacking, hard-coded to NFS primary data store
dcmd.setPrimaryStorageUrl("nfs://" + pool.getHostAddress() + pool.getPath());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Downloading " + templateId + " via " + vo.getHostId());
for (int retry = 0; retry < 2; retry ++){
Collections.shuffle(vos); // Shuffling to pick a random host in the vm deployment retries
StoragePoolHostVO vo = vos.get(0);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Downloading " + templateId + " via " + vo.getHostId());
}
dcmd.setLocalPath(vo.getLocalPath());
// set 120 min timeout for this command
PrimaryStorageDownloadAnswer answer = (PrimaryStorageDownloadAnswer)_agentMgr.easySend(
_hvGuruMgr.getGuruProcessedCommandTargetHost(vo.getHostId(), dcmd), dcmd);
if (answer != null && answer.getResult() ) {
templateStoragePoolRef.setDownloadPercent(100);
templateStoragePoolRef.setDownloadState(Status.DOWNLOADED);
templateStoragePoolRef.setLocalDownloadPath(answer.getInstallPath());
templateStoragePoolRef.setInstallPath(answer.getInstallPath());
templateStoragePoolRef.setTemplateSize(answer.getTemplateSize());
_tmpltPoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + templateId + " is downloaded via " + vo.getHostId());
}
return templateStoragePoolRef;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + templateId + " download to pool " + vo.getPoolId() + " failed due to " + (answer!=null?answer.getDetails():"return null")); }
}
}
dcmd.setLocalPath(vo.getLocalPath());
// set 120 min timeout for this command
PrimaryStorageDownloadAnswer answer = (PrimaryStorageDownloadAnswer)_agentMgr.easySend(
_hvGuruMgr.getGuruProcessedCommandTargetHost(vo.getHostId(), dcmd), dcmd);
if (answer != null && answer.getResult() ) {
templateStoragePoolRef.setDownloadPercent(100);
templateStoragePoolRef.setDownloadState(Status.DOWNLOADED);
templateStoragePoolRef.setLocalDownloadPath(answer.getInstallPath());
templateStoragePoolRef.setInstallPath(answer.getInstallPath());
templateStoragePoolRef.setTemplateSize(answer.getTemplateSize());
_tmpltPoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + templateId + " is downloaded via " + vo.getHostId());
}
return templateStoragePoolRef;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Template " + templateId + " download to pool " + vo.getPoolId() + " failed due to " + (answer!=null?answer.getDetails():"return null")); }
}
} finally {
_tmpltPoolDao.releaseFromLockTable(templateStoragePoolRefId);
}