You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by jd...@apache.org on 2015/03/04 11:17:54 UTC

incubator-lens git commit: LENS-364 Open session with wrong db is returning 404 but session is getting created with default db (jdhok)

Repository: incubator-lens
Updated Branches:
  refs/heads/master a6055de86 -> 765664c5e


LENS-364 Open session with wrong db is returning 404 but session is getting created with default db (jdhok)


Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/765664c5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/765664c5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/765664c5

Branch: refs/heads/master
Commit: 765664c5e93325302a59e98ab73ddbb326dc1294
Parents: a6055de
Author: jdhok <ja...@inmobi.com>
Authored: Wed Mar 4 15:47:17 2015 +0530
Committer: jdhok <ja...@inmobi.com>
Committed: Wed Mar 4 15:47:17 2015 +0530

----------------------------------------------------------------------
 .../lens/server/session/HiveSessionService.java | 24 +++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/765664c5/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java b/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
index 435eda9..4f76e46 100644
--- a/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
+++ b/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
@@ -46,7 +46,6 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.ql.metadata.Hive;
-import org.apache.hadoop.hive.ql.metadata.HiveException;
 import org.apache.hadoop.hive.ql.processors.SetProcessor;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hive.service.cli.CLIService;
@@ -200,24 +199,37 @@ public class HiveSessionService extends LensService implements SessionService {
     throws LensException {
     LensSessionHandle sessionid = super.openSession(username, password, configuration);
     LOG.info("Opened session " + sessionid + " for user " + username);
-    // add auxuiliary jars
-    String[] auxJars = getSession(sessionid).getSessionConf().getStrings(LensConfConstants.AUX_JARS);
 
     // Set current database
     if (StringUtils.isNotBlank(database)) {
       try {
         if (!Hive.get(getSession(sessionid).getHiveConf()).databaseExists(database)) {
+          closeSession(sessionid);
+          LOG.info("Closed session " + sessionid.getPublicId().toString() + " as db " + database + " does not exist");
           throw new NotFoundException("Database " + database + " does not exist");
         }
-      } catch (HiveException e) {
-        LOG.error("Error in checking if database exists " + database, e);
-        throw new LensException(e);
+      } catch (Exception e) {
+        if (!(e instanceof NotFoundException)) {
+          try {
+            closeSession(sessionid);
+          } catch (LensException e2) {
+            LOG.error("Error closing session " + sessionid.getPublicId().toString(), e2);
+          }
+
+          LOG.error("Error in checking if database exists " + database, e);
+          throw new LensException("Error in checking if database exists" + database, e);
+        } else {
+          throw (NotFoundException) e;
+        }
       }
 
       getSession(sessionid).setCurrentDatabase(database);
       LOG.info("Set database to " + database + " for session " + sessionid.getPublicId());
     }
 
+    // add auxuiliary jars
+    String[] auxJars = getSession(sessionid).getSessionConf().getStrings(LensConfConstants.AUX_JARS);
+
     if (auxJars != null) {
       LOG.info("Adding aux jars:" + auxJars);
       for (String jar : auxJars) {