Search in sources :

Example 6 with SnapshotScheduleVO

use of com.cloud.storage.SnapshotScheduleVO 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;
}
Also used : Account(com.cloud.user.Account) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) SnapshotScheduleVO(com.cloud.storage.SnapshotScheduleVO) SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO)

Example 7 with SnapshotScheduleVO

use of com.cloud.storage.SnapshotScheduleVO in project cloudstack by apache.

the class SnapshotSchedulerImpl method removeSchedule.

@Override
@DB
public boolean removeSchedule(final Long volumeId, final Long policyId) {
    // We can only remove schedules which are in the future. Not which are already executed in the past.
    final SnapshotScheduleVO schedule = _snapshotScheduleDao.getCurrentSchedule(volumeId, policyId, false);
    boolean success = true;
    if (schedule != null) {
        success = _snapshotScheduleDao.remove(schedule.getId());
    }
    if (!success) {
        s_logger.debug("Error while deleting Snapshot schedule with Id: " + schedule.getId());
    }
    return success;
}
Also used : SnapshotScheduleVO(com.cloud.storage.SnapshotScheduleVO) DB(com.cloud.utils.db.DB)

Aggregations

SnapshotScheduleVO (com.cloud.storage.SnapshotScheduleVO)7 DB (com.cloud.utils.db.DB)3 SnapshotPolicyVO (com.cloud.storage.SnapshotPolicyVO)2 SnapshotVO (com.cloud.storage.SnapshotVO)2 VolumeVO (com.cloud.storage.VolumeVO)2 Account (com.cloud.user.Account)2 Date (java.util.Date)2 AsyncJobVO (org.apache.cloudstack.framework.jobs.impl.AsyncJobVO)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConfigurationException (javax.naming.ConfigurationException)1 CreateSnapshotCmd (org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotCmd)1