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

This commit is contained in:
Yiqun Lin 2018-07-09 15:06:07 +08:00
parent 7a68ac607c
commit 43f7fe8aae
3 changed files with 102 additions and 1 deletions

View File

@ -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());

View File

@ -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);
}

View File

@ -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);
}
}
}