use of com.emc.storageos.model.vpool.VirtualPoolList in project coprhd-controller by CoprHD.
the class VirtualPoolService method getVirtualPoolList.
protected VirtualPoolList getVirtualPoolList(VirtualPool.Type type, String shortVdcId, String tenantId) {
URIQueryResultList vpoolList = new URIQueryResultList();
VirtualPoolList list = new VirtualPoolList();
TenantOrg tenant_input = null;
// if input tenant is not empty, but user have no access to it, return empty list.
if (!StringUtils.isEmpty(tenantId)) {
tenant_input = getTenantIfHaveAccess(tenantId);
if (tenant_input == null) {
return list;
}
}
StorageOSUser user = getUserFromContext();
List<VirtualPool> vpoolObjects = null;
if (_geoHelper.isLocalVdcId(shortVdcId)) {
_log.debug("retrieving virtual pools via the dbclient");
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVpoolTypeVpoolConstraint(type), vpoolList);
List<URI> allowed = new ArrayList<URI>();
for (URI vpool : vpoolList) {
allowed.add(vpool);
}
vpoolObjects = _dbClient.queryObject(VirtualPool.class, allowed);
} else {
_log.debug("retrieving virtual pools via the geoclient");
GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
try {
// TODO: query by constraint isn't working on the geosvc
// List<URI> resultList = geoClient.queryByConstraint(AlternateIdConstraint.Factory.getVpoolTypeVpoolConstraint(type),
// URIQueryResultList.class);
Iterator<URI> uriIter = geoClient.queryByType(VirtualPool.class, true);
List<URI> resultList = Lists.newArrayList(uriIter);
Iterator<VirtualPool> iter = geoClient.queryObjects(VirtualPool.class, resultList);
// iter);
vpoolObjects = Lists.newArrayList();
while (iter.hasNext()) {
VirtualPool p = iter.next();
if (type.toString().equals(p.getType())) {
vpoolObjects.add(p);
}
}
} catch (Exception ex) {
// TODO: revisit this exception
_log.error("error retrieving virtual pools from vdc " + shortVdcId, ex);
throw APIException.internalServerErrors.genericApisvcError("error retrieving remote pools", ex);
}
}
// else only return the list, which input tenant has access.
if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR)) {
for (VirtualPool virtualPool : vpoolObjects) {
if (tenant_input == null || _permissionsHelper.tenantHasUsageACL(tenant_input.getId(), virtualPool)) {
list.getVirtualPool().add(toVirtualPoolResource(virtualPool));
}
}
} else {
// otherwise, filter by only authorized to use
URI tenant = null;
if (tenant_input == null) {
tenant = URI.create(user.getTenantId());
} else {
tenant = tenant_input.getId();
}
Set<VirtualPool> vpoolSet = new HashSet<VirtualPool>();
for (VirtualPool virtualPool : vpoolObjects) {
if (_permissionsHelper.tenantHasUsageACL(tenant, virtualPool)) {
vpoolSet.add(virtualPool);
}
}
// if no tenant specified in request, also adding vpools which sub-tenants of the user have access to.
if (tenant_input == null) {
List<URI> subtenants = _permissionsHelper.getSubtenantsWithRoles(user);
for (VirtualPool virtualPool : vpoolObjects) {
if (_permissionsHelper.tenantHasUsageACL(subtenants, virtualPool)) {
vpoolSet.add(virtualPool);
}
}
}
for (VirtualPool virtualPool : vpoolSet) {
list.getVirtualPool().add(toVirtualPoolResource(virtualPool));
}
}
return list;
}
use of com.emc.storageos.model.vpool.VirtualPoolList in project coprhd-controller by CoprHD.
the class BlockVirtualPools method listByTenant.
/**
* Lists all virtual pools of specific tenant
* <p>
* API Call: <tt>GET /block/vpools</tt>
*
* @return the list of virtual pool references of specific tenant
*/
public List<NamedRelatedVirtualPoolRep> listByTenant(URI tenantId) {
UriBuilder builder = client.uriBuilder(baseUrl);
builder.queryParam(SearchConstants.TENANT_ID_PARAM, tenantId);
VirtualPoolList response = client.getURI(VirtualPoolList.class, builder.build());
return ResourceUtils.defaultList(response.getVirtualPool());
}
use of com.emc.storageos.model.vpool.VirtualPoolList in project coprhd-controller by CoprHD.
the class BlockVirtualPools method listByVDC.
/**
* Lists all virtual pools in a virtual data center
* <p>
* API Call: <tt>GET /block/vpools</tt>
*
* @return the list of virtual pool references in a virtual data center
*/
public List<NamedRelatedVirtualPoolRep> listByVDC(String shortVdcId) {
UriBuilder builder = client.uriBuilder(baseUrl);
builder.queryParam(SearchConstants.VDC_ID_PARAM, shortVdcId);
VirtualPoolList response = client.getURI(VirtualPoolList.class, builder.build());
return ResourceUtils.defaultList(response.getVirtualPool());
}
use of com.emc.storageos.model.vpool.VirtualPoolList in project coprhd-controller by CoprHD.
the class FileVirtualPools method listByVirtualArrayAndTenant.
public List<NamedRelatedVirtualPoolRep> listByVirtualArrayAndTenant(URI varrayId, URI tenantId) {
UriBuilder builder = client.uriBuilder(String.format(ID_URL_FORMAT, VARRAY_URL) + "/vpools");
builder.queryParam(SearchConstants.TENANT_ID_PARAM, tenantId);
VirtualPoolList response = client.getURI(VirtualPoolList.class, builder.build(varrayId));
return defaultList(response.getVirtualPool());
}
use of com.emc.storageos.model.vpool.VirtualPoolList in project coprhd-controller by CoprHD.
the class FileVirtualPools method listByTenant.
/**
* Lists all virtual pools of specific tenant
* <p>
* API Call: <tt>GET /file/vpools</tt>
*
* @return the list of virtual pool references of specific tenant
*/
public List<NamedRelatedVirtualPoolRep> listByTenant(URI tenantId) {
UriBuilder builder = client.uriBuilder(baseUrl);
builder.queryParam(SearchConstants.TENANT_ID_PARAM, tenantId);
VirtualPoolList response = client.getURI(VirtualPoolList.class, builder.build());
return ResourceUtils.defaultList(response.getVirtualPool());
}
Aggregations