Search in sources :

Example 1 with AggregationQueryResultList

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;
}
Also used : AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) HashMap(java.util.HashMap) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) ArrayList(java.util.ArrayList) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) List(java.util.List) URI(java.net.URI) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint)

Example 2 with AggregationQueryResultList

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();
}
Also used : Task(com.emc.storageos.db.client.model.Task) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 3 with AggregationQueryResultList

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);
}
Also used : AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList)

Example 4 with AggregationQueryResultList

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);
}
Also used : AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList)

Example 5 with AggregationQueryResultList

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);
}
Also used : AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) EventStatsRestRep(com.emc.storageos.model.event.EventStatsRestRep) 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