Skip to content

Commit 049e9c5

Browse files
author
Anuj Modi
committed
HNS-Blob fails FS init
1 parent fcdeb59 commit 049e9c5

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

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

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import org.apache.commons.lang3.StringUtils;
4747
import org.apache.hadoop.classification.VisibleForTesting;
48+
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidConfigurationValueException;
4849
import org.apache.hadoop.fs.impl.BackReference;
4950
import org.apache.hadoop.security.ProviderUtils;
5051
import org.apache.hadoop.util.Preconditions;
@@ -109,13 +110,16 @@
109110
import org.apache.hadoop.util.LambdaUtils;
110111
import org.apache.hadoop.util.Progressable;
111112

113+
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
112114
import static java.net.HttpURLConnection.HTTP_CONFLICT;
115+
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
113116
import static org.apache.hadoop.fs.CommonConfigurationKeys.IOSTATISTICS_LOGGING_LEVEL;
114117
import static org.apache.hadoop.fs.CommonConfigurationKeys.IOSTATISTICS_LOGGING_LEVEL_DEFAULT;
115118
import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_STANDARD_OPTIONS;
116119
import static org.apache.hadoop.fs.azurebfs.AbfsStatistic.*;
117120
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.CPK_IN_NON_HNS_ACCOUNT_ERROR_MESSAGE;
118121
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.DATA_BLOCKS_BUFFER;
122+
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ACCOUNT_IS_HNS_ENABLED;
119123
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_BLOCK_UPLOAD_ACTIVE_BLOCKS;
120124
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_BLOCK_UPLOAD_BUFFER_DIR;
121125
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.BLOCK_UPLOAD_ACTIVE_BLOCKS_DEFAULT;
@@ -213,6 +217,23 @@ public void initialize(URI uri, Configuration configuration)
213217

214218
TracingContext tracingContext = new TracingContext(clientCorrelationId,
215219
fileSystemId, FSOperationType.CREATE_FILESYSTEM, tracingHeaderFormat, listener);
220+
221+
/*
222+
* Validate the service type configured in the URI is valid for account type used.
223+
* HNS Account Cannot have Blob Endpoint URI.
224+
*/
225+
try {
226+
abfsConfiguration.validateConfiguredServiceType(
227+
tryGetIsNamespaceEnabled(new TracingContext(tracingContext)));
228+
} catch (InvalidConfigurationValueException ex) {
229+
LOG.debug("File system configured with Invalid Service Type", ex);
230+
throw ex;
231+
} catch (AzureBlobFileSystemException ex) {
232+
LOG.debug("Enable to determine account type for service type validation", ex);
233+
throw new InvalidConfigurationValueException(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, ex);
234+
}
235+
236+
// Create the file system if it does not exist.
216237
if (abfsConfiguration.getCreateRemoteFileSystemDuringInitialization()) {
217238
if (this.tryGetFileStatus(new Path(AbfsHttpConstants.ROOT_PATH), tracingContext) == null) {
218239
try {
@@ -223,25 +244,14 @@ public void initialize(URI uri, Configuration configuration)
223244
}
224245
}
225246

226-
/*
227-
* Validate the service type configured in the URI is valid for account type used.
228-
* HNS Account Cannot have Blob Endpoint URI.
229-
*/
230-
abfsConfiguration.validateConfiguredServiceType(getIsNamespaceEnabled(
231-
new TracingContext(clientCorrelationId, fileSystemId,
232-
FSOperationType.INIT, tracingHeaderFormat, listener)));
233-
234247
/*
235248
* Non-hierarchical-namespace account can not have a customer-provided-key(CPK).
236249
* Fail initialization of filesystem if the configs are provided. CPK is of
237250
* two types: GLOBAL_KEY, and ENCRYPTION_CONTEXT.
238251
*/
239252
if ((isEncryptionContextCPK(abfsConfiguration) || isGlobalKeyCPK(
240253
abfsConfiguration))
241-
&& !getIsNamespaceEnabled(
242-
new TracingContext(clientCorrelationId, fileSystemId,
243-
FSOperationType.CREATE_FILESYSTEM, tracingHeaderFormat,
244-
listener))) {
254+
&& !getIsNamespaceEnabled(new TracingContext(tracingContext))) {
245255
/*
246256
* Close the filesystem gracefully before throwing exception. Graceful close
247257
* will ensure that all resources are released properly.
@@ -1407,6 +1417,29 @@ private FileStatus tryGetFileStatus(final Path f, TracingContext tracingContext)
14071417
}
14081418
}
14091419

1420+
private boolean tryGetIsNamespaceEnabled(TracingContext tracingContext)
1421+
throws AzureBlobFileSystemException{
1422+
try {
1423+
return getIsNamespaceEnabled(tracingContext);
1424+
} catch (AbfsRestOperationException ex) {
1425+
/*
1426+
* Exception will be thrown for any non 400 error code.
1427+
* If status code is in 4xx range, it means it's an HNS account.
1428+
* If status code is in 5xx range, it means nothing can be inferred.
1429+
* In case of network errors status code will be -1.
1430+
*/
1431+
int statusCode = ex.getStatusCode();
1432+
if (statusCode > HTTP_BAD_REQUEST && statusCode < HTTP_INTERNAL_ERROR) {
1433+
LOG.debug("getNamespace failed with non 400 user error", ex);
1434+
statIncrement(ERROR_IGNORED);
1435+
return true;
1436+
}
1437+
throw ex;
1438+
} catch (AzureBlobFileSystemException ex) {
1439+
throw ex;
1440+
}
1441+
}
1442+
14101443
private boolean fileSystemExists() throws IOException {
14111444
LOG.debug(
14121445
"AzureBlobFileSystem.fileSystemExists uri: {}", uri);

0 commit comments

Comments
 (0)