Skip to content
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

HADOOP-17194. Adding Context class for AbfsClient in ABFS #2216

Merged
merged 3 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import org.apache.hadoop.fs.azurebfs.oauth2.IdentityTransformerInterface;
import org.apache.hadoop.fs.azurebfs.services.AbfsAclHelper;
import org.apache.hadoop.fs.azurebfs.services.AbfsClient;
import org.apache.hadoop.fs.azurebfs.services.AbfsClientContext;
import org.apache.hadoop.fs.azurebfs.services.AbfsCounters;
import org.apache.hadoop.fs.azurebfs.services.AbfsHttpOperation;
import org.apache.hadoop.fs.azurebfs.services.AbfsInputStream;
Expand Down Expand Up @@ -146,6 +147,7 @@ public class AzureBlobFileSystemStore implements Closeable {
private final UserGroupInformation userGroupInformation;
private final IdentityTransformerInterface identityTransformer;
private final AbfsPerfTracker abfsPerfTracker;
private final AbfsCounters abfsCounters;

/**
* The set of directories where we should store files as append blobs.
Expand Down Expand Up @@ -192,7 +194,8 @@ public AzureBlobFileSystemStore(URI uri, boolean isSecureScheme,
boolean usingOauth = (authType == AuthType.OAuth);
boolean useHttps = (usingOauth || abfsConfiguration.isHttpsAlwaysUsed()) ? true : isSecureScheme;
this.abfsPerfTracker = new AbfsPerfTracker(fileSystemName, accountName, this.abfsConfiguration);
initializeClient(uri, fileSystemName, accountName, useHttps, abfsCounters);
this.abfsCounters = abfsCounters;
initializeClient(uri, fileSystemName, accountName, useHttps);
final Class<? extends IdentityTransformerInterface> identityTransformerClass =
configuration.getClass(FS_AZURE_IDENTITY_TRANSFORM_CLASS, IdentityTransformer.class,
IdentityTransformerInterface.class);
Expand Down Expand Up @@ -1214,7 +1217,7 @@ public boolean isAtomicRenameKey(String key) {
}

private void initializeClient(URI uri, String fileSystemName,
String accountName, boolean isSecure, AbfsCounters abfsCounters)
String accountName, boolean isSecure)
mehakmeet marked this conversation as resolved.
Show resolved Hide resolved
throws IOException {
if (this.client != null) {
return;
Expand Down Expand Up @@ -1261,16 +1264,30 @@ private void initializeClient(URI uri, String fileSystemName,
LOG.trace("Initializing AbfsClient for {}", baseUrl);
if (tokenProvider != null) {
this.client = new AbfsClient(baseUrl, creds, abfsConfiguration,
new ExponentialRetryPolicy(abfsConfiguration.getMaxIoRetries()),
tokenProvider, abfsPerfTracker, abfsCounters);
tokenProvider,
populateAbfsClientContext());
} else {
this.client = new AbfsClient(baseUrl, creds, abfsConfiguration,
new ExponentialRetryPolicy(abfsConfiguration.getMaxIoRetries()),
sasTokenProvider, abfsPerfTracker, abfsCounters);
sasTokenProvider,
populateAbfsClientContext());
}
LOG.trace("AbfsClient init complete");
}

/**
* Populate a new AbfsClientContext instance with the desired properties.
*
* @return an instance of AbfsClientContext.
*/
private AbfsClientContext populateAbfsClientContext() {
return new AbfsClientContext()
.withExponentialRetryPolicy(
new ExponentialRetryPolicy(abfsConfiguration.getMaxIoRetries()))
.withAbfsCounters(abfsCounters)
.withAbfsPerfTracker(abfsPerfTracker)
.build();
}

private String getOctalNotation(FsPermission fsPermission) {
Preconditions.checkNotNull(fsPermission, "fsPermission");
return String.format(AbfsHttpConstants.PERMISSION_FORMAT, fsPermission.toOctal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ public class AbfsClient implements Closeable {

private AbfsClient(final URL baseUrl, final SharedKeyCredentials sharedKeyCredentials,
final AbfsConfiguration abfsConfiguration,
final ExponentialRetryPolicy exponentialRetryPolicy,
final AbfsPerfTracker abfsPerfTracker,
final AbfsCounters abfsCounters) {
final AbfsClientContext abfsClientContext) {
this.baseUrl = baseUrl;
this.sharedKeyCredentials = sharedKeyCredentials;
String baseUrlString = baseUrl.toString();
this.filesystem = baseUrlString.substring(baseUrlString.lastIndexOf(FORWARD_SLASH) + 1);
this.abfsConfiguration = abfsConfiguration;
this.retryPolicy = exponentialRetryPolicy;
this.retryPolicy = abfsClientContext.getExponentialRetryPolicy();
this.accountName = abfsConfiguration.getAccountName().substring(0, abfsConfiguration.getAccountName().indexOf(AbfsHttpConstants.DOT));
this.authType = abfsConfiguration.getAuthType(accountName);

Expand All @@ -105,29 +103,23 @@ private AbfsClient(final URL baseUrl, final SharedKeyCredentials sharedKeyCreden
}

this.userAgent = initializeUserAgent(abfsConfiguration, sslProviderName);
this.abfsPerfTracker = abfsPerfTracker;
this.abfsCounters = abfsCounters;
this.abfsPerfTracker = abfsClientContext.getAbfsPerfTracker();
this.abfsCounters = abfsClientContext.getAbfsCounters();
}

public AbfsClient(final URL baseUrl, final SharedKeyCredentials sharedKeyCredentials,
final AbfsConfiguration abfsConfiguration,
final ExponentialRetryPolicy exponentialRetryPolicy,
final AccessTokenProvider tokenProvider,
final AbfsPerfTracker abfsPerfTracker,
final AbfsCounters abfsCounters) {
this(baseUrl, sharedKeyCredentials, abfsConfiguration,
exponentialRetryPolicy, abfsPerfTracker, abfsCounters);
final AbfsClientContext abfsClientContext) {
this(baseUrl, sharedKeyCredentials, abfsConfiguration, abfsClientContext);
this.tokenProvider = tokenProvider;
}

public AbfsClient(final URL baseUrl, final SharedKeyCredentials sharedKeyCredentials,
final AbfsConfiguration abfsConfiguration,
final ExponentialRetryPolicy exponentialRetryPolicy,
final SASTokenProvider sasTokenProvider,
final AbfsPerfTracker abfsPerfTracker,
final AbfsCounters abfsCounters) {
this(baseUrl, sharedKeyCredentials, abfsConfiguration,
exponentialRetryPolicy, abfsPerfTracker, abfsCounters);
final AbfsClientContext abfsClientContext) {
this(baseUrl, sharedKeyCredentials, abfsConfiguration, abfsClientContext);
this.sasTokenProvider = sasTokenProvider;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* 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.fs.azurebfs.services;

/**
* Class to hold extra configurations for AbfsClient and further classes
* inside AbfsClient.
*/
public class AbfsClientContext {
mehakmeet marked this conversation as resolved.
Show resolved Hide resolved

private ExponentialRetryPolicy exponentialRetryPolicy;
mehakmeet marked this conversation as resolved.
Show resolved Hide resolved
private AbfsPerfTracker abfsPerfTracker;
private AbfsCounters abfsCounters;

public AbfsClientContext withExponentialRetryPolicy(
final ExponentialRetryPolicy exponentialRetryPolicy) {
this.exponentialRetryPolicy = exponentialRetryPolicy;
return this;
}

public AbfsClientContext withAbfsPerfTracker(
final AbfsPerfTracker abfsPerfTracker) {
this.abfsPerfTracker = abfsPerfTracker;
return this;
}

public AbfsClientContext withAbfsCounters(final AbfsCounters abfsCounters) {
this.abfsCounters = abfsCounters;
return this;
}

/**
* Build the context and get the instance with the properties selected.
*
* @return an instance of AbfsClientContext.
*/
public AbfsClientContext build() {
return this;
mehakmeet marked this conversation as resolved.
Show resolved Hide resolved
}

public ExponentialRetryPolicy getExponentialRetryPolicy() {
return exponentialRetryPolicy;
}

public AbfsPerfTracker getAbfsPerfTracker() {
return abfsPerfTracker;
}

public AbfsCounters getAbfsCounters() {
return abfsCounters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ public TestAbfsClient(){

private String getUserAgentString(AbfsConfiguration config,
boolean includeSSLProvider) throws MalformedURLException {
AbfsClientContext abfsClientContext = new AbfsClientContext();
AbfsClient client = new AbfsClient(new URL("https://azure.com"), null,
config, null, (AccessTokenProvider) null, null, null);
config, (AccessTokenProvider) null, abfsClientContext);
String sslProviderName = null;
if (includeSSLProvider) {
sslProviderName = DelegatingSSLSocketFactory.getDefaultFactory()
Expand Down Expand Up @@ -257,6 +258,12 @@ public static AbfsClient createTestClientFromCurrentContext(
abfsConfig.getAccountName(),
abfsConfig);

AbfsClientContext abfsClientContext =
new AbfsClientContext().withAbfsPerfTracker(tracker)
.withExponentialRetryPolicy(
new ExponentialRetryPolicy(abfsConfig.getMaxIoRetries()))
.build();

// Create test AbfsClient
AbfsClient testClient = new AbfsClient(
baseAbfsClientInstance.getBaseUrl(),
Expand All @@ -267,11 +274,10 @@ public static AbfsClient createTestClientFromCurrentContext(
abfsConfig.getStorageAccountKey())
: null),
abfsConfig,
new ExponentialRetryPolicy(abfsConfig.getMaxIoRetries()),
(currentAuthType == AuthType.OAuth
? abfsConfig.getTokenProvider()
: null),
tracker, null);
abfsClientContext);

return testClient;
}
Expand Down