use of com.emc.storageos.db.client.constraint.AggregationQueryResultList in project coprhd-controller by CoprHD.
the class TaskScrubberExecutor method findTasksForTenantNotPending.
/**
* returns non-pending task ids for a tenant
*
* @param dbClient
* @return a map of task ids in buckets of 10k each
*/
private Map<String, List<URI>> findTasksForTenantNotPending(URI tenantId) {
log.debug("searching for completed tasks for tenant {}", tenantId);
Constraint constraint = AggregatedConstraint.Factory.getAggregationConstraint(Task.class, "tenant", tenantId.toString(), "taskStatus");
AggregationQueryResultList queryResults = new AggregationQueryResultList();
dbClient.queryByConstraint(constraint, queryResults);
Iterator<AggregationQueryResultList.AggregatedEntry> it = queryResults.iterator();
Map<String, List<URI>> notPendingTasks = new HashMap<String, List<URI>>();
int batch = 0;
int count = 0;
// only used for logging
int totalCount = 0;
while (it.hasNext()) {
AggregationQueryResultList.AggregatedEntry entry = it.next();
if (!entry.getValue().equals(Task.Status.pending.name())) {
if (notPendingTasks.get(Integer.toString(batch)) == null) {
notPendingTasks.put(Integer.toString(batch), new ArrayList<URI>());
}
notPendingTasks.get(Integer.toString(batch)).add(entry.getId());
totalCount++;
count++;
if (count >= MAXIMUM_TASK_IN_ONE_QUERY) {
batch++;
count = 0;
}
}
}
log.debug("found {} completed tasks for tenant {}", totalCount, tenantId);
return notPendingTasks;
}
use of com.emc.storageos.db.client.constraint.AggregationQueryResultList in project coprhd-controller by CoprHD.
the class TaskUtils method findPendingTasksForResource.
/**
* returns pending tasks for a resource
*
* @param dbClient
* @param resourceId
* @return
*/
public static Iterator<Task> findPendingTasksForResource(DbClient dbClient, URI resourceId, URI tenantId) {
Constraint constraint = AggregatedConstraint.Factory.getAggregationConstraint(Task.class, "tenant", tenantId.toString(), "taskStatus");
AggregationQueryResultList queryResults = new AggregationQueryResultList();
dbClient.queryByConstraint(constraint, queryResults);
Iterator<AggregationQueryResultList.AggregatedEntry> it = queryResults.iterator();
List<URI> pendingTasks = new ArrayList<URI>();
while (it.hasNext()) {
AggregationQueryResultList.AggregatedEntry entry = it.next();
if (entry.getValue().equals(Task.Status.pending.name())) {
pendingTasks.add(entry.getId());
}
}
List<Task> pendingTasksForResource = new ArrayList<Task>();
Iterator<Task> pendingItr = dbClient.queryIterativeObjects(Task.class, pendingTasks);
while (pendingItr.hasNext()) {
Task task = pendingItr.next();
if (task.getResource().getURI().equals(resourceId)) {
pendingTasksForResource.add(task);
}
}
return pendingTasksForResource.iterator();
}
use of com.emc.storageos.db.client.constraint.AggregationQueryResultList in project coprhd-controller by CoprHD.
the class DbClientTest method checkAggregatedValues.
private void checkAggregatedValues(String groupBy, String groupByValue, String field, Class<? extends DataObject> clazz, Map<URI, ? extends DataObject> validatedObj) {
_logger.info("Checking aggregated index for class : " + clazz.getSimpleName() + "; field : " + field + "; groupField = " + groupBy + "; groupValue : " + groupByValue);
AggregationQueryResultList queryResults = new AggregationQueryResultList();
_dbClient.queryByConstraint(AggregatedConstraint.Factory.getAggregationConstraint(clazz, groupBy, groupByValue, field), queryResults);
Iterator<AggregationQueryResultList.AggregatedEntry> it = queryResults.iterator();
checkAggregatedQuery(it, clazz, field, validatedObj);
}
use of com.emc.storageos.db.client.constraint.AggregationQueryResultList in project coprhd-controller by CoprHD.
the class CustomQueryUtility method aggregatedPrimitiveField.
public static <T extends DataObject> AggregatedValue aggregatedPrimitiveField(DbClient dbClient, Class<T> clazz, String groupField, String groupValue, String aggregatedField) {
AggregationQueryResultList queryResults = new AggregationQueryResultList();
dbClient.queryByConstraint(AggregatedConstraint.Factory.getAggregationConstraint(clazz, groupField, groupValue, aggregatedField), queryResults);
Iterator<AggregationQueryResultList.AggregatedEntry> it = queryResults.iterator();
return getAggregatedValue(it);
}
use of com.emc.storageos.db.client.constraint.AggregationQueryResultList in project coprhd-controller by CoprHD.
the class EventService method getStats.
/**
* Get Stats
*
* @param tenantId
* @brief Show numbers of pending, approved, declined, and failed events for a tenant
* @return
*/
@GET
@Path("/stats")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public EventStatsRestRep getStats(@QueryParam(TENANT_QUERY_PARAM) URI tenantId) {
verifyAuthorizedInTenantOrg(tenantId, getUserFromContext());
int approved = 0;
int declined = 0;
int pending = 0;
int failed = 0;
Constraint constraint = AggregatedConstraint.Factory.getAggregationConstraint(ActionableEvent.class, "tenant", tenantId.toString(), "eventStatus");
AggregationQueryResultList queryResults = new AggregationQueryResultList();
_dbClient.queryByConstraint(constraint, queryResults);
Iterator<AggregationQueryResultList.AggregatedEntry> it = queryResults.iterator();
while (it.hasNext()) {
AggregationQueryResultList.AggregatedEntry entry = it.next();
if (entry.getValue().equals(ActionableEvent.Status.approved.name())) {
approved++;
} else if (entry.getValue().equals(ActionableEvent.Status.declined.name())) {
declined++;
} else if (entry.getValue().equals(ActionableEvent.Status.failed.name())) {
failed++;
} else {
pending++;
}
}
return new EventStatsRestRep(pending, approved, declined, failed);
}
Aggregations