org.apache.hadoop.fs.permission.FsPermission

Here are the examples of the java api org.apache.hadoop.fs.permission.FsPermission taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

428 Examples 7

19 Source : CrailHDFS.java
with Apache License 2.0
from zrlio

@Override
public void setPermission(Path f, FsPermission permission) throws AccessControlException, FileNotFoundException, UnresolvedLinkException, IOException {
}

19 Source : StorageStrategyTest.java
with Apache License 2.0
from zpochen

private void checkPathAndPermission(Path initialPath, Path resultPath, boolean isFile, int levels, StorageStrategy storageStrategy) throws IOException {
    replacedertEquals("Path type should match", isFile, fs.isFile(resultPath));
    replacedertEquals("Permission should match", FULL_PERMISSION, fs.getFileStatus(initialPath).getPermission());
    if (isFile) {
        replacedertEquals("Permission should match", new FsPermission(storageStrategy.getFilePermission()), fs.getFileStatus(resultPath).getPermission());
    }
    Path startingPath = initialPath;
    FsPermission folderPermission = new FsPermission(storageStrategy.getFolderPermission());
    for (int i = 1; i <= levels; i++) {
        startingPath = new Path(startingPath, "level" + i);
        replacedertEquals("Permission should match", folderPermission, fs.getFileStatus(startingPath).getPermission());
    }
}

19 Source : DelegatingFileSystem.java
with GNU General Public License v3.0
from sdadas

public boolean mkdirs(Path f, FsPermission permission) throws IOException {
    return fs.mkdirs(f, permission);
}

19 Source : DelegatingFileSystem.java
with GNU General Public License v3.0
from sdadas

public void setPermission(Path p, FsPermission permission) throws IOException {
    fs.setPermission(p, permission);
}

19 Source : MockS3FileSystem.java
with Apache License 2.0
from rdblue

@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
    return mock.mkdirs(f, permission);
}

19 Source : MockFileSystem.java
with Apache License 2.0
from pravega

@Override
public void setPermission(Path p, FsPermission permission) throws IOException {
    getFileData(p).setPermission(permission);
}

19 Source : MockFileSystem.java
with Apache License 2.0
from pravega

@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
    return true;
}

19 Source : ResourceFileSystem.java
with BSD 3-Clause "New" or "Revised" License
from osmlab

@Override
public boolean mkdirs(final Path hadoopPath, final FsPermission permission) throws IOException {
    return true;
}

19 Source : LocalDirsHandlerService.java
with Apache License 2.0
from NJUJYB

/**
 * Method which initializes the timertask and its interval time.
 */
@Override
protected void serviceInit(Configuration config) throws Exception {
    // Clone the configuration as we may do modifications to dirs-list
    Configuration conf = new Configuration(config);
    diskHealthCheckInterval = conf.getLong(YarnConfiguration.NM_DISK_HEALTH_CHECK_INTERVAL_MS, YarnConfiguration.DEFAULT_NM_DISK_HEALTH_CHECK_INTERVAL_MS);
    monitoringTimerTask = new MonitoringTimerTask(conf);
    isDiskHealthCheckerEnabled = conf.getBoolean(YarnConfiguration.NM_DISK_HEALTH_CHECK_ENABLE, true);
    minNeededHealthyDisksFactor = conf.getFloat(YarnConfiguration.NM_MIN_HEALTHY_DISKS_FRACTION, YarnConfiguration.DEFAULT_NM_MIN_HEALTHY_DISKS_FRACTION);
    lastDisksCheckTime = System.currentTimeMillis();
    super.serviceInit(conf);
    FileContext localFs;
    try {
        localFs = FileContext.getLocalFSFileContext(config);
    } catch (IOException e) {
        throw new YarnRuntimeException("Unable to get the local filesystem", e);
    }
    FsPermission perm = new FsPermission((short) 0755);
    boolean createSucceeded = localDirs.createNonExistentDirs(localFs, perm);
    createSucceeded &= logDirs.createNonExistentDirs(localFs, perm);
    if (!createSucceeded) {
        updateDirsAfterTest();
    }
    // Check the disk health immediately to weed out bad directories
    // before other init code attempts to use them.
    checkDirs();
}

19 Source : DockerContainerExecutor.java
with Apache License 2.0
from NJUJYB

/**
 * Create application log directories on all disks.
 */
void createAppLogDirs(String appId, List<String> logDirs, String user) throws IOException {
    boolean appLogDirStatus = false;
    FsPermission appLogDirPerms = new FsPermission(LOGDIR_PERM);
    for (String rootLogDir : logDirs) {
        // create $log.dir/$appid
        Path appLogDir = new Path(rootLogDir, appId);
        try {
            createDir(appLogDir, appLogDirPerms, true, user);
        } catch (IOException e) {
            LOG.warn("Unable to create the app-log directory : " + appLogDir, e);
            continue;
        }
        appLogDirStatus = true;
    }
    if (!appLogDirStatus) {
        throw new IOException("Not able to initialize app-log directories " + "in any of the configured local directories for app " + appId);
    }
}

