Search in sources :

Example 6 with AggregationQueryResultList

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);
}
Also used : TaskStatsRestRep(com.emc.storageos.model.tasks.TaskStatsRestRep) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

AggregationQueryResultList (com.emc.storageos.db.client.constraint.AggregationQueryResultList)6 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)4 Constraint (com.emc.storageos.db.client.constraint.Constraint)4 URI (java.net.URI)3 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 Task (com.emc.storageos.db.client.model.Task)1 EventStatsRestRep (com.emc.storageos.model.event.EventStatsRestRep)1 TaskStatsRestRep (com.emc.storageos.model.tasks.TaskStatsRestRep)1 HashMap (java.util.HashMap)1 List (java.util.List)1