/** * main() has some simple utility methods * @param argv the command and its arguments * @throws Exception upon error */ public static void main(String argv[]) throws Exception { FsShell shell = newShellInstance(); Configuration conf = new Configuration(); conf.setQuietMode(false); shell.setConf(conf); int res; try { res = ToolRunner.run(shell, argv); } finally { shell.close(); } System.exit(res); }
fsShell.setConf(conf);
fsShell.setConf(conf);
/** * main() has some simple utility methods * @param argv the command and its arguments * @throws Exception upon error */ public static void main(String argv[]) throws Exception { FsShell shell = newShellInstance(); Configuration conf = new Configuration(); conf.setQuietMode(false); shell.setConf(conf); int res; try { res = ToolRunner.run(shell, argv); } finally { shell.close(); } System.exit(res); }
/** * main() has some simple utility methods * @param argv the command and its arguments * @throws Exception upon error */ public static void main(String argv[]) throws Exception { FsShell shell = newShellInstance(); Configuration conf = new Configuration(); conf.setQuietMode(false); shell.setConf(conf); int res; try { res = ToolRunner.run(shell, argv); } finally { shell.close(); } System.exit(res); }
/** * main() has some simple utility methods * @param argv the command and its arguments * @throws Exception upon error */ public static void main(String argv[]) throws Exception { FsShell shell = newShellInstance(); Configuration conf = new Configuration(); conf.setQuietMode(false); shell.setConf(conf); int res; try { res = ToolRunner.run(shell, argv); } finally { shell.close(); } System.exit(res); }
/** * main() has some simple utility methods * @param argv the command and its arguments * @throws Exception upon error */ public static void main(String argv[]) throws Exception { FsShell shell = newShellInstance(); Configuration conf = new Configuration(); conf.setQuietMode(false); shell.setConf(conf); int res; try { res = ToolRunner.run(shell, argv); } finally { shell.close(); } System.exit(res); }
@Test public void testGetWithInvalidSourcePathShouldNotDisplayNullInConsole() throws Exception { Configuration conf = new Configuration(); FsShell shell = new FsShell(); shell.setConf(conf); final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final PrintStream out = new PrintStream(bytes); final PrintStream oldErr = System.err; System.setErr(out); final String results; try { FileSystem fileSys = FileSystem.getLocal(conf); String[] args = new String[3]; args[0] = "-get"; args[1] = "/invalidPath"; args[2] = "/test/tmp"; assertTrue("file exists", !fileSys.exists(new Path(args[1]))); int run = shell.run(args); results = bytes.toString(); assertTrue("Return code should be -1", run == -1); assertTrue(" Null is coming when source path is invalid. ",!results.contains("get: null")); assertTrue(" Not displaying the intended message ",results.contains("get: "+args[1]+": No such file or directory")); } finally { IOUtils.closeStream(out); System.setErr(oldErr); } }
@Override public void setFullFileStatus(Configuration conf, HdfsFileStatus sourceStatus, FileSystem fs, Path target) throws IOException { String group = sourceStatus.getFileStatus().getGroup(); String permission = Integer.toString(sourceStatus.getFileStatus().getPermission().toShort(), 8); //use FsShell to change group and permissions recursively try { FsShell fshell = new FsShell(); fshell.setConf(conf); run(fshell, new String[]{"-chgrp", "-R", group, target.toString()}); run(fshell, new String[]{"-chmod", "-R", permission, target.toString()}); } catch (Exception e) { throw new IOException("Unable to set permissions of " + target, e); } try { if (LOG.isDebugEnabled()) { //some trace logging getFullFileStatus(conf, fs, target).debugLog(); } } catch (Exception e) { //ignore. } }
@Override public void setFullFileStatus(Configuration conf, HdfsFileStatus sourceStatus, FileSystem fs, Path target) throws IOException { String group = sourceStatus.getFileStatus().getGroup(); String permission = Integer.toString(sourceStatus.getFileStatus().getPermission().toShort(), 8); //use FsShell to change group and permissions recursively try { FsShell fshell = new FsShell(); fshell.setConf(conf); run(fshell, new String[]{"-chgrp", "-R", group, target.toString()}); run(fshell, new String[]{"-chmod", "-R", permission, target.toString()}); } catch (Exception e) { throw new IOException("Unable to set permissions of " + target, e); } try { if (LOG.isDebugEnabled()) { //some trace logging getFullFileStatus(conf, fs, target).debugLog(); } } catch (Exception e) { //ignore. } }
@Override public void setFullFileStatus(Configuration conf, HdfsFileStatus sourceStatus, FileSystem fs, Path target) throws IOException { String group = sourceStatus.getFileStatus().getGroup(); String permission = Integer.toString(sourceStatus.getFileStatus().getPermission().toShort(), 8); //use FsShell to change group and permissions recursively try { FsShell fshell = new FsShell(); fshell.setConf(conf); run(fshell, new String[]{"-chgrp", "-R", group, target.toString()}); run(fshell, new String[]{"-chmod", "-R", permission, target.toString()}); } catch (Exception e) { throw new IOException("Unable to set permissions of " + target, e); } try { if (LOG.isDebugEnabled()) { //some trace logging getFullFileStatus(conf, fs, target).debugLog(); } } catch (Exception e) { //ignore. } }
@Test (timeout = 30000) public void testRmForceWithNonexistentGlob() throws Exception { Configuration conf = new Configuration(); FsShell shell = new FsShell(); shell.setConf(conf); final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final PrintStream err = new PrintStream(bytes); final PrintStream oldErr = System.err; System.setErr(err); try { int exit = shell.run(new String[]{"-rm", "-f", "nomatch*"}); assertEquals(0, exit); assertTrue(bytes.toString().isEmpty()); } finally { IOUtils.closeStream(err); System.setErr(oldErr); } }
Configuration conf = new Configuration(); conf.set(FS_DEFAULT_NAME_KEY, "hhhh://doesnotexist/"); shell.setConf(conf); String [] args = new String[2]; args[0] = "-ls"; int res = shell.run(args); System.out.println("res =" + res); shell.setConf(conf); final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final PrintStream out = new PrintStream(bytes);
@Test (timeout = 30000) public void testRmForceWithNonexistentGlob() throws Exception { Configuration conf = new Configuration(); FsShell shell = new FsShell(); shell.setConf(conf); final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final PrintStream err = new PrintStream(bytes); final PrintStream oldErr = System.err; System.setErr(err); try { int exit = shell.run(new String[]{"-rm", "-f", "nomatch*"}); assertEquals(0, exit); assertTrue(bytes.toString().isEmpty()); } finally { IOUtils.closeStream(err); System.setErr(oldErr); } }
@Test (timeout = 30000) public void testRmWithNonexistentGlob() throws Exception { Configuration conf = new Configuration(); FsShell shell = new FsShell(); shell.setConf(conf); final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final PrintStream err = new PrintStream(bytes); final PrintStream oldErr = System.err; System.setErr(err); final String results; try { int exit = shell.run(new String[]{"-rm", "nomatch*"}); assertEquals(1, exit); results = bytes.toString(); assertTrue(results.contains("rm: `nomatch*': No such file or directory")); } finally { IOUtils.closeStream(err); System.setErr(oldErr); } }
@Test (timeout = 30000) public void testRmWithNonexistentGlob() throws Exception { Configuration conf = new Configuration(); FsShell shell = new FsShell(); shell.setConf(conf); final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final PrintStream err = new PrintStream(bytes); final PrintStream oldErr = System.err; System.setErr(err); final String results; try { int exit = shell.run(new String[]{"-rm", "nomatch*"}); assertEquals(1, exit); results = bytes.toString(); assertTrue(results.contains("rm: `nomatch*': No such file or directory")); } finally { IOUtils.closeStream(err); System.setErr(oldErr); } }
@Test public void testDeleteSnapshotCommandWithIllegalArguments() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream psOut = new PrintStream(out); System.setOut(psOut); System.setErr(psOut); FsShell shell = new FsShell(); shell.setConf(conf); String[] argv1 = {"-deleteSnapshot", "/tmp"}; int val = shell.run(argv1); assertTrue(val == -1); assertTrue(out.toString().contains( argv1[0] + ": Incorrect number of arguments.")); out.reset(); String[] argv2 = {"-deleteSnapshot", "/tmp", "s1", "s2"}; val = shell.run(argv2); assertTrue(val == -1); assertTrue(out.toString().contains( argv2[0] + ": Incorrect number of arguments.")); psOut.close(); out.close(); }
DistributedFileSystem dfs = (DistributedFileSystem)cluster.getFileSystem(); FsShell shell = new FsShell(); shell.setConf(conf);
@Test public void testRenameSnapshotCommandWithIllegalArguments() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream psOut = new PrintStream(out); System.setOut(psOut); System.setErr(psOut); FsShell shell = new FsShell(); shell.setConf(conf); String[] argv1 = {"-renameSnapshot", "/tmp", "s1"}; int val = shell.run(argv1); assertTrue(val == -1); assertTrue(out.toString().contains( argv1[0] + ": Incorrect number of arguments.")); out.reset(); String[] argv2 = {"-renameSnapshot", "/tmp", "s1", "s2", "s3"}; val = shell.run(argv2); assertTrue(val == -1); assertTrue(out.toString().contains( argv2[0] + ": Incorrect number of arguments.")); psOut.close(); out.close(); } }
@Test public void testMoveWithTargetPortEmpty() throws Exception { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf) .format(true) .numDataNodes(2) .nameNodePort(8020) .waitSafeMode(true) .build(); FileSystem srcFs = cluster.getFileSystem(); FsShell shell = new FsShell(); shell.setConf(conf); String[] argv = new String[2]; argv[0] = "-mkdir"; argv[1] = "/testfile"; ToolRunner.run(shell, argv); argv = new String[3]; argv[0] = "-mv"; argv[1] = srcFs.getUri() + "/testfile"; argv[2] = "hdfs://" + srcFs.getUri().getHost() + "/testfile2"; int ret = ToolRunner.run(shell, argv); assertEquals("mv should have succeeded", 0, ret); } finally { if (cluster != null) { cluster.shutdown(); } } }