19 Source : DockerContainerExecutor.java
with Apache License 2.0
from NJUJYB

/**
 * Create application log directories on all disks.
 */
void createContainerLogDirs(String appId, String containerId, List<String> logDirs, String user) throws IOException {
    boolean containerLogDirStatus = false;
    FsPermission containerLogDirPerms = new FsPermission(LOGDIR_PERM);
    for (String rootLogDir : logDirs) {
        // create $log.dir/$appid/$containerid
        Path appLogDir = new Path(rootLogDir, appId);
        Path containerLogDir = new Path(appLogDir, containerId);
        try {
            createDir(containerLogDir, containerLogDirPerms, true, user);
        } catch (IOException e) {
            LOG.warn("Unable to create the container-log directory : " + appLogDir, e);
            continue;
        }
        containerLogDirStatus = true;
    }
    if (!containerLogDirStatus) {
        throw new IOException("Not able to initialize container-log directories " + "in any of the configured local directories for container " + containerId);
    }
}

19 Source : DockerContainerExecutor.java
with Apache License 2.0
from NJUJYB

/**
 * Initialize the local directories for a particular user.
 * <ul>.mkdir
 * <li>$local.dir/usercache/$user</li>
 * </ul>
 */
void createUserLocalDirs(List<String> localDirs, String user) throws IOException {
    boolean userDirStatus = false;
    FsPermission userperms = new FsPermission(USER_PERM);
    for (String localDir : localDirs) {
        // create $local.dir/usercache/$user and its immediate parent
        try {
            createDir(getUserCacheDir(new Path(localDir), user), userperms, true, user);
        } catch (IOException e) {
            LOG.warn("Unable to create the user directory : " + localDir, e);
            continue;
        }
        userDirStatus = true;
    }
    if (!userDirStatus) {
        throw new IOException("Not able to initialize user directories " + "in any of the configured local directories for user " + user);
    }
}

19 Source : DockerContainerExecutor.java
with Apache License 2.0
from NJUJYB

/**
 * Initialize the local cache directories for a particular user.
 * <ul>
 * <li>$local.dir/usercache/$user</li>
 * <li>$local.dir/usercache/$user/appcache</li>
 * <li>$local.dir/usercache/$user/filecache</li>
 * </ul>
 */
void createUserCacheDirs(List<String> localDirs, String user) throws IOException {
    LOG.info("Initializing user " + user);
    boolean appcacheDirStatus = false;
    boolean distributedCacheDirStatus = false;
    FsPermission appCachePerms = new FsPermission(APPCACHE_PERM);
    FsPermission fileperms = new FsPermission(FILECACHE_PERM);
    for (String localDir : localDirs) {
        // create $local.dir/usercache/$user/appcache
        Path localDirPath = new Path(localDir);
        final Path appDir = getAppcacheDir(localDirPath, user);
        try {
            createDir(appDir, appCachePerms, true, user);
            appcacheDirStatus = true;
        } catch (IOException e) {
            LOG.warn("Unable to create app cache directory : " + appDir, e);
        }
        // create $local.dir/usercache/$user/filecache
        final Path distDir = getFileCacheDir(localDirPath, user);
        try {
            createDir(distDir, fileperms, true, user);
            distributedCacheDirStatus = true;
        } catch (IOException e) {
            LOG.warn("Unable to create file cache directory : " + distDir, e);
        }
    }
    if (!appcacheDirStatus) {
        throw new IOException("Not able to initialize app-cache directories " + "in any of the configured local directories for user " + user);
    }
    if (!distributedCacheDirStatus) {
        throw new IOException("Not able to initialize distributed-cache directories " + "in any of the configured local directories for user " + user);
    }
}

19 Source : DockerContainerExecutor.java
with Apache License 2.0
from NJUJYB

/**
 * Initialize the local directories for a particular user.
 * <ul>
 * <li>$local.dir/usercache/$user/appcache/$appid</li>
 * </ul>
 * @param localDirs
 */
void createAppDirs(List<String> localDirs, String user, String appId) throws IOException {
    boolean initAppDirStatus = false;
    FsPermission appperms = new FsPermission(APPDIR_PERM);
    for (String localDir : localDirs) {
        Path fullAppDir = getApplicationDir(new Path(localDir), user, appId);
        // create $local.dir/usercache/$user/appcache/$appId
        try {
            createDir(fullAppDir, appperms, true, user);
            initAppDirStatus = true;
        } catch (IOException e) {
            LOG.warn("Unable to create app directory " + fullAppDir.toString(), e);
        }
    }
    if (!initAppDirStatus) {
        throw new IOException("Not able to initialize app directories " + "in any of the configured local directories for app " + appId.toString());
    }
}

19 Source : DirectoryCollection.java
with Apache License 2.0
from NJUJYB

