use of com.cloud.storage.VMTemplateZoneVO in project cloudstack by apache.
the class VMTemplateZoneDaoImpl method deleteByZoneId.
@Override
public void deleteByZoneId(long zoneId) {
SearchCriteria<VMTemplateZoneVO> sc = ZoneSearch.create();
sc.setParameters("zone_id", zoneId);
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
remove(sc);
txn.commit();
}
use of com.cloud.storage.VMTemplateZoneVO in project cloudstack by apache.
the class VMTemplateZoneDaoImpl method deletePrimaryRecordsForTemplate.
@Override
public void deletePrimaryRecordsForTemplate(long templateId) {
SearchCriteria<VMTemplateZoneVO> sc = TemplateSearch.create();
sc.setParameters("template_id", templateId);
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
remove(sc);
txn.commit();
}
use of com.cloud.storage.VMTemplateZoneVO in project cloudstack by apache.
the class TemplateServiceImpl method associateTemplateToZone.
// persist entry in template_zone_ref table. zoneId can be empty for
// region-wide image store, in that case,
// we will associate the template to all the zones.
@Override
public void associateTemplateToZone(long templateId, Long zoneId) {
List<Long> dcs = new ArrayList<Long>();
if (zoneId != null) {
dcs.add(zoneId);
} else {
List<DataCenterVO> zones = _dcDao.listAll();
for (DataCenterVO zone : zones) {
dcs.add(zone.getId());
}
}
for (Long id : dcs) {
VMTemplateZoneVO tmpltZoneVO = _vmTemplateZoneDao.findByZoneTemplate(id, templateId);
if (tmpltZoneVO == null) {
tmpltZoneVO = new VMTemplateZoneVO(id, templateId, new Date());
_vmTemplateZoneDao.persist(tmpltZoneVO);
} else {
tmpltZoneVO.setLastUpdated(new Date());
_vmTemplateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO);
}
}
}
use of com.cloud.storage.VMTemplateZoneVO in project cloudstack by apache.
the class TemplateServiceImpl method associateCrosszoneTemplatesToZone.
// update template_zone_ref for cross-zone template for newly added zone
@Override
public void associateCrosszoneTemplatesToZone(long dcId) {
VMTemplateZoneVO tmpltZone;
List<VMTemplateVO> allTemplates = _templateDao.listAll();
for (VMTemplateVO vt : allTemplates) {
if (vt.isCrossZones()) {
tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, vt.getId());
if (tmpltZone == null) {
VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, vt.getId(), new Date());
_vmTemplateZoneDao.persist(vmTemplateZone);
}
}
}
}
use of com.cloud.storage.VMTemplateZoneVO in project cloudstack by apache.
the class BareMetalTemplateAdapter method delete.
@Override
@DB
public boolean delete(TemplateProfile profile) {
VMTemplateVO template = profile.getTemplate();
Long templateId = template.getId();
boolean success = true;
String zoneName;
if (profile.getZoneIdList() != null && profile.getZoneIdList().size() > 1)
throw new CloudRuntimeException("Operation is not supported for more than one zone id at a time");
if (!template.isCrossZones() && profile.getZoneIdList() != null) {
// get the first element in the list
zoneName = profile.getZoneIdList().get(0).toString();
} else {
zoneName = "all zones";
}
s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
String eventType = EventTypes.EVENT_TEMPLATE_DELETE;
List<TemplateDataStoreVO> templateHostVOs = this._tmpltStoreDao.listByTemplate(templateId);
for (TemplateDataStoreVO vo : templateHostVOs) {
TemplateDataStoreVO lock = null;
try {
lock = _tmpltStoreDao.acquireInLockTable(vo.getId());
if (lock == null) {
s_logger.debug("Failed to acquire lock when deleting templateDataStoreVO with ID: " + vo.getId());
success = false;
break;
}
vo.setDestroyed(true);
_tmpltStoreDao.update(vo.getId(), vo);
} finally {
if (lock != null) {
_tmpltStoreDao.releaseFromLockTable(lock.getId());
}
}
}
if (profile.getZoneIdList() != null) {
UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), profile.getZoneIdList().get(0), templateId, null);
_usageEventDao.persist(usageEvent);
VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(profile.getZoneIdList().get(0), templateId);
if (templateZone != null) {
_tmpltZoneDao.remove(templateZone.getId());
}
} else {
List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
for (DataCenterVO dc : dcs) {
UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), dc.getId(), templateId, null);
_usageEventDao.persist(usageEvent);
}
}
s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
// If there are no more non-destroyed template host entries for this template, delete it
if (success && (_tmpltStoreDao.listByTemplate(templateId).size() == 0)) {
long accountId = template.getAccountId();
VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);
try {
if (lock == null) {
s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId);
success = false;
} else if (_tmpltDao.remove(templateId)) {
// Decrement the number of templates and total secondary storage space used by the account.
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
_resourceLimitMgr.recalculateResourceCount(accountId, template.getDomainId(), ResourceType.secondary_storage.getOrdinal());
}
} finally {
if (lock != null) {
_tmpltDao.releaseFromLockTable(lock.getId());
}
}
s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed.");
}
return success;
}
Aggregations