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.Snapshot;
|
||||||
import com.cloud.storage.Volume;
|
import com.cloud.storage.Volume;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.UserContext;
|
|
||||||
|
|
||||||
@Implementation(description="Creates an instant snapshot of a volume.", responseObject=SnapshotResponse.class)
|
@Implementation(description="Creates an instant snapshot of a volume.", responseObject=SnapshotResponse.class)
|
||||||
public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
||||||
|
|||||||
@ -18,9 +18,8 @@
|
|||||||
|
|
||||||
package com.cloud.storage.dao;
|
package com.cloud.storage.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.storage.Snapshot;
|
|
||||||
import com.cloud.storage.SnapshotVO;
|
import com.cloud.storage.SnapshotVO;
|
||||||
import com.cloud.utils.db.Filter;
|
import com.cloud.utils.db.Filter;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|||||||
@ -526,6 +526,10 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
|||||||
_snapshotDao.update(snapshotId, snapshot);
|
_snapshotDao.update(snapshotId, snapshot);
|
||||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), volume.getDataCenterId(), snapshotId, snapshot.getName(), null, null, volume.getSize());
|
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), volume.getDataCenterId(), snapshotId, snapshot.getName(), null, null, volume.getSize());
|
||||||
_usageEventDao.persist(usageEvent);
|
_usageEventDao.persist(usageEvent);
|
||||||
|
|
||||||
|
if (snapshot.getSnapshotType() == Type.RECURRING.ordinal()) {
|
||||||
|
_accountMgr.incrementResourceCount(snapshot.getAccountId(), ResourceType.snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -536,6 +540,12 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
|||||||
// 2) Create the next Snapshot pretending this is a valid snapshot.
|
// 2) Create the next Snapshot pretending this is a valid snapshot.
|
||||||
// 3) backupSnapshotToSecondaryStorage of the next snapshot
|
// 3) backupSnapshotToSecondaryStorage of the next snapshot
|
||||||
// will take care of cleaning up the state of this 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);
|
_snapshotDao.remove(snapshotId);
|
||||||
}
|
}
|
||||||
txn.commit();
|
txn.commit();
|
||||||
@ -987,6 +997,9 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
|||||||
if (volume == null) {
|
if (volume == null) {
|
||||||
throw new InvalidParameterValueException("Failed to create snapshot policy, unable to find a volume with id " + volumeId);
|
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
|
// If an account was passed in, make sure that it matches the account of the volume
|
||||||
checkAccountPermissions(volume.getAccountId(), volume.getDomainId(), "volume", volumeId);
|
checkAccountPermissions(volume.getAccountId(), volume.getDomainId(), "volume", volumeId);
|
||||||
@ -1028,6 +1041,15 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
|
|||||||
if (cmd.getMaxSnaps() > intervalMaxSnaps) {
|
if (cmd.getMaxSnaps() > intervalMaxSnaps) {
|
||||||
throw new InvalidParameterValueException("maxSnaps exceeds limit: " + intervalMaxSnaps + " for interval type: " + cmd.getIntervalType());
|
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());
|
SnapshotPolicyVO policy = new SnapshotPolicyVO(volumeId, cmd.getSchedule(), timezoneId, (short)type.ordinal(), cmd.getMaxSnaps());
|
||||||
// Create an event
|
// Create an event
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user