/**
 * Create any non-existent directories and parent directories, updating the
 * list of valid directories if necessary.
 * @param localFs local file system to use
 * @param perm absolute permissions to use for any directories created
 * @return true if there were no errors, false if at least one error occurred
 */
synchronized boolean createNonExistentDirs(FileContext localFs, FsPermission perm) {
    boolean failed = false;
    for (final String dir : localDirs) {
        try {
            createDir(localFs, new Path(dir), perm);
        } catch (IOException e) {
            LOG.warn("Unable to create directory " + dir + " error " + e.getMessage() + ", removing from the list of valid directories.");
            localDirs.remove(dir);
            errorDirs.add(dir);
            numFailures++;
            failed = true;
        }
    }
    return !failed;
}

19 Source : DefaultContainerExecutor.java
with Apache License 2.0
from NJUJYB

@Override
public int launchContainer(Container container, Path nmPrivateContainerScriptPath, Path nmPrivateTokensPath, String user, String appId, Path containerWorkDir, List<String> localDirs, List<String> logDirs) throws IOException {
    FsPermission dirPerm = new FsPermission(APPDIR_PERM);
    ContainerId containerId = container.getContainerId();
    // create container dirs on all disks
    String containerIdStr = ConverterUtils.toString(containerId);
    String appIdStr = ConverterUtils.toString(containerId.getApplicationAttemptId().getApplicationId());
    for (String sLocalDir : localDirs) {
        Path usersdir = new Path(sLocalDir, ContainerLocalizer.USERCACHE);
        Path userdir = new Path(usersdir, user);
        Path appCacheDir = new Path(userdir, ContainerLocalizer.APPCACHE);
        Path appDir = new Path(appCacheDir, appIdStr);
        Path containerDir = new Path(appDir, containerIdStr);
        createDir(containerDir, dirPerm, true, user);
    }
    // Create the container log-dirs on all disks
    createContainerLogDirs(appIdStr, containerIdStr, logDirs, user);
    Path tmpDir = new Path(containerWorkDir, YarnConfiguration.DEFAULT_CONTAINER_TEMP_DIR);
    createDir(tmpDir, dirPerm, false, user);
    // copy container tokens to work dir
    Path tokenDst = new Path(containerWorkDir, ContainerLaunch.FINAL_CONTAINER_TOKENS_FILE);
    copyFile(nmPrivateTokensPath, tokenDst, user);
    // copy launch script to work dir
    Path launchDst = new Path(containerWorkDir, ContainerLaunch.CONTAINER_SCRIPT);
    copyFile(nmPrivateContainerScriptPath, launchDst, user);
    // Create new local launch wrapper script
    LocalWrapperScriptBuilder sb = getLocalWrapperScriptBuilder(containerIdStr, containerWorkDir);
    // Fail fast if attempting to launch the wrapper script would fail due to
    // Windows path length limitation.
    if (Shell.WINDOWS && sb.getWrapperScriptPath().toString().length() > WIN_MAX_PATH) {
        throw new IOException(String.format("Cannot launch container using script at path %s, because it exceeds " + "the maximum supported path length of %d characters.  Consider " + "configuring shorter directories in %s.", sb.getWrapperScriptPath(), WIN_MAX_PATH, YarnConfiguration.NM_LOCAL_DIRS));
    }
    Path pidFile = getPidFilePath(containerId);
    if (pidFile != null) {
        sb.writeLocalWrapperScript(launchDst, pidFile);
    } else {
        LOG.info("Container " + containerIdStr + " was marked as inactive. Returning terminated error");
        return ExitCode.TERMINATED.getExitCode();
    }
    // create log dir under app
    // fork script
    Shell.CommandExecutor shExec = null;
    try {
        setScriptExecutable(launchDst, user);
        setScriptExecutable(sb.getWrapperScriptPath(), user);
        shExec = buildCommandExecutor(sb.getWrapperScriptPath().toString(), containerIdStr, user, pidFile, new File(containerWorkDir.toUri().getPath()), container.getLaunchContext().getEnvironment());
        if (isContainerActive(containerId)) {
            shExec.execute();
        } else {
            LOG.info("Container " + containerIdStr + " was marked as inactive. Returning terminated error");
            return ExitCode.TERMINATED.getExitCode();
        }
    } catch (IOException e) {
        if (null == shExec) {
            return -1;
        }
        int exitCode = shExec.getExitCode();
        LOG.warn("Exit code from container " + containerId + " is : " + exitCode);
        // 143 (SIGTERM) and 137 (SIGKILL) exit codes means the container was
        // terminated/killed forcefully. In all other cases, log the
        // container-executor's output
        if (exitCode != ExitCode.FORCE_KILLED.getExitCode() && exitCode != ExitCode.TERMINATED.getExitCode()) {
            LOG.warn("Exception from container-launch with container ID: " + containerId + " and exit code: " + exitCode, e);
            StringBuilder builder = new StringBuilder();
            builder.append("Exception from container-launch.\n");
            builder.append("Container id: " + containerId + "\n");
            builder.append("Exit code: " + exitCode + "\n");
            if (!Optional.fromNullable(e.getMessage()).or("").isEmpty()) {
                builder.append("Exception message: " + e.getMessage() + "\n");
            }
            builder.append("Stack trace: " + StringUtils.stringifyException(e) + "\n");
            if (!shExec.getOutput().isEmpty()) {
                builder.append("Shell output: " + shExec.getOutput() + "\n");
            }
            String diagnostics = builder.toString();
            logOutput(diagnostics);
            container.handle(new ContainerDiagnosticsUpdateEvent(containerId, diagnostics));
        } else {
            container.handle(new ContainerDiagnosticsUpdateEvent(containerId, "Container killed on request. Exit code is " + exitCode));
        }
        return exitCode;
    } finally {
        if (shExec != null)
            shExec.close();
    }
    return 0;
}

19 Source : SwiftNativeFileSystem.java
with Apache License 2.0
from NJUJYB

/**
 * Create the parent directories.
 * As an optimization, the entire hierarchy of parent
 * directories is <i>Not</i> polled. Instead
 * the tree is walked up from the last to the first,
 * creating directories until one that exists is found.
 *
 * This strategy means if a file is created in an existing directory,
 * one quick poll sufficies.
 *
 * There is a big replacedumption here: that all parent directories of an existing
 * directory also exists.
 * @param path path to create.
 * @param permission to apply to files
 * @return true if the operation was successful
 * @throws IOException on a problem
 */
@Override
public boolean mkdirs(Path path, FsPermission permission) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("SwiftFileSystem.mkdirs: " + path);
    }
    Path directory = makeAbsolute(path);
    // build a list of paths to create
    List<Path> paths = new ArrayList<Path>();
    while (shouldCreate(directory)) {
        // this directory needs creation, add to the list
        paths.add(0, directory);
        // now see if the parent needs to be created
        directory = directory.getParent();
    }
    // go through the list of directories to create
    for (Path p : paths) {
        if (isNotRoot(p)) {
            // perform a mkdir operation without any polling of
            // the far end first
            forceMkdir(p);
        }
    }
    // if an exception was not thrown, this operation is considered
    // a success
    return true;
}

19 Source : NativeS3FileSystem.java
with Apache License 2.0
from NJUJYB

@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
    Path absolutePath = makeAbsolute(f);
    List<Path> paths = new ArrayList<Path>();
    do {
        paths.add(0, absolutePath);
        absolutePath = absolutePath.getParent();
    } while (absolutePath != null);
    boolean result = true;
    for (Path path : paths) {
        result &= mkdir(path);
    }
    return result;
}

19 Source : S3FileSystem.java
with Apache License 2.0
from NJUJYB

/**
 * @param permission Currently ignored.
 */
@Override
public boolean mkdirs(Path path, FsPermission permission) throws IOException {
    Path absolutePath = makeAbsolute(path);
    List<Path> paths = new ArrayList<Path>();
    do {
        paths.add(0, absolutePath);
        absolutePath = absolutePath.getParent();
    } while (absolutePath != null);
    boolean result = true;
    for (Path p : paths) {
        result &= mkdir(p);
    }
    return result;
}

19 Source : HttpFSFileSystem.java
with Apache License 2.0
from NJUJYB

/**
 * Converts a <code>FsPermission</code> to a Unix octal representation.
 *
 * @param p the permission.
 *
 * @return the Unix string symbolic reprentation.
 */
public static String permissionToString(FsPermission p) {
    return Integer.toString((p == null) ? DEFAULT_PERMISSION : p.toShort(), 8);
}

19 Source : TestDFSPermission.java
with Apache License 2.0
from NJUJYB

/* create file/directory with the provided umask and permission; then it
   * checks if the permission is set correctly;
   * If the delete flag is true, delete the file afterwards; otherwise leave
   * it in the file system.
   */
private void createAndCheckPermission(OpType op, Path name, short umask, FsPermission permission, boolean delete) throws Exception {
    // create the file/directory
    create(op, name, umask, permission);
    // get the short form of the permission
    short permissionNum = (DEFAULT_PERMISSION.equals(permission)) ? MAX_PERMISSION : permission.toShort();
    // get the expected permission
    short expectedPermission = (op == OpType.CREATE) ? (short) (~umask & permissionNum) : (short) (~umask & permissionNum);
    // check if permission is correctly set
    checkPermission(name, expectedPermission, delete);
}

19 Source : JsonUtil.java
with Apache License 2.0
from NJUJYB

/**
 * Convert a string to a FsPermission object.
 */
private static FsPermission toFsPermission(final String s, Boolean aclBit, Boolean encBit) {
    FsPermission perm = new FsPermission(Short.parseShort(s, 8));
    final boolean aBit = (aclBit != null) ? aclBit : false;
    final boolean eBit = (encBit != null) ? encBit : false;
    if (aBit || eBit) {
        return new FsPermissionExtension(perm, aBit, eBit);
    } else {
        return perm;
    }
}

19 Source : JsonUtil.java
with Apache License 2.0
from NJUJYB

/**
 * Convert a HdfsFileStatus object to a Json string.
 */
public static String toJsonString(final HdfsFileStatus status, boolean includeType) {
    if (status == null) {
        return null;
    }
    final Map<String, Object> m = new TreeMap<String, Object>();
    m.put("pathSuffix", status.getLocalName());
    m.put("type", PathType.valueOf(status));
    if (status.isSymlink()) {
        m.put("symlink", status.getSymlink());
    }
    m.put("length", status.getLen());
    m.put("owner", status.getOwner());
    m.put("group", status.getGroup());
    FsPermission perm = status.getPermission();
    m.put("permission", toString(perm));
    if (perm.getAclBit()) {
        m.put("aclBit", true);
    }
    if (perm.getEncryptedBit()) {
        m.put("encBit", true);
    }
    m.put("accessTime", status.getAccessTime());
    m.put("modificationTime", status.getModificationTime());
    m.put("blockSize", status.getBlockSize());
    m.put("replication", status.getReplication());
    m.put("fileId", status.getFileId());
    m.put("childrenNum", status.getChildrenNum());
    m.put("storagePolicy", status.getStoragePolicy());
    return includeType ? toJsonString(FileStatus.clreplaced, m) : JSON.toString(m);
}

19 Source : JsonUtil.java
with Apache License 2.0
from NJUJYB

/**
 * Convert a Json map to a HdfsFileStatus object.
 */
public static HdfsFileStatus toFileStatus(final Map<?, ?> json, boolean includesType) {
    if (json == null) {
        return null;
    }
    final Map<?, ?> m = includesType ? (Map<?, ?>) json.get(FileStatus.clreplaced.getSimpleName()) : json;
    final String localName = (String) m.get("pathSuffix");
    final PathType type = PathType.valueOf((String) m.get("type"));
    final byte[] symlink = type != PathType.SYMLINK ? null : DFSUtil.string2Bytes((String) m.get("symlink"));
    final long len = (Long) m.get("length");
    final String owner = (String) m.get("owner");
    final String group = (String) m.get("group");
    final FsPermission permission = toFsPermission((String) m.get("permission"), (Boolean) m.get("aclBit"), (Boolean) m.get("encBit"));
    final long aTime = (Long) m.get("accessTime");
    final long mTime = (Long) m.get("modificationTime");
    final long blockSize = (Long) m.get("blockSize");
    final short replication = (short) (long) (Long) m.get("replication");
    final long fileId = m.containsKey("fileId") ? (Long) m.get("fileId") : INodeId.GRANDFATHER_INODE_ID;
    Long childrenNumLong = (Long) m.get("childrenNum");
    final int childrenNum = (childrenNumLong == null) ? -1 : childrenNumLong.intValue();
    final byte storagePolicy = m.containsKey("storagePolicy") ? (byte) (long) (Long) m.get("storagePolicy") : BlockStoragePolicySuite.ID_UNSPECIFIED;
    return new HdfsFileStatus(len, type == PathType.DIRECTORY, replication, blockSize, mTime, aTime, permission, owner, group, symlink, DFSUtil.string2Bytes(localName), fileId, childrenNum, null, storagePolicy);
}

19 Source : JsonUtil.java
with Apache License 2.0
from NJUJYB

/**
 * Convert a FsPermission object to a string.
 */
private static String toString(final FsPermission permission) {
    return String.format("%o", permission.toShort());
}

19 Source : HftpFileSystem.java
with Apache License 2.0
from NJUJYB

@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
    throw new IOException("Not supported");
}

19 Source : FSImageLoader.java
with Apache License 2.0
from NJUJYB

private String toString(FsPermission permission) {
    return String.format("%o", permission.toShort());
}

19 Source : INode.java
with Apache License 2.0
from NJUJYB

/**
 * Set the {@link FsPermission} of this {@link INode}
 */
INode setPermission(FsPermission permission, int latestSnapshotId) throws QuotaExceededException {
    recordModification(latestSnapshotId);
    setPermission(permission);
    return this;
}

19 Source : FSImageSerialization.java
with Apache License 2.0
from NJUJYB

public static void writeCachePoolInfo(ContentHandler contentHandler, CachePoolInfo info) throws SAXException {
    XMLUtils.addSaxString(contentHandler, "POOLNAME", info.getPoolName());
    final String ownerName = info.getOwnerName();
    final String groupName = info.getGroupName();
    final Long limit = info.getLimit();
    final FsPermission mode = info.getMode();
    final Long maxRelativeExpiry = info.getMaxRelativeExpiryMs();
    if (ownerName != null) {
        XMLUtils.addSaxString(contentHandler, "OWNERNAME", ownerName);
    }
    if (groupName != null) {
        XMLUtils.addSaxString(contentHandler, "GROUPNAME", groupName);
    }
    if (mode != null) {
        FSEditLogOp.fsPermissionToXml(contentHandler, mode);
    }
    if (limit != null) {
        XMLUtils.addSaxString(contentHandler, "LIMIT", Long.toString(limit));
    }
    if (maxRelativeExpiry != null) {
        XMLUtils.addSaxString(contentHandler, "MAXRELATIVEEXPIRY", Long.toString(maxRelativeExpiry));
    }
}

19 Source : FSImageSerialization.java
with Apache License 2.0
from NJUJYB

private static void writePermissionStatus(INodeAttributes inode, DataOutput out) throws IOException {
    final FsPermission p = TL_DATA.get().FILE_PERM;
    p.fromShort(inode.getFsPermissionShort());
    PermissionStatus.write(out, inode.getUserName(), inode.getGroupName(), p);
}

19 Source : CachePool.java
with Apache License 2.0
from NJUJYB

public CachePool setMode(FsPermission mode) {
    this.mode = new FsPermission(mode);
    return this;
}

19 Source : AclStorage.java
with Apache License 2.0
from NJUJYB

/**
 * Completely removes the ACL from an inode.
 *
 * @param inode INode to update
 * @param snapshotId int latest snapshot ID of inode
 * @throws QuotaExceededException if quota limit is exceeded
 */
public static void removeINodeAcl(INode inode, int snapshotId) throws QuotaExceededException {
    AclFeature f = inode.getAclFeature();
    if (f == null) {
        return;
    }
    FsPermission perm = inode.getFsPermission();
    List<AclEntry> featureEntries = f.getEntries();
    if (featureEntries.get(0).getScope() == AclEntryScope.ACCESS) {
        // Restore group permissions from the feature's entry to permission
        // bits, overwriting the mask, which is not part of a minimal ACL.
        AclEntry groupEntryKey = new AclEntry.Builder().setScope(AclEntryScope.ACCESS).setType(AclEntryType.GROUP).build();
        int groupEntryIndex = Collections.binarySearch(featureEntries, groupEntryKey, AclTransformation.ACL_ENTRY_COMPARATOR);
        replacedert groupEntryIndex >= 0;
        FsAction groupPerm = featureEntries.get(groupEntryIndex).getPermission();
        FsPermission newPerm = new FsPermission(perm.getUserAction(), groupPerm, perm.getOtherAction(), perm.getStickyBit());
        inode.setPermission(newPerm, snapshotId);
    }
    inode.removeAclFeature(snapshotId);
}

19 Source : AclStorage.java
with Apache License 2.0
from NJUJYB

/**
 * Creates the new FsPermission for an inode that is receiving a minimal ACL,
 * based on its access ACL entries.  For a correctly sorted ACL, the owner,
 * group and other permissions are in order.  Also preserve sticky bit and
 * toggle ACL bit off.
 *
 * @param accessEntries List<AclEntry> access ACL entries
 * @param existingPerm FsPermission existing permissions
 * @return FsPermission new permissions
 */
private static FsPermission createFsPermissionForMinimalAcl(List<AclEntry> accessEntries, FsPermission existingPerm) {
    return new FsPermission(accessEntries.get(0).getPermission(), accessEntries.get(1).getPermission(), accessEntries.get(2).getPermission(), existingPerm.getStickyBit());
}

19 Source : AclStorage.java
with Apache License 2.0
from NJUJYB

/**
 * Creates the new FsPermission for an inode that is receiving an extended
 * ACL, based on its access ACL entries.  For a correctly sorted ACL, the
 * first entry is the owner and the last 2 entries are the mask and other
 * entries respectively.  Also preserve sticky bit and toggle ACL bit on.
 * Note that this method intentionally copies the permissions of the mask
 * entry into the FsPermission group permissions.  This is consistent with the
 * POSIX ACLs model, which presents the mask as the permissions of the group
 * clreplaced.
 *
 * @param accessEntries List<AclEntry> access ACL entries
 * @param existingPerm FsPermission existing permissions
 * @return FsPermission new permissions
 */
private static FsPermission createFsPermissionForExtendedAcl(List<AclEntry> accessEntries, FsPermission existingPerm) {
    return new FsPermission(accessEntries.get(0).getPermission(), accessEntries.get(accessEntries.size() - 2).getPermission(), accessEntries.get(accessEntries.size() - 1).getPermission(), existingPerm.getStickyBit());
}

19 Source : CachePoolInfo.java
with Apache License 2.0
from NJUJYB

public CachePoolInfo setMode(FsPermission mode) {
    this.mode = mode;
    return this;
}

19 Source : Hdfs.java
with Apache License 2.0
from NJUJYB

@Override
public void mkdir(Path dir, FsPermission permission, boolean createParent) throws IOException, UnresolvedLinkException {
    dfs.primitiveMkdir(getUriPath(dir), permission, createParent);
}

19 Source : Hdfs.java
with Apache License 2.0
from NJUJYB

@Override
public void setPermission(Path f, FsPermission permission) throws IOException, UnresolvedLinkException {
    dfs.setPermission(getUriPath(f), permission);
}

19 Source : TestDiskChecker.java
with Apache License 2.0
from NJUJYB

public clreplaced TestDiskChecker {

    final FsPermission defaultPerm = new FsPermission("755");

    final FsPermission invalidPerm = new FsPermission("000");

    @Test(timeout = 30000)
    public void testMkdirs_dirExists() throws Throwable {
        _mkdirs(true, defaultPerm, defaultPerm);
    }

    @Test(timeout = 30000)
    public void testMkdirs_noDir() throws Throwable {
        _mkdirs(false, defaultPerm, defaultPerm);
    }

    @Test(timeout = 30000)
    public void testMkdirs_dirExists_badUmask() throws Throwable {
        _mkdirs(true, defaultPerm, invalidPerm);
    }

    @Test(timeout = 30000)
    public void testMkdirs_noDir_badUmask() throws Throwable {
        _mkdirs(false, defaultPerm, invalidPerm);
    }

    private void _mkdirs(boolean exists, FsPermission before, FsPermission after) throws Throwable {
        File localDir = make(stub(File.clreplaced).returning(exists).from.exists());
        when(localDir.mkdir()).thenReturn(true);
        // use default stubs
        Path dir = mock(Path.clreplaced);
        LocalFileSystem fs = make(stub(LocalFileSystem.clreplaced).returning(localDir).from.pathToFile(dir));
        FileStatus stat = make(stub(FileStatus.clreplaced).returning(after).from.getPermission());
        when(fs.getFileStatus(dir)).thenReturn(stat);
        try {
            DiskChecker.mkdirsWithExistsAndPermissionCheck(fs, dir, before);
            if (!exists)
                verify(fs).setPermission(dir, before);
            else {
                verify(fs).getFileStatus(dir);
                verify(stat).getPermission();
            }
        } catch (DiskErrorException e) {
            if (before != after)
                replacedertTrue(e.getMessage().startsWith("Incorrect permission"));
        }
    }

    @Test(timeout = 30000)
    public void testCheckDir_normal() throws Throwable {
        _checkDirs(true, new FsPermission("755"), true);
    }

    @Test(timeout = 30000)
    public void testCheckDir_notDir() throws Throwable {
        _checkDirs(false, new FsPermission("000"), false);
    }

    @Test(timeout = 30000)
    public void testCheckDir_notReadable() throws Throwable {
        _checkDirs(true, new FsPermission("000"), false);
    }

    @Test(timeout = 30000)
    public void testCheckDir_notWritable() throws Throwable {
        _checkDirs(true, new FsPermission("444"), false);
    }

    @Test(timeout = 30000)
    public void testCheckDir_notListable() throws Throwable {
        // not listable
        _checkDirs(true, new FsPermission("666"), false);
    }

    private void _checkDirs(boolean isDir, FsPermission perm, boolean success) throws Throwable {
        File localDir = File.createTempFile("test", "tmp");
        if (isDir) {
            localDir.delete();
            localDir.mkdir();
        }
        Shell.execCommand(Shell.getSetPermissionCommand(String.format("%04o", perm.toShort()), false, localDir.getAbsolutePath()));
        try {
            DiskChecker.checkDir(FileSystem.getLocal(new Configuration()), new Path(localDir.getAbsolutePath()), perm);
            replacedertTrue("checkDir success", success);
        } catch (DiskErrorException e) {
            replacedertFalse("checkDir success", success);
        }
        localDir.delete();
    }

    /**
     * These test cases test to test the creation of a local folder with correct
     * permission for result of mapper.
     */
    @Test(timeout = 30000)
    public void testCheckDir_normal_local() throws Throwable {
        _checkDirs(true, "755", true);
    }

    @Test(timeout = 30000)
    public void testCheckDir_notDir_local() throws Throwable {
        _checkDirs(false, "000", false);
    }

    @Test(timeout = 30000)
    public void testCheckDir_notReadable_local() throws Throwable {
        _checkDirs(true, "000", false);
    }

    @Test(timeout = 30000)
    public void testCheckDir_notWritable_local() throws Throwable {
        _checkDirs(true, "444", false);
    }

    @Test(timeout = 30000)
    public void testCheckDir_notListable_local() throws Throwable {
        _checkDirs(true, "666", false);
    }

    private void _checkDirs(boolean isDir, String perm, boolean success) throws Throwable {
        File localDir = File.createTempFile("test", "tmp");
        if (isDir) {
            localDir.delete();
            localDir.mkdir();
        }
        Shell.execCommand(Shell.getSetPermissionCommand(perm, false, localDir.getAbsolutePath()));
        try {
            DiskChecker.checkDir(localDir);
            replacedertTrue("checkDir success", success);
        } catch (DiskErrorException e) {
            e.printStackTrace();
            replacedertFalse("checkDir success", success);
        }
        localDir.delete();
        System.out.println("checkDir success: " + success);
    }
}

