Search in sources :

Example 1 with GlusterVolumeSnapshotSchedule

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule 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)

Example 2 with GlusterVolumeSnapshotSchedule

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

the class GlusterVolumeSnapshotListModel method editSnapshotSchedule.

public void editSnapshotSchedule() {
    if (getWindow() != null) {
        return;
    }
    final UIConstants constants = ConstantsManager.getInstance().getConstants();
    final GlusterVolumeSnapshotModel snapshotModel = new GlusterVolumeSnapshotModel(true, true);
    snapshotModel.setHelpTag(HelpTag.edit_volume_snapshot_schedule);
    // $NON-NLS-1$
    snapshotModel.setHashName("edit_volume_snapshot_schedule");
    snapshotModel.setTitle(constants.editVolumeSnapshotScheduleTitle());
    setWindow(snapshotModel);
    snapshotModel.startProgress();
    AsyncDataProvider.getInstance().getVolumeSnapshotSchedule(new AsyncQuery<>(new AsyncCallback<GlusterVolumeSnapshotSchedule>() {

        @Override
        public void onSuccess(final GlusterVolumeSnapshotSchedule schedule) {
            if (schedule == null) {
                snapshotModel.setMessage(ConstantsManager.getInstance().getConstants().unableToFetchVolumeSnapshotSchedule());
                return;
            }
            snapshotModel.getSnapshotName().setEntity(schedule.getSnapshotNamePrefix());
            snapshotModel.getDescription().setEntity(schedule.getSnapshotDescription());
            snapshotModel.getRecurrence().setSelectedItem(schedule.getRecurrence());
            if (schedule.getEndByDate() == null) {
                snapshotModel.getEndByOptions().setSelectedItem(EndDateOptions.NoEndDate);
            } else {
                snapshotModel.getEndByOptions().setSelectedItem(EndDateOptions.HasEndDate);
                snapshotModel.getEndDate().setEntity(schedule.getEndByDate());
            }
            if (schedule.getRecurrence() != GlusterVolumeSnapshotScheduleRecurrence.UNKNOWN) {
                Map<String, String> timeZones = TimeZoneType.GENERAL_TIMEZONE.getTimeZoneList();
                snapshotModel.getTimeZones().setSelectedItem(Linq.firstOrNull(timeZones.entrySet(), item -> item.getKey().startsWith(schedule.getTimeZone())));
            }
            switch(schedule.getRecurrence()) {
                case INTERVAL:
                    snapshotModel.getInterval().setSelectedItem(String.valueOf(schedule.getInterval()));
                    break;
                case HOURLY:
                    break;
                case DAILY:
                    snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
                    break;
                case WEEKLY:
                    List<DayOfWeek> daysList = new ArrayList<>();
                    for (String day : schedule.getDays().split(",")) {
                        // $NON-NLS-1$
                        daysList.add(getDayOfWeek(day));
                    }
                    snapshotModel.getDaysOfTheWeek().setSelectedItem(daysList);
                    snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
                    break;
                case MONTHLY:
                    snapshotModel.getDaysOfMonth().setSelectedItem(schedule.getDays());
                    snapshotModel.getExecutionTime().setEntity(getExecutionTimeValue(schedule));
                    break;
            }
            snapshotModel.getStartAt().setEntity(schedule.getStartDate());
            snapshotModel.stopProgress();
        }

        private DayOfWeek getDayOfWeek(String day) {
            switch(day) {
                case // $NON-NLS-1$
                "Sun":
                    return DayOfWeek.Sunday;
                case // $NON-NLS-1$
                "Mon":
                    return DayOfWeek.Monday;
                case // $NON-NLS-1$
                "Tue":
                    return DayOfWeek.Tuesday;
                case // $NON-NLS-1$
                "Wed":
                    return DayOfWeek.Wednesday;
                case // $NON-NLS-1$
                "Thu":
                    return DayOfWeek.Thursday;
                case // $NON-NLS-1$
                "Fri":
                    return DayOfWeek.Friday;
                case // $NON-NLS-1$
                "Sat":
                    return DayOfWeek.Saturday;
                default:
                    return null;
            }
        }

        private Date getExecutionTimeValue(GlusterVolumeSnapshotSchedule schedule) {
            Date dt = new Date();
            dt.setHours(schedule.getExecutionTime().getHours());
            dt.setMinutes(schedule.getExecutionTime().getMinutes());
            return dt;
        }
    }), getEntity().getId());
    snapshotModel.getClusterName().setEntity(getEntity().getClusterName());
    snapshotModel.getVolumeName().setEntity(getEntity().getName());
    // $NON-NLS-1$
    UICommand okCommand = UICommand.createDefaultOkUiCommand("onEditSnapshotSchedule", this);
    snapshotModel.getCommands().add(okCommand);
    // $NON-NLS-1$
    UICommand cancelCommand = UICommand.createCancelUiCommand("cancel", this);
    snapshotModel.getCommands().add(cancelCommand);
}
Also used : Time(java.sql.Time) TimeZoneType(org.ovirt.engine.core.common.TimeZoneType) Date(java.util.Date) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) ScheduleGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters) GlusterSnapshotStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterSnapshotStatus) Map(java.util.Map) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) GlusterVolumeParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeParameters) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) GlusterVolumeSnapshotActionParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeSnapshotActionParameters) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) CreateGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.CreateGlusterVolumeSnapshotParameters) GlusterVolumeSnapshotScheduleRecurrence(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotScheduleRecurrence) Linq(org.ovirt.engine.ui.uicommonweb.Linq) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus) List(java.util.List) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) Comparator(java.util.Comparator) Collections(java.util.Collections) EndDateOptions(org.ovirt.engine.ui.uicommonweb.models.gluster.GlusterVolumeSnapshotModel.EndDateOptions) DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) ArrayList(java.util.ArrayList) Date(java.util.Date) GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants)

