diff --git a/server/src/com/cloud/storage/dao/VMTemplateHostDao.java b/server/src/com/cloud/storage/dao/VMTemplateHostDao.java index 9f4aba0a7f9..d58ff20c280 100755 --- a/server/src/com/cloud/storage/dao/VMTemplateHostDao.java +++ b/server/src/com/cloud/storage/dao/VMTemplateHostDao.java @@ -61,5 +61,6 @@ public interface VMTemplateHostDao extends GenericDao { void deleteByHost(Long hostId); VMTemplateHostVO findLocalSecondaryStorageByHostTemplate(long hostId, long templateId); - + + List listByTemplateHostStatus(long templateId, long hostId, Status... states); } diff --git a/server/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java b/server/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java index 9bf79300327..5db30fdfa45 100755 --- a/server/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java +++ b/server/src/com/cloud/storage/dao/VMTemplateHostDaoImpl.java @@ -53,6 +53,7 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase HostSearch; protected final SearchBuilder TemplateSearch; protected final SearchBuilder HostTemplateSearch; + protected final SearchBuilder HostTemplateStateSearch; protected final SearchBuilder HostDestroyedSearch; protected final SearchBuilder PoolTemplateSearch; protected final SearchBuilder HostTemplatePoolSearch; @@ -72,7 +73,7 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase params) throws ConfigurationException { @@ -228,9 +235,17 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase listByTemplateHostStatus(long templateId, long hostId, VMTemplateHostVO.Status... states) { + SearchCriteria sc = HostTemplateStateSearch.create(); + sc.setParameters("template_id", templateId); + sc.setParameters("host_id", hostId); + sc.setParameters("states", (Object[])states); + return search(sc, null); + } + @Override public List listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateHostVO.Status downloadState) { Transaction txn = Transaction.currentTxn(); diff --git a/server/src/com/cloud/storage/download/DownloadMonitor.java b/server/src/com/cloud/storage/download/DownloadMonitor.java index 1739dcdbb63..48eb5a3461a 100644 --- a/server/src/com/cloud/storage/download/DownloadMonitor.java +++ b/server/src/com/cloud/storage/download/DownloadMonitor.java @@ -34,7 +34,7 @@ import com.cloud.utils.component.Manager; */ public interface DownloadMonitor extends Manager{ - public boolean downloadTemplateToStorage(Long templateId, Long zoneId); + public boolean downloadTemplateToStorage(VMTemplateVO template, Long zoneId); public void cancelAllDownloads(Long templateId); diff --git a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java index 08bc4348e27..d4249382970 100755 --- a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java +++ b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java @@ -197,9 +197,9 @@ public class DownloadMonitorImpl implements DownloadMonitor { } - public boolean isTemplateUpdateable(Long templateId, Long datacenterId) { + public boolean isTemplateUpdateable(Long templateId, Long hostId) { List downloadsInProgress = - _vmTemplateHostDao.listByTemplateStatus(templateId, datacenterId, VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS); + _vmTemplateHostDao.listByTemplateHostStatus(templateId.longValue(), hostId.longValue(), VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS, VMTemplateHostVO.Status.DOWNLOADED); return (downloadsInProgress.size() == 0); } @@ -355,19 +355,23 @@ public class DownloadMonitorImpl implements DownloadMonitor { @Override - public boolean downloadTemplateToStorage(Long templateId, Long zoneId) { + public boolean downloadTemplateToStorage(VMTemplateVO template, Long zoneId) { List dcs = new ArrayList(); if (zoneId == null) { dcs.addAll(_dcDao.listAll()); } else { dcs.add(_dcDao.findById(zoneId)); } + long templateId = template.getId(); + boolean isPublic = template.isFeatured() || template.isPublicTemplate(); for ( DataCenterVO dc : dcs ) { List ssHosts = _hostDao.listAllSecondaryStorageHosts(dc.getId()); for ( HostVO ssHost : ssHosts ) { if (isTemplateUpdateable(ssHost.getId(), templateId)) { - initiateTemplateDownload(templateId, ssHost); + if (! isPublic ) { + break; + } } } } diff --git a/server/src/com/cloud/template/HyervisorTemplateAdapter.java b/server/src/com/cloud/template/HyervisorTemplateAdapter.java index 81345a84df0..8eb19c6b4ef 100644 --- a/server/src/com/cloud/template/HyervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HyervisorTemplateAdapter.java @@ -107,7 +107,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem public VMTemplateVO create(TemplateProfile profile) { VMTemplateVO template = persistTemplate(profile); - _downloadMonitor.downloadTemplateToStorage(profile.getTemplateId(), profile.getZoneId()); + _downloadMonitor.downloadTemplateToStorage(template, profile.getZoneId()); _accountMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template); return template; diff --git a/server/src/com/cloud/template/TemplateManager.java b/server/src/com/cloud/template/TemplateManager.java index 7279510d5a8..31e79b34001 100755 --- a/server/src/com/cloud/template/TemplateManager.java +++ b/server/src/com/cloud/template/TemplateManager.java @@ -39,42 +39,6 @@ import com.cloud.storage.VMTemplateVO; */ public interface TemplateManager extends TemplateService{ - /** - * Creates a Template - * - * @param zoneId - * zone to create the template in - * @param displayText - * user readable name. - * @param isPublic - * is this a public template? - * @param featured - * is this template featured? - * @param isExtractable - * is this template extractable? - * @param format - * which image format is the template. - * @param fs - * what is the file system on the template - * @param url - * url to download the template from. - * @param chksum - * chksum to compare it to. - * @param requiresHvm - * does this template require hvm? - * @param bits - * is the os contained on the template 32 bit? - * @param enablePassword - * Does the template support password change. - * @param guestOSId - * OS that is on the template - * @param bootable - * true if this template will represent a bootable ISO - * @return id of the template created. - */ - Long createInZone(long zoneId, long userId, String displayText, boolean isPublic, boolean featured, boolean isExtractable, ImageFormat format, TemplateType type, URI url, String chksum, - boolean requiresHvm, int bits, boolean enablePassword, long guestOSId, boolean bootable); - /** * Prepares a template for vm creation for a certain storage pool. * diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index a65a0fb4672..967cd7fea4d 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -703,28 +703,6 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe protected TemplateManagerImpl() { } - @Override - public Long createInZone(long zoneId, long userId, String displayText, - boolean isPublic, boolean featured, boolean isExtractable, ImageFormat format, - TemplateType type, URI url, String chksum, boolean requiresHvm, - int bits, boolean enablePassword, long guestOSId, boolean bootable) { - Long id = _tmpltDao.getNextInSequence(Long.class, "id"); - - UserVO user = _userDao.findById(userId); - long accountId = user.getAccountId(); - - VMTemplateVO template = new VMTemplateVO(id, displayText, format, isPublic, featured, isExtractable, type, url.toString(), requiresHvm, bits, accountId, chksum, displayText, enablePassword, guestOSId, bootable, null); - - Long templateId = _tmpltDao.addTemplateToZone(template, zoneId); - UserAccount userAccount = _userAccountDao.findById(userId); - - _downloadMonitor.downloadTemplateToStorage(id, zoneId); - - _accountMgr.incrementResourceCount(userAccount.getAccountId(), ResourceType.template); - - return templateId; - } - @Override public boolean templateIsDeleteable(VMTemplateHostVO templateHostRef) { VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templateHostRef.getTemplateId());