cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/4.3 to a888a69
Date Mon, 11 Nov 2013 22:34:56 GMT
Updated Branches:
  refs/heads/4.3 b1c02b475 -> a888a6950


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/a888a695
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a888a695
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a888a695

Branch: refs/heads/4.3
Commit: a888a6950a771eb4b593f0f7136dc14451335007
Parents: b1c02b4
Author: Min Chen <min.chen@citrix.com>
Authored: Mon Nov 11 14:29:24 2013 -0800
Committer: Min Chen <min.chen@citrix.com>
Committed: Mon Nov 11 14:29:24 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/a888a695/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/a888a695/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/a888a695/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;


Mime
View raw message