@Override boolean apply(Path p) throws IOException { fs.setOwner(p, username, groupname); return true; } }.run(src);
@Override public void setOwner(Path p, String username, String groupname ) throws IOException { fs.setOwner(p, username, groupname); }
private void setOwnerParallel(FileSystem outputFs, String filesUser, String filesGroup, Configuration conf, List<Path> traversedPath) throws IOException { setConfigParallel(outputFs, traversedPath, (fs, path) -> { try { fs.setOwner(path, filesUser, filesGroup); } catch (IOException e) { throw new RuntimeException( "set owner for file " + path + " to " + filesUser + ":" + filesGroup + " failed", e); } }, conf); }
@Override public Object call() throws Exception { fs.setOwner(null, "aUser", "aGroup"); return null; } }, NullPointerException.class, "Ouch! Argument cannot be null: p");
@Override public Object call() throws Exception { fs.setOwner(file, null, "aGroup"); return null; } }, NullPointerException.class, "Ouch! Argument cannot be null: username");
@Override public Object call() throws Exception { fs.setOwner(file, "aUser", null); return null; } }, NullPointerException.class, "Ouch! Argument cannot be null: grpName");
/** * 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 * @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); }
@Override public void setOwner(Path f, String username, String groupname) throws IOException { checkPath(f); fsImpl.setOwner(f, username, groupname); }
public void setOwner(Path p, String username, String groupname) throws java.io.IOException { this.underlyingFs.setOwner(replaceScheme(p, this.replacementScheme, this.underlyingScheme), username, groupname); }
@Nullable @Override public Object call() throws Exception { fs.setOwner(path, "user", "group"); return null; } }, IOException.class, "File system is stopped.");
@Override public void setOwner(final Path f, final String username, final String groupname) throws AccessControlException, FileNotFoundException, IOException { InodeTree.ResolveResult<FileSystem> res = fsState.resolve(getUriPath(f), true); res.targetFileSystem.setOwner(res.remainingPath, username, groupname); }
/** * Tests that {@link HdfsUtils#setFullFileStatus(Configuration, HdfsUtils.HadoopFileStatus, String, FileSystem, Path, boolean)} * does not throw an exception when setting the group and without recursion. */ @Test public void testSetFullFileStatusFailInheritGroup() throws IOException { Configuration conf = new Configuration(); conf.set("dfs.namenode.acls.enabled", "false"); HdfsUtils.HadoopFileStatus mockHadoopFileStatus = mock(HdfsUtils.HadoopFileStatus.class); FileStatus mockSourceStatus = mock(FileStatus.class); FileSystem fs = mock(FileSystem.class); when(mockSourceStatus.getGroup()).thenReturn("fakeGroup1"); when(mockHadoopFileStatus.getFileStatus()).thenReturn(mockSourceStatus); doThrow(RuntimeException.class).when(fs).setOwner(any(Path.class), any(String.class), any(String.class)); HdfsUtils.setFullFileStatus(conf, mockHadoopFileStatus, "fakeGroup2", fs, new Path("fakePath"), false); verify(fs).setOwner(any(Path.class), any(String.class), any(String.class)); }
protected void changeOwner(final ProcessContext context, final FileSystem hdfs, final Path name) { try { // Change owner and group of file if configured to do so String owner = context.getProperty(REMOTE_OWNER).getValue(); String group = context.getProperty(REMOTE_GROUP).getValue(); if (owner != null || group != null) { hdfs.setOwner(name, owner, group); } } catch (Exception e) { getLogger().warn("Could not change owner or group of {} on HDFS due to {}", new Object[]{name, e.getMessage()}, e); } }
static void setStoragePermissions(String db, String tbl, String user, String group, short permissions) throws IOException { final Path p = getWhPathForHiveObject(db, tbl); fs.setPermission(p, new FsPermission(permissions)); fs.setOwner(p, user, group); }
private static void changeDBPermissions(final String db, final short perm, final String u, final String g) throws Exception { Path p = getWhPathForHiveObject(db, null); fs.setPermission(p, new FsPermission(perm)); fs.setOwner(p, u, g); }
/** * @throws Exception If failed. */ @Test public void testSetOwnerIfOutputStreamIsNotClosed() throws Exception { Path fsHome = new Path(primaryFsUri); Path file = new Path(fsHome, "myFile"); FSDataOutputStream os = fs.create(file); fs.setOwner(file, "aUser", "aGroup"); os.close(); assertEquals("aUser", fs.getFileStatus(file).getOwner()); assertEquals("aGroup", fs.getFileStatus(file).getGroup()); }
protected void changeOwner(final ProcessContext context, final FileSystem hdfs, final Path name, final FlowFile flowFile) { try { // Change owner and group of file if configured to do so String owner = context.getProperty(REMOTE_OWNER).evaluateAttributeExpressions(flowFile).getValue(); String group = context.getProperty(REMOTE_GROUP).evaluateAttributeExpressions(flowFile).getValue(); owner = owner == null || owner.isEmpty() ? null : owner; group = group == null || group.isEmpty() ? null : group; if (owner != null || group != null) { hdfs.setOwner(name, owner, group); } } catch (Exception e) { getLogger().warn("Could not change owner or group of {} on HDFS due to {}", new Object[]{name, e}); } }
/** @throws Exception If failed. */ @Test public void testSetOwnerCheckNonRecursiveness() throws Exception { Path fsHome = new Path(primaryFsUri); Path file = new Path(fsHome, "/tmp/my"); FSDataOutputStream os = fs.create(file); os.close(); Path tmpDir = new Path(fsHome, "/tmp"); fs.setOwner(file, "fUser", "fGroup"); fs.setOwner(tmpDir, "dUser", "dGroup"); assertEquals("dUser", fs.getFileStatus(tmpDir).getOwner()); assertEquals("dGroup", fs.getFileStatus(tmpDir).getGroup()); assertEquals("fUser", fs.getFileStatus(file).getOwner()); assertEquals("fGroup", fs.getFileStatus(file).getGroup()); }
private static void createPartitionedTable(final Driver hiveDriver, final String user, final String group) throws Exception { executeQuery(hiveDriver, String.format(partitionStudentDef, db_general, g_partitioned_student_u0_700)); executeQuery(hiveDriver, String.format("INSERT OVERWRITE TABLE %s.%s PARTITION(age) SELECT rownum, name, age, gpa, studentnum FROM %s.%s", db_general, g_partitioned_student_u0_700, db_general, g_student_all_755)); final Path p = getWhPathForHiveObject(TestStorageBasedHiveAuthorization.db_general, TestStorageBasedHiveAuthorization.g_partitioned_student_u0_700); fs.setPermission(p, new FsPermission(TestStorageBasedHiveAuthorization._700)); fs.setOwner(p, user, group); }
/** @throws Exception If failed. */ @Test public void testSetOwner() throws Exception { Path fsHome = new Path(primaryFsUri); final Path file = new Path(fsHome, "/tmp/my"); FSDataOutputStream os = fs.create(file); os.close(); assertEquals(getClientFsUser(), fs.getFileStatus(file).getOwner()); fs.setOwner(file, "aUser", "aGroup"); assertEquals("aUser", fs.getFileStatus(file).getOwner()); assertEquals("aGroup", fs.getFileStatus(file).getGroup()); }