You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by we...@apache.org on 2015/01/12 12:31:03 UTC
git commit: updated refs/heads/4.5 to 2720a1b
Repository: cloudstack
Updated Branches:
refs/heads/4.5 435871438 -> 2720a1b49
CLOUDSTACK-8146: Resource count of primary storage does not consider the detached volumes
(cherry picked from commit b528047fb6f1c199e5e1cfe991a10b72a2b32a49)
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2720a1b4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2720a1b4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2720a1b4
Branch: refs/heads/4.5
Commit: 2720a1b49fb6bcd4771a043fabcbac945e7b389e
Parents: 4358714
Author: Wei Zhou <w....@tech.leaseweb.com>
Authored: Mon Jan 12 12:25:28 2015 +0100
Committer: Wei Zhou <w....@tech.leaseweb.com>
Committed: Mon Jan 12 12:30:09 2015 +0100
----------------------------------------------------------------------
.../com/cloud/storage/dao/VolumeDaoImpl.java | 21 +++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2720a1b4/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 24de717..61cce8d 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
@@ -65,6 +65,7 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
protected final SearchBuilder<VolumeVO> AllFieldsSearch;
protected GenericSearchBuilder<VolumeVO, Long> CountByAccount;
protected GenericSearchBuilder<VolumeVO, SumCount> primaryStorageSearch;
+ protected GenericSearchBuilder<VolumeVO, SumCount> primaryStorageSearch2;
protected GenericSearchBuilder<VolumeVO, SumCount> secondaryStorageSearch;
@Inject
ResourceTagDao _tagsDao;
@@ -367,7 +368,6 @@ 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("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();
@@ -375,6 +375,18 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
primaryStorageSearch.and("isRemoved", primaryStorageSearch.entity().getRemoved(), Op.NULL);
primaryStorageSearch.done();
+ primaryStorageSearch2 = createSearchBuilder(SumCount.class);
+ primaryStorageSearch2.select("sum", Func.SUM, primaryStorageSearch2.entity().getSize());
+ primaryStorageSearch2.and("accountId", primaryStorageSearch2.entity().getAccountId(), Op.EQ);
+ primaryStorageSearch2.and().op("instanceId", primaryStorageSearch2.entity().getInstanceId(), Op.NULL);
+ primaryStorageSearch2.or("virtualRouterVmIds", primaryStorageSearch2.entity().getInstanceId(), Op.NIN);
+ primaryStorageSearch2.cp();
+ primaryStorageSearch2.and().op("path", primaryStorageSearch2.entity().getPath(), Op.NNULL);
+ primaryStorageSearch2.or("states", primaryStorageSearch2.entity().getState(), Op.IN);
+ primaryStorageSearch2.cp();
+ primaryStorageSearch2.and("displayVolume", primaryStorageSearch2.entity().isDisplayVolume(), Op.EQ);
+ primaryStorageSearch2.and("isRemoved", primaryStorageSearch2.entity().getRemoved(), Op.NULL);
+
secondaryStorageSearch = createSearchBuilder(SumCount.class);
secondaryStorageSearch.select("sum", Func.SUM, secondaryStorageSearch.entity().getSize());
secondaryStorageSearch.and("accountId", secondaryStorageSearch.entity().getAccountId(), Op.EQ);
@@ -405,11 +417,14 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
@Override
public long primaryStorageUsedForAccount(long accountId, List<Long> virtualRouters) {
- SearchCriteria<SumCount> sc = primaryStorageSearch.create();
- sc.setParameters("accountId", accountId);
+ SearchCriteria<SumCount> sc;
if (!virtualRouters.isEmpty()) {
+ sc = primaryStorageSearch2.create();
sc.setParameters("virtualRouterVmIds", virtualRouters.toArray(new Object[virtualRouters.size()]));
+ } else {
+ sc = primaryStorageSearch.create();
}
+ sc.setParameters("accountId", accountId);
sc.setParameters("states", State.Allocated);
sc.setParameters("displayVolume", 1);
List<SumCount> storageSpace = customSearch(sc, null);