You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/11/11 23:47:57 UTC

git commit: updated refs/heads/master to 8b7b7a0

Updated Branches:
  refs/heads/master 4f0dbaa44 -> 8b7b7a041


Delay in displaying VM migrate dialog due to get vm snapshot size for a
storage pool.


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

Branch: refs/heads/master
Commit: 8b7b7a041dc4022972d02f796ae070b99bbf63dc
Parents: 4f0dbaa
Author: Min Chen <mi...@citrix.com>
Authored: Mon Nov 11 14:29:24 2013 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Mon Nov 11 14:40:16 2013 -0800

----------------------------------------------------------------------
 .../src/com/cloud/storage/dao/VolumeDao.java    |  2 ++
 .../com/cloud/storage/dao/VolumeDaoImpl.java    | 24 ++++++++++++++++++++
 .../com/cloud/capacity/CapacityManagerImpl.java | 17 ++------------
 3 files changed, 28 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b7b7a04/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
index 1f5083a..24ade51 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
@@ -37,6 +37,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
 
     Pair<Long, Long> getNonDestroyedCountAndTotalByPool(long poolId);
 
+    long getVMSnapshotSizeByPool(long poolId);
+
     List<VolumeVO> findByInstance(long id);
 
     List<VolumeVO> findByInstanceAndType(long id, Volume.Type vType);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b7b7a04/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
index 54b6465..2fb9dba 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
@@ -59,6 +59,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
     protected final SearchBuilder<VolumeVO> DetachedAccountIdSearch;
     protected final SearchBuilder<VolumeVO> TemplateZoneSearch;
     protected final GenericSearchBuilder<VolumeVO, SumCount> TotalSizeByPoolSearch;
+    protected final GenericSearchBuilder<VolumeVO, SumCount> TotalVMSnapshotSizeByPoolSearch;
     protected final GenericSearchBuilder<VolumeVO, Long> ActiveTemplateSearch;
     protected final SearchBuilder<VolumeVO> InstanceStatesSearch;
     protected final SearchBuilder<VolumeVO> AllFieldsSearch;
@@ -316,6 +317,15 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
         TotalSizeByPoolSearch.and("state", TotalSizeByPoolSearch.entity().getState(), Op.NEQ);
         TotalSizeByPoolSearch.done();
 
+        TotalVMSnapshotSizeByPoolSearch = createSearchBuilder(SumCount.class);
+        TotalVMSnapshotSizeByPoolSearch.select("sum", Func.SUM, TotalVMSnapshotSizeByPoolSearch.entity().getVmSnapshotChainSize());
+        TotalVMSnapshotSizeByPoolSearch.and("poolId", TotalVMSnapshotSizeByPoolSearch.entity().getPoolId(), Op.EQ);
+        TotalVMSnapshotSizeByPoolSearch.and("removed", TotalVMSnapshotSizeByPoolSearch.entity().getRemoved(), Op.NULL);
+        TotalVMSnapshotSizeByPoolSearch.and("state", TotalVMSnapshotSizeByPoolSearch.entity().getState(), Op.NEQ);
+        TotalVMSnapshotSizeByPoolSearch.and("vType", TotalVMSnapshotSizeByPoolSearch.entity().getVolumeType(), Op.EQ);
+        TotalVMSnapshotSizeByPoolSearch.and("instanceId", TotalVMSnapshotSizeByPoolSearch.entity().getInstanceId(), Op.NNULL);
+        TotalVMSnapshotSizeByPoolSearch.done();
+
         ActiveTemplateSearch = createSearchBuilder(Long.class);
         ActiveTemplateSearch.and("pool", ActiveTemplateSearch.entity().getPoolId(), Op.EQ);
         ActiveTemplateSearch.and("template", ActiveTemplateSearch.entity().getTemplateId(), Op.EQ);
@@ -517,6 +527,20 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
     }
 
     @Override
+    public long getVMSnapshotSizeByPool(long poolId) {
+        SearchCriteria<SumCount> sc = TotalVMSnapshotSizeByPoolSearch.create();
+        sc.setParameters("poolId", poolId);
+        sc.setParameters("state", State.Destroy);
+        sc.setParameters("vType", Volume.Type.ROOT.toString());
+        List<SumCount> results = customSearch(sc, null);
+        if (results != null) {
+            return results.get(0).sum;
+        } else {
+            return 0;
+        }
+    }
+
+    @Override
     @DB
     public boolean remove(Long id) {
         TransactionLegacy txn = TransactionLegacy.currentTxn();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b7b7a04/server/src/com/cloud/capacity/CapacityManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/capacity/CapacityManagerImpl.java b/server/src/com/cloud/capacity/CapacityManagerImpl.java
index a9b9ae4..70491bc 100755
--- a/server/src/com/cloud/capacity/CapacityManagerImpl.java
+++ b/server/src/com/cloud/capacity/CapacityManagerImpl.java
@@ -28,6 +28,7 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
+
 import org.apache.cloudstack.framework.config.ConfigDepot;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.Configurable;
@@ -69,7 +70,6 @@ import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.StorageManager;
 import com.cloud.storage.VMTemplateStoragePoolVO;
 import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.VMTemplatePoolDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.utils.DateUtil;
@@ -474,19 +474,6 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
 
     }
 
-    private long getVMSnapshotAllocatedCapacity(StoragePoolVO pool){
-        List<VolumeVO> volumes = _volumeDao.findByPoolId(pool.getId());
-        long totalSize = 0;
-        for (VolumeVO volume : volumes) {
-            if(volume.getInstanceId() == null)
-                continue;
-            Long chainSize = volume.getVmSnapshotChainSize();
-            if(chainSize != null)
-                totalSize += chainSize;
-        }
-        return totalSize;
-    }
-
     @Override
     public long getAllocatedPoolCapacity(StoragePoolVO pool, VMTemplateVO templateForVmCreation){
 
@@ -495,7 +482,7 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
         long totalAllocatedSize = sizes.second() + sizes.first() * _extraBytesPerVolume;
 
         // Get size for VM Snapshots
-        totalAllocatedSize = totalAllocatedSize + getVMSnapshotAllocatedCapacity(pool);
+        totalAllocatedSize = totalAllocatedSize + _volumeDao.getVMSnapshotSizeByPool(pool.getId());
 
         // Iterate through all templates on this storage pool
         boolean tmpinstalled = false;