HDFS-13710. RBF: setQuota and getQuotaUsage should check the 
dfs.federation.router.quota.enable. Contributed by yanghuafeng.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/43f7fe8a
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/43f7fe8a
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/43f7fe8a

Branch: refs/heads/HDDS-48
Commit: 43f7fe8aae0eca89cce4d67bfc4965fe8ce63e38
Parents: 7a68ac6
Author: Yiqun Lin <yq...@apache.org>
Authored: Mon Jul 9 15:06:07 2018 +0800
Committer: Yiqun Lin <yq...@apache.org>
Committed: Mon Jul 9 15:06:07 2018 +0800

----------------------------------------------------------------------
 .../hdfs/server/federation/router/Quota.java    |  8 ++
 .../federation/router/RouterRpcServer.java      |  1 -
 .../router/TestDisableRouterQuota.java          | 94 ++++++++++++++++++++
 3 files changed, 102 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/43f7fe8a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java
 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java
index 413a4e1..75d3e04 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java
@@ -67,6 +67,9 @@ public class Quota {
   public void setQuota(String path, long namespaceQuota,
       long storagespaceQuota, StorageType type) throws IOException {
     rpcServer.checkOperation(OperationCategory.WRITE);
+    if (!router.isQuotaEnabled()) {
+      throw new IOException("The quota system is disabled in Router.");
+    }
 
     // Set quota for current path and its children mount table path.
     final List<RemoteLocation> locations = getQuotaRemoteLocations(path);
@@ -91,6 +94,11 @@ public class Quota {
    * @throws IOException
    */
   public QuotaUsage getQuotaUsage(String path) throws IOException {
+    rpcServer.checkOperation(OperationCategory.READ);
+    if (!router.isQuotaEnabled()) {
+      throw new IOException("The quota system is disabled in Router.");
+    }
+
     final List<RemoteLocation> quotaLocs = getValidQuotaLocations(path);
     RemoteMethod method = new RemoteMethod("getQuotaUsage",
         new Class<?>[] {String.class}, new RemoteParam());

http://git-wip-us.apache.org/repos/asf/hadoop/blob/43f7fe8a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java
 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java
index 716ebee..7031af7 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterRpcServer.java
@@ -1996,7 +1996,6 @@ public class RouterRpcServer extends AbstractService
 
   @Override // ClientProtocol
   public QuotaUsage getQuotaUsage(String path) throws IOException {
-    checkOperation(OperationCategory.READ);
     return this.quotaCall.getQuotaUsage(path);
   }
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/43f7fe8a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java
 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java
new file mode 100644
index 0000000..2632f59
--- /dev/null
+++ 
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestDisableRouterQuota.java
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.federation.router;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
+
+import java.io.IOException;
+
+import org.apache.hadoop.test.GenericTestUtils;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+/**
+ * Test the behavior when disabling the Router quota.
+ */
+public class TestDisableRouterQuota {
+
+  private static Router router;
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    // Build and start a router
+    router = new Router();
+    Configuration routerConf = new RouterConfigBuilder()
+        .quota(false) //set false to verify the quota disabled in Router
+        .rpc()
+        .build();
+    router.init(routerConf);
+    router.setRouterId("TestRouterId");
+    router.start();
+  }
+
+  @AfterClass
+  public static void tearDown() throws IOException {
+    if (router != null) {
+      router.stop();
+      router.close();
+    }
+  }
+
+  @Before
+  public void checkDisableQuota() {
+    assertFalse(router.isQuotaEnabled());
+  }
+
+  @Test
+  public void testSetQuota() throws Exception {
+    long nsQuota = 1024;
+    long ssQuota = 1024;
+
+    try {
+      Quota quotaModule = router.getRpcServer().getQuotaModule();
+      quotaModule.setQuota("/test", nsQuota, ssQuota, null);
+      fail("The setQuota call should fail.");
+    } catch (IOException ioe) {
+      GenericTestUtils.assertExceptionContains(
+          "The quota system is disabled in Router.", ioe);
+    }
+  }
+
+  @Test
+  public void testGetQuotaUsage() throws Exception {
+    try {
+      Quota quotaModule = router.getRpcServer().getQuotaModule();
+      quotaModule.getQuotaUsage("/test");
+      fail("The getQuotaUsage call should fail.");
+    } catch (IOException ioe) {
+      GenericTestUtils.assertExceptionContains(
+          "The quota system is disabled in Router.", ioe);
+    }
+  }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to