Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 39E1417753 for ; Wed, 25 Mar 2015 14:54:46 +0000 (UTC) Received: (qmail 82063 invoked by uid 500); 25 Mar 2015 14:54:32 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 81955 invoked by uid 500); 25 Mar 2015 14:54:32 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 80057 invoked by uid 99); 25 Mar 2015 14:54:31 -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, 25 Mar 2015 14:54:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 62B22E2EEB; Wed, 25 Mar 2015 14:54:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kasha@apache.org To: common-commits@hadoop.apache.org Date: Wed, 25 Mar 2015 14:54:50 -0000 Message-Id: <1d7394707d1d4a87ac4015e992c9ee8e@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [20/51] [abbrv] hadoop git commit: HDFS-7942. NFS: support regexp grouping in nfs.exports.allowed.hosts. Contributed by Brandon Li HDFS-7942. NFS: support regexp grouping in nfs.exports.allowed.hosts. Contributed by Brandon Li Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/36af4a91 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/36af4a91 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/36af4a91 Branch: refs/heads/YARN-2139 Commit: 36af4a913c97113bd0486c48e1cb864c5cba46fd Parents: 82eda77 Author: Brandon Li Authored: Mon Mar 23 10:06:47 2015 -0700 Committer: Brandon Li Committed: Mon Mar 23 10:06:47 2015 -0700 ---------------------------------------------------------------------- .../java/org/apache/hadoop/nfs/NfsExports.java | 2 +- .../org/apache/hadoop/nfs/TestNfsExports.java | 22 ++++++++++++++++++-- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 ++ .../src/site/markdown/HdfsNfsGateway.md | 8 ++++--- 4 files changed, 28 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/36af4a91/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java index 8b6b46a..af96565 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java @@ -391,7 +391,7 @@ public class NfsExports { return new CIDRMatch(privilege, new SubnetUtils(pair[0], pair[1]).getInfo()); } else if (host.contains("*") || host.contains("?") || host.contains("[") - || host.contains("]")) { + || host.contains("]") || host.contains("(") || host.contains(")")) { if (LOG.isDebugEnabled()) { LOG.debug("Using Regex match for '" + host + "' and " + privilege); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/36af4a91/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java b/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java index 349e82a..542975d 100644 --- a/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java +++ b/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java @@ -23,8 +23,8 @@ import org.junit.Test; public class TestNfsExports { - private final String address1 = "192.168.0.1"; - private final String address2 = "10.0.0.1"; + private final String address1 = "192.168.0.12"; + private final String address2 = "10.0.0.12"; private final String hostname1 = "a.b.com"; private final String hostname2 = "a.b.org"; @@ -165,6 +165,24 @@ public class TestNfsExports { } @Test + public void testRegexGrouping() { + NfsExports matcher = new NfsExports(CacheSize, ExpirationPeriod, + "192.168.0.(12|34)"); + Assert.assertEquals(AccessPrivilege.READ_ONLY, + matcher.getAccessPrivilege(address1, hostname1)); + // address1 will hit the cache + Assert.assertEquals(AccessPrivilege.READ_ONLY, + matcher.getAccessPrivilege(address1, hostname2)); + + matcher = new NfsExports(CacheSize, ExpirationPeriod, "\\w*.a.b.com"); + Assert.assertEquals(AccessPrivilege.READ_ONLY, + matcher.getAccessPrivilege("1.2.3.4", "web.a.b.com")); + // address "1.2.3.4" will hit the cache + Assert.assertEquals(AccessPrivilege.READ_ONLY, + matcher.getAccessPrivilege("1.2.3.4", "email.a.b.org")); + } + + @Test public void testMultiMatchers() throws Exception { long shortExpirationPeriod = 1 * 1000 * 1000 * 1000; // 1s NfsExports matcher = new NfsExports(CacheSize, shortExpirationPeriod, http://git-wip-us.apache.org/repos/asf/hadoop/blob/36af4a91/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index e82c4c4..8c99876 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1232,6 +1232,8 @@ Release 2.7.0 - UNRELEASED HDFS-6841. Use Time.monotonicNow() wherever applicable instead of Time.now() (Vinayakumar B via kihwal) + HDFS-7942. NFS: support regexp grouping in nfs.exports.allowed.hosts (brandonli) + BREAKDOWN OF HDFS-7584 SUBTASKS AND RELATED JIRAS HDFS-7720. Quota by Storage Type API, tools and ClientNameNode http://git-wip-us.apache.org/repos/asf/hadoop/blob/36af4a91/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HdfsNfsGateway.md ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HdfsNfsGateway.md b/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HdfsNfsGateway.md index e6666d4..b7e1733 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HdfsNfsGateway.md +++ b/hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HdfsNfsGateway.md @@ -144,10 +144,12 @@ It's strongly recommended for the users to update a few configuration properties * By default, the export can be mounted by any client. To better control the access, users can update the following property. The value string contains machine name and access privilege, separated by whitespace - characters. The machine name format can be a single host, a Java regular expression, or an IPv4 address. The access + characters. The machine name format can be a single host, a "*", a Java regular expression, or an IPv4 address. The access privilege uses rw or ro to specify read/write or read-only access of the machines to exports. If the access privilege is not provided, the default is read-only. Entries are separated by ";". - For example: "192.168.0.0/22 rw ; host.\*\\.example\\.com ; host1.test.org ro;". Only the NFS gateway needs to restart after - this property is updated. + For example: "192.168.0.0/22 rw ; \\\\w\*\\\\.example\\\\.com ; host1.test.org ro;". Only the NFS gateway needs to restart after + this property is updated. Note that, here Java regular expression is differnt with the regrulation expression used in + Linux NFS export table, such as, using "\\\\w\*\\\\.example\\\\.com" instead of "\*.example.com", "192\\\\.168\\\\.0\\\\.(11|22)" + instead of "192.168.0.[11|22]" and so on. nfs.exports.allowed.hosts