use of com.emc.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.
the class OrderExecution method createOrder.
@Util
public static OrderCreateParam createOrder(CatalogServiceRestRep service, ServiceDescriptorRestRep descriptor, Map<String, String> parameters) {
OrderCreateParam order = new OrderCreateParam();
order.setTenantId(uri(Models.currentAdminTenant()));
order.setCatalogService(service.getId());
List<Parameter> orderParameters = Lists.newArrayList();
List<ServiceFieldRestRep> fields = ServiceDescriptorUtils.getAllFieldList(descriptor.getItems());
for (ServiceFieldRestRep field : fields) {
String value = parameters.get(field.getName());
if (StringUtils.isNotBlank(value)) {
orderParameters.add(createOrderParameter(field, value));
}
}
order.setParameters(orderParameters);
return order;
}
use of com.emc.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.
the class ViPRService method findObsoleteReplica.
/**
* Find obsolete replicas for given resource according to defined retention policy of this order
*
* @param resourceId
* @return the replica to be removed. Otherwise null in case of no removal required
*/
protected List<RetainedReplica> findObsoleteReplica(String resourceId) {
List<RetainedReplica> obsoleteReplicas = new ArrayList<RetainedReplica>();
ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
Integer maxNumOfCopies = Integer.MAX_VALUE;
try {
OrderCreateParam param = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
String additionalScheduleInfo = param.getAdditionalScheduleInfo();
maxNumOfCopies = Integer.parseInt(additionalScheduleInfo);
} catch (Exception ex) {
error("Unexpected exception when checking scheduler retention", ex);
return obsoleteReplicas;
}
List<NamedElement> replicaIdList = modelClient.findBy(RetainedReplica.class, "scheduledEventId", event.getId());
List<RetainedReplica> replicas = new ArrayList<RetainedReplica>();
for (NamedElement uri : replicaIdList) {
RetainedReplica retention = modelClient.findById(RetainedReplica.class, uri.getId());
if (retention.getResourceId().toString().equals(resourceId)) {
replicas.add(retention);
}
}
if (replicas.size() >= maxNumOfCopies) {
Collections.sort(replicas, new Comparator<RetainedReplica>() {
public int compare(RetainedReplica o1, RetainedReplica o2) {
return o1.getCreationTime().compareTo(o2.getCreationTime());
}
});
// get top oldest records
int endIndex = replicas.size() - maxNumOfCopies + 1;
obsoleteReplicas.addAll(replicas.subList(0, endIndex));
}
return obsoleteReplicas;
}
use of com.emc.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.
the class ViPRService method isRetentionRequired.
/**
* Check if it is a recurrent order and retention policy is defined
*
* @return true if retention policy defined
*/
protected boolean isRetentionRequired() {
ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
if (event == null) {
return false;
}
try {
OrderCreateParam param = OrderCreateParam.deserialize(org.apache.commons.codec.binary.Base64.decodeBase64(event.getOrderCreationParam().getBytes(UTF_8)));
String additionalScheduleInfo = param.getAdditionalScheduleInfo();
if (additionalScheduleInfo == null) {
return false;
}
Integer.parseInt(additionalScheduleInfo);
} catch (Exception ex) {
error("Unexpected exception when checking scheduler retention", ex);
return false;
}
return true;
}
use of com.emc.vipr.model.catalog.OrderCreateParam 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.vipr.model.catalog.OrderCreateParam in project coprhd-controller by CoprHD.
the class CatalogApi method createAndValidateOrder.
private static OrderCreateParam createAndValidateOrder(String serviceId) {
CatalogServiceRestRep service = CatalogServiceUtils.getCatalogService(uri(serviceId));
ServiceDescriptorRestRep descriptor = service.getServiceDescriptor();
// Filter out actual Service Parameters
Map<String, String> parameters = parseParameters(service, descriptor);
if (Validation.hasErrors()) {
response.status = HttpStatus.SC_BAD_REQUEST;
renderApi(getValidationErrors());
}
// Create request and perform selection
OrderCreateParam order = createOrder(service, descriptor, parameters);
return order;
}
Aggregations