cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sanjaytripa...@apache.org
Subject git commit: updated refs/heads/master to c3d8e20
Date Tue, 07 Jan 2014 09:43:54 GMT
Updated Branches:
  refs/heads/master 6d75c3195 -> c3d8e207c


CLOUDSTACK-5314: Negative (-ve) values for primary storage and volumes are shown in the resource
count table.


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

Branch: refs/heads/master
Commit: c3d8e207c84d9bf8424e88412e8e49da4232bc73
Parents: 6d75c31
Author: Sanjay Tripathi <sanjay.tripathi@citrix.com>
Authored: Tue Jan 7 14:25:45 2014 +0530
Committer: Sanjay Tripathi <sanjay.tripathi@citrix.com>
Committed: Tue Jan 7 15:07:02 2014 +0530

----------------------------------------------------------------------
 .../src/com/cloud/storage/dao/SnapshotDao.java  |  9 -------
 .../com/cloud/storage/dao/SnapshotDaoImpl.java  | 20 ---------------
 .../resourcelimit/ResourceLimitManagerImpl.java | 27 +++++++++++++++++++-
 .../com/cloud/storage/VolumeApiServiceImpl.java |  4 +--
 server/src/com/cloud/vm/UserVmManagerImpl.java  |  2 +-
 5 files changed, 29 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c3d8e207/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java b/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
index d42ef66..f55352b 100644
--- a/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
@@ -57,13 +57,4 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long>,
StateDao<Snap
 
     List<SnapshotVO> listAllByStatus(Snapshot.State... status);
 
-    /**
-     * Gets the Total Secondary Storage space (in bytes) used by snapshots
-     * allocated for an account
-     *
-     * @param account
-     * @return total Secondary Storage space allocated
-     */
-    long secondaryStorageUsedForAccount(long accountId);
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c3d8e207/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
index f153198..d401065 100644
--- a/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
@@ -36,7 +36,6 @@ import com.cloud.storage.Snapshot.Type;
 import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
-import com.cloud.storage.dao.VolumeDaoImpl.SumCount;
 import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.Filter;
@@ -46,7 +45,6 @@ import com.cloud.utils.db.JoinBuilder.JoinType;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
-import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.dao.VMInstanceDao;
@@ -72,7 +70,6 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long>
implements
     private SearchBuilder<SnapshotVO> InstanceIdSearch;
     private SearchBuilder<SnapshotVO> StatusSearch;
     private GenericSearchBuilder<SnapshotVO, Long> CountSnapshotsByAccount;
-    private GenericSearchBuilder<SnapshotVO, SumCount> secondaryStorageSearch;
     @Inject
     ResourceTagDao _tagsDao;
     @Inject
@@ -193,12 +190,6 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long>
implements
 
         InstanceIdSearch.join("instanceSnapshots", volumeSearch, volumeSearch.entity().getId(),
InstanceIdSearch.entity().getVolumeId(), JoinType.INNER);
         InstanceIdSearch.done();
-
-        secondaryStorageSearch = createSearchBuilder(SumCount.class);
-        secondaryStorageSearch.select("sum", Func.SUM, secondaryStorageSearch.entity().getSize());
-        secondaryStorageSearch.and("accountId", secondaryStorageSearch.entity().getAccountId(),
Op.EQ);
-        secondaryStorageSearch.and("isRemoved", secondaryStorageSearch.entity().getRemoved(),
Op.NULL);
-        secondaryStorageSearch.done();
     }
 
     @Override
@@ -333,15 +324,4 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long>
implements
         return true;
     }
 