Example 3 with GlusterVolumeSnapshotSchedule

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

the class RescheduleGlusterVolumeSnapshotCommand method executeCommand.

@Override
protected void executeCommand() {
    Guid volumeId = getGlusterVolumeId();
    GlusterVolumeSnapshotSchedule fetchedSchedule = glusterVolumeSnapshotScheduleDao.getByVolumeId(volumeId);
    String jobId = fetchedSchedule.getJobId();
    // delete the existing job
    getDbSchedulUtil().deleteJob(jobId);
    GlusterVolumeSnapshotSchedule schedule = getSchedule();
    if (schedule.getRecurrence() != null) {
        // Keep a copy of the execution time before conversion to engine time zone
        Time originalExecutionTime = schedule.getExecutionTime();
        try {
            String newJobId = scheduleJob();
            setSucceeded(true);
            schedule.setJobId(newJobId);
            // reverting to original execution time in UI populated time zone
            schedule.setExecutionTime(originalExecutionTime);
            glusterVolumeSnapshotScheduleDao.updateScheduleByVolumeId(volumeId, schedule);
        } catch (Exception ex) {
            setSucceeded(false);
            handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_RESCHEDULE_FAILED, ex.getMessage());
        }
    } else {
        glusterVolumeSnapshotScheduleDao.removeByVolumeId(volumeId);
        setSucceeded(true);
    }
}
Also used : GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) Time(java.sql.Time) Guid(org.ovirt.engine.core.compat.Guid)

Example 4 with GlusterVolumeSnapshotSchedule

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

the class GlusterVolumeSnapshotScheduleDaoTest method testRemoveByVolumeId.

@Test
public void testRemoveByVolumeId() {
    dao.removeByVolumeId(VOLUME_ID_1);
    GlusterVolumeSnapshotSchedule schedule = dao.getByVolumeId(VOLUME_ID_1);
    assertNull(schedule);
}
Also used : GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) Test(org.junit.Test)

Example 5 with GlusterVolumeSnapshotSchedule

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

the class GlusterVolumeSnapshotScheduleDaoTest method testUpdateShceduleByVolumeId.

@Test
public void testUpdateShceduleByVolumeId() {
    GlusterVolumeSnapshotSchedule schedule = dao.getByVolumeId(VOLUME_ID_1);
    schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.HOURLY);
    schedule.setStartDate(new Date());
    schedule.setInterval(0);
    dao.updateScheduleByVolumeId(VOLUME_ID_1, schedule);
    GlusterVolumeSnapshotSchedule fetchedSchedule = dao.getByVolumeId(VOLUME_ID_1);
    assertNotNull(fetchedSchedule);
    assertEquals(fetchedSchedule, schedule);
}
Also used : GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) Date(java.util.Date) Test(org.junit.Test)

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