cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [4/8] git commit: updated refs/heads/object_store_migration to 9da56fe
Date Sat, 26 Oct 2013 04:18:47 GMT
Delete cache entries of template, snapshot, and volume when
deleteTemplate, deleteSnapshot, deleteVolume are invoked.

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

Branch: refs/heads/object_store_migration
Commit: 730832d8fa5e75d7a30f990046ab3a004abda0fa
Parents: 184e539
Author: Min Chen <min.chen@citrix.com>
Authored: Wed Oct 23 14:05:05 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Wed Oct 23 14:05:05 2013 -0700

----------------------------------------------------------------------
 .../subsystem/api/storage/DataStoreManager.java |  3 ++
 .../api/storage/SnapshotDataFactory.java        |  4 +++
 .../api/storage/TemplateDataFactory.java        |  4 +++
 .../api/storage/VolumeDataFactory.java          |  4 +++
 .../storage/datastore/db/ImageStoreDao.java     |  2 ++
 .../datastore/db/SnapshotDataStoreDao.java      |  2 ++
 .../datastore/db/TemplateDataStoreDao.java      |  2 ++
 .../storage/image/TemplateDataFactoryImpl.java  | 16 ++++++++++
 .../manager/ImageStoreProviderManagerImpl.java  | 15 +++++++--
 .../snapshot/SnapshotDataFactoryImpl.java       | 22 +++++++++++--
 .../snapshot/XenserverSnapshotStrategy.java     | 31 ++++++++++++------
 .../storage/datastore/DataStoreManagerImpl.java |  5 +++
 .../datastore/ImageStoreProviderManager.java    |  2 ++
 .../storage/image/db/ImageStoreDaoImpl.java     | 10 +++++-
 .../image/db/SnapshotDataStoreDaoImpl.java      |  8 +++++
 .../image/db/TemplateDataStoreDaoImpl.java      |  8 +++++
 .../image/db/VolumeDataStoreDaoImpl.java        |  1 +
 .../storage/volume/VolumeDataFactoryImpl.java   | 33 +++++++++++++++++---
 .../com/cloud/storage/VolumeApiServiceImpl.java | 12 +++++--
 .../template/HypervisorTemplateAdapter.java     | 29 ++++++++++-------
 .../com/cloud/template/TemplateManagerImpl.java |  1 +
 21 files changed, 181 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java
index 0884453..7fbec0a 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreManager.java
@@ -19,6 +19,7 @@
 package org.apache.cloudstack.engine.subsystem.api.storage;
 
 import java.util.List;
