mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-5303: fix incorrect resource count (snapshot, secondary_storage)
(cherry picked from commit fa43987e43)
This commit is contained in:
parent
3d9a6ecbcd
commit
4bb85cd7f9
|
|
@ -173,6 +173,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();
|
||||
|
||||
|
|
@ -268,6 +269,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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -425,8 +425,10 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
|
|||
snapshotCheck.getDataCenterId(), snapshotId, snapshotCheck.getName(), null, null, 0L,
|
||||
snapshotCheck.getClass().getName(), snapshotCheck.getUuid());
|
||||
}
|
||||
_resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.snapshot);
|
||||
_resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage, new Long(snapshotStoreRef.getSize()));
|
||||
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(snapshotStoreRef.getSize()));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
|
|
@ -948,7 +950,6 @@ 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);
|
||||
SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Image);
|
||||
// Correct the resource count of snapshot in case of delta snapshots.
|
||||
_resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getSize()));
|
||||
|
|
@ -957,6 +958,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
|
|||
}
|
||||
} catch(Exception e) {
|
||||
s_logger.debug("Failed to create snapshot", e);
|
||||
_resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.snapshot);
|
||||
_resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize()));
|
||||
throw new CloudRuntimeException("Failed to create snapshot", e);
|
||||
}
|
||||
|
|
@ -1100,6 +1102,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);
|
||||
_resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, new Long(volume.getSize()));
|
||||
return snapshot;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue