/** * Create a cache pool. * * Only the superuser should be able to call this function. * * @param info The info for the cache pool to create. * @return Information about the cache pool we created. */ public CachePoolInfo addCachePool(CachePoolInfo info) throws IOException { assert namesystem.hasWriteLock(); CachePool pool; try { CachePoolInfo.validate(info); String poolName = info.getPoolName(); pool = cachePools.get(poolName); if (pool != null) { throw new InvalidRequestException("Cache pool " + poolName + " already exists."); } pool = CachePool.createFromInfoAndDefaults(info); cachePools.put(pool.getPoolName(), pool); } catch (IOException e) { LOG.info("addCachePool of " + info + " failed: ", e); throw e; } LOG.info("addCachePool of {} successful.", info); return pool.getInfo(true); }
/** * Returns a {@link CacheDirectiveInfo} based on this CacheDirective. * <p> * This always sets an absolute expiry time, never a relative TTL. */ public CacheDirectiveInfo toInfo() { return new CacheDirectiveInfo.Builder(). setId(id). setPath(new Path(path)). setReplication(replication). setPool(pool.getPoolName()). setExpiration(CacheDirectiveInfo.Expiration.newAbsolute(expiryTime)). build(); }
if (!srcPool.getPoolName().equals(destPool.getPoolName())) { checkWritePermission(pc, destPool); if (!flags.contains(CacheFlag.FORCE)) {
/** * Throws an exception if the CachePool does not have enough capacity to * cache the given path at the replication factor. * * @param pool CachePool where the path is being cached * @param path Path that is being cached * @param replication Replication factor of the path * @throws InvalidRequestException if the pool does not have enough capacity */ private void checkLimit(CachePool pool, String path, short replication) throws InvalidRequestException { CacheDirectiveStats stats = computeNeeded(path, replication); if (pool.getLimit() == CachePoolInfo.LIMIT_UNLIMITED) { return; } if (pool.getBytesNeeded() + stats.getBytesNeeded() > pool.getLimit()) { throw new InvalidRequestException("Caching path " + path + " of size " + stats.getBytesNeeded() / replication + " bytes at replication " + replication + " would exceed pool " + pool.getPoolName() + "'s remaining capacity of " + (pool.getLimit() - pool.getBytesNeeded()) + " bytes."); } }
/** * Whether a cache pool can be accessed by the current context * * @param pool CachePool being accessed * @param access type of action being performed on the cache pool * @throws AccessControlException if pool cannot be accessed */ public void checkPermission(CachePool pool, FsAction access) throws AccessControlException { FsPermission mode = pool.getMode(); if (isSuperUser()) { return; } if (getUser().equals(pool.getOwnerName()) && mode.getUserAction().implies(access)) { return; } if (isMemberOfGroup(pool.getGroupName()) && mode.getGroupAction().implies(access)) { return; } if (!getUser().equals(pool.getOwnerName()) && !isMemberOfGroup(pool.getGroupName()) && mode.getOtherAction().implies(access)) { return; } throw new AccessControlException("Permission denied while accessing pool " + pool.getPoolName() + ": user " + getUser() + " does not have " + access.toString() + " permissions."); }
directive.getId(), file.getFullPathName(), pool.getPoolName(), pool.getBytesNeeded(), pool.getLimit());
/** * Create a cache pool. * * Only the superuser should be able to call this function. * * @param info The info for the cache pool to create. * @return Information about the cache pool we created. */ public CachePoolInfo addCachePool(CachePoolInfo info) throws IOException { assert namesystem.hasWriteLock(); CachePool pool; try { CachePoolInfo.validate(info); String poolName = info.getPoolName(); pool = cachePools.get(poolName); if (pool != null) { throw new InvalidRequestException("Cache pool " + poolName + " already exists."); } pool = CachePool.createFromInfoAndDefaults(info); cachePools.put(pool.getPoolName(), pool); } catch (IOException e) { LOG.info("addCachePool of " + info + " failed: ", e); throw e; } LOG.info("addCachePool of {} successful.", info); return pool.getInfo(true); }
/** * Returns a {@link CacheDirectiveInfo} based on this CacheDirective. * <p> * This always sets an absolute expiry time, never a relative TTL. */ public CacheDirectiveInfo toInfo() { return new CacheDirectiveInfo.Builder(). setId(id). setPath(new Path(path)). setReplication(replication). setPool(pool.getPoolName()). setExpiration(CacheDirectiveInfo.Expiration.newAbsolute(expiryTime)). build(); }
/** * Returns a {@link CacheDirectiveInfo} based on this CacheDirective. * <p> * This always sets an absolute expiry time, never a relative TTL. */ public CacheDirectiveInfo toInfo() { return new CacheDirectiveInfo.Builder(). setId(id). setPath(new Path(path)). setReplication(replication). setPool(pool.getPoolName()). setExpiration(CacheDirectiveInfo.Expiration.newAbsolute(expiryTime)). build(); }
/** * Create a cache pool. * * Only the superuser should be able to call this function. * * @param info The info for the cache pool to create. * @return Information about the cache pool we created. */ public CachePoolInfo addCachePool(CachePoolInfo info) throws IOException { assert namesystem.hasWriteLock(); CachePool pool; try { CachePoolInfo.validate(info); String poolName = info.getPoolName(); pool = cachePools.get(poolName); if (pool != null) { throw new InvalidRequestException("Cache pool " + poolName + " already exists."); } pool = CachePool.createFromInfoAndDefaults(info); cachePools.put(pool.getPoolName(), pool); } catch (IOException e) { LOG.info("addCachePool of " + info + " failed: ", e); throw e; } LOG.info("addCachePool of {} successful.", info); return pool.getInfo(true); }
if (!srcPool.getPoolName().equals(destPool.getPoolName())) { checkWritePermission(pc, destPool); if (!flags.contains(CacheFlag.FORCE)) {
/** * Throws an exception if the CachePool does not have enough capacity to * cache the given path at the replication factor. * * @param pool CachePool where the path is being cached * @param path Path that is being cached * @param replication Replication factor of the path * @throws InvalidRequestException if the pool does not have enough capacity */ private void checkLimit(CachePool pool, String path, short replication) throws InvalidRequestException { CacheDirectiveStats stats = computeNeeded(path, replication); if (pool.getLimit() == CachePoolInfo.LIMIT_UNLIMITED) { return; } if (pool.getBytesNeeded() + (stats.getBytesNeeded() * replication) > pool .getLimit()) { throw new InvalidRequestException("Caching path " + path + " of size " + stats.getBytesNeeded() / replication + " bytes at replication " + replication + " would exceed pool " + pool.getPoolName() + "'s remaining capacity of " + (pool.getLimit() - pool.getBytesNeeded()) + " bytes."); } }
if (!srcPool.getPoolName().equals(destPool.getPoolName())) { checkWritePermission(pc, destPool); if (!flags.contains(CacheFlag.FORCE)) {
/** * Whether a cache pool can be accessed by the current context * * @param pool CachePool being accessed * @param access type of action being performed on the cache pool * @throws AccessControlException if pool cannot be accessed */ public void checkPermission(CachePool pool, FsAction access) throws AccessControlException { FsPermission mode = pool.getMode(); if (isSuperUser()) { return; } if (getUser().equals(pool.getOwnerName()) && mode.getUserAction().implies(access)) { return; } if (getGroups().contains(pool.getGroupName()) && mode.getGroupAction().implies(access)) { return; } if (mode.getOtherAction().implies(access)) { return; } throw new AccessControlException("Permission denied while accessing pool " + pool.getPoolName() + ": user " + getUser() + " does not have " + access.toString() + " permissions."); } }
/** * Throws an exception if the CachePool does not have enough capacity to * cache the given path at the replication factor. * * @param pool CachePool where the path is being cached * @param path Path that is being cached * @param replication Replication factor of the path * @throws InvalidRequestException if the pool does not have enough capacity */ private void checkLimit(CachePool pool, String path, short replication) throws InvalidRequestException { CacheDirectiveStats stats = computeNeeded(path, replication); if (pool.getLimit() == CachePoolInfo.LIMIT_UNLIMITED) { return; } if (pool.getBytesNeeded() + (stats.getBytesNeeded() * replication) > pool .getLimit()) { throw new InvalidRequestException("Caching path " + path + " of size " + stats.getBytesNeeded() / replication + " bytes at replication " + replication + " would exceed pool " + pool.getPoolName() + "'s remaining capacity of " + (pool.getLimit() - pool.getBytesNeeded()) + " bytes."); } }
/** * Whether a cache pool can be accessed by the current context * * @param pool CachePool being accessed * @param access type of action being performed on the cache pool * @throws AccessControlException if pool cannot be accessed */ public void checkPermission(CachePool pool, FsAction access) throws AccessControlException { FsPermission mode = pool.getMode(); if (isSuperUser()) { return; } if (getUser().equals(pool.getOwnerName()) && mode.getUserAction().implies(access)) { return; } if (isMemberOfGroup(pool.getGroupName()) && mode.getGroupAction().implies(access)) { return; } if (mode.getOtherAction().implies(access)) { return; } throw new AccessControlException("Permission denied while accessing pool " + pool.getPoolName() + ": user " + getUser() + " does not have " + access.toString() + " permissions."); } }
directive.getId(), file.getFullPathName(), pool.getPoolName(), pool.getBytesNeeded(), pool.getLimit());
directive.getId(), file.getFullPathName(), pool.getPoolName(), pool.getBytesNeeded(), pool.getLimit());