cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devd...@apache.org
Subject [2/3] git commit: updated refs/heads/master to 3771e8a
Date Fri, 19 Jul 2013 10:44:15 GMT
CLOUDSTACK-3492: [Regression]Update Resource Count for an account is updating the primary storage
incorretly.

The issue is that while calculating the used primary storage size, the updateResourceCount
API is also calculating the disk size of virtual router VM, created for that account and
because of this, the API is returning the incorrect result.


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

Branch: refs/heads/master
Commit: 539eb38908ede53a36d4bb680b848caf9fe469c4
Parents: 6e63f10
Author: Sanjay Tripathi <sanjay.tripathi@citrix.com>
Authored: Tue Jul 16 14:52:56 2013 +0530
Committer: Devdeep Singh <devdeep@gmail.com>
Committed: Fri Jul 19 16:04:10 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/storage/dao/VolumeDao.java    |  3 ++-
 .../com/cloud/storage/dao/VolumeDaoImpl.java    | 13 ++++++++++--
 .../src/com/cloud/vm/dao/VMInstanceDao.java     |  2 +-
 .../src/com/cloud/vm/dao/VMInstanceDaoImpl.java | 22 ++++++++++----------
 .../resourcelimit/ResourceLimitManagerImpl.java |  5 +++--
 5 files changed, 28 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/539eb389/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 fb7dc70..7b58e7d 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
@@ -80,9 +80,10 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
      * Gets the Total Primary Storage space allocated for an account
      * 
      * @param account
+     * @param list of ids of virtual router VMs under this account
      * @return total Primary Storage space (in bytes) used
      */
