use of com.emc.storageos.db.client.TimestampedURIQueryResult in project coprhd-controller by CoprHD.
the class TaskService method getLatestTasks.
// This method uses heap sort to return latest n tasks where n <= 10K.
private TasksList getLatestTasks(Set<URI> tenantIds, String startTime, String endTime, Integer maxCount) {
PriorityQueue<TimestampedURIQueryResult.TimestampedURI> taskHeap = new PriorityQueue<>(maxCount, new MinTaskComparator());
Date startWindowDate = TimeUtils.getDateTimestamp(startTime);
Date endWindowDate = TimeUtils.getDateTimestamp(endTime);
// Fetch index entries and load into sorted set
int taskCount = 0;
for (URI normalizedTenantId : tenantIds) {
log.debug("Retriving tasks from tenant {}", normalizedTenantId);
TimestampedURIQueryResult taskIds = new TimestampedURIQueryResult();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTimedTenantOrgTaskConstraint(normalizedTenantId, startWindowDate, endWindowDate), taskIds);
Iterator<TimestampedURIQueryResult.TimestampedURI> it = taskIds.iterator();
while (it.hasNext()) {
TimestampedURIQueryResult.TimestampedURI timestampedURI = it.next();
// Add first maxCount tasks to PQ
if (taskHeap.size() < maxCount) {
taskHeap.add(timestampedURI);
taskCount++;
} else {
// Add the rest tasks into PQ if task timestamp is >= than the lowest timestamp task in PQ
if (timestampedURI.getTimestamp() >= taskHeap.peek().getTimestamp()) {
taskHeap.poll();
taskHeap.add(timestampedURI);
}
taskCount++;
}
}
}
log.debug("The number of tasks of all tenants is {}, heap size is {}", taskCount, taskHeap.size());
List<NamedRelatedResourceRep> resourceReps = Lists.newArrayList();
while (!taskHeap.isEmpty()) {
TimestampedURIQueryResult.TimestampedURI uri = taskHeap.poll();
RestLinkRep link = new RestLinkRep("self", RestLinkFactory.newLink(ResourceTypeEnum.TASK, uri.getUri()));
resourceReps.add(new NamedRelatedResourceRep(uri.getUri(), link, uri.getName()));
}
return new TasksList(resourceReps);
}
use of com.emc.storageos.db.client.TimestampedURIQueryResult in project coprhd-controller by CoprHD.
the class TaskService method getAllTasks.
// Original method to return task list. Will be used when max_count is either NOT specified or set but > max limit like 10K.
// This could cause out of memory issue
private TasksList getAllTasks(Set<URI> tenantIds, String startTime, String endTime, Integer maxCount) {
// Entries from the index, sorted with most recent first
Set<TimestampedURIQueryResult.TimestampedURI> sortedIndexEntries = Sets.newTreeSet(new TaskComparator());
Date startWindowDate = TimeUtils.getDateTimestamp(startTime);
Date endWindowDate = TimeUtils.getDateTimestamp(endTime);
// Fetch index entries and load into sorted set
List<NamedRelatedResourceRep> resourceReps = Lists.newArrayList();
for (URI normalizedTenantId : tenantIds) {
TimestampedURIQueryResult taskIds = new TimestampedURIQueryResult();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTimedTenantOrgTaskConstraint(normalizedTenantId, startWindowDate, endWindowDate), taskIds);
Iterator<TimestampedURIQueryResult.TimestampedURI> it = taskIds.iterator();
while (it.hasNext()) {
TimestampedURIQueryResult.TimestampedURI timestampedURI = it.next();
sortedIndexEntries.add(timestampedURI);
}
}
if (maxCount == null || maxCount < 0) {
maxCount = FETCH_ALL;
} else {
maxCount = Math.min(maxCount, sortedIndexEntries.size());
}
// Produce the requested number of results
Iterator<TimestampedURIQueryResult.TimestampedURI> it = sortedIndexEntries.iterator();
int pos = 0;
while (it.hasNext() && (maxCount == FETCH_ALL || pos < maxCount)) {
TimestampedURIQueryResult.TimestampedURI uri = it.next();
RestLinkRep link = new RestLinkRep("self", RestLinkFactory.newLink(ResourceTypeEnum.TASK, uri.getUri()));
resourceReps.add(new NamedRelatedResourceRep(uri.getUri(), link, uri.getName()));
pos++;
}
return new TasksList(resourceReps);
}
Aggregations