Search in sources :

Example 1 with GeoServiceClient

use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.

the class FileVirtualPoolService method queryFilteredBulkResourceReps.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected FileVirtualPoolBulkRep queryFilteredBulkResourceReps(List<URI> ids) {
    if (isSystemOrRestrictedSystemAdmin()) {
        return queryBulkResourceReps(ids);
    }
    if (!ids.iterator().hasNext()) {
        return new FileVirtualPoolBulkRep();
    }
    // get vdc id from the first id; assume all id's are from the same vdc
    String shortVdcId = VdcUtil.getVdcId(VirtualArray.class, ids.iterator().next()).toString();
    Iterator<VirtualPool> dbIterator;
    if (shortVdcId.equals(VdcUtil.getLocalShortVdcId())) {
        dbIterator = _dbClient.queryIterativeObjects(getResourceClass(), ids);
    } else {
        GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
        try {
            dbIterator = geoClient.queryObjects(getResourceClass(), ids);
        } catch (Exception ex) {
            // TODO: revisit this exception
            _log.error("error retrieving bulk virtual pools from vdc " + shortVdcId, ex);
            throw APIException.internalServerErrors.genericApisvcError("error retrieving remote virtual pool", ex);
        }
    }
    BulkList.ResourceFilter filter = new BulkList.VirtualPoolFilter(Type.file, getUserFromContext(), _permissionsHelper);
    return new FileVirtualPoolBulkRep(BulkList.wrapping(dbIterator, MapFileVirtualPool.getInstance(), filter));
}
Also used : FileVirtualPoolBulkRep(com.emc.storageos.model.vpool.FileVirtualPoolBulkRep) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) GeoServiceClient(com.emc.storageos.security.geo.GeoServiceClient) BulkList(com.emc.storageos.api.service.impl.response.BulkList) VirtualPoolMapper.toFileVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toFileVirtualPool) MapFileVirtualPool(com.emc.storageos.api.mapper.functions.MapFileVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 2 with GeoServiceClient

use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.

the class BlockVirtualPoolService method queryFilteredBulkResourceReps.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected BlockVirtualPoolBulkRep queryFilteredBulkResourceReps(List<URI> ids) {
    if (isSystemOrRestrictedSystemAdmin()) {
        return queryBulkResourceReps(ids);
    }
    if (!ids.iterator().hasNext()) {
        return new BlockVirtualPoolBulkRep();
    }
    // get vdc id from the first id; assume all id's are from the same vdc
    String shortVdcId = VdcUtil.getVdcId(getResourceClass(), ids.iterator().next()).toString();
    Iterator<VirtualPool> dbIterator;
    if (shortVdcId.equals(VdcUtil.getLocalShortVdcId())) {
        dbIterator = _dbClient.queryIterativeObjects(getResourceClass(), ids);
    } else {
        GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
        try {
            dbIterator = geoClient.queryObjects(getResourceClass(), ids);
        } catch (Exception ex) {
            // TODO: revisit this exception
            _log.error("error retrieving bulk virtual pools from vdc " + shortVdcId, ex);
            throw APIException.internalServerErrors.genericApisvcError("error retrieving remote virtual pool", ex);
        }
    }
    BulkList.ResourceFilter filter = new BulkList.VirtualPoolFilter(Type.block, getUserFromContext(), _permissionsHelper);
    return new BlockVirtualPoolBulkRep(BulkList.wrapping(dbIterator, BLOCK_VPOOL_MAPPER, filter));
}
Also used : BlockVirtualPoolBulkRep(com.emc.storageos.model.vpool.BlockVirtualPoolBulkRep) GeoServiceClient(com.emc.storageos.security.geo.GeoServiceClient) BulkList(com.emc.storageos.api.service.impl.response.BulkList) VirtualPoolMapper.toBlockVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toBlockVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 3 with GeoServiceClient

use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.

the class VirtualArrayService method getVirtualArrayList.

/**
 * List VirtualArrays in zone the user is authorized to see
 *
 * @brief List VirtualArrays in zone
 * @return List of VirtualArrays
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VirtualArrayList getVirtualArrayList(@DefaultValue("") @QueryParam(VDC_ID_QUERY_PARAM) String shortVdcId, @DefaultValue("") @QueryParam(TENANT_ID_QUERY_PARAM) String tenantId) {
    _geoHelper.verifyVdcId(shortVdcId);
    VirtualArrayList list = new VirtualArrayList();
    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;
        }
    }
    List<VirtualArray> nhObjList = Collections.emptyList();
    if (_geoHelper.isLocalVdcId(shortVdcId)) {
        _log.debug("retrieving virtual arrays via dbclient");
        final List<URI> ids = _dbClient.queryByType(VirtualArray.class, true);
        nhObjList = _dbClient.queryObject(VirtualArray.class, ids);
    } else {
        _log.debug("retrieving virtual arrays via geoclient");
        try {
            GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
            final List<URI> ids = Lists.newArrayList(geoClient.queryByType(VirtualArray.class, true));
            nhObjList = Lists.newArrayList(geoClient.queryObjects(VirtualArray.class, ids));
        } catch (Exception ex) {
            // TODO: revisit this exception
            _log.error("error retrieving virtual arrays", ex);
            throw APIException.internalServerErrors.genericApisvcError("error retrieving virtual arrays", ex);
        }
    }
    StorageOSUser user = getUserFromContext();
    // else only return the list, which input tenant has access.
    if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR)) {
        for (VirtualArray nh : nhObjList) {
            if (tenant_input == null || _permissionsHelper.tenantHasUsageACL(tenant_input.getId(), nh)) {
                list.getVirtualArrays().add(toNamedRelatedResource(ResourceTypeEnum.VARRAY, nh.getId(), nh.getLabel()));
            }
        }
    } 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<VirtualArray> varraySet = new HashSet<VirtualArray>();
        for (VirtualArray virtualArray : nhObjList) {
            if (_permissionsHelper.tenantHasUsageACL(tenant, virtualArray)) {
                varraySet.add(virtualArray);
            }
        }
        // if no tenant specified in request, also adding varrays which sub-tenants of the user have access to.
        if (tenant_input == null) {
            List<URI> subtenants = _permissionsHelper.getSubtenantsWithRoles(user);
            for (VirtualArray virtualArray : nhObjList) {
                if (_permissionsHelper.tenantHasUsageACL(subtenants, virtualArray)) {
                    varraySet.add(virtualArray);
                }
            }
        }
        for (VirtualArray virtualArray : varraySet) {
            list.getVirtualArrays().add(toNamedRelatedResource(ResourceTypeEnum.VARRAY, virtualArray.getId(), virtualArray.getLabel()));
        }
    }
    return list;
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) GeoServiceClient(com.emc.storageos.security.geo.GeoServiceClient) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with GeoServiceClient

use of com.emc.storageos.security.geo.GeoServiceClient in project coprhd-controller by CoprHD.

the class VirtualArrayService method queryFilteredBulkResourceReps.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected VirtualArrayBulkRep queryFilteredBulkResourceReps(List<URI> ids) {
    if (isSystemOrRestrictedSystemAdmin()) {
        return queryBulkResourceReps(ids);
    }
    if (!ids.iterator().hasNext()) {
        return new VirtualArrayBulkRep();
    }
    // get vdc id from the first id; assume all id's are from the same vdc
    String shortVdcId = VdcUtil.getVdcId(getResourceClass(), ids.iterator().next()).toString();
    Iterator<VirtualArray> dbIterator;
    if (shortVdcId.equals(VdcUtil.getLocalShortVdcId())) {
        dbIterator = _dbClient.queryIterativeObjects(getResourceClass(), ids);
    } else {
        GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
        try {
            dbIterator = geoClient.queryObjects(getResourceClass(), ids);
        } catch (Exception ex) {
            // TODO: revisit this exception
            _log.error("error retrieving bulk virtual arrays from vdc " + shortVdcId, ex);
            throw APIException.internalServerErrors.genericApisvcError("error retrieving remote array", ex);
        }
    }
    BulkList.ResourceFilter filter = new BulkList.VirtualArrayACLFilter(getUserFromContext(), _permissionsHelper);
    return new VirtualArrayBulkRep(BulkList.wrapping(dbIterator, MapVirtualArray.getInstance(), filter));
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) GeoServiceClient(com.emc.storageos.security.geo.GeoServiceClient) BulkList(com.emc.storageos.api.service.impl.response.BulkList) VirtualArrayBulkRep(com.emc.storageos.model.varray.VirtualArrayBulkRep) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 5 with GeoServiceClient

use of com.emc.storageos.security.geo.GeoServiceClient 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)

Aggregations

GeoServiceClient (com.emc.storageos.security.geo.GeoServiceClient)17 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)12 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)8 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)8 MapVirtualArray (com.emc.storageos.api.mapper.functions.MapVirtualArray)4 BulkList (com.emc.storageos.api.service.impl.response.BulkList)4 VirtualPoolMapper.toBlockVirtualPool (com.emc.storageos.api.mapper.VirtualPoolMapper.toBlockVirtualPool)2 VirtualPoolMapper.toFileVirtualPool (com.emc.storageos.api.mapper.VirtualPoolMapper.toFileVirtualPool)2 VirtualPoolMapper.toObjectVirtualPool (com.emc.storageos.api.mapper.VirtualPoolMapper.toObjectVirtualPool)2 MapFileVirtualPool (com.emc.storageos.api.mapper.functions.MapFileVirtualPool)2 MapObjectVirtualPool (com.emc.storageos.api.mapper.functions.MapObjectVirtualPool)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 VdcNodeCheckParam (com.emc.storageos.geomodel.VdcNodeCheckParam)2 VirtualArrayBulkRep (com.emc.storageos.model.varray.VirtualArrayBulkRep)2 BlockVirtualPoolBulkRep (com.emc.storageos.model.vpool.BlockVirtualPoolBulkRep)2 FileVirtualPoolBulkRep (com.emc.storageos.model.vpool.FileVirtualPoolBulkRep)2 ObjectVirtualPoolBulkRep (com.emc.storageos.model.vpool.ObjectVirtualPoolBulkRep)2 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)2 URI (java.net.URI)2