Search in sources :

Example 1 with VirtualPoolList

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;
}
Also used : ArrayList(java.util.ArrayList) GeoServiceClient(com.emc.storageos.security.geo.GeoServiceClient) VirtualPoolList(com.emc.storageos.model.vpool.VirtualPoolList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) HashSet(java.util.HashSet)

Example 2 with VirtualPoolList

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());
}
Also used : VirtualPoolList(com.emc.storageos.model.vpool.VirtualPoolList) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 3 with VirtualPoolList

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());
}
Also used : VirtualPoolList(com.emc.storageos.model.vpool.VirtualPoolList) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 4 with VirtualPoolList

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());
}
Also used : VirtualPoolList(com.emc.storageos.model.vpool.VirtualPoolList) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 5 with VirtualPoolList

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());
}
Also used : VirtualPoolList(com.emc.storageos.model.vpool.VirtualPoolList) UriBuilder(javax.ws.rs.core.UriBuilder)

Aggregations

VirtualPoolList (com.emc.storageos.model.vpool.VirtualPoolList)13 UriBuilder (javax.ws.rs.core.UriBuilder)9 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)3 URI (java.net.URI)3 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1 TagAssignment (com.emc.storageos.model.TagAssignment)1 ACLAssignmentChanges (com.emc.storageos.model.auth.ACLAssignmentChanges)1 ACLAssignments (com.emc.storageos.model.auth.ACLAssignments)1