mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
bug 8493: Don't allow to create a snapshot policy with max value exceeding domain/account snapshot limit
status 8493: resolved fixed Also increase/reduce resource count when recurring snapshot is taken/removed
This commit is contained in:
parent
74e878ea7f
commit
7b13c89956
@ -33,7 +33,6 @@ import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
@Implementation(description="Creates an instant snapshot of a volume.", responseObject=SnapshotResponse.class)
|
||||
public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
||||
|
||||
@ -20,7 +20,6 @@ package com.cloud.storage.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@ -527,6 +527,10 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), volume.getDataCenterId(), snapshotId, snapshot.getName(), null, null, volume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
|
||||
if (snapshot.getSnapshotType() == Type.RECURRING.ordinal()) {
|
||||
_accountMgr.incrementResourceCount(snapshot.getAccountId(), ResourceType.snapshot);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
// Just mark it as removed in the database. When the next snapshot it taken,
|
||||
@ -536,6 +540,12 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
// 2) Create the next Snapshot pretending this is a valid snapshot.
|
||||
// 3) backupSnapshotToSecondaryStorage of the next snapshot
|
||||
// will take care of cleaning up the state of this snapshot
|
||||
|
||||
if (snapshot.getSnapshotType() == Type.RECURRING.ordinal()) {
|
||||
_accountMgr.decrementResourceCount(snapshot.getAccountId(), ResourceType.snapshot);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), 0L, snapshotId, snapshot.getName(), null, null, 0L);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
_snapshotDao.remove(snapshotId);
|
||||
}
|
||||
txn.commit();
|
||||
@ -988,6 +998,9 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
throw new InvalidParameterValueException("Failed to create snapshot policy, unable to find a volume with id " + volumeId);
|
||||
}
|
||||
|
||||
AccountVO owner = _accountDao.findById(volume.getAccountId());
|
||||
DomainVO domain = _domainDao.findById(owner.getDomainId());
|
||||
|
||||
// If an account was passed in, make sure that it matches the account of the volume
|
||||
checkAccountPermissions(volume.getAccountId(), volume.getDomainId(), "volume", volumeId);
|
||||
|
||||
@ -1029,6 +1042,15 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
||||
throw new InvalidParameterValueException("maxSnaps exceeds limit: " + intervalMaxSnaps + " for interval type: " + cmd.getIntervalType());
|
||||
}
|
||||
|
||||
|
||||
//Verify that max doesn't exceed domain and account snapshot limits
|
||||
long accountLimit = _accountMgr.findCorrectResourceLimit(owner, ResourceType.snapshot);
|
||||
long domainLimit = _accountMgr.findCorrectResourceLimit(domain, ResourceType.snapshot);
|
||||
int max = cmd.getMaxSnaps().intValue();
|
||||
if (owner.getType() != Account.ACCOUNT_TYPE_ADMIN && ((accountLimit != -1 && max > accountLimit ) || (domainLimit != -1 && max > domainLimit))){
|
||||
throw new InvalidParameterValueException("Max number of snapshots shouldn't exceed the domain/account level snapshot limit");
|
||||
}
|
||||
|
||||
SnapshotPolicyVO policy = new SnapshotPolicyVO(volumeId, cmd.getSchedule(), timezoneId, (short)type.ordinal(), cmd.getMaxSnaps());
|
||||
// Create an event
|
||||
try{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user