List of usage examples for org.apache.hadoop.fs FileSystem setOwner
public void setOwner(Path p, String username, String groupname) throws IOException
From source file:com.trendmicro.hdfs.webdav.test.TestPutSimple.java
License:Apache License
@BeforeClass public static void setup() throws Exception { Configuration conf = minicluster.getConfiguration(); conf.set("hadoop.proxyuser." + UserGroupInformation.getCurrentUser().getShortUserName() + ".groups", "users"); conf.set("hadoop.proxyuser." + UserGroupInformation.getCurrentUser().getShortUserName() + ".hosts", "localhost"); conf.set("hadoop.webdav.authentication.type", "simple"); conf.setBoolean("hadoop.webdav.authentication.simple.anonymous.allowed", true); minicluster.startMiniCluster(gatewayUser); LOG.info("Gateway started on port " + minicluster.getGatewayPort()); FsPermission.setUMask(conf, new FsPermission((short) 0)); FileSystem fs = minicluster.getTestFileSystem(); Path path = new Path("/test"); assertTrue(fs.mkdirs(path, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL))); fs.setOwner(path, ownerUser.getShortUserName(), ownerUser.getGroupNames()[0]); ownerUser.doAs(new PrivilegedExceptionAction<Void>() { public Void run() throws Exception { FileSystem fs = minicluster.getTestFileSystem(); assertTrue(fs.mkdirs(new Path("/test/rw"), new FsPermission(FsAction.ALL, FsAction.WRITE_EXECUTE, FsAction.NONE))); assertTrue(fs.mkdirs(new Path("/test/ro"), new FsPermission(FsAction.READ_EXECUTE, FsAction.NONE, FsAction.NONE))); assertTrue(fs.mkdirs(new Path("/test/public"), new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL))); return null; }//from ww w . j a va2s .c o m }); }
From source file:etl.cmd.test.XFsTestCase.java
License:Apache License
private Path initFileSystem(FileSystem fs) throws Exception { Path path = new Path(fs.getWorkingDirectory(), java.util.UUID.randomUUID().toString()); Path testDirInFs = fs.makeQualified(path); System.out.println(XLog.format("Setting FS testcase work dir[{0}]", testDirInFs)); if (fs.exists(testDirInFs)) { setAllPermissions(fs, testDirInFs); }/*from w w w.ja va 2s . c o m*/ fs.delete(testDirInFs, true); if (!fs.mkdirs(path)) { throw new IOException(XLog.format("Could not create FS testcase dir [{0}]", testDirInFs)); } fs.setOwner(testDirInFs, getTestUser(), getTestGroup()); fs.setPermission(testDirInFs, FsPermission.valueOf("-rwxrwx--x")); return testDirInFs; }
From source file:fr.ens.biologie.genomique.eoulsan.modules.mgmt.hadoop.DistCp.java
License:LGPL
private static void updatePermissions(final FileStatus src, final FileStatus dst, final EnumSet<FileAttribute> preseved, final FileSystem destFileSys) throws IOException { String owner = null;/*from w w w.j a v a2 s. c o m*/ String group = null; if (preseved.contains(FileAttribute.USER) && !src.getOwner().equals(dst.getOwner())) { owner = src.getOwner(); } if (preseved.contains(FileAttribute.GROUP) && !src.getGroup().equals(dst.getGroup())) { group = src.getGroup(); } if (owner != null || group != null) { destFileSys.setOwner(dst.getPath(), owner, group); } if (preseved.contains(FileAttribute.PERMISSION) && !src.getPermission().equals(dst.getPermission())) { destFileSys.setPermission(dst.getPath(), src.getPermission()); } }
From source file:gobblin.data.management.copy.writer.FileAwareInputStreamDataWriter.java
License:Apache License
private void ensureDirectoryExists(FileSystem fs, Path path, Iterator<OwnerAndPermission> ownerAndPermissionIterator) throws IOException { if (fs.exists(path)) { return;//w ww . j av a 2s . c o m } if (ownerAndPermissionIterator.hasNext()) { OwnerAndPermission ownerAndPermission = ownerAndPermissionIterator.next(); if (path.getParent() != null) { ensureDirectoryExists(fs, path.getParent(), ownerAndPermissionIterator); } if (!fs.mkdirs(path)) { // fs.mkdirs returns false if path already existed. Do not overwrite permissions return; } if (ownerAndPermission.getFsPermission() != null) { log.debug("Applying permissions %s to path %s.", ownerAndPermission.getFsPermission(), path); fs.setPermission(path, addExecutePermissionToOwner(ownerAndPermission.getFsPermission())); } String group = ownerAndPermission.getGroup(); String owner = ownerAndPermission.getOwner(); if (group != null || owner != null) { log.debug("Applying owner %s and group %s to path %s.", owner, group, path); fs.setOwner(path, owner, group); } } else { fs.mkdirs(path); } }
From source file:gobblin.util.HadoopUtils.java
License:Apache License
/** * Set the group associated with a given path. * * @param fs the {@link FileSystem} instance used to perform the file operation * @param path the given path/* ww w . j a v a 2 s. c o m*/ * @param group the group associated with the path * @throws IOException */ public static void setGroup(FileSystem fs, Path path, String group) throws IOException { fs.setOwner(path, fs.getFileStatus(path).getOwner(), group); }
From source file:gobblin.util.HadoopUtils.java
License:Apache License
/** * Try to set owner and permissions for the path. Will not throw exception. *///from w w w . ja v a 2 s .c om public static void setPermissions(Path location, Optional<String> owner, Optional<String> group, FileSystem fs, FsPermission permission) { try { if (!owner.isPresent()) { return; } if (!group.isPresent()) { return; } fs.setOwner(location, owner.get(), group.get()); fs.setPermission(location, permission); if (!fs.isDirectory(location)) { return; } for (FileStatus fileStatus : fs.listStatus(location)) { setPermissions(fileStatus.getPath(), owner, group, fs, permission); } } catch (IOException e) { log.warn("Exception occurred while trying to change permissions : " + e.getMessage()); } }
From source file:hdfs.jsr203.attribute.HadoopPosixFileAttributeView.java
License:Apache License
@Override public void setOwner(UserPrincipal owner) throws IOException { FileSystem fs = path.getFileSystem().getHDFS(); fs.setOwner(path.getRawResolvedPath(), owner.getName(), null); }
From source file:hdfs.jsr203.attribute.HadoopPosixFileAttributeView.java
License:Apache License
@Override public void setGroup(GroupPrincipal group) throws IOException { FileSystem fs = path.getFileSystem().getHDFS(); fs.setOwner(path.getRawResolvedPath(), null, group.getName()); }
From source file:io.hops.experiments.utils.DFSOperationsUtils.java
License:Apache License
public static void chown(FileSystem dfs, String pathStr) throws IOException { if (SERVER_LESS_MODE) { serverLessModeRandomWait();/*from w w w . j av a2 s. c o m*/ return; } dfs.setOwner(new Path(pathStr), System.getProperty("user.name"), System.getProperty("user.name")); }
From source file:org.apache.ambari.fast_hdfs_resource.Resource.java
License:Apache License
public static void setOwner(Resource resource, FileSystem dfs, Path pathHadoop) throws IOException { if (!(resource.getOwner() == null && resource.getGroup() == null)) { dfs.setOwner(pathHadoop, resource.getOwner(), resource.getGroup()); // Get the list of sub-directories and files HashSet<String> resultSet = new HashSet<String>(); if (resource.isRecursiveChown()) resource.fillDirectoryList(dfs, resource.getTarget(), resultSet); if (resource.isChangePermissionOnParents()) resource.fillInParentDirectories(dfs, resource.getTarget(), resultSet); for (String path : resultSet) { dfs.setOwner(new Path(path), resource.getOwner(), resource.getGroup()); }/*from w w w. jav a 2s .c om*/ } }