Search in sources :

Example 1 with ScheduleGlusterVolumeSnapshotParameters

use of org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotListModel method scheduleSnapshot.

private void scheduleSnapshot(final GlusterVolumeSnapshotModel snapshotModel, boolean reschedule) {
    GlusterVolumeEntity volumeEntity = getEntity();
    final GlusterVolumeSnapshotSchedule schedule = new GlusterVolumeSnapshotSchedule();
    schedule.setSnapshotNamePrefix(snapshotModel.getSnapshotName().getEntity());
    schedule.setSnapshotDescription(snapshotModel.getDescription().getEntity());
    schedule.setClusterId(volumeEntity.getClusterId());
    schedule.setVolumeId(volumeEntity.getId());
    switch(snapshotModel.getRecurrence().getSelectedItem()) {
        case INTERVAL:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.INTERVAL);
            schedule.setInterval(Integer.valueOf(snapshotModel.getInterval().getSelectedItem()));
            break;
        case HOURLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.HOURLY);
            break;
        case DAILY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.DAILY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            break;
        case WEEKLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.WEEKLY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            StringBuilder sb = new StringBuilder();
            for (DayOfWeek day : snapshotModel.getDaysOfTheWeek().getSelectedItem()) {
                sb.append(day.name().substring(0, 3));
                // $NON-NLS-1$
                sb.append(',');
            }
            schedule.setDays(sb.toString());
            break;
        case MONTHLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.MONTHLY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            schedule.setDays(snapshotModel.getDaysOfMonth().getSelectedItem());
            break;
    }
    Date startAt = snapshotModel.getStartAt().getEntity();
    schedule.setStartDate(startAt);
    schedule.setTimeZone(snapshotModel.getTimeZones().getSelectedItem().getKey());
    if (snapshotModel.getEndByOptions().getSelectedItem() == EndDateOptions.NoEndDate) {
        schedule.setEndByDate(null);
    } else {
        schedule.setEndByDate(snapshotModel.getEndDate().getEntity());
    }
    ScheduleGlusterVolumeSnapshotParameters params = new ScheduleGlusterVolumeSnapshotParameters(schedule, snapshotModel.getDisableCliSchedule().getEntity());
    snapshotModel.startProgress();
    ActionType actionType = null;
    if (reschedule) {
        actionType = ActionType.RescheduleGlusterVolumeSnapshot;
    } else {
        actionType = ActionType.ScheduleGlusterVolumeSnapshot;
    }
    Frontend.getInstance().runAction(actionType, params, result -> {
        GlusterVolumeSnapshotListModel localModel = (GlusterVolumeSnapshotListModel) result.getState();
        snapshotModel.stopProgress();
        localModel.postSnapshotAction(result.getReturnValue());
    }, this, snapshotModel.getDisableCliSchedule().getEntity());
}
Also used : DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) ActionType(org.ovirt.engine.core.common.action.ActionType) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) Date(java.util.Date) ScheduleGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters)

Aggregations

Date (java.util.Date)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 ScheduleGlusterVolumeSnapshotParameters (org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters)1 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)1 GlusterVolumeSnapshotSchedule (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule)1 DayOfWeek (org.ovirt.engine.core.compat.DayOfWeek)1