use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class OrderScheduleTimeCallback method process.
@Override
public void process() throws MigrationCallbackException {
log.info("Handle Order schedule time ...");
DbClient dbClient = getDbClient();
List<URI> orders = dbClient.queryByType(Order.class, true);
for (URI uri : orders) {
Order order = dbClient.queryObject(Order.class, uri);
if (order == null)
continue;
if (order.getScheduledEventId() == null) {
if (order.getExecutionWindowId() == null || order.getExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
Calendar scheduleTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
scheduleTime.setTime(order.getLastUpdated());
order.setExecutionWindowId(new NamedURI(ExecutionWindow.NEXT, "NEXT"));
order.setScheduledTime(scheduleTime);
} else {
// For original orders, set schedule time to
// either 1) the next execution window starting time
// or 2) the current time if it is in current execution window
ExecutionWindow executionWindow = dbClient.queryObject(ExecutionWindow.class, order.getExecutionWindowId().getURI());
if (executionWindow == null)
continue;
ExecutionWindowHelper helper = new ExecutionWindowHelper(executionWindow);
order.setScheduledTime(helper.getScheduledTime());
}
dbClient.updateObject(order);
}
}
return;
}
use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class ScheduledEventService method getNextExecutionWindow.
public URI getNextExecutionWindow(Collection<URI> windows, Calendar time) {
Calendar nextWindowTime = null;
URI nextWindow = null;
for (URI window : windows) {
ExecutionWindow executionWindow = _dbClient.queryObject(ExecutionWindow.class, window);
if (executionWindow == null)
continue;
ExecutionWindowHelper helper = new ExecutionWindowHelper(executionWindow);
Calendar windowTime = helper.calculateCurrentOrNext(time);
if (nextWindowTime == null || nextWindowTime.after(windowTime)) {
nextWindowTime = windowTime;
nextWindow = window;
}
}
return nextWindow;
}
use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class ExecutionWindowHelperTest method testDailyWindowBeforeTime.
@Test
public void testDailyWindowBeforeTime() {
// Daily at 1:15am
ExecutionWindow window = createDailyWindow(1, 15);
setLengthInHours(window, 1);
ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
// before, different hour
Calendar beforeTime = getDateTimeUTC(2000, Calendar.JANUARY, 1, 0, 10, 0);
// Should be the same date
assertDateTime(helper.calculateNext(beforeTime), 2000, Calendar.JANUARY, 1, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2000, Calendar.JANUARY, 1, 1, 15, 0);
// a few minutes before, the same hour
beforeTime = getDateTimeUTC(2000, Calendar.JANUARY, 1, 1, 10, 0);
// Should be the same date
assertDateTime(helper.calculateNext(beforeTime), 2000, Calendar.JANUARY, 1, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2000, Calendar.JANUARY, 1, 1, 15, 0);
}
use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class ExecutionWindowHelperTest method testWeeklyDuringTime.
@Test
public void testWeeklyDuringTime() {
// Weekly on Sunday at 1:15am
ExecutionWindow window = createWeeklyWindow(Calendar.SUNDAY, 1, 15);
setLengthInHours(window, 1);
ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
// Start of the window
Calendar duringTime = getDateTimeUTC(2013, Calendar.MAY, 5, 1, 15, 0);
assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 5, 1, 15, 0);
Assert.assertTrue(helper.isActive(duringTime));
// One minute after start
duringTime = getDateTimeUTC(2013, Calendar.MAY, 5, 1, 16, 0);
assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 5, 1, 15, 0);
Assert.assertTrue(helper.isActive(duringTime));
// One minute before end
duringTime = getDateTimeUTC(2013, Calendar.MAY, 5, 2, 14, 0);
assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 5, 1, 15, 0);
Assert.assertTrue(helper.isActive(duringTime));
// End of the window
duringTime = getDateTimeUTC(2013, Calendar.MAY, 5, 2, 15, 0);
assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 12, 1, 15, 0);
Assert.assertFalse(helper.isActive(duringTime));
}
use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class ExecutionWindowHelperTest method testMonthlyNearEndOfMonth.
@Test
public void testMonthlyNearEndOfMonth() {
// Monthly on the 31st at 1:15am
ExecutionWindow window = createMonthlyWindow(31, 1, 15);
setLengthInHours(window, 1);
ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
// February
Calendar february = getDateTimeUTC(2013, Calendar.FEBRUARY, 1, 0, 0, 0);
assertDateTime(helper.calculateNext(february), 2013, Calendar.FEBRUARY, 28, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(february), 2013, Calendar.FEBRUARY, 28, 1, 15, 0);
// March
Calendar march = getDateTimeUTC(2013, Calendar.MARCH, 1, 0, 0, 0);
assertDateTime(helper.calculateNext(march), 2013, Calendar.MARCH, 31, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(march), 2013, Calendar.MARCH, 31, 1, 15, 0);
// April
Calendar april = getDateTimeUTC(2013, Calendar.APRIL, 1, 0, 0, 0);
assertDateTime(helper.calculateNext(april), 2013, Calendar.APRIL, 30, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(april), 2013, Calendar.APRIL, 30, 1, 15, 0);
}
Aggregations