cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [2/3] git commit: updated refs/heads/object_store to cb0659a
Date Tue, 21 May 2013 19:02:55 GMT
Clean up template_zone_ref entries in case of create template failure.

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2af36aa8
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2af36aa8
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2af36aa8

Branch: refs/heads/object_store
Commit: 2af36aa87b1a101099fd37c7d60e230af39bdca2
Parents: 8f549db
Author: Min Chen <min.chen@citrix.com>
Authored: Tue May 21 12:00:59 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Tue May 21 12:00:59 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/storage/dao/VMTemplateZoneDao.java   |    8 +++--
 .../cloud/storage/dao/VMTemplateZoneDaoImpl.java   |   29 +++++++++++----
 .../cache/manager/StorageCacheManagerImpl.java     |   11 +++---
 .../com/cloud/template/TemplateManagerImpl.java    |    5 ++-
 4 files changed, 35 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2af36aa8/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java
index bb3aa01..27e05c9 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDao.java
@@ -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);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2af36aa8/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java
index 916e0ac..27b554c 100644
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java
@@ -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();
+
+    }
+
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2af36aa8/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
index c76e67b..d2895fd 100644
--- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
+++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java
@@ -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);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2af36aa8/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index dca892f..21615c9 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -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);
 


Mime
View raw message