Skip to content

Commit 018d61b

Browse files
shyjsarahJingsongLi
authored andcommitted
[oss] add fs.oss.sld.enabled to support oss private link (#6413)
1 parent b1cc1e5 commit 018d61b

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • paimon-filesystems/paimon-oss-impl/src/main/java/org/apache/paimon/oss

paimon-filesystems/paimon-oss-impl/src/main/java/org/apache/paimon/oss/OSSFileIO.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
import org.apache.paimon.fs.FileIO;
2323
import org.apache.paimon.options.Options;
2424
import org.apache.paimon.utils.IOUtils;
25+
import org.apache.paimon.utils.ReflectionUtils;
2526

27+
import com.aliyun.oss.OSSClient;
28+
import com.aliyun.oss.common.comm.ServiceClient;
2629
import org.apache.hadoop.conf.Configuration;
2730
import org.apache.hadoop.fs.FileSystem;
2831
import org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem;
32+
import org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystemStore;
2933
import org.slf4j.Logger;
3034
import org.slf4j.LoggerFactory;
3135

@@ -56,6 +60,7 @@ public class OSSFileIO extends HadoopCompliantFileIO {
5660
private static final String OSS_ACCESS_KEY_ID = "fs.oss.accessKeyId";
5761
private static final String OSS_ACCESS_KEY_SECRET = "fs.oss.accessKeySecret";
5862
private static final String OSS_SECURITY_TOKEN = "fs.oss.securityToken";
63+
private static final String OSS_SECOND_LEVEL_DOMAIN_ENABLED = "fs.oss.sld.enabled";
5964

6065
private static final Map<String, String> CASE_SENSITIVE_KEYS =
6166
new HashMap<String, String>() {
@@ -137,6 +142,11 @@ protected AliyunOSSFileSystem createFileSystem(org.apache.hadoop.fs.Path path) {
137142
} catch (IOException e) {
138143
throw new UncheckedIOException(e);
139144
}
145+
146+
if (hadoopOptions.getBoolean(OSS_SECOND_LEVEL_DOMAIN_ENABLED, false)) {
147+
enableSecondLevelDomain(fs);
148+
}
149+
140150
return fs;
141151
};
142152

@@ -156,6 +166,19 @@ public void close() {
156166
}
157167
}
158168

169+
public void enableSecondLevelDomain(AliyunOSSFileSystem fs) {
170+
AliyunOSSFileSystemStore store = fs.getStore();
171+
try {
172+
OSSClient ossClient = ReflectionUtils.getPrivateFieldValue(store, "ossClient");
173+
ServiceClient serviceClient =
174+
ReflectionUtils.getPrivateFieldValue(ossClient, "serviceClient");
175+
serviceClient.getClientConfiguration().setSLDEnabled(true);
176+
} catch (Exception e) {
177+
LOG.error("Failed to enable second level domain.", e);
178+
throw new RuntimeException("Failed to enable second level domain.", e);
179+
}
180+
}
181+
159182
private static class CacheKey {
160183

161184
private final Options options;

0 commit comments

Comments
 (0)