19 Source : FileSystemTestWrapper.java
with Apache License 2.0
from NJUJYB

@Override
public void setPermission(final Path f, final FsPermission permission) throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException {
    fs.setPermission(f, permission);
}

19 Source : FileContextTestWrapper.java
with Apache License 2.0
from NJUJYB

@Override
public void setPermission(final Path f, final FsPermission permission) throws AccessControlException, FileNotFoundException, UnsupportedFileSystemException, IOException {
    fc.setPermission(f, permission);
}

19 Source : FileContextTestWrapper.java
with Apache License 2.0
from NJUJYB

@Override
public void mkdir(Path dir, FsPermission permission, boolean createParent) throws AccessControlException, FileAlreadyExistsException, FileNotFoundException, ParentNotDirectoryException, UnsupportedFileSystemException, IOException {
    fc.mkdir(dir, permission, createParent);
}

19 Source : FileContextPermissionBase.java
with Apache License 2.0
from NJUJYB

void doFilePermissionCheck(FsPermission expectedPerm, FsPermission actualPerm) {
    replacedert.replacedertEquals(expectedPerm.applyUMask(getFileMask()), actualPerm);
}

19 Source : FileContextPermissionBase.java
with Apache License 2.0
from NJUJYB

@Test
public void testSetPermission() throws IOException {
    if (Path.WINDOWS) {
        System.out.println("Cannot run test for Windows");
        return;
    }
    String filename = "foo";
    Path f = fileContextTestHelper.getTestRootPath(fc, filename);
    createFile(fc, f);
    try {
        // create files and manipulate them.
        FsPermission all = new FsPermission((short) 0777);
        FsPermission none = new FsPermission((short) 0);
        fc.setPermission(f, none);
        doFilePermissionCheck(none, fc.getFileStatus(f).getPermission());
        fc.setPermission(f, all);
        doFilePermissionCheck(all, fc.getFileStatus(f).getPermission());
    } finally {
        cleanupFile(fc, f);
    }
}

19 Source : ViewFileSystem.java
with Apache License 2.0
from NJUJYB

@Override
public void setPermission(final Path f, final FsPermission permission) throws AccessControlException, FileNotFoundException, IOException {
    InodeTree.ResolveResult<FileSystem> res = fsState.resolve(getUriPath(f), true);
    res.targetFileSystem.setPermission(res.remainingPath, permission);
}

19 Source : ViewFileSystem.java
with Apache License 2.0
from NJUJYB

@Override
public boolean mkdirs(final Path dir, final FsPermission permission) throws IOException {
    InodeTree.ResolveResult<FileSystem> res = fsState.resolve(getUriPath(dir), false);
    return res.targetFileSystem.mkdirs(res.remainingPath, permission);
}

19 Source : ChRootedFs.java
with Apache License 2.0
from NJUJYB

@Override
public void setPermission(final Path f, final FsPermission permission) throws IOException, UnresolvedLinkException {
    myFs.setPermission(fullPath(f), permission);
}

19 Source : ChRootedFs.java
with Apache License 2.0
from NJUJYB

@Override
public void mkdir(final Path dir, final FsPermission permission, final boolean createParent) throws IOException, UnresolvedLinkException {
    myFs.mkdir(fullPath(dir), permission, createParent);
}

19 Source : RawLocalFileSystem.java
with Apache License 2.0
from NJUJYB

@Override
public boolean mkdirs(Path f, FsPermission permission) throws IOException {
    boolean b = mkdirs(f);
    if (b) {
        setPermission(f, permission);
    }
    return b;
}

19 Source : RawLocalFileSystem.java
with Apache License 2.0
from NJUJYB

@Override
protected boolean primitiveMkdir(Path f, FsPermission absolutePermission) throws IOException {
    boolean b = mkdirs(f);
    setPermission(f, absolutePermission);
    return b;
}

19 Source : FTPFileSystem.java
with Apache License 2.0
from NJUJYB

/**
 * Convert the file information in FTPFile to a {@link FileStatus} object. *
 *
 * @param ftpFile
 * @param parentPath
 * @return FileStatus
 */
private FileStatus getFileStatus(FTPFile ftpFile, Path parentPath) {
    long length = ftpFile.getSize();
    boolean isDir = ftpFile.isDirectory();
    int blockReplication = 1;
    // Using default block size since there is no way in FTP client to know of
    // block sizes on server. The replacedumption could be less than ideal.
    long blockSize = DEFAULT_BLOCK_SIZE;
    long modTime = ftpFile.getTimestamp().getTimeInMillis();
    long accessTime = 0;
    FsPermission permission = getPermissions(ftpFile);
    String user = ftpFile.getUser();
    String group = ftpFile.getGroup();
    Path filePath = new Path(parentPath, ftpFile.getName());
    return new FileStatus(length, isDir, blockReplication, blockSize, modTime, accessTime, permission, user, group, filePath.makeQualified(this));
}

See More Examples