-    @Override
-    public long secondaryStorageUsedForAccount(long accountId) {
-        SearchCriteria<SumCount> sc = secondaryStorageSearch.create();
-        sc.setParameters("accountId", accountId);
-        List<SumCount> storageSpace = customSearch(sc, null);
-        if (storageSpace != null) {
-            return storageSpace.get(0).sum;
-        } else {
-            return 0;
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c3d8e207/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 8d49d4d..3a7251b 100755
--- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -35,8 +35,11 @@ import org.springframework.stereotype.Component;
 
 import org.apache.cloudstack.acl.SecurityChecker.AccessType;
 import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 
@@ -68,6 +71,8 @@ import com.cloud.projects.dao.ProjectAccountDao;
 import com.cloud.projects.dao.ProjectDao;
 import com.cloud.service.ServiceOfferingVO;
 import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.dao.SnapshotDao;
@@ -149,8 +154,11 @@ public class ResourceLimitManagerImpl extends ManagerBase implements
ResourceLim
     private TemplateDataStoreDao _vmTemplateStoreDao;
     @Inject
     private VlanDao _vlanDao;
+    @Inject
+    private SnapshotDataStoreDao _snapshotDataStoreDao;
 
     protected GenericSearchBuilder<TemplateDataStoreVO, SumCount> templateSizeSearch;
+    protected GenericSearchBuilder<SnapshotDataStoreVO, SumCount> snapshotSizeSearch;
 
     protected SearchBuilder<ResourceCountVO> ResourceCountSearch;
     ScheduledExecutorService _rcExecutor;
@@ -189,6 +197,15 @@ public class ResourceLimitManagerImpl extends ManagerBase implements
ResourceLim
         templateSizeSearch.join("templates", join1, templateSizeSearch.entity().getTemplateId(),
join1.entity().getId(), JoinBuilder.JoinType.INNER);
         templateSizeSearch.done();
 
+        snapshotSizeSearch = _snapshotDataStoreDao.createSearchBuilder(SumCount.class);
+        snapshotSizeSearch.select("sum", Func.SUM, snapshotSizeSearch.entity().getSize());
+        snapshotSizeSearch.and("state", snapshotSizeSearch.entity().getState(), Op.EQ);
+        snapshotSizeSearch.and("storeRole", snapshotSizeSearch.entity().getRole(), Op.EQ);
+        SearchBuilder<SnapshotVO> join2 = _snapshotDao.createSearchBuilder();
+        join2.and("accountId", join2.entity().getAccountId(), Op.EQ);
+        snapshotSizeSearch.join("snapshots", join2, snapshotSizeSearch.entity().getSnapshotId(),
join2.entity().getId(), JoinBuilder.JoinType.INNER);
+        snapshotSizeSearch.done();
+
         _resourceCountCheckInterval = NumbersUtil.parseInt(_configDao.getValue(Config.ResourceCountCheckInterval.key()),
0);
         if (_resourceCountCheckInterval > 0) {
             _rcExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ResourceCountChecker"));
@@ -922,7 +939,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
 
     public long calculateSecondaryStorageForAccount(long accountId) {
         long totalVolumesSize = _volumeDao.secondaryStorageUsedForAccount(accountId);
-        long totalSnapshotsSize = _snapshotDao.secondaryStorageUsedForAccount(accountId);
+        long totalSnapshotsSize = 0;
         long totalTemplatesSize = 0;
 
         SearchCriteria<SumCount> sc = templateSizeSearch.create();
@@ -934,6 +951,14 @@ public class ResourceLimitManagerImpl extends ManagerBase implements
ResourceLim
             totalTemplatesSize = templates.get(0).sum;
         }
 
+        SearchCriteria<SumCount> sc2 = snapshotSizeSearch.create();
+        sc2.setParameters("state", ObjectInDataStoreStateMachine.State.Ready);
+        sc2.setParameters("storeRole", DataStoreRole.Image);
+        sc2.setJoinParameters("snapshots", "accountId", accountId);
+        List<SumCount> snapshots = _snapshotDataStoreDao.customSearch(sc2, null);
+        if (snapshots != null) {
+            totalSnapshotsSize = snapshots.get(0).sum;
+        }
         return totalVolumesSize + totalSnapshotsSize + totalTemplatesSize;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c3d8e207/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 313817b..4de635c 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -759,7 +759,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
             if (!created) {
                 s_logger.trace("Decrementing volume resource count for account id=" + volume.getAccountId()
+ " as volume failed to create on the backend");
                 _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume,
cmd.getDisplayVolume());
-                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage,
cmd.getDisplayVolume(), new Long(volume.getSize()));
+                _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(),
ResourceType.primary_storage.getOrdinal());
             }
         }
     }
@@ -1005,7 +1005,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
                     /* If volume is in primary storage, decrement primary storage count else
decrement secondary
                      storage count (in case of upload volume). */
                     if (volume.getFolder() != null || volume.getPath() != null || volume.getState()
== Volume.State.Allocated) {
-                        _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage,
volume.isDisplayVolume(), new Long(volume.getSize()));
+                        _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(),
volume.getDomainId(), ResourceType.primary_storage.getOrdinal());
                     } else {
                         _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(),
volume.getDomainId(), ResourceType.secondary_storage.getOrdinal());
                     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c3d8e207/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 257601c..0ec392d 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -1663,7 +1663,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
             // Update Resource count
             if (vm.getAccountId() != Account.ACCOUNT_ID_SYSTEM && !rootVol.isEmpty())
{
                 _resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.volume);
-                _resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.primary_storage,
new Long(rootVol.get(0).getSize()));
+                _resourceLimitMgr.recalculateResourceCount(vm.getAccountId(), vm.getDomainId(),
ResourceType.primary_storage.getOrdinal());
             }
 
             // Only if vm is not expunged already, cleanup it's resources


Mime
View raw message