Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D38AD200BE3 for ; Thu, 8 Dec 2016 00:58:37 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D222C160B26; Wed, 7 Dec 2016 23:58:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 01002160B0C for ; Thu, 8 Dec 2016 00:58:36 +0100 (CET) Received: (qmail 25618 invoked by uid 500); 7 Dec 2016 23:58:36 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 25609 invoked by uid 99); 7 Dec 2016 23:58:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Dec 2016 23:58:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E5EC7DFF56; Wed, 7 Dec 2016 23:58:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: wang@apache.org To: common-commits@hadoop.apache.org Message-Id: <02e02a23025d4d399150d079c5d87fd7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HDFS-9057. allow/disallow snapshots via webhdfs (Contributed by Brahma Reddy Battula) Date: Wed, 7 Dec 2016 23:58:35 +0000 (UTC) archived-at: Wed, 07 Dec 2016 23:58:38 -0000 Repository: hadoop Updated Branches: refs/heads/branch-2 9cba7c6d7 -> 4b21b47f5 HDFS-9057. allow/disallow snapshots via webhdfs (Contributed by Brahma Reddy Battula) (cherry picked from commit 6d2332ae375e26d024358c6e75fdb3c68a781a66) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/4b21b47f Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/4b21b47f Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/4b21b47f Branch: refs/heads/branch-2 Commit: 4b21b47f5607027672403fce211165abe03b9a77 Parents: 9cba7c6 Author: Vinayakumar B Authored: Sun Nov 8 16:24:27 2015 +0530 Committer: Andrew Wang Committed: Wed Dec 7 15:58:15 2016 -0800 ---------------------------------------------------------------------- .../hadoop/hdfs/web/WebHdfsFileSystem.java | 12 +++++ .../hadoop/hdfs/web/resources/PutOpParam.java | 2 + .../web/resources/NamenodeWebHdfsMethods.java | 8 +++ .../org/apache/hadoop/hdfs/web/TestWebHDFS.java | 55 ++++++++++++++++++++ 4 files changed, 77 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/4b21b47f/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java index c0d6de9..308e0d8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java @@ -1231,6 +1231,12 @@ public class WebHdfsFileSystem extends FileSystem new FsPathRunner(op, p, new AclPermissionParam(aclSpec)).run(); } + public void allowSnapshot(final Path p) throws IOException { + statistics.incrementWriteOps(1); + final HttpOpParam.Op op = PutOpParam.Op.ALLOWSNAPSHOT; + new FsPathRunner(op, p).run(); + } + @Override public Path createSnapshot(final Path path, final String snapshotName) throws IOException { @@ -1246,6 +1252,12 @@ public class WebHdfsFileSystem extends FileSystem }.run(); } + public void disallowSnapshot(final Path p) throws IOException { + statistics.incrementWriteOps(1); + final HttpOpParam.Op op = PutOpParam.Op.DISALLOWSNAPSHOT; + new FsPathRunner(op, p).run(); + } + @Override public void deleteSnapshot(final Path path, final String snapshotName) throws IOException { http://git-wip-us.apache.org/repos/asf/hadoop/blob/4b21b47f/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java index d1e08fd..f36f874 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/PutOpParam.java @@ -46,6 +46,8 @@ public class PutOpParam extends HttpOpParam { SETXATTR(false, HttpURLConnection.HTTP_OK), REMOVEXATTR(false, HttpURLConnection.HTTP_OK), + ALLOWSNAPSHOT(false, HttpURLConnection.HTTP_OK), + DISALLOWSNAPSHOT(false, HttpURLConnection.HTTP_OK), CREATESNAPSHOT(false, HttpURLConnection.HTTP_OK), RENAMESNAPSHOT(false, HttpURLConnection.HTTP_OK), http://git-wip-us.apache.org/repos/asf/hadoop/blob/4b21b47f/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java index 80bff88..91a9d37 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java @@ -645,6 +645,10 @@ public class NamenodeWebHdfsMethods { np.removeXAttr(fullpath, XAttrHelper.buildXAttr(xattrName.getXAttrName())); return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build(); } + case ALLOWSNAPSHOT: { + np.allowSnapshot(fullpath); + return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build(); + } case CREATESNAPSHOT: { String snapshotPath = np.createSnapshot(fullpath, snapshotName.getValue()); final String js = JsonUtil.toJsonString( @@ -656,6 +660,10 @@ public class NamenodeWebHdfsMethods { snapshotName.getValue()); return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build(); } + case DISALLOWSNAPSHOT: { + np.disallowSnapshot(fullpath); + return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build(); + } default: throw new UnsupportedOperationException(op + " is not supported"); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/4b21b47f/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java index 7ac928e..9855a38 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java @@ -63,6 +63,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.TestDFSClientRetries; import org.apache.hadoop.hdfs.TestFileCreation; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; +import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus; import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotTestHelper; import org.apache.hadoop.hdfs.server.namenode.web.resources.NamenodeWebHdfsMethods; @@ -420,6 +421,60 @@ public class TestWebHDFS { } /** + * Test allow and disallow snapshot through WebHdfs. Verifying webhdfs with + * Distributed filesystem methods. + */ + @Test + public void testWebHdfsAllowandDisallowSnapshots() throws Exception { + MiniDFSCluster cluster = null; + final Configuration conf = WebHdfsTestUtil.createConf(); + try { + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); + cluster.waitActive(); + final DistributedFileSystem dfs = cluster.getFileSystem(); + final WebHdfsFileSystem webHdfs = WebHdfsTestUtil + .getWebHdfsFileSystem(conf, WebHdfsConstants.WEBHDFS_SCHEME); + + final Path bar = new Path("/bar"); + dfs.mkdirs(bar); + + // allow snapshots on /bar using webhdfs + webHdfs.allowSnapshot(bar); + webHdfs.createSnapshot(bar, "s1"); + final Path s1path = SnapshotTestHelper.getSnapshotRoot(bar, "s1"); + Assert.assertTrue(webHdfs.exists(s1path)); + SnapshottableDirectoryStatus[] snapshottableDirs = + dfs.getSnapshottableDirListing(); + assertEquals(1, snapshottableDirs.length); + assertEquals(bar, snapshottableDirs[0].getFullPath()); + dfs.deleteSnapshot(bar, "s1"); + dfs.disallowSnapshot(bar); + snapshottableDirs = dfs.getSnapshottableDirListing(); + assertNull(snapshottableDirs); + + // disallow snapshots on /bar using webhdfs + dfs.allowSnapshot(bar); + snapshottableDirs = dfs.getSnapshottableDirListing(); + assertEquals(1, snapshottableDirs.length); + assertEquals(bar, snapshottableDirs[0].getFullPath()); + webHdfs.disallowSnapshot(bar); + snapshottableDirs = dfs.getSnapshottableDirListing(); + assertNull(snapshottableDirs); + try { + webHdfs.createSnapshot(bar); + fail("Cannot create snapshot on a non-snapshottable directory"); + } catch (Exception e) { + GenericTestUtils.assertExceptionContains( + "Directory is not a snapshottable directory", e); + } + } finally { + if (cluster != null) { + cluster.shutdown(); + } + } + } + + /** * Test snapshot creation through WebHdfs */ @Test --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org