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