Search in sources :

Example 6 with GlusterVolumeSnapshotSchedule

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotScheduleDaoTest method testGetByVolumeId.

@Test
public void testGetByVolumeId() {
    GlusterVolumeSnapshotSchedule schedule = dao.getByVolumeId(VOLUME_ID_1);
    assertNotNull(schedule);
    assertEquals(schedule, existingSchedule);
}
Also used : GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) Test(org.junit.Test)

Example 7 with GlusterVolumeSnapshotSchedule

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotScheduleDaoTest method insertSnapshotSchedule.

private GlusterVolumeSnapshotSchedule insertSnapshotSchedule() {
    GlusterVolumeSnapshotSchedule schedule = new GlusterVolumeSnapshotSchedule();
    schedule.setClusterId(CLUSTER_ID);
    schedule.setVolumeId(VOLUME_ID_2);
    schedule.setJobId("test_job_id");
    schedule.setSnapshotNamePrefix("prefix");
    schedule.setSnapshotDescription("desc");
    schedule.setInterval(0);
    schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.DAILY);
    schedule.setTimeZone("Asia/Calcutta");
    schedule.setExecutionTime(new Time(10, 30, 0));
    schedule.setEndByDate(null);
    dao.save(schedule);
    return schedule;
}
Also used : GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) Time(java.sql.Time)

Example 8 with GlusterVolumeSnapshotSchedule

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotScheduleDaoTest method testSaveAndGetByVolumeId.

@Test
public void testSaveAndGetByVolumeId() {
    GlusterVolumeSnapshotSchedule schedule = dao.getByVolumeId(VOLUME_ID_2);
    assertNull(schedule);
    newSchedule = insertSnapshotSchedule();
    schedule = dao.getByVolumeId(VOLUME_ID_2);
    assertNotNull(schedule);
    assertEquals(schedule, newSchedule);
}
Also used : GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) Test(org.junit.Test)

Example 9 with GlusterVolumeSnapshotSchedule

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule in project ovirt-engine by oVirt.

the class GlusterSnapshotScheduleJob method onTimer.

@OnTimerMethodAnnotation("onTimer")
public void onTimer(String serverId, String volumeId, String snapshotNamePrefix, String description, boolean force) {
    final GlusterVolumeEntity volume = glusterVolumeDao.getById(new Guid(volumeId));
    if (volume == null) {
        log.error("Error while creating volume snapshot. Volume is null.");
        return;
    }
    final GlusterVolumeSnapshotEntity snapshot = new GlusterVolumeSnapshotEntity();
    snapshot.setClusterId(volume.getClusterId());
    snapshot.setVolumeId(volume.getId());
    snapshot.setSnapshotName(snapshotNamePrefix);
    snapshot.setDescription(description);
    ActionReturnValue returnValue = backend.runInternalAction(ActionType.CreateGlusterVolumeSnapshot, new CreateGlusterVolumeSnapshotParameters(snapshot, force));
    if (!returnValue.getSucceeded()) {
        log.error("Error while creating snapshot for volume '{}': {}", volume.getName(), returnValue.getExecuteFailedMessages().toString());
        Map<String, String> customValues = new HashMap<>();
        customValues.put(GlusterConstants.VOLUME_SNAPSHOT_NAME, snapshot.getSnapshotName());
        customValues.put(GlusterConstants.VOLUME_NAME, volume.getName());
        logUtil.logAuditMessage(volume.getClusterId(), volume.getClusterName(), volume, null, AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED, customValues);
    }
    // Check if next schedule available, and if not delete the scheduling details from DB
    GlusterVolumeSnapshotSchedule schedule = glusterVolumeSnapshotScheduleDao.getByVolumeId(volume.getId());
    Date endDate = glusterUtil.convertDate(schedule.getEndByDate(), schedule.getTimeZone());
    if (endDate != null && endDate.before(new Date())) {
        glusterVolumeSnapshotScheduleDao.removeByVolumeId(volume.getId());
        logUtil.logAuditMessage(volume.getClusterId(), volume.getClusterName(), volume, null, AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED, Collections.singletonMap(GlusterConstants.VOLUME_NAME, volume.getName()));
    }
}
Also used : GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) CreateGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.CreateGlusterVolumeSnapshotParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) HashMap(java.util.HashMap) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) Guid(org.ovirt.engine.core.compat.Guid) Date(java.util.Date) OnTimerMethodAnnotation(org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation)

Aggregations

GlusterVolumeSnapshotSchedule (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule)9 Date (java.util.Date)4 Test (org.junit.Test)4 Time (java.sql.Time)3 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)3 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 ActionType (org.ovirt.engine.core.common.action.ActionType)2 CreateGlusterVolumeSnapshotParameters (org.ovirt.engine.core.common.action.gluster.CreateGlusterVolumeSnapshotParameters)2 ScheduleGlusterVolumeSnapshotParameters (org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters)2 GlusterVolumeSnapshotEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity)2 DayOfWeek (org.ovirt.engine.core.compat.DayOfWeek)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TimeZoneType (org.ovirt.engine.core.common.TimeZoneType)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1