use of com.emc.storageos.db.client.constraint.AggregationQueryResultList in project coprhd-controller by CoprHD.
the class TaskService method getStats.
/**
* Returns task status count information for the specified Tenant.
*
* @brief Task Status count
* @param tenantId
* Tenant URI of the tenant the count is required for. If not supplied, the logged in users tenant will
* be used.
* A value of 'system' will return system tasks
* @return Count of tasks in different statuses
*/
@GET
@Path("/stats")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public TaskStatsRestRep getStats(@QueryParam(TENANT_QUERY_PARAM) URI tenantId) {
Set<URI> tenantIds = getTenantsFromRequest(tenantId);
verifyUserHasAccessToTenants(tenantIds);
int ready = 0;
int error = 0;
int pending = 0;
for (URI normalizedTenantId : tenantIds) {
Constraint constraint = AggregatedConstraint.Factory.getAggregationConstraint(Task.class, "tenant", normalizedTenantId.toString(), "taskStatus");
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(Task.Status.ready.name())) {
ready++;
} else if (entry.getValue().equals(Task.Status.error.name())) {
error++;
} else {
pending++;
}
}
}
return new TaskStatsRestRep(pending, ready, error);
}
Aggregations