diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index 2a204519228a4..d195c8cdae681 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -4565,6 +4565,11 @@ public static boolean isAclEnabled(Configuration conf) { public static final String DEFAULT_GPG_WEBAPP_HTTPS_ADDRESS = "0.0.0.0:" + DEFAULT_GPG_WEBAPP_HTTPS_PORT; + public static final String GPG_WEBAPP_CONNECT_TIMEOUT = GPG_WEBAPP_PREFIX + "connect-timeout"; + public static final long DEFAULT_GPG_WEBAPP_CONNECT_TIMEOUT = TimeUnit.SECONDS.toMillis(30); + public static final String GPG_WEBAPP_READ_TIMEOUT = GPG_WEBAPP_PREFIX + "read-timeout"; + public static final long DEFAULT_GPG_WEBAPP_READ_TIMEOUT = TimeUnit.SECONDS.toMillis(30); + /** * Connection and Read timeout from the Router to RM. */ diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml index 72e8cc70f8743..c2be5d420bfcf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml @@ -5723,4 +5723,27 @@ 50000 + + + Set the connect timeout interval, in milliseconds. + A value of 0 means no timeout, otherwise values must be between 1 and Integer#MAX_VALUE. + This ensures that the connection is established within a specified time, + or it triggers a connection timeout exception. + + yarn.federation.gpg.webapp.connect-timeout + 30s + + + + + Set the read timeout interval, in milliseconds. + A value of 0 means no timeout, otherwise values must be between 1 and Integer#MAX_VALUE. + This timeout specifies the maximum time a client should wait for data to be read from a server + once the connection has been established. + If data is not received within the specified time, a read timeout exception is raised. + + yarn.federation.gpg.webapp.read-timeout + 30s + + diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java index 02344a51493c6..13e1a8a01273f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java @@ -27,6 +27,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; import javax.ws.rs.core.MediaType; @@ -65,7 +66,7 @@ private GPGUtils() { */ public static T invokeRMWebService(String webAddr, String path, final Class returnType, Configuration conf, String selectParam) { - Client client = Client.create(); + Client client = createJerseyClient(conf); T obj; // webAddr stores the form of host:port in subClusterInfo @@ -128,4 +129,22 @@ public static Map createUniformWeights( } return weights; } + + /** + * Create JerseyClient based on configuration file. + * We will set the timeout when creating JerseyClient. + * + * @param conf Configuration. + * @return JerseyClient. + */ + public static Client createJerseyClient(Configuration conf) { + Client client = Client.create(); + int connectTimeOut = (int) conf.getTimeDuration(YarnConfiguration.GPG_WEBAPP_CONNECT_TIMEOUT, + YarnConfiguration.DEFAULT_GPG_WEBAPP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS); + client.setConnectTimeout(connectTimeOut); + int readTimeout = (int) conf.getTimeDuration(YarnConfiguration.GPG_WEBAPP_READ_TIMEOUT, + YarnConfiguration.DEFAULT_GPG_WEBAPP_READ_TIMEOUT, TimeUnit.MILLISECONDS); + client.setReadTimeout(readTimeout); + return client; + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/test/java/org/apache/hadoop/yarn/server/globalpolicygenerator/TestGPGPolicyFacade.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/test/java/org/apache/hadoop/yarn/server/globalpolicygenerator/TestGPGPolicyFacade.java index d20d6c0485f19..d5408dfdafbc5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/test/java/org/apache/hadoop/yarn/server/globalpolicygenerator/TestGPGPolicyFacade.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/test/java/org/apache/hadoop/yarn/server/globalpolicygenerator/TestGPGPolicyFacade.java @@ -42,7 +42,6 @@ import org.junit.Test; import org.mockito.Matchers; -import java.io.IOException; import java.util.HashSet; import java.util.Set; @@ -73,7 +72,7 @@ public TestGPGPolicyFacade() { } @Before - public void setUp() throws IOException, YarnException { + public void setUp() throws YarnException { stateStore = new MemoryFederationStateStore(); stateStore.init(conf); facade.reinitialize(stateStore, conf);