You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fluo.apache.org by mw...@apache.org on 2018/01/02 16:24:09 UTC

[fluo] branch master updated: Closed file system which is not eventually closed. (#988)

This is an automated email from the ASF dual-hosted git repository.

mwalch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/fluo.git


The following commit(s) were added to refs/heads/master by this push:
     new d45f1f7  Closed file system which is not eventually closed. (#988)
d45f1f7 is described below

commit d45f1f77ba1f8501e27b66d2676d2ffb92525d56
Author: Furkan KAMACI <fu...@gmail.com>
AuthorDate: Tue Jan 2 19:24:06 2018 +0300

    Closed file system which is not eventually closed. (#988)
---
 .../org/apache/fluo/core/client/FluoAdminImpl.java | 27 ++++++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java b/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
index e711705..8d717f3 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
@@ -324,9 +324,7 @@ public class FluoAdminImpl implements FluoAdmin {
     String dfsAppRoot = dfsRoot + "/" + appName;
     String dfsDestDir = dfsAppRoot + "/" + destDir;
 
-    FileSystem fs;
-    try {
-      fs = FileSystem.get(new URI(dfsRoot), new Configuration());
+    try (FileSystem fs = FileSystem.get(new URI(dfsRoot), new Configuration())) {
       fs.delete(new Path(dfsDestDir), true);
       fs.mkdirs(new Path(dfsAppRoot));
       fs.copyFromLocalFile(new Path(srcDir), new Path(dfsDestDir));
@@ -340,11 +338,19 @@ public class FluoAdminImpl implements FluoAdmin {
     String dfsAppRoot = config.getDfsRoot() + "/" + config.getApplicationName();
     String dfsDestDir = dfsAppRoot + "/" + destDir;
 
-    FileSystem fs;
+    FileSystem fs = null;
     try {
       fs = FileSystem.get(new URI(config.getDfsRoot()), new Configuration());
       fs.mkdirs(new Path(dfsDestDir));
     } catch (Exception e) {
+      logger.error("Failed to create DFS directory {}", dfsDestDir);
+      if (fs != null) {
+        try {
+          fs.close();
+        } catch (IOException ioe) {
+          throw new IllegalStateException(ioe);
+        }
+      }
       throw new IllegalStateException(e);
     }
 
@@ -356,12 +362,23 @@ public class FluoAdminImpl implements FluoAdmin {
         fs.copyFromLocalFile(new Path(jarPath), new Path(dfsDestDir));
       } catch (IOException e) {
         logger.error("Failed to copy file {} to DFS directory {}", jarPath, dfsDestDir);
+        try {
+          fs.close();
+        } catch (IOException ioe) {
+          throw new IllegalStateException(ioe);
+        }
         throw new IllegalStateException(e);
       }
       if (classpath.length() != 0) {
         classpath.append(",");
       }
-      classpath.append(dfsDestDir + "/" + jarName);
+      classpath.append(dfsDestDir).append("/").append(jarName);
+    }
+
+    try {
+      fs.close();
+    } catch (IOException e) {
+      throw new IllegalStateException(e);
     }
     return classpath.toString();
   }

-- 
To stop receiving notification emails like this one, please contact
['"commits@fluo.apache.org" <co...@fluo.apache.org>'].