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 413a4e1d099..75d3e0498dd 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 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 quotaLocs = getValidQuotaLocations(path); RemoteMethod method = new RemoteMethod("getQuotaUsage", new Class[] {String.class}, new RemoteParam()); 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 716ebee9bc4..7031af71fa8 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); } 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 00000000000..2632f5936fb --- /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); + } + } + +}