private static void run(FsShell shell, String[] command) throws Exception { LOG.debug(ArrayUtils.toString(command)); int retval = shell.run(command); LOG.debug("Return value is :" + retval); } }
private static void run(FsShell shell, String[] command) throws Exception { LOG.debug(ArrayUtils.toString(command)); int retval = shell.run(command); LOG.debug("Return value is :" + retval); } public static class HadoopFileStatus {
int retryCount = 10; while (exitCode != 0 && retryCount >= 1) { exitCode = shell.run(new String[] { "-chmod", "-R", "777", input }); retryCount--; Thread.sleep(5000);
/** * Tests that HdfsUtils#setFullFileStatus * does not thrown an exception when setting permissions and with recursion. */ @Test public void testSetFullFileStatusFailInheritPermsRecursive() throws Exception { Configuration conf = new Configuration(); conf.set("dfs.namenode.acls.enabled", "false"); Path fakeTarget = new Path("fakePath"); HdfsUtils.HadoopFileStatus mockHadoopFileStatus = mock(HdfsUtils.HadoopFileStatus.class); FileStatus mockSourceStatus = mock(FileStatus.class); FsShell mockFsShell = mock(FsShell.class); when(mockSourceStatus.getPermission()).thenReturn(new FsPermission((short) 777)); when(mockHadoopFileStatus.getFileStatus()).thenReturn(mockSourceStatus); doThrow(RuntimeException.class).when(mockFsShell).run(any(String[].class)); HdfsUtils.setFullFileStatus(conf, mockHadoopFileStatus, "", mock(FileSystem.class), fakeTarget, true, mockFsShell); verify(mockFsShell).run(new String[]{"-chmod", "-R", any(String.class), fakeTarget.toString()}); } }
/** * Tests that {@link HdfsUtils#setFullFileStatus(Configuration, HdfsUtils.HadoopFileStatus, String, FileSystem, Path, boolean)} * does not throw an exception when setting the group and with recursion. */ @Test public void testSetFullFileStatusFailInheritGroupRecursive() throws Exception { Configuration conf = new Configuration(); conf.set("dfs.namenode.acls.enabled", "false"); String fakeSourceGroup = "fakeGroup1"; String fakeTargetGroup = "fakeGroup2"; Path fakeTarget = new Path("fakePath"); HdfsUtils.HadoopFileStatus mockHadoopFileStatus = mock(HdfsUtils.HadoopFileStatus.class); FileStatus mockSourceStatus = mock(FileStatus.class); FsShell mockFsShell = mock(FsShell.class); when(mockSourceStatus.getGroup()).thenReturn(fakeSourceGroup); when(mockHadoopFileStatus.getFileStatus()).thenReturn(mockSourceStatus); doThrow(RuntimeException.class).when(mockFsShell).run(any(String[].class)); HdfsUtils.setFullFileStatus(conf, mockHadoopFileStatus, fakeTargetGroup, mock(FileSystem.class), fakeTarget, true, mockFsShell); verify(mockFsShell).run(new String[]{"-chgrp", "-R", fakeSourceGroup, fakeTarget.toString()}); }
/** * Tests that HdfsUtils#setFullFileStatus * does not thrown an exception when setting ACLs and with recursion. */ @Test public void testSetFullFileStatusFailInheritAclsRecursive() throws Exception { Configuration conf = new Configuration(); conf.set("dfs.namenode.acls.enabled", "true"); Path fakeTarget = new Path("fakePath"); HdfsUtils.HadoopFileStatus mockHadoopFileStatus = mock(HdfsUtils.HadoopFileStatus.class); FileStatus mockSourceStatus = mock(FileStatus.class); FsShell mockFsShell = mock(FsShell.class); AclStatus mockAclStatus = mock(AclStatus.class); when(mockSourceStatus.getPermission()).thenReturn(new FsPermission((short) 777)); when(mockAclStatus.toString()).thenReturn(""); when(mockHadoopFileStatus.getFileStatus()).thenReturn(mockSourceStatus); when(mockHadoopFileStatus.getAclEntries()).thenReturn(new ArrayList<>()); when(mockHadoopFileStatus.getAclStatus()).thenReturn(mockAclStatus); doThrow(RuntimeException.class).when(mockFsShell).run(any(String[].class)); HdfsUtils.setFullFileStatus(conf, mockHadoopFileStatus, "", mock(FileSystem.class), fakeTarget, true, mockFsShell); verify(mockFsShell).run(new String[]{"-setfacl", "-R", "--set", any(String.class), fakeTarget.toString()}); }
int retryCount = 10; while (exitCode != 0 && retryCount >= 1) { exitCode = shell.run(new String[] { "-chmod", "-R", "777", input }); retryCount--; Thread.sleep(5000);
int ret = dfs.run(tokens); if (ret != 0) { console.printError("Command " + command + " failed with exit code = " + ret);
int ret = dfs.run(tokens); if (ret != 0) { console.printError("Command " + command + " failed with exit code = " + ret);
FsShell shell=new FsShell(conf); try { shell.run(new String[]{"-chmod","-R","777","user/usr1/data"}); } catch ( Exception e) { LOG.error("Couldnt change the file permissions ",e); throw new IOException(e); }
static String execCmd(FsShell shell, String... args) throws Exception { ByteArrayOutputStream baout = new ByteArrayOutputStream(); PrintStream out = new PrintStream(baout, true); PrintStream old = System.out; System.setOut(out); shell.run(args); out.close(); System.setOut(old); return baout.toString(); }
private static void run(FsShell shell, String[] command) throws Exception { LOG.debug(ArrayUtils.toString(command)); int retval = shell.run(command); LOG.debug("Return value is :" + retval); } public static class HadoopFileStatus {
@Override public int exec(List<String> args, Reader in, Writer out) throws InterruptedException, IOException { FsShell fsShell = new FsShellWithIO(configuration, in, out); try { return fsShell.run(args.subList(1, args.size()).toArray(new String[args.size() - 1])); } catch (Exception e) { LOGGER.error("Failed to execute hdfs shell with args: " + args, e); return 1; } }
@Override public void invoke(String[] command) throws Exception { try { String[] dfsCommands = new String[command.length - 1]; System.arraycopy(command, 1, dfsCommands, 0, dfsCommands.length); fsShell.run(dfsCommands); } catch (Exception e) { context.getError().println("ERROR: " + e.getMessage()); } }
protected void run(FsShell shell, String[] command) throws Exception { LOG.debug(ArrayUtils.toString(command)); int retval = shell.run(command); LOG.debug("Return value is :" + retval); }
private int runCmd(FsShell shell, String... args) throws IOException { try { return shell.run(args); } catch (IOException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IOException(StringUtils.stringifyException(e)); } }
protected void run(FsShell shell, String[] command) throws Exception { LOG.debug(ArrayUtils.toString(command)); int retval = shell.run(command); LOG.debug("Return value is :" + retval); }
static String execCmd(FsShell shell, String... args) throws Exception { ByteArrayOutputStream baout = new ByteArrayOutputStream(); PrintStream out = new PrintStream(baout, true); PrintStream old = System.out; System.setOut(out); shell.run(args); out.close(); System.setOut(old); return baout.toString(); }
static String execCmd(FsShell shell, final String[] args) throws Exception { ByteArrayOutputStream baout = new ByteArrayOutputStream(); PrintStream out = new PrintStream(baout, true); PrintStream old = System.out; System.setOut(out); int ret = shell.run(args); out.close(); System.setOut(old); return String.valueOf(ret); }
protected void run(FsShell shell, String[] command) throws Exception { LOG.debug(ArrayUtils.toString(command)); int retval = shell.run(command); LOG.debug("Return value is :" + retval); }