-    long primaryStorageUsedForAccount(long accountId);
+    long primaryStorageUsedForAccount(long accountId, List<Long> virtualRouters);
 
     /**
      * Gets the Total Secondary Storage space used by volumes allocated for an

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/539eb389/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 ba85466..f87cd4e 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
@@ -318,7 +318,10 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long>
implements Vol
         primaryStorageSearch = createSearchBuilder(SumCount.class);
         primaryStorageSearch.select("sum", Func.SUM, primaryStorageSearch.entity().getSize());
         primaryStorageSearch.and("accountId", primaryStorageSearch.entity().getAccountId(),
Op.EQ);
-        primaryStorageSearch.and("path", primaryStorageSearch.entity().getPath(), Op.NNULL);
+        primaryStorageSearch.and("virtualRouterVmIds", primaryStorageSearch.entity().getInstanceId(),
Op.NIN);
+        primaryStorageSearch.and().op("path", primaryStorageSearch.entity().getPath(), Op.NNULL);
+        primaryStorageSearch.or("states", primaryStorageSearch.entity().getState(), Op.IN);
+        primaryStorageSearch.cp();
         primaryStorageSearch.and("isRemoved", primaryStorageSearch.entity().getRemoved(),
Op.NULL);
         primaryStorageSearch.done();
 
@@ -326,6 +329,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long>
implements Vol
         secondaryStorageSearch.select("sum", Func.SUM, secondaryStorageSearch.entity().getSize());
         secondaryStorageSearch.and("accountId", secondaryStorageSearch.entity().getAccountId(),
Op.EQ);
         secondaryStorageSearch.and("path", secondaryStorageSearch.entity().getPath(), Op.NULL);
+        secondaryStorageSearch.and("states", secondaryStorageSearch.entity().getState(),
Op.NIN);
         secondaryStorageSearch.and("isRemoved", secondaryStorageSearch.entity().getRemoved(),
Op.NULL);
         secondaryStorageSearch.done();
     }
@@ -349,9 +353,13 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long>
implements Vol
     }
 
     @Override
-    public long primaryStorageUsedForAccount(long accountId) {
+    public long primaryStorageUsedForAccount(long accountId, List<Long> virtualRouters)
{
         SearchCriteria<SumCount> sc = primaryStorageSearch.create();
         sc.setParameters("accountId", accountId);
+        if (!virtualRouters.isEmpty()) {
+            sc.setParameters("virtualRouterVmIds", virtualRouters.toArray(new Object[virtualRouters.size()]));
+        }
+        sc.setParameters("states", State.Allocated);
         List<SumCount> storageSpace = customSearch(sc, null);
         if (storageSpace != null) {
             return storageSpace.get(0).sum;
@@ -364,6 +372,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long>
implements Vol
     public long secondaryStorageUsedForAccount(long accountId) {
         SearchCriteria<SumCount> sc = secondaryStorageSearch.create();
         sc.setParameters("accountId", accountId);
+        sc.setParameters("states", State.Allocated);
         List<SumCount> storageSpace = customSearch(sc, null);
         if (storageSpace != null) {
             return storageSpace.get(0).sum;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/539eb389/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java b/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java
index e564052..2fe8140 100644
--- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java
+++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java
@@ -90,7 +90,7 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>,
StateDao<
     List<VMInstanceVO> listByTypeAndState(VirtualMachine.Type type, State state);
 
     List<VMInstanceVO> listByAccountId(long accountId);
-    public Long countAllocatedVirtualRoutersForAccount(long accountId);
+    public List<Long> findIdsOfAllocatedVirtualRoutersForAccount(long accountId);
 
     List<VMInstanceVO> listByClusterId(long clusterId);  // this does not pull up VMs
which are starting
     List<VMInstanceVO> listLHByClusterId(long clusterId);  // get all the VMs even
starting one on this cluster

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/539eb389/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
index ec04085..8cbc6b6 100644
--- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
@@ -79,7 +79,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long>
implem
     protected SearchBuilder<VMInstanceVO> HostUpSearch;
     protected SearchBuilder<VMInstanceVO> InstanceNameSearch;
     protected SearchBuilder<VMInstanceVO> HostNameSearch;
-    protected GenericSearchBuilder<VMInstanceVO, Long> CountVirtualRoutersByAccount;
+    protected GenericSearchBuilder<VMInstanceVO, Long> FindIdsOfVirtualRoutersByAccount;
     protected GenericSearchBuilder<VMInstanceVO, Long> CountRunningByHost;
     protected GenericSearchBuilder<VMInstanceVO, Long> CountRunningByAccount;
     protected SearchBuilder<VMInstanceVO> NetworkTypeSearch;
@@ -197,12 +197,12 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO,
Long> implem
         HostNameSearch.and("hostName", HostNameSearch.entity().getHostName(), Op.EQ);
         HostNameSearch.done();
 
-        CountVirtualRoutersByAccount = createSearchBuilder(Long.class);
-        CountVirtualRoutersByAccount.select(null, Func.COUNT, null);
-        CountVirtualRoutersByAccount.and("account", CountVirtualRoutersByAccount.entity().getAccountId(),
SearchCriteria.Op.EQ);
-        CountVirtualRoutersByAccount.and("type", CountVirtualRoutersByAccount.entity().getType(),
SearchCriteria.Op.EQ);
-        CountVirtualRoutersByAccount.and("state", CountVirtualRoutersByAccount.entity().getState(),
SearchCriteria.Op.NIN);
-        CountVirtualRoutersByAccount.done();
+        FindIdsOfVirtualRoutersByAccount = createSearchBuilder(Long.class);
+        FindIdsOfVirtualRoutersByAccount.selectField(FindIdsOfVirtualRoutersByAccount.entity().getId());
+        FindIdsOfVirtualRoutersByAccount.and("account", FindIdsOfVirtualRoutersByAccount.entity().getAccountId(),
SearchCriteria.Op.EQ);
+        FindIdsOfVirtualRoutersByAccount.and("type", FindIdsOfVirtualRoutersByAccount.entity().getType(),
SearchCriteria.Op.EQ);
+        FindIdsOfVirtualRoutersByAccount.and("state", FindIdsOfVirtualRoutersByAccount.entity().getState(),
SearchCriteria.Op.NIN);
+        FindIdsOfVirtualRoutersByAccount.done();
 
         CountRunningByHost = createSearchBuilder(Long.class);
         CountRunningByHost.select(null, Func.COUNT, null);
@@ -441,12 +441,12 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO,
Long> implem
 	}
 
     @Override
-    public Long countAllocatedVirtualRoutersForAccount(long accountId) {
-    	SearchCriteria<Long> sc = CountVirtualRoutersByAccount.create();
+    public List<Long> findIdsOfAllocatedVirtualRoutersForAccount(long accountId) {
+        SearchCriteria<Long> sc = FindIdsOfVirtualRoutersByAccount.create();
         sc.setParameters("account", accountId);
         sc.setParameters("type", VirtualMachine.Type.DomainRouter);
-		sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging});
-        return customSearch(sc, null).get(0);
+        sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging});
+        return customSearch(sc, null);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/539eb389/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
index 665c2e1..bfa6981 100755
--- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -820,7 +820,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
             newCount = _userVmDao.countAllocatedVMsForAccount(accountId);
         } else if (type == Resource.ResourceType.volume) {
             newCount = _volumeDao.countAllocatedVolumesForAccount(accountId);
-            long virtualRouterCount = _vmDao.countAllocatedVirtualRoutersForAccount(accountId);
+            long virtualRouterCount = _vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId).size();
             newCount = newCount - virtualRouterCount; // don't count the volumes of virtual
router
         } else if (type == Resource.ResourceType.snapshot) {
             newCount = _snapshotDao.countSnapshotsForAccount(accountId);
@@ -839,7 +839,8 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         } else if (type == Resource.ResourceType.memory) {
             newCount = calculateMemoryForAccount(accountId);
         } else if (type == Resource.ResourceType.primary_storage) {
-            newCount = _volumeDao.primaryStorageUsedForAccount(accountId);
+            List<Long> virtualRouters = _vmDao.findIdsOfAllocatedVirtualRoutersForAccount(accountId);
+            newCount = _volumeDao.primaryStorageUsedForAccount(accountId, virtualRouters);
         } else if (type == Resource.ResourceType.secondary_storage) {
             newCount = calculateSecondaryStorageForAccount(accountId);
         } else {


Mime
View raw message