From 9608601330520990d4470971389d574cfa09736e Mon Sep 17 00:00:00 2001 From: Kihwal Lee Date: Tue, 5 Apr 2016 09:17:57 -0500 Subject: [PATCH] HDFS-10239. Fsshell mv fails if port usage doesn't match in src and destination paths. Contributed by Kuhu Shukla. Conflicts: hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java (cherry picked from commit ef3da823573cbf16fd1d84479330dd457f95e0ff) --- .../apache/hadoop/fs/shell/MoveCommands.java | 6 +++- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../org/apache/hadoop/hdfs/TestDFSShell.java | 33 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java index 1c7316ae65c..20cecb4bedb 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/MoveCommands.java @@ -100,7 +100,11 @@ class MoveCommands { @Override protected void processPath(PathData src, PathData target) throws IOException { - if (!src.fs.getUri().equals(target.fs.getUri())) { + String srcUri = src.fs.getUri().getScheme() + "://" + + src.fs.getUri().getHost(); + String dstUri = target.fs.getUri().getScheme() + "://" + + target.fs.getUri().getHost(); + if (!srcUri.equals(dstUri)) { throw new PathIOException(src.toString(), "Does not match target filesystem"); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 3a77f027fd6..bb37eb85960 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -158,6 +158,9 @@ Release 2.7.3 - UNRELEASED HDFS-9917. IBR accumulate more objects when SNN was down for sometime. (Brahma Reddy Battula via vinayakumarb) + HDFS-10239. Fsshell mv fails if port usage doesn't match in src and + destination paths (Kuhu Shukla via kihwal) + Release 2.7.2 - 2016-01-25 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java index 828d89d8da1..99247758c06 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java @@ -519,7 +519,38 @@ public class TestDFSShell { } } } - + + @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://localhost/testfile2"; + int ret = ToolRunner.run(shell, argv); + assertEquals("mv should have succeeded", 0, ret); + } finally { + if (cluster != null) { + cluster.shutdown(); + } + } + } + @Test (timeout = 30000) public void testURIPaths() throws Exception { Configuration srcConf = new HdfsConfiguration();