use of com.emc.storageos.db.client.model.uimodels.ScheduledEvent 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.model.uimodels.ScheduledEvent in project coprhd-controller by CoprHD.
the class ExecutionUtils method createContext.
public static void createContext(ModelClient modelClient, Order order) {
// Ensure there is no existing context
destroyContext();
// Initialize the execution state for this order
ExecutionState state = modelClient.executionStates().findById(order.getExecutionStateId());
state.setStartDate(new Date());
ExecutionContext context = currentContext();
context.setOrder(order);
context.setModelClient(modelClient);
context.setExecutionState(state);
URI scheduledEventId = order.getScheduledEventId();
if (scheduledEventId != null) {
ScheduledEvent event = modelClient.findById(ScheduledEvent.class, scheduledEventId);
context.setScheduledEvent(event);
}
CatalogService catalogService = modelClient.catalogServices().findById(order.getCatalogServiceId());
if (null != catalogService) {
context.setServiceName(catalogService.getLabel());
}
List<OrderParameter> orderParameters = modelClient.orderParameters().findByOrderId(order.getId());
Map<String, Object> params = Maps.newLinkedHashMap();
for (OrderParameter param : orderParameters) {
params.put(param.getLabel(), param.getValue());
}
context.setParameters(params);
}
use of com.emc.storageos.db.client.model.uimodels.ScheduledEvent in project coprhd-controller by CoprHD.
the class ScheduledEventFinder method findScheduledEventsByExecutionWindow.
public List<ScheduledEvent> findScheduledEventsByExecutionWindow(String executionWindowId) {
List<ScheduledEvent> results = Lists.newArrayList();
if (StringUtils.isBlank(executionWindowId)) {
return results;
}
Set<URI> eventIds = Sets.newHashSet();
List<NamedElement> scheduledEventElems = client.findByAlternateId(ScheduledEvent.class, ScheduledEvent.EVENT_STATUS, ScheduledEventStatus.APPROVED.name());
for (NamedElement scheduledEventElem : scheduledEventElems) {
ScheduledEvent scheduledEvent = client.findById(ScheduledEvent.class, scheduledEventElem.getId());
if (scheduledEvent.getExecutionWindowId() != null && scheduledEvent.getExecutionWindowId().getURI() != null && executionWindowId.equalsIgnoreCase(scheduledEvent.getExecutionWindowId().getURI().toString())) {
results.add(scheduledEvent);
}
}
results.addAll(findByIds(Lists.newArrayList(eventIds)));
return results;
}
Aggregations