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>());
}
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());
}
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);
}
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);
}
});
}
Aggregations