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);
}
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);
}
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);
}
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);
}
}
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();
}
Aggregations