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
@ -30,4 +30,6 @@ public interface VMTemplateZoneDao extends GenericDao<VMTemplateZoneVO, Long> {
|
|||||||
|
|
||||||
public List<VMTemplateZoneVO> listByZoneTemplate(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 javax.ejb.Local;
|
||||||
|
|
||||||
|
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ import com.cloud.storage.VMTemplateZoneVO;
|
|||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.Transaction;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Local(value={VMTemplateZoneDao.class})
|
@Local(value={VMTemplateZoneDao.class})
|
||||||
@ -86,4 +88,17 @@ public class VMTemplateZoneDaoImpl extends GenericDaoBase<VMTemplateZoneVO, Long
|
|||||||
return listBy(sc);
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -155,7 +155,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
|||||||
result = future.get();
|
result = future.get();
|
||||||
|
|
||||||
if (result.isFailed()) {
|
if (result.isFailed()) {
|
||||||
cacheStore.delete(data);
|
objOnCacheStore.processEvent(Event.OperationFailed);
|
||||||
} else {
|
} else {
|
||||||
objOnCacheStore.processEvent(Event.OperationSuccessed, result.getAnswer());
|
objOnCacheStore.processEvent(Event.OperationSuccessed, result.getAnswer());
|
||||||
return objOnCacheStore;
|
return objOnCacheStore;
|
||||||
@ -168,7 +168,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
|||||||
s_logger.debug("create cache storage failed: " + e.toString());
|
s_logger.debug("create cache storage failed: " + e.toString());
|
||||||
} finally {
|
} finally {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
cacheStore.delete(data);
|
objOnCacheStore.processEvent(Event.OperationFailed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,8 +191,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataObject deleteCacheObject(DataObject data) {
|
public boolean deleteCacheObject(DataObject data) {
|
||||||
// TODO Auto-generated method stub
|
return objectInStoreMgr.delete(data);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1456,8 +1456,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
|||||||
if (privateTemplate == null) {
|
if (privateTemplate == null) {
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
txn.start();
|
txn.start();
|
||||||
// Remove the template_store_ref record first, otherwise, we cannot remove the template record due to FK constraints
|
// template_store_ref entries should have been removed using our DataObject.processEvent command in case of failure.
|
||||||
this._tmplStoreDao.deletePrimaryRecordsForTemplate(templateId);
|
// Remove the template_zone_ref record
|
||||||
|
this._tmpltZoneDao.deletePrimaryRecordsForTemplate(templateId);
|
||||||
// Remove the template record
|
// Remove the template record
|
||||||
this._tmpltDao.expunge(templateId);
|
this._tmpltDao.expunge(templateId);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user