YARN-11592. Add timeout to GPGUtils#invokeRMWebService. (#6189) Contributed by Shilun Fan.

Reviewed-by: Inigo Goiri <inigoiri@apache.org>
Signed-off-by: Shilun Fan <slfan1989@apache.org>
This commit is contained in:
slfan1989 2023-10-28 07:09:09 +08:00 committed by GitHub
parent e4eda40ac9
commit 40e8300719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 3 deletions

View File

@ -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.
*/

View File

@ -5723,4 +5723,27 @@
<value>50000</value>
</property>
<property>
<description>
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.
</description>
<name>yarn.federation.gpg.webapp.connect-timeout</name>
<value>30s</value>
</property>
<property>
<description>
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.
</description>
<name>yarn.federation.gpg.webapp.read-timeout</name>
<value>30s</value>
</property>
</configuration>

View File

@ -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> T invokeRMWebService(String webAddr, String path, final Class<T> 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<SubClusterIdInfo, Float> 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;
}
}

View File

@ -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);