Repository: hadoop
Updated Branches:
  refs/heads/trunk c13dea87d -> e30938af1


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


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e30938af
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e30938af
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e30938af

Branch: refs/heads/trunk
Commit: e30938af1270e079587e7bc06b755f9e93e660a5
Parents: c13dea8
Author: Inigo Goiri <inigo...@apache.org>
Authored: Wed May 23 11:55:31 2018 -0700
Committer: Inigo Goiri <inigo...@apache.org>
Committed: Wed May 23 11:55:31 2018 -0700

----------------------------------------------------------------------
 .../hadoop/yarn/client/cli/SchedConfCLI.java    | 42 ++++++++++++--------
 .../yarn/webapp/util/YarnWebServiceUtils.java   | 17 +++++---
 2 files changed, 38 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/e30938af/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java
----------------------------------------------------------------------
diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java
index 11bfdd7..a5f3b80 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/SchedConfCLI.java
@@ -132,25 +132,35 @@ public class SchedConfCLI extends Configured implements 
Tool {
     }
 
     Client webServiceClient = Client.create();
-    WebResource webResource = webServiceClient.resource(WebAppUtils.
-        getRMWebAppURLWithScheme(getConf()));
-    ClientResponse response = webResource.path("ws").path("v1").path("cluster")
-        .path("scheduler-conf").accept(MediaType.APPLICATION_JSON)
-        .entity(YarnWebServiceUtils.toJson(updateInfo,
-            SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON)
-        .put(ClientResponse.class);
-    if (response != null) {
-      if (response.getStatus() == Status.OK.getStatusCode()) {
-        System.out.println("Configuration changed successfully.");
-        return 0;
+    WebResource webResource = webServiceClient
+        .resource(WebAppUtils.getRMWebAppURLWithScheme(getConf()));
+    ClientResponse response = null;
+
+    try {
+      response =
+          webResource.path("ws").path("v1").path("cluster")
+              .path("scheduler-conf").accept(MediaType.APPLICATION_JSON)
+              .entity(YarnWebServiceUtils.toJson(updateInfo,
+                  SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON)
+              .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 {
-        System.err.println("Configuration change unsuccessful: "
-            + response.getEntity(String.class));
+        System.err.println("Configuration change unsuccessful: null response");
       }
-    } else {
-      System.err.println("Configuration change unsuccessful: null response");
+      return -1;
+    } finally {
+      if (response != null) {
+        response.close();
+      }
+      webServiceClient.destroy();
     }
-    return -1;
   }
 
   @VisibleForTesting

http://git-wip-us.apache.org/repos/asf/hadoop/blob/e30938af/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/YarnWebServiceUtils.java
----------------------------------------------------------------------
diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/YarnWebServiceUtils.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/YarnWebServiceUtils.java
index 1cf1e97..e7bca2c 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/YarnWebServiceUtils.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/YarnWebServiceUtils.java
@@ -58,11 +58,18 @@ public final class YarnWebServiceUtils {
 
     WebResource webResource = webServiceClient.resource(webAppAddress);
 
-    ClientResponse response = webResource.path("ws").path("v1")
-        .path("cluster").path("nodes")
-        .path(nodeId).accept(MediaType.APPLICATION_JSON)
-        .get(ClientResponse.class);
-    return response.getEntity(JSONObject.class);
+    ClientResponse response = null;
+    try {
+      response = webResource.path("ws").path("v1").path("cluster")
+          .path("nodes").path(nodeId).accept(MediaType.APPLICATION_JSON)
+          .get(ClientResponse.class);
+      return response.getEntity(JSONObject.class);
+    } finally {
+      if (response != null) {
+        response.close();
+      }
+      webServiceClient.destroy();
+    }
   }
 
   @SuppressWarnings("rawtypes")


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to