use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class ExecutionWindowHelperTest method testMonthly.
@Test
public void testMonthly() {
// Monthly on the 15th at 1:15am
ExecutionWindow window = createMonthlyWindow(15, 1, 15);
setLengthInHours(window, 1);
ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
// Just before window
Calendar beforeTime = getDateTimeUTC(2013, Calendar.MAY, 15, 1, 10, 0);
assertDateTime(helper.calculateNext(beforeTime), 2013, Calendar.MAY, 15, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2013, Calendar.MAY, 15, 1, 15, 0);
// Just after the window
Calendar afterTime = getDateTimeUTC(2013, Calendar.APRIL, 16, 1, 10, 0);
assertDateTime(helper.calculateNext(afterTime), 2013, Calendar.MAY, 15, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(afterTime), 2013, Calendar.MAY, 15, 1, 15, 0);
// Start of the window
Calendar duringTime = getDateTimeUTC(2013, Calendar.MAY, 15, 1, 15, 0);
assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.JUNE, 15, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 15, 1, 15, 0);
Assert.assertTrue(helper.isActive(duringTime));
// One minute after start
duringTime = getDateTimeUTC(2013, Calendar.MAY, 15, 1, 16, 0);
assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.JUNE, 15, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 15, 1, 15, 0);
Assert.assertTrue(helper.isActive(duringTime));
// One minute before end
duringTime = getDateTimeUTC(2013, Calendar.MAY, 15, 2, 14, 0);
assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.JUNE, 15, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.MAY, 15, 1, 15, 0);
Assert.assertTrue(helper.isActive(duringTime));
// End of the window
duringTime = getDateTimeUTC(2013, Calendar.MAY, 15, 2, 15, 0);
assertDateTime(helper.calculateNext(duringTime), 2013, Calendar.JUNE, 15, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(duringTime), 2013, Calendar.JUNE, 15, 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 testWeeklyBeforeTime.
@Test
public void testWeeklyBeforeTime() {
// Weekly on Sunday at 1:15am
ExecutionWindow window = createWeeklyWindow(Calendar.SUNDAY, 1, 15);
setLengthInHours(window, 1);
ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
Calendar beforeTime = getDateTimeUTC(2013, Calendar.MAY, 5, 1, 10, 0);
assertDateTime(helper.calculateNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
beforeTime = getDateTimeUTC(2013, Calendar.MAY, 4, 1, 10, 0);
assertDateTime(helper.calculateNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
beforeTime = getDateTimeUTC(2013, Calendar.MAY, 3, 1, 10, 0);
assertDateTime(helper.calculateNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
beforeTime = getDateTimeUTC(2013, Calendar.MAY, 2, 1, 10, 0);
assertDateTime(helper.calculateNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
beforeTime = getDateTimeUTC(2013, Calendar.MAY, 1, 1, 10, 0);
assertDateTime(helper.calculateNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
assertDateTime(helper.calculateCurrentOrNext(beforeTime), 2013, Calendar.MAY, 5, 1, 15, 0);
}
use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class OrderService method scheduleReoccurenceOrders.
private void scheduleReoccurenceOrders() throws Exception {
lock = coordinatorClient.getLock(LOCK_NAME);
try {
lock.acquire();
List<ScheduledEvent> scheduledEvents = dataManager.getAllReoccurrenceEvents();
for (ScheduledEvent event : scheduledEvents) {
if (event.getEventStatus() != ScheduledEventStatus.APPROVED) {
log.debug("Skipping event {} which is not in APPROVED status.", event.getId());
continue;
}
URI orderId = event.getLatestOrderId();
Order order = getOrderById(orderId, false);
if (!(OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.SUCCESS) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.PARTIAL_SUCCESS) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.ERROR) || OrderStatus.valueOf(order.getOrderStatus()).equals(OrderStatus.CANCELLED))) {
log.debug("Skipping event {} whose latest order {} is not finished yet.", event.getId(), order.getId());
continue;
}
log.info("Trying to schedule a new order for event {} : {}", event.getId(), ScheduleInfo.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getScheduleInfo().getBytes(UTF_8))).toString());
StorageOSUser user = StorageOSUser.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getStorageOSUser().getBytes(UTF_8)));
OrderCreateParam createParam = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
ScheduleInfo scheduleInfo = ScheduleInfo.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getScheduleInfo().getBytes(UTF_8)));
Calendar nextScheduledTime = ScheduleTimeHelper.getNextScheduledTime(order.getScheduledTime(), scheduleInfo);
int retry = 0;
if (order.getExecutionWindowId() != null && !order.getExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
ExecutionWindow window = client.executionWindows().findById(order.getExecutionWindowId().getURI());
if (window != null) {
ExecutionWindowHelper helper = new ExecutionWindowHelper(window);
if (nextScheduledTime != null && !helper.isActive(nextScheduledTime)) {
log.warn("Execution window {} might be changed after the event is scheduled.", order.getExecutionWindowId().getURI());
log.warn("Otherwise it is a HOURLY scheduled event");
do {
nextScheduledTime = ScheduleTimeHelper.getNextScheduledTime(nextScheduledTime, scheduleInfo);
retry++;
} while (nextScheduledTime != null && !helper.isActive(nextScheduledTime) && retry < ScheduleTimeHelper.SCHEDULE_TIME_RETRY_THRESHOLD);
if (retry == ScheduleTimeHelper.SCHEDULE_TIME_RETRY_THRESHOLD) {
log.error("Failed to find next scheduled time that match with {}", order.getExecutionWindowId().getURI());
nextScheduledTime = null;
}
}
} else {
log.error("Execution window {} does not exist.", order.getExecutionWindowId().getURI());
}
}
if (nextScheduledTime == null) {
log.info("Scheduled event {} should be set finished.", event.getId());
event.setEventStatus(ScheduledEventStatus.FINISHED);
} else {
createParam.setScheduledTime(ScheduleTimeHelper.convertCalendarToStr(nextScheduledTime));
order = createNewOrder(user, uri(order.getTenant()), createParam);
orderManager.processOrder(order);
event.setLatestOrderId(order.getId());
log.info("Scheduled an new order {} for event {} ...", order.getId(), event.getId());
}
client.save(event);
}
} catch (Exception e) {
log.error("Failed to schedule next orders", e);
} finally {
try {
lock.release();
} catch (Exception e) {
log.error("Error releasing order scheduler lock", e);
}
}
}
use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class ScheduledEventService method match.
/**
* Check if schedule time info is matched with the desired execution window set by admin.
* @param scheduleInfo schedule time info
* @param window desired execution window set by admin
* @return empty for matching, otherwise including detail unmatched reason.
*/
private String match(ScheduleInfo scheduleInfo, ExecutionWindow window) {
String msg = "";
ExecutionWindowHelper windowHelper = new ExecutionWindowHelper(window);
if (!windowHelper.inHourMinWindow(scheduleInfo.getHourOfDay(), scheduleInfo.getMinuteOfHour())) {
msg = "Schedule hour/minute info does not match with execution window.";
return msg;
}
if (scheduleInfo.getReoccurrence() == 1)
return msg;
switch(scheduleInfo.getCycleType()) {
case MINUTELY:
case HOURLY:
log.warn("Not all of the orders would be scheduled due to schedule cycle type {}", scheduleInfo.getCycleType());
break;
case DAILY:
if (!window.getExecutionWindowType().equals(ExecutionWindowType.DAILY.name())) {
msg = "Schedule cycle type has conflicts with execution window.";
}
break;
case WEEKLY:
if (window.getExecutionWindowType().equals(ExecutionWindowType.MONTHLY.name())) {
msg = "Schedule cycle type has conflicts with execution window.";
} else if (window.getExecutionWindowType().equals(ExecutionWindowType.WEEKLY.name())) {
if (window.getDayOfWeek() != Integer.valueOf(scheduleInfo.getSectionsInCycle().get(0))) {
msg = "Scheduled date has conflicts with execution window.";
}
}
break;
case MONTHLY:
if (window.getExecutionWindowType().equals(ExecutionWindowType.WEEKLY.name())) {
msg = "Schedule cycle type has conflicts with execution window.";
} else if (window.getExecutionWindowType().equals(ExecutionWindowType.MONTHLY.name())) {
if (window.getDayOfMonth() != Integer.valueOf(scheduleInfo.getSectionsInCycle().get(0))) {
msg = "Scheduled date has conflicts with execution window.";
}
}
break;
default:
log.error("not expected schedule cycle.");
}
return msg;
}
use of com.emc.storageos.db.client.util.ExecutionWindowHelper in project coprhd-controller by CoprHD.
the class OrderManagerImpl method createOrder.
public Order createOrder(Order order, List<OrderParameter> orderParameters, StorageOSUser user) {
CatalogService catalogService = catalogServiceManager.getCatalogServiceById(order.getCatalogServiceId());
ServiceDescriptor serviceDescriptor = ServiceDescriptorUtil.getServiceDescriptorByName(serviceDescriptors, workflowServiceDescriptor, catalogService.getBaseService());
order.setOrderNumber(getNextOrderNumber());
order.setSummary(catalogService.getTitle());
if (order.getScheduledEventId() == null) {
if (catalogService.getExecutionWindowRequired()) {
if (catalogService.getDefaultExecutionWindowId() == null || catalogService.getDefaultExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
// For default execution window, null is deemed as NEXT window as well.
// But we always need to set order execution window to NEXT explicitly to different it
// with INFINITE window in new scheduler framework.
// Set schedule time to latest updated time. It would still be scheduled in executed window
Calendar scheduleTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
scheduleTime.setTime(new Date());
order.setScheduledTime(scheduleTime);
order.setExecutionWindowId(new NamedURI(ExecutionWindow.NEXT, "NEXT"));
} else {
// 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 = client.findById(catalogService.getDefaultExecutionWindowId().getURI());
ExecutionWindowHelper helper = new ExecutionWindowHelper(executionWindow);
order.setScheduledTime(helper.getScheduledTime());
order.setExecutionWindowId(catalogService.getDefaultExecutionWindowId());
}
} else {
// If no execution window is indicated, order will be submitted to DQ immediately.
;
}
} else {
// ExecutionWindow and ScheduleTime are already set via Parameter
;
}
order.setMessage("");
order.setSubmittedByUserId(user.getUserName());
order.setOrderStatus(OrderStatus.PENDING.name());
createExecutionState(order, user);
client.save(order);
Map<String, String> assetOptions = getAssetValues(serviceDescriptor, orderParameters);
for (OrderParameter orderParameter : orderParameters) {
ServiceField serviceField = findServiceField(serviceDescriptor, orderParameter.getLabel());
String friendlyLabel = serviceField.getLabel();
StringBuilder friendlyValue = new StringBuilder();
List<String> values = TextUtils.parseCSV(orderParameter.getValue());
for (String value : values) {
if (friendlyValue.length() > 0) {
friendlyValue.append(",");
}
friendlyValue.append(getFriendlyValue(serviceField, value, assetOptions, user));
}
orderParameter.setFriendlyLabel(friendlyLabel);
orderParameter.setFriendlyValue(friendlyValue.toString());
createOrderParameter(orderParameter);
}
return order;
}
Aggregations