YARN-8336. Fix potential connection leak in SchedConfCLI and YarnWebServiceUtils. Contributed by Giovanni Matteo Fumarola.

This commit is contained in:
Inigo Goiri 2018-05-23 11:55:31 -07:00
parent c13dea87d9
commit e30938af12
2 changed files with 38 additions and 21 deletions

View File

@ -132,25 +132,35 @@ public int run(String[] args) throws Exception {
} }
Client webServiceClient = Client.create(); Client webServiceClient = Client.create();
WebResource webResource = webServiceClient.resource(WebAppUtils. WebResource webResource = webServiceClient
getRMWebAppURLWithScheme(getConf())); .resource(WebAppUtils.getRMWebAppURLWithScheme(getConf()));
ClientResponse response = webResource.path("ws").path("v1").path("cluster") ClientResponse response = null;
.path("scheduler-conf").accept(MediaType.APPLICATION_JSON)
.entity(YarnWebServiceUtils.toJson(updateInfo, try {
SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON) response =
.put(ClientResponse.class); webResource.path("ws").path("v1").path("cluster")
if (response != null) { .path("scheduler-conf").accept(MediaType.APPLICATION_JSON)
if (response.getStatus() == Status.OK.getStatusCode()) { .entity(YarnWebServiceUtils.toJson(updateInfo,
System.out.println("Configuration changed successfully."); SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON)
return 0; .put(ClientResponse.class);
if (response != null) {
if (response.getStatus() == Status.OK.getStatusCode()) {
System.out.println("Configuration changed successfully.");
return 0;
} else {
System.err.println("Configuration change unsuccessful: "
+ response.getEntity(String.class));
}
} else { } else {
System.err.println("Configuration change unsuccessful: " System.err.println("Configuration change unsuccessful: null response");
+ response.getEntity(String.class));
} }
} else { return -1;
System.err.println("Configuration change unsuccessful: null response"); } finally {
if (response != null) {
response.close();
}
webServiceClient.destroy();
} }
return -1;
} }
@VisibleForTesting @VisibleForTesting

View File

@ -58,11 +58,18 @@ public static JSONObject getNodeInfoFromRMWebService(Configuration conf,
WebResource webResource = webServiceClient.resource(webAppAddress); WebResource webResource = webServiceClient.resource(webAppAddress);
ClientResponse response = webResource.path("ws").path("v1") ClientResponse response = null;
.path("cluster").path("nodes") try {
.path(nodeId).accept(MediaType.APPLICATION_JSON) response = webResource.path("ws").path("v1").path("cluster")
.get(ClientResponse.class); .path("nodes").path(nodeId).accept(MediaType.APPLICATION_JSON)
return response.getEntity(JSONObject.class); .get(ClientResponse.class);
return response.getEntity(JSONObject.class);
} finally {
if (response != null) {
response.close();
}
webServiceClient.destroy();
}
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")