-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HDFS-15423 RBF: WebHDFS create shouldn't choose DN from all sub-clusters #2605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
297652d
HDFS-15423 [RBF] WebHDFS create file in the resolved nameservice
fengnanli 167d2fc
Address comments
fengnanli bd3a7bb
More fixes
fengnanli 98c69ac
Fix all flaky tests
fengnanli 862d0e6
Fix initialization for variables
fengnanli d6e854c
Fix log
fengnanli 636c5f7
More comments
fengnanli 0dcd395
Address comments
fengnanli e413f34
Address comments
fengnanli 91053da
Address comments
fengnanli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
...c/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterWebHdfsMethods.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| /** | ||
| * 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 static org.apache.hadoop.hdfs.server.federation.FederationTestUtils.createMountTableEntry; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.URL; | ||
| import java.util.Collections; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterContext; | ||
| import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder; | ||
| import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster; | ||
| import org.apache.hadoop.hdfs.server.federation.resolver.order.DestinationOrder; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Test suite for Router Web Hdfs methods. | ||
| */ | ||
| public class TestRouterWebHdfsMethods { | ||
| static final Logger LOG = | ||
| LoggerFactory.getLogger(TestRouterWebHdfsMethods.class); | ||
|
|
||
| private static StateStoreDFSCluster cluster; | ||
| private static RouterContext router; | ||
| private static String httpUri; | ||
|
|
||
| @BeforeClass | ||
| public static void globalSetUp() throws Exception { | ||
| cluster = new StateStoreDFSCluster(false, 2); | ||
| Configuration conf = new RouterConfigBuilder() | ||
| .stateStore() | ||
| .rpc() | ||
| .http() | ||
| .admin() | ||
| .build(); | ||
| cluster.addRouterOverrides(conf); | ||
| cluster.startCluster(); | ||
| cluster.startRouters(); | ||
| cluster.waitClusterUp(); | ||
| router = cluster.getRandomRouter(); | ||
| httpUri = "http://"+router.getHttpAddress(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() { | ||
| if (cluster != null) { | ||
| cluster.shutdown(); | ||
| cluster = null; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testWebHdfsCreate() throws Exception { | ||
| // the file is created at default ns (ns0) | ||
| String path = "/tmp/file"; | ||
| URL url = new URL(getUri(path)); | ||
| LOG.info("URL: {}", url); | ||
| HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | ||
| conn.setRequestMethod("PUT"); | ||
| assertEquals(HttpURLConnection.HTTP_CREATED, conn.getResponseCode()); | ||
| verifyFile("ns0", path, true); | ||
| verifyFile("ns1", path, false); | ||
| conn.disconnect(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testWebHdfsCreateWithMounts() throws Exception { | ||
| // the file is created at mounted ns (ns1) | ||
| String mountPoint = "/tmp-ns1"; | ||
goiri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| String path = "/tmp-ns1/file"; | ||
| createMountTableEntry( | ||
| router.getRouter(), mountPoint, | ||
| DestinationOrder.RANDOM, Collections.singletonList("ns1")); | ||
| URL url = new URL(getUri(path)); | ||
| LOG.info("URL: {}", url); | ||
| HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | ||
| conn.setRequestMethod("PUT"); | ||
| assertEquals(HttpURLConnection.HTTP_CREATED, conn.getResponseCode()); | ||
| verifyFile("ns1", path, true); | ||
| verifyFile("ns0", path, false); | ||
| conn.disconnect(); | ||
| } | ||
|
|
||
| private String getUri(String path) { | ||
| final String user = System.getProperty("user.name"); | ||
| final StringBuilder uri = new StringBuilder(httpUri); | ||
| uri.append("/webhdfs/v1"). | ||
| append(path). | ||
| append("?op=CREATE"). | ||
| append("&user.name=" + user); | ||
| return uri.toString(); | ||
| } | ||
|
|
||
| private void verifyFile(String ns, String path, boolean shouldExist) | ||
| throws Exception { | ||
| FileSystem fs = cluster.getNamenode(ns, null).getFileSystem(); | ||
| try { | ||
| fs.getFileStatus(new Path(path)); | ||
| if (!shouldExist) { | ||
| fail(path + " should not exist in ns " + ns); | ||
| } | ||
| } catch (FileNotFoundException e) { | ||
| if (shouldExist) { | ||
| fail(path + " should exist in ns " + ns); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetNsFromDataNodeNetworkLocation() { | ||
| assertEquals("ns0", RouterWebHdfsMethods | ||
| .getNsFromDataNodeNetworkLocation("/ns0/rack-info1")); | ||
fengnanli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assertEquals("ns0", RouterWebHdfsMethods | ||
| .getNsFromDataNodeNetworkLocation("/ns0/row1/rack-info1")); | ||
| assertEquals("", RouterWebHdfsMethods | ||
| .getNsFromDataNodeNetworkLocation("/row0")); | ||
| assertEquals("", RouterWebHdfsMethods | ||
| .getNsFromDataNodeNetworkLocation("whatever-rack-info1")); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.