From c326fc89b06a8fe0978306378ba217748c7f2054 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Mon, 20 Nov 2017 18:56:42 +0000 Subject: [PATCH] HADOOP-15024 Support user agent configuration and include that & Hadoop version information to oss server. Contributed by Sammi Chen. --- .../hadoop/fs/aliyun/oss/AliyunOSSFileSystemStore.java | 4 ++++ .../java/org/apache/hadoop/fs/aliyun/oss/Constants.java | 7 +++++++ .../src/site/markdown/tools/hadoop-aliyun/index.md | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystemStore.java b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystemStore.java index 2e8edc7715..a7f13c082c 100644 --- a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystemStore.java +++ b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystemStore.java @@ -53,6 +53,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.PathFilter; import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.util.VersionInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,6 +102,9 @@ public void initialize(URI uri, Configuration conf, ESTABLISH_TIMEOUT_DEFAULT)); clientConf.setSocketTimeout(conf.getInt(SOCKET_TIMEOUT_KEY, SOCKET_TIMEOUT_DEFAULT)); + clientConf.setUserAgent( + conf.get(USER_AGENT_PREFIX, USER_AGENT_PREFIX_DEFAULT) + ", Hadoop/" + + VersionInfo.getVersion()); String proxyHost = conf.getTrimmed(PROXY_HOST_KEY, ""); int proxyPort = conf.getInt(PROXY_PORT_KEY, -1); diff --git a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java index 04a2ccd6c5..baa171fc5f 100644 --- a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java +++ b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java @@ -18,6 +18,8 @@ package org.apache.hadoop.fs.aliyun.oss; +import com.aliyun.oss.common.utils.VersionInfoUtils; + /** * ALL configuration constants for OSS filesystem. */ @@ -26,6 +28,11 @@ public final class Constants { private Constants() { } + // User agent + public static final String USER_AGENT_PREFIX = "fs.oss.user.agent.prefix"; + public static final String USER_AGENT_PREFIX_DEFAULT = + VersionInfoUtils.getDefaultUserAgent(); + // Class of credential provider public static final String ALIYUN_OSS_CREDENTIALS_PROVIDER_KEY = "fs.oss.credentials.provider"; diff --git a/hadoop-tools/hadoop-aliyun/src/site/markdown/tools/hadoop-aliyun/index.md b/hadoop-tools/hadoop-aliyun/src/site/markdown/tools/hadoop-aliyun/index.md index 2913279d8b..9f24ce6677 100644 --- a/hadoop-tools/hadoop-aliyun/src/site/markdown/tools/hadoop-aliyun/index.md +++ b/hadoop-tools/hadoop-aliyun/src/site/markdown/tools/hadoop-aliyun/index.md @@ -274,7 +274,7 @@ XInclude inclusion. Here is an example of `contract-test-options.xml`: fs.oss.impl - org.apache.hadoop.fs.aliyun.AliyunOSSFileSystem + org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem