mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Fixed multiple bugs in registerTemplate/registerIso:
1) throw exception when try to register template/iso when there are no zones in the system 2) don't add the template to template_zone_ref when the zone is removed 3) Don't try to download the template when template failed to persist in the DB
This commit is contained in:
parent
a5a5ff82e4
commit
5423f744b3
@ -377,7 +377,6 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager{
|
||||
return limits;
|
||||
}
|
||||
|
||||
|
||||
//If account is not specified, default it to caller account
|
||||
if (accountId == null) {
|
||||
if (domainId == null) {
|
||||
|
||||
@ -61,6 +61,7 @@ import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Func;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Local(value={VMTemplateDao.class})
|
||||
public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implements VMTemplateDao {
|
||||
@ -683,7 +684,9 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
txn.start();
|
||||
VMTemplateVO tmplt2 = findById(tmplt.getId());
|
||||
if (tmplt2 == null){
|
||||
persist(tmplt);
|
||||
if (persist(tmplt) == null) {
|
||||
throw new CloudRuntimeException("Failed to persist the template " + tmplt);
|
||||
}
|
||||
if(tmplt.getDetails() != null) {
|
||||
_templateDetailsDao.persist(tmplt.getId(), tmplt.getDetails());
|
||||
}
|
||||
|
||||
@ -116,6 +116,10 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
|
||||
public VMTemplateVO create(TemplateProfile profile) {
|
||||
VMTemplateVO template = persistTemplate(profile);
|
||||
|
||||
if (template == null) {
|
||||
throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate());
|
||||
}
|
||||
|
||||
_downloadMonitor.downloadTemplateToStorage(template, profile.getZoneId());
|
||||
_resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.EnumUtils;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
|
||||
public abstract class TemplateAdapterBase implements TemplateAdapter {
|
||||
@ -236,7 +237,11 @@ public abstract class TemplateAdapterBase implements TemplateAdapter {
|
||||
profile.getDetails());
|
||||
|
||||
if (zoneId == null || zoneId == -1) {
|
||||
List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
|
||||
List<DataCenterVO> dcs = _dcDao.listAll();
|
||||
|
||||
if (dcs.isEmpty()) {
|
||||
throw new CloudRuntimeException("No zones are present in the system, can't add template");
|
||||
}
|
||||
|
||||
for (DataCenterVO dc: dcs) {
|
||||
_tmpltDao.addTemplateToZone(template, dc.getId());
|
||||
@ -245,7 +250,7 @@ public abstract class TemplateAdapterBase implements TemplateAdapter {
|
||||
} else {
|
||||
_tmpltDao.addTemplateToZone(template, zoneId);
|
||||
}
|
||||
return template;
|
||||
return _tmpltDao.findById(template.getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user