try {
if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) {
return templateStoragePoolRef;
}
String url = origUrl + "/" + templateHostRef.getInstallPath();
PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(template.getUniqueName(), url, template.getFormat(),
template.getAccountId(), pool.getId(), pool.getUuid(), _primaryStorageDownloadWait);
HostVO secondaryStorageHost = _hostDao.findById(templateHostRef.getHostId());
assert(secondaryStorageHost != null);
dcmd.setSecondaryStorageUrl(secondaryStorageHost.getStorageUrl());
// TODO temporary hacking, hard-coded to NFS primary data store
dcmd.setPrimaryStorageUrl("nfs://" + pool.getHostAddress() + pool.getPath());
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() ) {