Search in sources :

Example 26 with Constraint

use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.

the class DbClientTest method queryInPaginate.

private <T extends QueryResultList<URI>> void queryInPaginate(Constraint constraint, Class<T> clazz, int objCount, int pageCount, int times) throws IllegalAccessException, InstantiationException {
    int queryTimes = 0;
    int count = 0;
    URI nextId = null;
    while (true) {
        T result = (T) clazz.newInstance();
        _dbClient.queryByConstraint(constraint, result, nextId, pageCount);
        Iterator<URI> it = result.iterator();
        if (!it.hasNext()) {
            break;
        }
        queryTimes++;
        while (it.hasNext()) {
            nextId = it.next();
            count++;
        }
    }
    Assert.assertEquals(objCount, count);
    Assert.assertEquals(times, queryTimes);
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Example 27 with Constraint

use of com.emc.storageos.db.client.constraint.Constraint 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)

Example 28 with Constraint

use of com.emc.storageos.db.client.constraint.Constraint 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)

Example 29 with Constraint

use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.

the class TenantsService method clearTenantACLs.

/**
 * Clear any tenant USE ACLs associated with the provided tenant id from the indicated CF
 *
 * @param clazz CF type to clear of tenant ACLs
 * @param tenantId the tenant id
 * @param specifier optional specifier (e.g. block or file for VirtualPools)
 */
private void clearTenantACLs(Class<? extends DataObjectWithACLs> clazz, URI tenantId, String specifier) {
    PermissionsKey permissionKey;
    if (StringUtils.isNotBlank(specifier)) {
        permissionKey = new PermissionsKey(PermissionsKey.Type.TENANT, tenantId.toString(), specifier);
    } else {
        permissionKey = new PermissionsKey(PermissionsKey.Type.TENANT, tenantId.toString());
    }
    URIQueryResultList resultURIs = new URIQueryResultList();
    Constraint aclConstraint = ContainmentPermissionsConstraint.Factory.getObjsWithPermissionsConstraint(permissionKey.toString(), clazz);
    _dbClient.queryByConstraint(aclConstraint, resultURIs);
    List<URI> ids = new ArrayList<URI>();
    for (URI result : resultURIs) {
        ids.add(result);
    }
    Iterator<? extends DataObjectWithACLs> objectIter = _dbClient.queryIterativeObjects(clazz, ids);
    if ((objectIter != null) && (objectIter.hasNext())) {
        List<DataObjectWithACLs> objectList = new ArrayList<DataObjectWithACLs>();
        while (objectIter.hasNext()) {
            objectList.add(objectIter.next());
        }
        for (DataObjectWithACLs object : objectList) {
            _log.info("Removing USE ACL for deleted subtenant {} from object {}", tenantId, object.getId());
            object.removeAcl(permissionKey.toString(), ACL.USE.toString());
        }
        _dbClient.updateAndReindexObject(objectList);
    }
}
Also used : AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) PermissionsKey(com.emc.storageos.security.authorization.PermissionsKey) ArrayList(java.util.ArrayList) DataObjectWithACLs(com.emc.storageos.db.client.model.DataObjectWithACLs) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 30 with Constraint

use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.

the class BiosCommandResultTest method setUp.

@Before
public void setUp() throws Exception {
    _isi = new IsilonFileStorageDevice();
    IsilonApiFactory factory = new IsilonApiFactory();
    factory.init();
    _isi.setIsilonApiFactory(factory);
    _isi.setDbClient(new DummyDbClient() {

        @Override
        public List<URI> queryByConstraint(Constraint constraint) throws DatabaseException {
            return new ArrayList<>();
        }
    });
    // storage device object for tests to use
    _device = new StorageSystem();
    _device.setIpAddress(ip);
    _device.setPortNumber(Integer.parseInt(portNumber));
    _device.setUsername(userName);
    _device.setPassword(password);
    _pool = new StoragePool();
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) IsilonApiFactory(com.emc.storageos.isilon.restapi.IsilonApiFactory) Constraint(com.emc.storageos.db.client.constraint.Constraint) DummyDbClient(com.emc.storageos.util.DummyDbClient) ArrayList(java.util.ArrayList) List(java.util.List) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Before(org.junit.Before)

Aggregations

Constraint (com.emc.storageos.db.client.constraint.Constraint)34 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)25 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)24 URI (java.net.URI)23 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)18 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)16 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)16 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)14 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)13 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 NamedURI (com.emc.storageos.db.client.model.NamedURI)7 Volume (com.emc.storageos.db.client.model.Volume)5 AggregationQueryResultList (com.emc.storageos.db.client.constraint.AggregationQueryResultList)4 Project (com.emc.storageos.db.client.model.Project)4 ProtectionSet (com.emc.storageos.db.client.model.ProtectionSet)4 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 DataObject (com.emc.storageos.db.client.model.DataObject)3 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)3 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)2