mirror of https://github.com/apache/cloudstack.git
private template may be downloaded to multiple secondary storage in a zone,
fixed it
This commit is contained in:
parent
31549b337e
commit
ccc3c79466
|
|
@ -61,5 +61,6 @@ public interface VMTemplateHostDao extends GenericDao<VMTemplateHostVO, Long> {
|
|||
void deleteByHost(Long hostId);
|
||||
|
||||
VMTemplateHostVO findLocalSecondaryStorageByHostTemplate(long hostId, long templateId);
|
||||
|
||||
|
||||
List<VMTemplateHostVO> listByTemplateHostStatus(long templateId, long hostId, Status... states);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
|
|||
protected final SearchBuilder<VMTemplateHostVO> HostSearch;
|
||||
protected final SearchBuilder<VMTemplateHostVO> TemplateSearch;
|
||||
protected final SearchBuilder<VMTemplateHostVO> HostTemplateSearch;
|
||||
protected final SearchBuilder<VMTemplateHostVO> HostTemplateStateSearch;
|
||||
protected final SearchBuilder<VMTemplateHostVO> HostDestroyedSearch;
|
||||
protected final SearchBuilder<VMTemplateHostVO> PoolTemplateSearch;
|
||||
protected final SearchBuilder<VMTemplateHostVO> HostTemplatePoolSearch;
|
||||
|
|
@ -72,7 +73,7 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
|
|||
+ "t.download_pct, t.size, t.physical_size, t.download_state, t.error_str, t.local_path, "
|
||||
+ "t.install_path, t.url, t.destroyed, t.is_copy FROM template_host_ref t, host h "
|
||||
+ "where t.host_id = h.id and h.data_center_id=? "
|
||||
+ " and t.template_id=? and t.download_state = ?" ;
|
||||
+ " and t.template_id=? and t.download_state = ?" ;
|
||||
|
||||
protected static final String DOWNLOADS_STATE_DC_POD=
|
||||
"SELECT * FROM template_host_ref t, host h where t.host_id = h.id and h.data_center_id=? and h.pod_id=? "
|
||||
|
|
@ -111,18 +112,24 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
|
|||
TemplateStatusSearch = createSearchBuilder();
|
||||
TemplateStatusSearch.and("template_id", TemplateStatusSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
TemplateStatusSearch.and("download_state", TemplateStatusSearch.entity().getDownloadState(), SearchCriteria.Op.EQ);
|
||||
TemplateStatusSearch.done();
|
||||
|
||||
TemplateStatesSearch = createSearchBuilder();
|
||||
TemplateStatesSearch.and("template_id", TemplateStatesSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
TemplateStatesSearch.and("states", TemplateStatesSearch.entity().getDownloadState(), SearchCriteria.Op.IN);
|
||||
TemplateStatesSearch.done();
|
||||
|
||||
PoolTemplateSearch = createSearchBuilder();
|
||||
PoolTemplateSearch.and("pool_id", PoolTemplateSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
|
||||
PoolTemplateSearch.and("template_id", PoolTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
PoolTemplateSearch.done();
|
||||
}
|
||||
TemplateStatusSearch.done();
|
||||
|
||||
TemplateStatesSearch = createSearchBuilder();
|
||||
TemplateStatesSearch.and("template_id", TemplateStatesSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
TemplateStatesSearch.and("states", TemplateStatesSearch.entity().getDownloadState(), SearchCriteria.Op.IN);
|
||||
TemplateStatesSearch.done();
|
||||
|
||||
HostTemplateStateSearch = createSearchBuilder();
|
||||
HostTemplateStateSearch.and("template_id", HostTemplateStateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
HostTemplateStateSearch.and("host_id", HostTemplateStateSearch.entity().getHostId(), SearchCriteria.Op.EQ);
|
||||
HostTemplateStateSearch.and("states", HostTemplateStateSearch.entity().getDownloadState(), SearchCriteria.Op.IN);
|
||||
HostTemplateStateSearch.done();
|
||||
|
||||
PoolTemplateSearch = createSearchBuilder();
|
||||
PoolTemplateSearch.and("pool_id", PoolTemplateSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
|
||||
PoolTemplateSearch.and("template_id", PoolTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
PoolTemplateSearch.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
|
|
@ -228,9 +235,17 @@ public class VMTemplateHostDaoImpl extends GenericDaoBase<VMTemplateHostVO, Long
|
|||
s_logger.warn("Exception: ", e);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMTemplateHostVO> listByTemplateHostStatus(long templateId, long hostId, VMTemplateHostVO.Status... states) {
|
||||
SearchCriteria<VMTemplateHostVO> 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<VMTemplateHostVO> listByTemplateStatus(long templateId, long datacenterId, long podId, VMTemplateHostVO.Status downloadState) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -197,9 +197,9 @@ public class DownloadMonitorImpl implements DownloadMonitor {
|
|||
}
|
||||
|
||||
|
||||
public boolean isTemplateUpdateable(Long templateId, Long datacenterId) {
|
||||
public boolean isTemplateUpdateable(Long templateId, Long hostId) {
|
||||
List<VMTemplateHostVO> 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<DataCenterVO> dcs = new ArrayList<DataCenterVO>();
|
||||
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<HostVO> ssHosts = _hostDao.listAllSecondaryStorageHosts(dc.getId());
|
||||
for ( HostVO ssHost : ssHosts ) {
|
||||
if (isTemplateUpdateable(ssHost.getId(), templateId)) {
|
||||
|
||||
initiateTemplateDownload(templateId, ssHost);
|
||||
if (! isPublic ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue