Skip to content

Commit

Permalink
YARN-11592. Add timeout to GPGUtils#invokeRMWebService. (#6189) Contr…
Browse files Browse the repository at this point in the history
…ibuted by Shilun Fan.

Reviewed-by: Inigo Goiri <[email protected]>
Signed-off-by: Shilun Fan <[email protected]>
  • Loading branch information
slfan1989 authored Oct 27, 2023
1 parent e4eda40 commit 40e8300
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.junit.Test;
import org.mockito.Matchers;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 40e8300

Please sign in to comment.