mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Clean up template_zone_ref entries in case of create template failure.
This commit is contained in:
parent
8f549db518
commit
2af36aa87b
@ -23,11 +23,13 @@ import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface VMTemplateZoneDao extends GenericDao<VMTemplateZoneVO, Long> {
|
||||
public List<VMTemplateZoneVO> listByZoneId(long id);
|
||||
|
||||
|
||||
public List<VMTemplateZoneVO> listByTemplateId(long templateId);
|
||||
|
||||
|
||||
public VMTemplateZoneVO findByZoneTemplate(long zoneId, long templateId);
|
||||
|
||||
|
||||
public List<VMTemplateZoneVO> listByZoneTemplate(Long zoneId, long templateId);
|
||||
|
||||
public void deletePrimaryRecordsForTemplate(long templateId);
|
||||
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -27,32 +28,33 @@ import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Component
|
||||
@Local(value={VMTemplateZoneDao.class})
|
||||
public class VMTemplateZoneDaoImpl extends GenericDaoBase<VMTemplateZoneVO, Long> implements VMTemplateZoneDao {
|
||||
public static final Logger s_logger = Logger.getLogger(VMTemplateZoneDaoImpl.class.getName());
|
||||
|
||||
|
||||
protected final SearchBuilder<VMTemplateZoneVO> ZoneSearch;
|
||||
protected final SearchBuilder<VMTemplateZoneVO> TemplateSearch;
|
||||
protected final SearchBuilder<VMTemplateZoneVO> ZoneTemplateSearch;
|
||||
|
||||
|
||||
|
||||
|
||||
public VMTemplateZoneDaoImpl () {
|
||||
ZoneSearch = createSearchBuilder();
|
||||
ZoneSearch.and("zone_id", ZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||
ZoneSearch.done();
|
||||
|
||||
|
||||
TemplateSearch = createSearchBuilder();
|
||||
TemplateSearch.and("template_id", TemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
TemplateSearch.done();
|
||||
|
||||
|
||||
ZoneTemplateSearch = createSearchBuilder();
|
||||
ZoneTemplateSearch.and("zone_id", ZoneTemplateSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
|
||||
ZoneTemplateSearch.and("template_id", ZoneTemplateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
|
||||
ZoneTemplateSearch.done();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<VMTemplateZoneVO> listByZoneId(long id) {
|
||||
@ -84,6 +86,19 @@ public class VMTemplateZoneDaoImpl extends GenericDaoBase<VMTemplateZoneVO, Long
|
||||
}
|
||||
sc.setParameters("template_id", templateId);
|
||||
return listBy(sc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deletePrimaryRecordsForTemplate(long templateId) {
|
||||
SearchCriteria<VMTemplateZoneVO> sc = TemplateSearch.create();
|
||||
sc.setParameters("template_id", templateId);
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
remove(sc);
|
||||
txn.commit();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
||||
s_logger.debug("there is already one in the cache store");
|
||||
return objectInStoreMgr.get(data, cacheStore);
|
||||
}
|
||||
|
||||
|
||||
//TODO: consider multiple thread to create
|
||||
DataObject objOnCacheStore = cacheStore.create(data);
|
||||
|
||||
@ -155,7 +155,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
||||
result = future.get();
|
||||
|
||||
if (result.isFailed()) {
|
||||
cacheStore.delete(data);
|
||||
objOnCacheStore.processEvent(Event.OperationFailed);
|
||||
} else {
|
||||
objOnCacheStore.processEvent(Event.OperationSuccessed, result.getAnswer());
|
||||
return objOnCacheStore;
|
||||
@ -168,7 +168,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
||||
s_logger.debug("create cache storage failed: " + e.toString());
|
||||
} finally {
|
||||
if (result == null) {
|
||||
cacheStore.delete(data);
|
||||
objOnCacheStore.processEvent(Event.OperationFailed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,8 +191,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataObject deleteCacheObject(DataObject data) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public boolean deleteCacheObject(DataObject data) {
|
||||
return objectInStoreMgr.delete(data);
|
||||
}
|
||||
}
|
||||
@ -1456,8 +1456,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
if (privateTemplate == null) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
// Remove the template_store_ref record first, otherwise, we cannot remove the template record due to FK constraints
|
||||
this._tmplStoreDao.deletePrimaryRecordsForTemplate(templateId);
|
||||
// template_store_ref entries should have been removed using our DataObject.processEvent command in case of failure.
|
||||
// Remove the template_zone_ref record
|
||||
this._tmpltZoneDao.deletePrimaryRecordsForTemplate(templateId);
|
||||
// Remove the template record
|
||||
this._tmpltDao.expunge(templateId);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user