-
Notifications
You must be signed in to change notification settings - Fork 8.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
HADOOP-16256: HTTPFileSystem disallows users from configuring the connectionTimeout and readTimeout of HttpClient #774
base: trunk
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
package org.apache.hadoop.fs.http; | ||
|
||
|
||
import com.google.common.base.Preconditions; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FSDataInputStream; | ||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
|
@@ -39,13 +40,19 @@ | |
abstract class AbstractHttpFileSystem extends FileSystem { | ||
private static final long DEFAULT_BLOCK_SIZE = 4096; | ||
private static final Path WORKING_DIR = new Path("/"); | ||
private static final String CONF_HTTP_READ_TIMEOUT = "yarn.nodemanager.localizer.http.read.timeout.ms"; | ||
private static final String CONF_HTTP_CONNECT_TIMEOUT = "yarn.nodemanager.localizer.http.connect.timeout.ms"; | ||
private static final Integer DEFAULT_HTTP_READ_TIMEOUT_IN_MILLIS = 5000; | ||
private static final Integer DEFAULT_HTTP_CONNECT_TIMEOUT_IN_MILLIS = 5000; | ||
|
||
private URI uri; | ||
private Configuration conf; | ||
|
||
@Override | ||
public void initialize(URI name, Configuration conf) throws IOException { | ||
super.initialize(name, conf); | ||
this.uri = name; | ||
this.conf = conf; | ||
} | ||
|
||
public abstract String getScheme(); | ||
|
@@ -57,7 +64,14 @@ public URI getUri() { | |
|
||
@Override | ||
public FSDataInputStream open(Path path, int bufferSize) throws IOException { | ||
int httpConnectTimeoutInMillis = conf.getInt(CONF_HTTP_CONNECT_TIMEOUT, DEFAULT_HTTP_CONNECT_TIMEOUT_IN_MILLIS); | ||
int httpReadTimeoutInMillis = conf.getInt(CONF_HTTP_READ_TIMEOUT, DEFAULT_HTTP_READ_TIMEOUT_IN_MILLIS); | ||
Preconditions.checkState(httpConnectTimeoutInMillis > 0, "Http connection timeout has to greater than zero."); | ||
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. better:
This lists the property name and the actual value set. |
||
Preconditions.checkState(httpReadTimeoutInMillis > 0, "Http read timeout has to greater than zero."); | ||
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. +Same here |
||
|
||
URLConnection conn = path.toUri().toURL().openConnection(); | ||
conn.setConnectTimeout(httpConnectTimeoutInMillis); | ||
conn.setReadTimeout(httpReadTimeoutInMillis); | ||
InputStream in = conn.getInputStream(); | ||
return new FSDataInputStream(new HttpDataInputStream(in)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.io.IOUtils; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
@@ -64,4 +65,38 @@ public void testHttpFileSystem() throws IOException, URISyntaxException, | |
assertEquals("/foo", req.getPath()); | ||
} | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testHttpFileSystemWithNegativeHttpConnectTimeout() throws Exception { | ||
URI mockURI = new URI("dummyURI"); | ||
|
||
Configuration conf = new Configuration(false); | ||
conf.set("fs.http.impl", HttpFileSystem.class.getCanonicalName()); | ||
conf.set("yarn.nodemanager.localizer.http.connect.timeout.ms", "-1"); | ||
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. use the values set in |
||
conf.set("yarn.nodemanager.localizer.http.read.timeout.ms", "1000"); | ||
|
||
Path mockPath = Mockito.mock(Path.class); | ||
|
||
HttpFileSystem httpFileSystem = new HttpFileSystem(); | ||
httpFileSystem.initialize(mockURI, conf); | ||
|
||
httpFileSystem.open(mockPath, 1000); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void testHttpFileSystemWithNegativeHttpReadTimeout() throws Exception { | ||
URI mockURI = new URI("dummyURI"); | ||
|
||
Configuration conf = new Configuration(false); | ||
conf.set("fs.http.impl", HttpFileSystem.class.getCanonicalName()); | ||
conf.set("yarn.nodemanager.localizer.http.connect.timeout.ms", "1000"); | ||
conf.set("yarn.nodemanager.localizer.http.read.timeout.ms", "-1"); | ||
|
||
Path mockPath = Mockito.mock(Path.class); | ||
|
||
HttpFileSystem httpFileSystem = new HttpFileSystem(); | ||
httpFileSystem.initialize(mockURI, conf); | ||
|
||
httpFileSystem.open(mockPath, 1000); | ||
} | ||
} |
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.
HttpFileSystemConstants