cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weiz...@apache.org
Subject [1/2] git commit: updated refs/heads/4.2 to e312282
Date Thu, 05 Dec 2013 18:53:18 GMT
Updated Branches:
  refs/heads/4.2 dfded8834 -> e312282d7


CLOUDSTACK-5303: fix incorrect resource count (snapshot, secondary_storage


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

Branch: refs/heads/4.2
Commit: fa43987e43162c6f87ca8e341afe55e4f45ef058
Parents: dfded88
Author: Wei Zhou <w.zhou@leaseweb.com>
Authored: Thu Dec 5 19:30:18 2013 +0100
Committer: Wei Zhou <w.zhou@leaseweb.com>
Committed: Thu Dec 5 19:30:18 2013 +0100

----------------------------------------------------------------------
 .../src/com/cloud/storage/dao/SnapshotDaoImpl.java   |  2 ++
 .../cloud/storage/snapshot/SnapshotManagerImpl.java  | 15 +++++++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa43987e/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 f5319ea..d318d9e 100644
--- a/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
@@ -176,6 +176,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long>
implements
         CountSnapshotsByAccount = createSearchBuilder(Long.class);
         CountSnapshotsByAccount.select(null, Func.COUNT, null);
         CountSnapshotsByAccount.and("account", CountSnapshotsByAccount.entity().getAccountId(),
SearchCriteria.Op.EQ);
+        CountSnapshotsByAccount.and("status", CountSnapshotsByAccount.entity().getState(),
SearchCriteria.Op.NIN);
         CountSnapshotsByAccount.and("removed", CountSnapshotsByAccount.entity().getRemoved(),
SearchCriteria.Op.NULL);
         CountSnapshotsByAccount.done();
 
@@ -277,6 +278,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long>
implements
     public Long countSnapshotsForAccount(long accountId) {
         SearchCriteria<Long> sc = CountSnapshotsByAccount.create();
         sc.setParameters("account", accountId);
+        sc.setParameters("status", State.Error, State.Destroyed);
         return customSearch(sc, null).get(0);
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fa43987e/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index 7177841..9ba0221 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -483,10 +483,16 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
         			UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_DELETE, snapshotCheck.getAccountId(),
         					snapshotCheck.getDataCenterId(), snapshotId, snapshotCheck.getName(), null,
null, 0L,
         					snapshotCheck.getClass().getName(), snapshotCheck.getUuid());
+                }
+                if (snapshotCheck.getState() != Snapshot.State.Error && snapshotCheck.getState()
!= Snapshot.State.Destroyed) {
+                    _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(),
ResourceType.snapshot);
+                    if (snapshotCheck.getState() == Snapshot.State.BackedUp)
+                        _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(),
ResourceType.secondary_storage,
+                                new Long(snapshotCheck.getSize()));
+                    else if (!backup && snapshotCheck.getState() == Snapshot.State.CreatedOnPrimary)
+                        _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(),
ResourceType.primary_storage,
+                                new Long(snapshotCheck.getSize()));
         		}
-                _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.snapshot);
-                _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage,
-                        new Long(snapshotCheck.getSize()));
         	}
         	return result;
         } catch (Exception e) {
@@ -1012,12 +1018,12 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
                 UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(),
                         snapshot.getDataCenterId(), snapshotId, snapshot.getName(), null,
null,
                         volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
-                _resourceLimitMgr.incrementResourceCount(snapshotOwner.getId(), ResourceType.snapshot);
             } catch (Exception e) {
                 s_logger.debug("post process snapshot failed", e);
             }
         } catch(Exception e) {
             s_logger.debug("Failed to create snapshot", e);
+            _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.snapshot);
             if (backup) {
                 _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage,
                         new Long(volume.getSize()));
@@ -1171,6 +1177,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
         if (snapshot == null) {
             throw new CloudRuntimeException("Failed to create snapshot for volume: " + volume.getId());
         }
+        _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.snapshot);
         if (backup) {
             _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage,
                     new Long(volume.getSize()));


Mime
View raw message