Skip to content

Commit 44da465

Browse files
anujmodi2021Anuj Modi
authored andcommitted
HADOOP-19284: [ABFS] Allow "fs.azure.account.hns.enabled" to be set as Account Specific Config (#7062)
1 parent 4b38645 commit 44da465

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/AbfsConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ public AbfsConfiguration(final Configuration rawConfig, String accountName)
414414
}
415415

416416
public Trilean getIsNamespaceEnabledAccount() {
417-
return Trilean.getTrilean(isNamespaceEnabledAccount);
417+
return Trilean.getTrilean(
418+
getString(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, isNamespaceEnabledAccount));
418419
}
419420

420421
/**

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemE2E.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_HTTP_READ_TIMEOUT;
4141
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_MAX_IO_RETRIES;
4242
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_TOLERATE_CONCURRENT_APPEND;
43+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ACCOUNT_IS_HNS_ENABLED;
4344
import static org.apache.hadoop.fs.contract.ContractTestUtils.assertPathDoesNotExist;
4445
import static org.apache.hadoop.fs.contract.ContractTestUtils.assertPathExists;
4546
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
@@ -259,6 +260,9 @@ public void testHttpReadTimeout() throws Exception {
259260

260261
public void testHttpTimeouts(int connectionTimeoutMs, int readTimeoutMs)
261262
throws Exception {
263+
// This is to make sure File System creation goes through before network calls start failing.
264+
assumeValidTestConfigPresent(this.getRawConfiguration(), FS_AZURE_ACCOUNT_IS_HNS_ENABLED);
265+
262266
Configuration conf = this.getRawConfiguration();
263267
// set to small values that will cause timeouts
264268
conf.setInt(AZURE_HTTP_CONNECTION_TIMEOUT, connectionTimeoutMs);

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestGetNameSpaceEnabled.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
4141
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
4242
import static java.net.HttpURLConnection.HTTP_UNAVAILABLE;
43+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_MAX_IO_RETRIES;
44+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.accountProperty;
4345
import static org.mockito.ArgumentMatchers.any;
4446
import static org.mockito.ArgumentMatchers.anyString;
4547
import static org.mockito.Mockito.doReturn;
@@ -125,6 +127,8 @@ private AzureBlobFileSystem getNewFSWithHnsConf(
125127
Configuration rawConfig = new Configuration();
126128
rawConfig.addResource(TEST_CONFIGURATION_FILE_NAME);
127129
rawConfig.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, isNamespaceEnabledAccount);
130+
rawConfig.set(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED,
131+
this.getAccountName()), isNamespaceEnabledAccount);
128132
rawConfig
129133
.setBoolean(AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION, true);
130134
rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY,
@@ -265,4 +269,65 @@ private void ensureGetAclDetermineHnsStatusAccuratelyInternal(int statusCode,
265269
Mockito.verify(mockClient, times(1))
266270
.getAclStatus(anyString(), any(TracingContext.class));
267271
}
272+
273+
@Test
274+
public void testAccountSpecificConfig() throws Exception {
275+
Configuration rawConfig = new Configuration();
276+
rawConfig.addResource(TEST_CONFIGURATION_FILE_NAME);
277+
rawConfig.unset(FS_AZURE_ACCOUNT_IS_HNS_ENABLED);
278+
rawConfig.unset(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED,
279+
this.getAccountName()));
280+
String testAccountName = "testAccount.dfs.core.windows.net";
281+
String otherAccountName = "otherAccount.dfs.core.windows.net";
282+
String defaultUri = this.getTestUrl().replace(this.getAccountName(), testAccountName);
283+
String otherUri = this.getTestUrl().replace(this.getAccountName(), otherAccountName);
284+
285+
// Set both account specific and account agnostic config for test account
286+
rawConfig.set(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, testAccountName), FALSE_STR);
287+
rawConfig.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, TRUE_STR);
288+
// Assert that account specific config takes precedence
289+
rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri);
290+
assertFileSystemInitWithExpectedHNSSettings(rawConfig, false);
291+
// Assert that other account still uses account agnostic config
292+
rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, otherUri);
293+
assertFileSystemInitWithExpectedHNSSettings(rawConfig, true);
294+
295+
// Set only the account specific config for test account
296+
rawConfig.set(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, testAccountName), FALSE_STR);
297+
rawConfig.unset(FS_AZURE_ACCOUNT_IS_HNS_ENABLED);
298+
// Assert that only account specific config is enough for test account
299+
rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri);
300+
assertFileSystemInitWithExpectedHNSSettings(rawConfig, false);
301+
302+
// Set only account agnostic config
303+
rawConfig.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, FALSE_STR);
304+
rawConfig.unset(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, testAccountName));
305+
rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri);
306+
assertFileSystemInitWithExpectedHNSSettings(rawConfig, false);
307+
308+
// Unset both account specific and account agnostic config
309+
rawConfig.unset(FS_AZURE_ACCOUNT_IS_HNS_ENABLED);
310+
rawConfig.unset(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, testAccountName));
311+
rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri);
312+
rawConfig.set(AZURE_MAX_IO_RETRIES, "0");
313+
// Assert that file system init fails with UnknownHost exception as getAcl() is needed.
314+
try {
315+
assertFileSystemInitWithExpectedHNSSettings(rawConfig, false);
316+
} catch (Exception e) {
317+
Assertions.assertThat(e.getCause().getMessage())
318+
.describedAs("getAcl() to determine HNS Nature of account should"
319+
+ "fail with Unknown Host Exception").contains("UnknownHostException");
320+
}
321+
}
322+
323+
private void assertFileSystemInitWithExpectedHNSSettings(
324+
Configuration configuration, boolean expectedIsHnsEnabledValue) throws IOException {
325+
try (AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration)) {
326+
Assertions.assertThat(getIsNamespaceEnabled(fs)).describedAs(
327+
"getIsNamespaceEnabled should return true when the "
328+
+ "account specific config is not set").isEqualTo(expectedIsHnsEnabledValue);
329+
} catch (Exception e) {
330+
throw e;
331+
}
332+
}
268333
}

0 commit comments

Comments
 (0)