-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HADOOP-16922. ABFS: Change User-Agent header #1938
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
Changes from all commits
b508ce2
bfa75cb
a396b3c
acaea3b
ba069d8
a9769e6
b5a00d3
322f778
a0a3728
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,32 +679,60 @@ public AuthType getAuthType() { | |
|
||
@VisibleForTesting | ||
String initializeUserAgent(final AbfsConfiguration abfsConfiguration, | ||
final String sslProviderName) { | ||
final String sslProviderName) { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append("(JavaJRE "); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have org.apache.hadoop.util.VersionInfo,getVersion() in there too? Lets people pin the blame on the logs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CLIENT_VERSION includes org.apache.hadoop.util.VersionInfo,getVersion() |
||
sb.append(APN_VERSION); | ||
sb.append(SINGLE_WHITE_SPACE); | ||
sb.append(CLIENT_VERSION); | ||
sb.append(SINGLE_WHITE_SPACE); | ||
|
||
sb.append("("); | ||
|
||
sb.append(System.getProperty(JAVA_VENDOR) | ||
.replaceAll(SINGLE_WHITE_SPACE, EMPTY_STRING)); | ||
sb.append(SINGLE_WHITE_SPACE); | ||
sb.append("JavaJRE"); | ||
sb.append(SINGLE_WHITE_SPACE); | ||
sb.append(System.getProperty(JAVA_VERSION)); | ||
sb.append("; "); | ||
sb.append( | ||
System.getProperty(OS_NAME).replaceAll(SINGLE_WHITE_SPACE, EMPTY_STRING)); | ||
sb.append(" "); | ||
sb.append(SEMICOLON); | ||
sb.append(SINGLE_WHITE_SPACE); | ||
|
||
sb.append(System.getProperty(OS_NAME) | ||
.replaceAll(SINGLE_WHITE_SPACE, EMPTY_STRING)); | ||
sb.append(SINGLE_WHITE_SPACE); | ||
sb.append(System.getProperty(OS_VERSION)); | ||
if (sslProviderName != null && !sslProviderName.isEmpty()) { | ||
sb.append("; "); | ||
sb.append(sslProviderName); | ||
} | ||
String tokenProviderField = | ||
ExtensionHelper.getUserAgentSuffix(tokenProvider, ""); | ||
if (!tokenProviderField.isEmpty()) { | ||
sb.append("; ").append(tokenProviderField); | ||
} | ||
sb.append(FORWARD_SLASH); | ||
sb.append(System.getProperty(OS_ARCH)); | ||
sb.append(SEMICOLON); | ||
|
||
appendIfNotEmpty(sb, sslProviderName, true); | ||
appendIfNotEmpty(sb, | ||
ExtensionHelper.getUserAgentSuffix(tokenProvider, EMPTY_STRING), true); | ||
|
||
sb.append(SINGLE_WHITE_SPACE); | ||
sb.append(abfsConfiguration.getClusterName()); | ||
sb.append(FORWARD_SLASH); | ||
sb.append(abfsConfiguration.getClusterType()); | ||
|
||
sb.append(")"); | ||
final String userAgentComment = sb.toString(); | ||
String customUserAgentId = abfsConfiguration.getCustomUserAgentPrefix(); | ||
if (customUserAgentId != null && !customUserAgentId.isEmpty()) { | ||
return String.format(Locale.ROOT, CLIENT_VERSION + " %s %s", | ||
userAgentComment, customUserAgentId); | ||
|
||
appendIfNotEmpty(sb, abfsConfiguration.getCustomUserAgentPrefix(), false); | ||
|
||
return String.format(Locale.ROOT, sb.toString()); | ||
} | ||
|
||
private void appendIfNotEmpty(StringBuilder sb, String regEx, | ||
boolean shouldAppendSemiColon) { | ||
if (regEx == null || regEx.trim().isEmpty()) { | ||
return; | ||
} | ||
sb.append(SINGLE_WHITE_SPACE); | ||
sb.append(regEx); | ||
if (shouldAppendSemiColon) { | ||
sb.append(SEMICOLON); | ||
} | ||
return String.format(Locale.ROOT, CLIENT_VERSION + " %s", userAgentComment); | ||
} | ||
|
||
@VisibleForTesting | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you pulled this out somewhere or made static you could have a unit test which would validate some of this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are test cases written to validate this as this method is package protected and with the @VisibleForTesting.