Search in sources :

Example 1 with SnapshotPolicyVO

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

the class SnapshotManagerImpl method deletePolicy.

protected boolean deletePolicy(long userId, Long policyId) {
    SnapshotPolicyVO snapshotPolicy = _snapshotPolicyDao.findById(policyId);
    _snapSchedMgr.removeSchedule(snapshotPolicy.getVolumeId(), snapshotPolicy.getId());
    return _snapshotPolicyDao.remove(policyId);
}
Also used : SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO)

Example 2 with SnapshotPolicyVO

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

the class SnapshotManagerImpl method getSnapshotType.

private Type getSnapshotType(Long policyId) {
    if (policyId.equals(Snapshot.MANUAL_POLICY_ID)) {
        return Type.MANUAL;
    } else {
        SnapshotPolicyVO spstPolicyVO = _snapshotPolicyDao.findById(policyId);
        IntervalType intvType = DateUtil.getIntervalType(spstPolicyVO.getInterval());
        return getSnapshotType(intvType);
    }
}
Also used : IntervalType(com.cloud.utils.DateUtil.IntervalType) SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO)

Example 3 with SnapshotPolicyVO

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

the class SnapshotManagerImpl method createSnapshotPolicy.

protected SnapshotPolicyVO createSnapshotPolicy(long volumeId, String schedule, String timezone, IntervalType intervalType, int maxSnaps, boolean display) {
    SnapshotPolicyVO policy = new SnapshotPolicyVO(volumeId, schedule, timezone, intervalType, maxSnaps, display);
    policy = _snapshotPolicyDao.persist(policy);
    _snapSchedMgr.scheduleNextSnapshotJob(policy);
    s_logger.debug(String.format("Created snapshot policy %s.", new ReflectionToStringBuilder(policy, ToStringStyle.JSON_STYLE).setExcludeFieldNames("id", "uuid", "active")));
    return policy;
}
Also used : ReflectionToStringBuilder(org.apache.commons.lang3.builder.ReflectionToStringBuilder) SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO)

Example 4 with SnapshotPolicyVO

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

the class SnapshotManagerImpl method deletePoliciesForVolume.

@Override
public void deletePoliciesForVolume(Long volumeId) {
    List<SnapshotPolicyVO> policyInstances = listPoliciesforVolume(volumeId);
    for (SnapshotPolicyVO policyInstance : policyInstances) {
        deletePolicy(policyInstance.getId());
    }
    // We also want to delete the manual snapshots scheduled for this volume
    // We can only delete the schedules in the future, not the ones which are already executing.
    SnapshotScheduleVO snapshotSchedule = _snapshotScheduleDao.getCurrentSchedule(volumeId, Snapshot.MANUAL_POLICY_ID, false);
    if (snapshotSchedule != null) {
        _snapshotScheduleDao.expunge(snapshotSchedule.getId());
    }
}
Also used : SnapshotScheduleVO(com.cloud.storage.SnapshotScheduleVO) SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO)

Example 5 with SnapshotPolicyVO

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

the class SnapshotSchedulerImpl method start.

@Override
@DB
public boolean start() {
    // reschedule all policies after management restart
    final List<SnapshotPolicyVO> policyInstances = _snapshotPolicyDao.listAll();
    for (final SnapshotPolicyVO policyInstance : policyInstances) {
        if (policyInstance.getId() != Snapshot.MANUAL_POLICY_ID) {
            scheduleNextSnapshotJob(policyInstance);
        }
    }
    if (_testTimerTask != null) {
        _testClockTimer = new Timer("TestClock");
        // Run the test clock every 60s. Because every tick is counted as 1 minute.
        // Else it becomes too confusing.
        _testClockTimer.schedule(_testTimerTask, 100 * 1000L, 60 * 1000L);
    } else {
        final TimerTask timerTask = new ManagedContextTimerTask() {

            @Override
            protected void runInContext() {
                try {
                    final Date currentTimestamp = new Date();
                    poll(currentTimestamp);
                } catch (final Throwable t) {
                    s_logger.warn("Catch throwable in snapshot scheduler ", t);
                }
            }
        };
        _testClockTimer = new Timer("SnapshotPollTask");
        _testClockTimer.schedule(timerTask, _snapshotPollInterval * 1000L, _snapshotPollInterval * 1000L);
    }
    return true;
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) ManagedContextTimerTask(org.apache.cloudstack.managed.context.ManagedContextTimerTask) SnapshotPolicyVO(com.cloud.storage.SnapshotPolicyVO) ManagedContextTimerTask(org.apache.cloudstack.managed.context.ManagedContextTimerTask) Date(java.util.Date) DB(com.cloud.utils.db.DB)

Aggregations

SnapshotPolicyVO (com.cloud.storage.SnapshotPolicyVO)20 IntervalType (com.cloud.utils.DateUtil.IntervalType)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 VolumeVO (com.cloud.storage.VolumeVO)3 ResourceType (com.cloud.configuration.Resource.ResourceType)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 SnapshotScheduleVO (com.cloud.storage.SnapshotScheduleVO)2 SnapshotVO (com.cloud.storage.SnapshotVO)2 Account (com.cloud.user.Account)2 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 VerificationMode (org.mockito.verification.VerificationMode)2 ActionEvent (com.cloud.event.ActionEvent)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 ResourceObjectType (com.cloud.server.ResourceTag.ResourceObjectType)1 DataStoreRole (com.cloud.storage.DataStoreRole)1 ScopeType (com.cloud.storage.ScopeType)1