tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [19/50] [abbrv] git commit: TAJO-1072: CLI gets stuck when wrong host/port is provided. (Jihun Kang via hyunsik)
Date Wed, 15 Oct 2014 09:16:49 GMT
TAJO-1072: CLI gets stuck when wrong host/port is provided. (Jihun Kang via hyunsik)

Closes #169


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

Branch: refs/heads/block_iteration
Commit: 4e203f03fb533e04577f5c2947823fedd8680b8a
Parents: a90438f
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Sat Oct 4 09:11:59 2014 -0700
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Sat Oct 4 09:11:59 2014 -0700

----------------------------------------------------------------------
 CHANGES                                         |   6 +-
 .../main/java/org/apache/tajo/cli/TajoCli.java  | 107 +++++++++++--------
 2 files changed, 70 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/4e203f03/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 3876a1e..73d2bc6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -155,9 +155,13 @@ Release 0.9.0 - unreleased
 
   BUG FIXES
 
+    TAJO-1072: CLI gets stuck when wrong host/port is provided. 
+    (Jihun Kang via hyunsik)
+
     TAJO-1081: Non-forwarded (simple) query shows wrong rows. (hyunsik)
 
-    TAJO-981: Help command (\?) in tsql takes too long time. (YeonSu Han via jaehwa)
+    TAJO-981: Help command (\?) in tsql takes too long time. (YeonSu Han via 
+    jaehwa)
 
     TAJO-962: Column reference used in LIMIT clause incurs NPE.
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/4e203f03/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
index 51c8c9f..05b919c 100644
--- a/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
+++ b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
@@ -21,8 +21,10 @@ package org.apache.tajo.cli;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.protobuf.ServiceException;
+
 import jline.UnsupportedTerminal;
 import jline.console.ConsoleReader;
+
 import org.apache.commons.cli.*;
 import org.apache.tajo.*;
 import org.apache.tajo.TajoProtos.QueryState;
@@ -236,35 +238,45 @@ public class TajoCli {
       client = new TajoClient(conf, baseDatabase);
     }
 
-    checkMasterStatus();
-    context.setCurrentDatabase(client.getCurrentDatabase());
-    initHistory();
-    initCommands();
+    try {
+      checkMasterStatus();
+      context.setCurrentDatabase(client.getCurrentDatabase());
+      initHistory();
+      initCommands();
 
-    if (cmd.getOptionValues("conf") != null) {
-      processSessionVarCommand(cmd.getOptionValues("conf"));
-    }
-
-    if (cmd.hasOption("c")) {
-      displayFormatter.setScirptMode();
-      int exitCode = executeScript(cmd.getOptionValue("c"));
-      sout.flush();
-      System.exit(exitCode);
-    }
-    if (cmd.hasOption("f")) {
-      displayFormatter.setScirptMode();
-      cmd.getOptionValues("");
-      File sqlFile = new File(cmd.getOptionValue("f"));
-      if (sqlFile.exists()) {
-        String script = FileUtil.readTextFile(new File(cmd.getOptionValue("f")));
-        script = replaceParam(script, cmd.getOptionValues("param"));
-        int exitCode = executeScript(script);
+      if (cmd.getOptionValues("conf") != null) {
+        processSessionVarCommand(cmd.getOptionValues("conf"));
+      }
+
+      if (cmd.hasOption("c")) {
+        displayFormatter.setScirptMode();
+        int exitCode = executeScript(cmd.getOptionValue("c"));
         sout.flush();
         System.exit(exitCode);
-      } else {
-        System.err.println(ERROR_PREFIX + "No such a file \"" + cmd.getOptionValue("f") +
"\"");
-        System.exit(-1);
       }
+      if (cmd.hasOption("f")) {
+        displayFormatter.setScirptMode();
+        cmd.getOptionValues("");
+        File sqlFile = new File(cmd.getOptionValue("f"));
+        if (sqlFile.exists()) {
+          String script = FileUtil.readTextFile(new File(cmd.getOptionValue("f")));
+          script = replaceParam(script, cmd.getOptionValues("param"));
+          int exitCode = executeScript(script);
+          sout.flush();
+          System.exit(exitCode);
+        } else {
+          System.err.println(ERROR_PREFIX + "No such a file \"" + cmd.getOptionValue("f")
+ "\"");
+          System.exit(-1);
+        }
+      }
+    } catch (Exception e) {
+      System.err.println(ERROR_PREFIX + "Exception was thrown. Caused by " + e.getMessage());
+      
+      if (client != null) {
+        client.close();
+      }
+      
+      throw e;
     }
 
     addShutdownHook();
@@ -386,29 +398,40 @@ public class TajoCli {
     sout.write("Try \\? for help.\n");
 
     SimpleParser parser = new SimpleParser();
-    while((line = reader.readLine(currentPrompt + "> ")) != null) {
-      if (line.equals("")) {
-        continue;
-      }
-      wasError = false;
-      if (line.startsWith("{")) {
-        executeJsonQuery(line);
-      } else {
-        List<ParsedResult> parsedResults = parser.parseLines(line);
+    
+    try {
+      while((line = reader.readLine(currentPrompt + "> ")) != null) {
+        if (line.equals("")) {
+          continue;
+        }
+        wasError = false;
+        if (line.startsWith("{")) {
+          executeJsonQuery(line);
+        } else {
+          List<ParsedResult> parsedResults = parser.parseLines(line);
 
-        if (parsedResults.size() > 0) {
-          for (ParsedResult parsed : parsedResults) {
-            history.addStatement(parsed.getHistoryStatement() + (parsed.getType() == STATEMENT
? ";" : ""));
+          if (parsedResults.size() > 0) {
+            for (ParsedResult parsed : parsedResults) {
+              history.addStatement(parsed.getHistoryStatement() + (parsed.getType() == STATEMENT
? ";" : ""));
+            }
           }
-        }
 
-        exitCode = executeParsedResults(parsedResults);
-        currentPrompt = updatePrompt(parser.getState());
+          exitCode = executeParsedResults(parsedResults);
+          currentPrompt = updatePrompt(parser.getState());
 
-        if (exitCode != 0 && context.getBool(SessionVars.ON_ERROR_STOP)) {
-          return exitCode;
+          if (exitCode != 0 && context.getBool(SessionVars.ON_ERROR_STOP)) {
+            return exitCode;
+          }
         }
       }
+    } catch (Exception e) {
+      System.err.println(ERROR_PREFIX + "Exception was thrown. Casued by " + e.getMessage());
+      
+      if (client != null) {
+        client.close();
+      }
+      
+      throw e;
     }
     return exitCode;
   }


Mime
View raw message