+
 import com.cloud.storage.DataStoreRole;
 
 public interface DataStoreManager {
@@ -37,4 +38,6 @@ public interface DataStoreManager {
     DataStore getImageCacheStore(long zoneId);
 
     List<DataStore> listImageStores();
+
+    List<DataStore> listImageCacheStores();
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java
index 0b8d1f1..d5255f4 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cloudstack.engine.subsystem.api.storage;
 
+import java.util.List;
+
 import com.cloud.storage.DataStoreRole;
 
 public interface SnapshotDataFactory {
@@ -26,4 +28,6 @@ public interface SnapshotDataFactory {
     SnapshotInfo getSnapshot(DataObject obj, DataStore store);
 
     SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role);
+
+    List<SnapshotInfo> listSnapshotOnCache(long snapshotId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateDataFactory.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateDataFactory.java
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateDataFactory.java
index 980ed31..801c442 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateDataFactory.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateDataFactory.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cloudstack.engine.subsystem.api.storage;
 
+import java.util.List;
+
 import com.cloud.storage.DataStoreRole;
 
 public interface TemplateDataFactory {
@@ -30,4 +32,6 @@ public interface TemplateDataFactory {
     TemplateInfo getTemplate(long templateId, DataStoreRole storeRole, Long zoneId);
 
     TemplateInfo getReadyTemplateOnCache(long templateId);
+
+    List<TemplateInfo> listTemplateOnCache(long templateId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java
index 99e3b59..3de0b5b 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cloudstack.engine.subsystem.api.storage;
 
+import java.util.List;
+
 import com.cloud.storage.DataStoreRole;
 
 public interface VolumeDataFactory {
@@ -28,4 +30,6 @@ public interface VolumeDataFactory {
     VolumeInfo getVolume(long volumeId, DataStoreRole storeRole);
 
     VolumeInfo getVolume(long volumeId);
+
+    List<VolumeInfo> listVolumeOnCache(long volumeId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
index f95e66c..d0f8fe8 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java
@@ -36,4 +36,6 @@ public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long>
{
     List<ImageStoreVO> findImageCacheByScope(ZoneScope scope);
 
     List<ImageStoreVO> listImageStores();
+
+    List<ImageStoreVO> listImageCacheStores();
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
index df74c17..19eac38 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
@@ -43,4 +43,6 @@ StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Even
     List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId);
 
     void duplicateCacheRecordsOnRegionStore(long storeId);
+
+    List<SnapshotDataStoreVO> listOnCache(long snapshotId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
index fc61be5..95cbdb6 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java
@@ -66,4 +66,6 @@ StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Even
     void duplicateCacheRecordsOnRegionStore(long storeId);
 
     TemplateDataStoreVO findReadyOnCache(long templateId);
+
+    List<TemplateDataStoreVO> listOnCache(long templateId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java
index fe1c62c..6369311 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java
@@ -18,6 +18,9 @@
  */
 package org.apache.cloudstack.storage.image;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.inject.Inject;
 
 import org.apache.log4j.Logger;
@@ -127,4 +130,17 @@ public class TemplateDataFactoryImpl implements TemplateDataFactory {
 
     }
 
+    @Override
+    public List<TemplateInfo> listTemplateOnCache(long templateId) {
+        List<TemplateDataStoreVO> cacheTmpls = templateStoreDao.listOnCache(templateId);
+        List<TemplateInfo> tmplObjs = new ArrayList<TemplateInfo>();
+        for (TemplateDataStoreVO cacheTmpl : cacheTmpls) {
+            long storeId = cacheTmpl.getDataStoreId();
+            DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
+            TemplateInfo tmplObj = getTemplate(templateId, store);
+            tmplObjs.add(tmplObj);
+        }
+        return tmplObjs;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
index 64ef78f..0991860 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java
@@ -26,6 +26,9 @@ import java.util.Map;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider;
@@ -37,8 +40,6 @@ import org.apache.cloudstack.storage.image.ImageStoreDriver;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
 import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 
 import com.cloud.storage.ScopeType;
 import com.cloud.storage.dao.VMTemplateDao;
@@ -95,6 +96,16 @@ public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager
     }
 
     @Override
+    public List<DataStore> listImageCacheStores() {
+        List<ImageStoreVO> stores = dataStoreDao.listImageCacheStores();
+        List<DataStore> imageStores = new ArrayList<DataStore>();
+        for (ImageStoreVO store : stores) {
+            imageStores.add(getImageStore(store.getId()));
+        }
+        return imageStores;
+    }
+
+    @Override
     public List<DataStore> listImageStoresByScope(ZoneScope scope) {
         List<ImageStoreVO> stores = dataStoreDao.findByScope(scope);
         List<DataStore> imageStores = new ArrayList<DataStore>();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
index aafdad0..6205fe4 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
@@ -18,8 +18,13 @@
  */
 package org.apache.cloudstack.storage.snapshot;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.inject.Inject;
 
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@@ -28,7 +33,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
-import org.springframework.stereotype.Component;
 
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.SnapshotVO;
@@ -70,8 +74,22 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
         if (snapshotStore == null) {
             return null;
         }
-        DataStore store = this.storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
+        DataStore store = storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
         SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
         return so;
     }
+
+    @Override
+    public List<SnapshotInfo> listSnapshotOnCache(long snapshotId) {
+        List<SnapshotDataStoreVO> cacheSnapshots = snapshotStoreDao.listOnCache(snapshotId);
+        List<SnapshotInfo> snapObjs = new ArrayList<SnapshotInfo>();
+        for (SnapshotDataStoreVO cacheSnap : cacheSnapshots) {
+            long storeId = cacheSnap.getDataStoreId();
+            DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
+            SnapshotInfo tmplObj = getSnapshot(snapshotId, store);
+            snapObjs.add(tmplObj);
+        }
+        return snapObjs;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
index 6a874d6..cf67aeb 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java
@@ -16,8 +16,13 @@
 // under the License.
 package org.apache.cloudstack.storage.snapshot;
 
+import java.util.List;
+
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
@@ -33,8 +38,6 @@ import org.apache.cloudstack.storage.command.CreateObjectAnswer;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.cloudstack.storage.to.SnapshotObjectTO;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
 
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.storage.DataStoreRole;
@@ -74,7 +77,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
         if (parentSnapshot != null && snapshot.getPath().equalsIgnoreCase(parentSnapshot.getPath()))
{
             s_logger.debug("backup an empty snapshot");
             // don't need to backup this snapshot
-            SnapshotDataStoreVO parentSnapshotOnBackupStore = this.snapshotStoreDao.findBySnapshot(
+            SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(
                     parentSnapshot.getId(), DataStoreRole.Image);
             if (parentSnapshotOnBackupStore != null && parentSnapshotOnBackupStore.getState()
== State.Ready) {
                 DataStore store = dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(),
@@ -96,7 +99,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
                     s_logger.debug("Failed to change state: " + snapshot.getId() + ": " +
e.toString());
                     throw new CloudRuntimeException(e.toString());
                 }
-                return this.snapshotDataFactory.getSnapshot(snapObj.getId(), store);
+                return snapshotDataFactory.getSnapshot(snapObj.getId(), store);
             } else {
                 s_logger.debug("parent snapshot hasn't been backed up yet");
             }
@@ -114,7 +117,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
             int i;
             SnapshotDataStoreVO parentSnapshotOnBackupStore = null;
             for (i = 1; i < deltaSnap; i++) {
-                parentSnapshotOnBackupStore = this.snapshotStoreDao.findBySnapshot(parentSnapshot.getId(),
+                parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(parentSnapshot.getId(),
                         DataStoreRole.Image);
                 if (parentSnapshotOnBackupStore == null) {
                     break;
@@ -125,7 +128,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
                     break;
                 }
 
-                parentSnapshotOnBackupStore = this.snapshotStoreDao.findBySnapshot(prevBackupId,
DataStoreRole.Image);
+                parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(prevBackupId,
DataStoreRole.Image);
             }
             if (i >= deltaSnap) {
                 fullBackup = true;
@@ -133,7 +136,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
         }
 
         snapshot.addPayload(fullBackup);
-        return this.snapshotSvr.backupSnapshot(snapshot);
+        return snapshotSvr.backupSnapshot(snapshot);
     }
 
     protected boolean deleteSnapshotChain(SnapshotInfo snapshot) {
@@ -167,7 +170,15 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
                     }
                 }
                 if (!deleted) {
-                    boolean r = this.snapshotSvr.deleteSnapshot(snapshot);
+                    boolean r = snapshotSvr.deleteSnapshot(snapshot);
+                    if (r) {
+                        // delete snapshot in cache if there is
+                        List<SnapshotInfo> cacheSnaps = snapshotDataFactory.listSnapshotOnCache(snapshot.getId());
+                        for (SnapshotInfo cacheSnap : cacheSnaps) {
+                            s_logger.debug("Delete snapshot " + snapshot.getId() + " from
image cache store: " + cacheSnap.getDataStore().getName());
+                            cacheSnap.delete();
+                        }
+                    }
                     if (!resultIsSet) {
                         result = r;
                         resultIsSet = true;
@@ -203,7 +214,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
         // first mark the snapshot as destroyed, so that ui can't see it, but we
         // may not destroy the snapshot on the storage, as other snapshots may
         // depend on it.
-        SnapshotInfo snapshotOnImage = this.snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Image);
+        SnapshotInfo snapshotOnImage = snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Image);
         if (snapshotOnImage == null) {
             s_logger.debug("Can't find snapshot on backup storage, delete it in db");
             snapshotDao.remove(snapshotId);
@@ -276,7 +287,7 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
             snapshot = result.getSnashot();
             DataStore primaryStore = snapshot.getDataStore();
 
-            SnapshotInfo backupedSnapshot = this.backupSnapshot(snapshot);
+            SnapshotInfo backupedSnapshot = backupSnapshot(snapshot);
 
             try {
                 SnapshotInfo parent = snapshot.getParent();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
index a9263a9..88061aa 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
@@ -107,6 +107,11 @@ public class DataStoreManagerImpl implements DataStoreManager {
         return imageDataStoreMgr.listImageStores();
     }
 
+    @Override
+    public List<DataStore> listImageCacheStores() {
+        return imageDataStoreMgr.listImageCacheStores();
+    }
+
     public void setPrimaryStoreMgr(PrimaryDataStoreProviderManager primaryStoreMgr) {
         this.primaryStoreMgr = primaryStoreMgr;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
index be66cc5..8afb3d9 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
@@ -32,6 +32,8 @@ public interface ImageStoreProviderManager {
 
     List<DataStore> listImageStores();
 
+    List<DataStore> listImageCacheStores();
+
     List<DataStore> listImageStoresByScope(ZoneScope scope);
 
     List<DataStore> listImageStoreByProvider(String provider);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
index b9ef9c3..13a7f47 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageStoreDaoImpl.java
@@ -23,10 +23,11 @@ import java.util.Map;
 
 import javax.naming.ConfigurationException;
 
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
-import org.springframework.stereotype.Component;
 
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.ScopeType;
@@ -118,4 +119,11 @@ public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO,
Long> implem
         return listBy(sc);
     }
 
+    @Override
+    public List<ImageStoreVO> listImageCacheStores() {
+        SearchCriteria<ImageStoreVO> sc = createSearchCriteria();
+        sc.addAnd("role", SearchCriteria.Op.EQ, DataStoreRole.ImageCache);
+        return listBy(sc);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
index 5a21ae2..96a0c17 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
@@ -263,4 +263,12 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
 
     }
 
+    @Override
+    public List<SnapshotDataStoreVO> listOnCache(long snapshotId) {
+        SearchCriteria<SnapshotDataStoreVO> sc = storeSnapshotSearch.create();
+        sc.setParameters("snapshot_id", snapshotId);
+        sc.setParameters("store_role", DataStoreRole.ImageCache);
+        return search(sc, null);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
index 25f3486..5c1ec33 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java
@@ -335,6 +335,14 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
     }
 
     @Override
+    public List<TemplateDataStoreVO> listOnCache(long templateId) {
+        SearchCriteria<TemplateDataStoreVO> sc = templateRoleSearch.create();
+        sc.setParameters("template_id", templateId);
+        sc.setParameters("store_role", DataStoreRole.ImageCache);
+        return search(sc, null);
+    }
+
+    @Override
     public List<TemplateDataStoreVO> listByTemplate(long templateId) {
         SearchCriteria<TemplateDataStoreVO> sc = templateSearch.create();
         sc.setParameters("template_id", templateId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
index e2adb3e..4118079 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java
@@ -43,6 +43,7 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO,
Lo
     private static final Logger s_logger = Logger.getLogger(VolumeDataStoreDaoImpl.class);
     private SearchBuilder<VolumeDataStoreVO> updateStateSearch;
     private SearchBuilder<VolumeDataStoreVO> volumeSearch;
+    private SearchBuilder<VolumeDataStoreVO> volumeRoleSearch;
     private SearchBuilder<VolumeDataStoreVO> storeSearch;
     private SearchBuilder<VolumeDataStoreVO> cacheSearch;
     private SearchBuilder<VolumeDataStoreVO> storeVolumeSearch;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeDataFactoryImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeDataFactoryImpl.java
b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeDataFactoryImpl.java
index 1d75ba1..8065f9c 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeDataFactoryImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeDataFactoryImpl.java
@@ -18,8 +18,13 @@
  */
 package org.apache.cloudstack.storage.volume;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.inject.Inject;
 
+import org.springframework.stereotype.Component;
+
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@@ -27,7 +32,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
-import org.springframework.stereotype.Component;
 
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.VolumeVO;
@@ -58,13 +62,13 @@ public class VolumeDataFactoryImpl implements VolumeDataFactory {
         if (storeRole == DataStoreRole.Image) {
             VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
             if (volumeStore != null) {
-                DataStore store = this.storeMgr.getDataStore(volumeStore.getDataStoreId(),
DataStoreRole.Image);
+                DataStore store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
                 vol = VolumeObject.getVolumeObject(store, volumeVO);
             }
         } else {
             // Primary data store
             if (volumeVO.getPoolId() != null) {
-                DataStore store = this.storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
+                DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
                 vol = VolumeObject.getVolumeObject(store, volumeVO);
             }
         }
@@ -82,11 +86,11 @@ public class VolumeDataFactoryImpl implements VolumeDataFactory {
             DataStore store = null;
             VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
             if (volumeStore != null) {
-                store = this.storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
+                store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
             }
             vol = VolumeObject.getVolumeObject(store, volumeVO);
         } else {
-            DataStore store = this.storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
+            DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
             vol = VolumeObject.getVolumeObject(store, volumeVO);
         }
         return vol;
@@ -99,4 +103,23 @@ public class VolumeDataFactoryImpl implements VolumeDataFactory {
         return vol;
     }
 
+    @Override
+    public List<VolumeInfo> listVolumeOnCache(long volumeId) {
+        List<VolumeInfo> cacheVols = new ArrayList<VolumeInfo>();
+        // find all image cache stores for this zone scope
+        List<DataStore> cacheStores = storeMgr.listImageCacheStores();
+        if (cacheStores == null || cacheStores.size() == 0) {
+            return cacheVols;
+        }
+        for (DataStore store : cacheStores) {
+            // check if the volume is stored there
+            VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(store.getId(),
volumeId);
+            if (volStore != null) {
+                VolumeInfo vol = getVolume(volumeId, store);
+                cacheVols.add(vol);
+            }
+        }
+        return cacheVols;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
index 00df333..12f0102 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -25,6 +25,8 @@ import java.util.concurrent.ExecutionException;
 
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
 import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
@@ -64,7 +66,6 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -945,6 +946,13 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
                 AsyncCallFuture<VolumeApiResult> future2 = volService.expungeVolumeAsync(volOnSecondary);
                 future2.get();
             }
+            // delete all cache entries for this volume
+            List<VolumeInfo> cacheVols = volFactory.listVolumeOnCache(volume.getId());
+            for (VolumeInfo volOnCache : cacheVols) {
+                s_logger.info("Delete volume from image cache store: " + volOnCache.getDataStore().getName());
+                volOnCache.delete();
+            }
+
         } catch (Exception e) {
             s_logger.warn("Failed to expunge volume:", e);
             return false;
@@ -1725,7 +1733,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
 
     @Inject
     public void setStoragePoolAllocators(List<StoragePoolAllocator> storagePoolAllocators)
{
-        this._storagePoolAllocators = storagePoolAllocators;
+        _storagePoolAllocators = storagePoolAllocators;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/server/src/com/cloud/template/HypervisorTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
index 00e6222..b33a192 100755
--- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java
+++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java
@@ -25,6 +25,8 @@ import java.util.concurrent.ExecutionException;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
 import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
 import org.apache.cloudstack.api.command.user.template.DeleteTemplateCmd;
@@ -44,7 +46,6 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.framework.async.AsyncRpcContext;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity;
-import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.alert.AlertManager;
@@ -56,11 +57,11 @@ import com.cloud.event.UsageEventUtils;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.org.Grouping;
+import com.cloud.storage.ScopeType;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.TemplateType;
 import com.cloud.storage.TemplateProfile;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.storage.ScopeType;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.VMTemplateZoneVO;
 import com.cloud.storage.dao.VMTemplateZoneDao;
@@ -182,7 +183,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
         }
 
         // find all eligible image stores for this zone scope
-        List<DataStore> imageStores = this.storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId()));
+        List<DataStore> imageStores = storeMgr.getImageStoresByScope(new ZoneScope(profile.getZoneId()));
         if ( imageStores == null || imageStores.size() == 0 ){
             throw new CloudRuntimeException("Unable to find image store to download template
"+ profile.getTemplate());
         }
@@ -205,12 +206,12 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
                 }
             }
 
-            TemplateInfo tmpl = this.imageFactory.getTemplate(template.getId(), imageStore);
+            TemplateInfo tmpl = imageFactory.getTemplate(template.getId(), imageStore);
             CreateTemplateContext<TemplateApiResult> context = new CreateTemplateContext<TemplateApiResult>(null,
tmpl);
             AsyncCallbackDispatcher<HypervisorTemplateAdapter, TemplateApiResult> caller
= AsyncCallbackDispatcher.create(this);
             caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
             caller.setContext(context);
-            this.imageService.createTemplateAsync(tmpl, imageStore, caller);
+            imageService.createTemplateAsync(tmpl, imageStore, caller);
             if( !(profile.getIsPublic() || profile.getFeatured()) ){  // If private template
then break
                 break;
             }
@@ -237,7 +238,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
             // populated template entry
             _tmpltDao.remove(template.getId());
         } else {
-            VMTemplateVO tmplt = this._tmpltDao.findById(template.getId());
+            VMTemplateVO tmplt = _tmpltDao.findById(template.getId());
             long accountId = tmplt.getAccountId();
             if (template.getSize() != null) {
                 // publish usage event
@@ -283,7 +284,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
         VMTemplateVO template = profile.getTemplate();
 
         // find all eligible image stores for this template
-        List<DataStore> imageStores = this.templateMgr.getImageStoreByTemplate(template.getId(),
profile.getZoneId());
+        List<DataStore> imageStores = templateMgr.getImageStoreByTemplate(template.getId(),
profile.getZoneId());
         if (imageStores == null || imageStores.size() == 0) {
             // already destroyed on image stores
             s_logger.info("Unable to find image store still having template: " + template.getName()
@@ -321,7 +322,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
                 }
 
                 s_logger.info("Delete template from image store: " + imageStore.getName());
-                AsyncCallFuture<TemplateApiResult> future = this.imageService.deleteTemplateAsync(this.imageFactory
+                AsyncCallFuture<TemplateApiResult> future = imageService.deleteTemplateAsync(imageFactory
                         .getTemplate(template.getId(), imageStore));
                 try {
                     TemplateApiResult result = future.get();
@@ -350,9 +351,15 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
             }
         }
         if (success) {
+            // delete all cache entries for this template
+            List<TemplateInfo> cacheTmpls = imageFactory.listTemplateOnCache(template.getId());
+            for (TemplateInfo tmplOnCache : cacheTmpls) {
+                s_logger.info("Delete template from image cache store: " + tmplOnCache.getDataStore().getName());
+                tmplOnCache.delete();
+            }
 
             // find all eligible image stores for this template
-            List<DataStore> iStores = this.templateMgr.getImageStoreByTemplate(template.getId(),
null);
+            List<DataStore> iStores = templateMgr.getImageStoreByTemplate(template.getId(),
null);
             if (iStores == null || iStores.size() == 0) {
                 // remove template from vm_templates table
                 if (_tmpltDao.remove(template.getId())) {
@@ -380,7 +387,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
             throw new InvalidParameterValueException("The DomR template cannot be deleted.");
         }
 
-        if (zoneId != null && (this.storeMgr.getImageStore(zoneId) == null)) {
+        if (zoneId != null && (storeMgr.getImageStore(zoneId) == null)) {
             throw new InvalidParameterValueException("Failed to find a secondary storage
in the specified zone.");
         }
 
@@ -392,7 +399,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
         TemplateProfile profile = super.prepareDelete(cmd);
         Long zoneId = profile.getZoneId();
 
-        if (zoneId != null && (this.storeMgr.getImageStore(zoneId) == null)) {
+        if (zoneId != null && (storeMgr.getImageStore(zoneId) == null)) {
             throw new InvalidParameterValueException("Failed to find a secondary storage
in the specified zone.");
         }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/730832d8/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 452e079..3b2ec58 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -1707,6 +1707,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         return stores;
     }
 
+
     @Override
     public VMTemplateVO updateTemplate(UpdateIsoCmd cmd) {
         return updateTemplateOrIso(cmd);


Mime
View raw message