use of com.cloud.storage.SnapshotPolicyVO in project cloudstack by apache.
the class SnapshotManagerImpl method findRecurringSnapshotSchedule.
@Override
public List<SnapshotScheduleVO> findRecurringSnapshotSchedule(ListRecurringSnapshotScheduleCmd cmd) {
Long volumeId = cmd.getVolumeId();
Long policyId = cmd.getSnapshotPolicyId();
Account account = CallContext.current().getCallingAccount();
// Verify parameters
VolumeVO volume = _volsDao.findById(volumeId);
if (volume == null) {
throw new InvalidParameterValueException("Failed to list snapshot schedule, unable to find a volume with id " + volumeId);
}
if (account != null) {
long volAcctId = volume.getAccountId();
if (_accountMgr.isAdmin(account.getId())) {
Account userAccount = _accountDao.findById(Long.valueOf(volAcctId));
if (!_domainDao.isChildDomain(account.getDomainId(), userAccount.getDomainId())) {
throw new PermissionDeniedException("Unable to list snapshot schedule for volume " + volumeId + ", permission denied.");
}
} else if (account.getId() != volAcctId) {
throw new PermissionDeniedException("Unable to list snapshot schedule, account " + account.getAccountName() + " does not own volume id " + volAcctId);
}
}
// List only future schedules, not past ones.
List<SnapshotScheduleVO> snapshotSchedules = new ArrayList<SnapshotScheduleVO>();
if (policyId == null) {
List<SnapshotPolicyVO> policyInstances = listPoliciesforVolume(volumeId);
for (SnapshotPolicyVO policyInstance : policyInstances) {
SnapshotScheduleVO snapshotSchedule = _snapshotScheduleDao.getCurrentSchedule(volumeId, policyInstance.getId(), false);
snapshotSchedules.add(snapshotSchedule);
}
} else {
snapshotSchedules.add(_snapshotScheduleDao.getCurrentSchedule(volumeId, policyId, false));
}
return snapshotSchedules;
}
use of com.cloud.storage.SnapshotPolicyVO in project cloudstack by apache.
the class SnapshotManagerImpl method deleteSnapshotPolicies.
@Override
public boolean deleteSnapshotPolicies(DeleteSnapshotPoliciesCmd cmd) {
Long policyId = cmd.getId();
List<Long> policyIds = cmd.getIds();
if ((policyId == null) && (policyIds == null)) {
throw new InvalidParameterValueException("No policy id (or list of ids) specified.");
}
if (policyIds == null) {
policyIds = new ArrayList<Long>();
policyIds.add(policyId);
} else if (policyIds.size() <= 0) {
// Not even sure how this is even possible
throw new InvalidParameterValueException("There are no policy ids");
}
if (policyIds.contains(Snapshot.MANUAL_POLICY_ID)) {
throw new InvalidParameterValueException("Invalid Policy id given: " + Snapshot.MANUAL_POLICY_ID);
}
for (Long policy : policyIds) {
SnapshotPolicyVO snapshotPolicyVO = _snapshotPolicyDao.findById(policy);
if (snapshotPolicyVO == null) {
throw new InvalidParameterValueException("Policy id given: " + policy + " does not exist");
}
VolumeVO volume = _volsDao.findById(snapshotPolicyVO.getVolumeId());
if (volume == null) {
throw new InvalidParameterValueException("Policy id given: " + policy + " does not belong to a valid volume");
}
_accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume);
}
for (Long pId : policyIds) {
if (!deletePolicy(pId)) {
s_logger.warn("Failed to delete snapshot policy with Id: " + policyId);
return false;
}
}
return true;
}
use of com.cloud.storage.SnapshotPolicyVO in project cloudstack by apache.
the class SnapshotManagerImpl method persistSnapshotPolicy.
protected SnapshotPolicyVO persistSnapshotPolicy(VolumeVO volume, String schedule, String timezone, IntervalType intervalType, int maxSnaps, boolean display, boolean active, Map<String, String> tags) {
long volumeId = volume.getId();
String volumeDescription = volume.getVolumeDescription();
GlobalLock createSnapshotPolicyLock = GlobalLock.getInternLock("createSnapshotPolicy_" + volumeId);
boolean isLockAcquired = createSnapshotPolicyLock.lock(5);
if (!isLockAcquired) {
throw new CloudRuntimeException(String.format("Unable to aquire lock for creating snapshot policy [%s] for %s.", intervalType, volumeDescription));
}
s_logger.debug(String.format("Acquired lock for creating snapshot policy [%s] for volume %s.", intervalType, volumeDescription));
try {
SnapshotPolicyVO policy = _snapshotPolicyDao.findOneByVolumeInterval(volumeId, intervalType);
if (policy == null) {
policy = createSnapshotPolicy(volumeId, schedule, timezone, intervalType, maxSnaps, display);
} else {
updateSnapshotPolicy(policy, schedule, timezone, intervalType, maxSnaps, active, display);
}
createTagsForSnapshotPolicy(tags, policy);
CallContext.current().putContextParameter(SnapshotPolicy.class, policy.getUuid());
return policy;
} finally {
createSnapshotPolicyLock.unlock();
}
}
use of com.cloud.storage.SnapshotPolicyVO in project cloudstack by apache.
the class SnapshotManagerImpl method deletePolicy.
protected boolean deletePolicy(Long policyId) {
SnapshotPolicyVO snapshotPolicy = _snapshotPolicyDao.findById(policyId);
_snapSchedMgr.removeSchedule(snapshotPolicy.getVolumeId(), snapshotPolicy.getId());
taggedResourceService.deleteTags(Collections.singletonList(snapshotPolicy.getUuid()), ResourceObjectType.SnapshotPolicy, null);
return _snapshotPolicyDao.remove(policyId);
}
use of com.cloud.storage.SnapshotPolicyVO in project cloudstack by apache.
the class SnapshotTestWithFakeData method createSnapshotPolicy.
protected SnapshotPolicyVO createSnapshotPolicy(Long volId) {
SnapshotPolicyVO policyVO = new SnapshotPolicyVO(volId, "jfkd", "fdfd", DateUtil.IntervalType.DAILY, 8, true);
policyVO = snapshotPolicyDao.persist(policyVO);
return policyVO;
}
Aggregations