Search in sources :

Example 1 with DayOfWeek

use of org.ovirt.engine.core.compat.DayOfWeek in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotModel method init.

private void init() {
    setDataCenter(new EntityModel<String>());
    setClusterName(new EntityModel<String>());
    setVolumeName(new EntityModel<String>());
    setSnapshotName(new EntityModel<String>());
    setDescription(new EntityModel<String>());
    setRecurrence(new ListModel<GlusterVolumeSnapshotScheduleRecurrence>());
    setInterval(new ListModel<String>());
    setEndByOptions(new ListModel<EndDateOptions>());
    setTimeZones(new ListModel<Map.Entry<String, String>>());
    setDaysOfMonth(new ListModel<String>());
    setStartAt(new EntityModel<>(new Date()));
    setEndDate(new EntityModel<>(new Date()));
    setExecutionTime(new EntityModel<>(new Date()));
    setDisableCliSchedule(new EntityModel<>(false));
    initIntervals();
    initTimeZones();
    recurrence.setItems(Arrays.asList(GlusterVolumeSnapshotScheduleRecurrence.values()), GlusterVolumeSnapshotScheduleRecurrence.UNKNOWN);
    endByOptions.setItems(Arrays.asList(EndDateOptions.values()));
    List<String> values = new ArrayList<>();
    for (DayOfWeek day : DayOfWeek.values()) {
        values.add(day.toString().substring(0, 3));
    }
    daysOfWeek = new ListModel<>();
    List<DayOfWeek> daysList = Arrays.asList(DayOfWeek.values());
    List<List<DayOfWeek>> list = new ArrayList<>();
    list.add(daysList);
    daysOfWeek.setItems(list, new ArrayList<DayOfWeek>());
}
Also used : DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) ArrayList(java.util.ArrayList) Date(java.util.Date) GlusterVolumeSnapshotScheduleRecurrence(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotScheduleRecurrence) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with DayOfWeek

use of org.ovirt.engine.core.compat.DayOfWeek 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 3 with DayOfWeek

use of org.ovirt.engine.core.compat.DayOfWeek 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 4 with DayOfWeek

use of org.ovirt.engine.core.compat.DayOfWeek in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotCreatePopupView method initEditors.

private void initEditors() {
    snapshotNameEditor = new StringEntityModelTextBoxEditor();
    snapshotNameEditor.hideLabel();
    EnableableFormLabel label = new EnableableFormLabel();
    label.setText(constants.volumeSnapshotNamePrefixLabel());
    snapshotNameEditorWithInfo = new EntityModelWidgetWithInfo(label, snapshotNameEditor);
    snapshotNameEditorWithInfo.setExplanation(templates.italicText(constants.snapshotNameInfo()));
    startAtEditor = new EntityModelDateTimeBoxEditor();
    startAtEditor.getContentWidget().setDateTimeFormat(GwtBootstrapDateTimePicker.DEFAULT_DATE_TIME_FORMAT);
    startAtEditor.getContentWidget().showDateAndTime();
    daysOfWeekEditor = new ListModelCheckBoxGroupEditor<>(new AbstractRenderer<DayOfWeek>() {

        @Override
        public String render(DayOfWeek object) {
            return object.toString().substring(0, 3);
        }
    });
    endDate = new EntityModelDateTimeBoxEditor();
    endDate.getContentWidget().setDateTimeFormat(GwtBootstrapDateTimePicker.DEFAULT_DATE_TIME_FORMAT);
    endDate.getContentWidget().showDateAndTime();
    executionTimeEditor = new EntityModelDateTimeBoxEditor();
    // $NON-NLS-1$
    executionTimeEditor.getContentWidget().setDateTimeFormat("hh:ii");
    executionTimeEditor.getContentWidget().showTimeOnly();
    recurrenceEditor = new ListModelListBoxEditor<>(new AbstractRenderer<GlusterVolumeSnapshotScheduleRecurrence>() {

        @Override
        public String render(GlusterVolumeSnapshotScheduleRecurrence object) {
            return EnumTranslator.getInstance().translate(object);
        }
    });
}
Also used : DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) EntityModelWidgetWithInfo(org.ovirt.engine.ui.common.widget.EntityModelWidgetWithInfo) GlusterVolumeSnapshotScheduleRecurrence(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotScheduleRecurrence) AbstractRenderer(com.google.gwt.text.shared.AbstractRenderer) EnableableFormLabel(org.ovirt.engine.ui.common.widget.label.EnableableFormLabel) EntityModelDateTimeBoxEditor(org.ovirt.engine.ui.common.widget.editor.EntityModelDateTimeBoxEditor) StringEntityModelTextBoxEditor(org.ovirt.engine.ui.common.widget.editor.generic.StringEntityModelTextBoxEditor)

Aggregations

DayOfWeek (org.ovirt.engine.core.compat.DayOfWeek)4 Date (java.util.Date)3 GlusterVolumeSnapshotScheduleRecurrence (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotScheduleRecurrence)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ActionType (org.ovirt.engine.core.common.action.ActionType)2 ScheduleGlusterVolumeSnapshotParameters (org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters)2 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)2 GlusterVolumeSnapshotSchedule (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule)2 AbstractRenderer (com.google.gwt.text.shared.AbstractRenderer)1 Time (java.sql.Time)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 TimeZoneType (org.ovirt.engine.core.common.TimeZoneType)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 CreateGlusterVolumeSnapshotParameters (org.ovirt.engine.core.common.action.gluster.CreateGlusterVolumeSnapshotParameters)1 GlusterVolumeParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeParameters)1 GlusterVolumeSnapshotActionParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeSnapshotActionParameters)1