YARN-7402. [GPG] Fix potential connection leak in GPGUtils. Contributed by Giovanni Matteo Fumarola.
This commit is contained in:
parent
b97ad37403
commit
8aec1a5ddd
@ -18,21 +18,22 @@
|
||||
|
||||
package org.apache.hadoop.yarn.server.globalpolicygenerator;
|
||||
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
|
||||
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
|
||||
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
|
||||
|
||||
import com.sun.jersey.api.client.Client;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
|
||||
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
|
||||
|
||||
/**
|
||||
* GPGUtils contains utility functions for the GPG.
|
||||
@ -53,15 +54,23 @@ public static <T> T invokeRMWebService(Configuration conf, String webAddr,
|
||||
T obj = null;
|
||||
|
||||
WebResource webResource = client.resource(webAddr);
|
||||
ClientResponse response = webResource.path("ws/v1/cluster").path(path)
|
||||
ClientResponse response = null;
|
||||
try {
|
||||
response = webResource.path("ws/v1/cluster").path(path)
|
||||
.accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
|
||||
if (response.getStatus() == HttpServletResponse.SC_OK) {
|
||||
if (response.getStatus() == SC_OK) {
|
||||
obj = response.getEntity(returnType);
|
||||
} else {
|
||||
throw new YarnRuntimeException("Bad response from remote web service: "
|
||||
+ response.getStatus());
|
||||
throw new YarnRuntimeException(
|
||||
"Bad response from remote web service: " + response.getStatus());
|
||||
}
|
||||
return obj;
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
client.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user