-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Support accessing OSS with proxy #18139
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import alluxio.Constants; | ||
import alluxio.PositionReader; | ||
import alluxio.conf.AlluxioConfiguration; | ||
import alluxio.conf.Configuration; | ||
import alluxio.conf.PropertyKey; | ||
import alluxio.retry.RetryPolicy; | ||
import alluxio.underfs.ObjectUnderFileSystem; | ||
|
@@ -29,6 +30,7 @@ | |
import com.aliyun.oss.OSS; | ||
import com.aliyun.oss.OSSClientBuilder; | ||
import com.aliyun.oss.ServiceException; | ||
import com.aliyun.oss.common.comm.Protocol; | ||
import com.aliyun.oss.model.AbortMultipartUploadRequest; | ||
import com.aliyun.oss.model.DeleteObjectsRequest; | ||
import com.aliyun.oss.model.DeleteObjectsResult; | ||
|
@@ -380,9 +382,80 @@ public static ClientBuilderConfiguration initializeOSSClientConfig( | |
ossClientConf.setConnectionTTL(alluxioConf.getMs(PropertyKey.UNDERFS_OSS_CONNECT_TTL)); | ||
ossClientConf.setMaxConnections(alluxioConf.getInt(PropertyKey.UNDERFS_OSS_CONNECT_MAX)); | ||
ossClientConf.setMaxErrorRetry(alluxioConf.getInt(PropertyKey.UNDERFS_OSS_RETRY_MAX)); | ||
if (isProxyEnabled(alluxioConf)) { | ||
String proxyHost = getProxyHost(alluxioConf); | ||
int proxyPort = getProxyPort(alluxioConf); | ||
ossClientConf.setProxyHost(proxyHost); | ||
ossClientConf.setProxyPort(proxyPort); | ||
ossClientConf.setProtocol(getProtocol()); | ||
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. add a log here if proxy is used (so you know) 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. good idea, done |
||
LOG.info("the proxy for OSS is enabled, the proxy endpoint is: {}:{}", proxyHost, proxyPort); | ||
} | ||
return ossClientConf; | ||
} | ||
|
||
private static boolean isProxyEnabled(AlluxioConfiguration alluxioConf) { | ||
return getProxyHost(alluxioConf) != null && getProxyPort(alluxioConf) > 0; | ||
} | ||
|
||
private static int getProxyPort(AlluxioConfiguration alluxioConf) { | ||
int proxyPort = alluxioConf.getInt(PropertyKey.UNDERFS_OSS_PROXY_PORT); | ||
if (proxyPort >= 0) { | ||
return proxyPort; | ||
} else { | ||
try { | ||
return getProxyPortFromSystemProperty(); | ||
} catch (NumberFormatException e) { | ||
return proxyPort; | ||
} | ||
} | ||
} | ||
|
||
private static String getProxyHost(AlluxioConfiguration alluxioConf) { | ||
String proxyHost = alluxioConf.getString(PropertyKey.UNDERFS_OSS_PROXY_HOST); | ||
if (proxyHost != null) { | ||
return proxyHost; | ||
} else { | ||
return getProxyHostFromSystemProperty(); | ||
} | ||
} | ||
|
||
private static Protocol getProtocol() { | ||
String protocol = Configuration.getString(PropertyKey.UNDERFS_OSS_PROTOCOL); | ||
return protocol.equals(Protocol.HTTPS.toString()) ? Protocol.HTTPS : Protocol.HTTP; | ||
} | ||
|
||
/** | ||
* Returns the Java system property for proxy port depending on | ||
* {@link #getProtocol()}: i.e. if protocol is https, returns | ||
* the value of the system property https.proxyPort, otherwise | ||
* returns value of http.proxyPort. Defaults to {@link this.proxyPort} | ||
* if the system property is not set with a valid port number. | ||
*/ | ||
private static int getProxyPortFromSystemProperty() { | ||
return getProtocol() == Protocol.HTTPS | ||
? Integer.parseInt(getSystemProperty("https.proxyPort")) | ||
: Integer.parseInt(getSystemProperty("http.proxyPort")); | ||
} | ||
|
||
/** | ||
* Returns the Java system property for proxy host depending on | ||
* {@link #getProtocol()}: i.e. if protocol is https, returns | ||
* the value of the system property https.proxyHost, otherwise | ||
* returns value of http.proxyHost. | ||
*/ | ||
private static String getProxyHostFromSystemProperty() { | ||
return getProtocol() == Protocol.HTTPS | ||
? getSystemProperty("https.proxyHost") | ||
: getSystemProperty("http.proxyHost"); | ||
} | ||
|
||
/** | ||
* Returns the value for the given system property. | ||
*/ | ||
private static String getSystemProperty(String property) { | ||
return System.getProperty(property); | ||
} | ||
|
||
@Override | ||
protected InputStream openObject(String key, OpenOptions options, RetryPolicy retryPolicy) | ||
throws IOException { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does it need a default? port 0 means assign dynamically right? So I'm afraid it's not the best default to use? I think you will need to configure this anyway (there's an existing port the proxy uses, instead of for the alluxio proc to allocate). So maybe no need for a default?
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 the port is 0(or not > 0), we think the proxy configuration is not enabled, so we don't set proxy in the oss config.