Repository: lens Updated Branches: refs/heads/master 0ba17ef5c -> b7773d6c7
LENS-853 : Quit shell should close session all times Project: http://git-wip-us.apache.org/repos/asf/lens/repo Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/b7773d6c Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/b7773d6c Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/b7773d6c Branch: refs/heads/master Commit: b7773d6c74cc323be10c0f416f4ec93d8711fe00 Parents: 0ba17ef Author: Raju Bairishetti <r...@apache.org> Authored: Sat Mar 5 07:45:27 2016 +0530 Committer: Amareshwari Sriramadasu <amareshw...@apache.org> Committed: Sat Mar 5 07:45:27 2016 +0530 ---------------------------------------------------------------------- .../apache/lens/cli/commands/BaseLensCommand.java | 12 +++++++----- .../lens/cli/TestLensConnectionCliCommands.java | 1 - .../org/apache/lens/cli/TestLensQueryCommands.java | 15 ++++++++++++++- .../apache/lens/server/session/SessionResource.java | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lens/blob/b7773d6c/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java ---------------------------------------------------------------------- diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java index 0c10198..be1ca12 100644 --- a/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java +++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/BaseLensCommand.java @@ -57,7 +57,8 @@ public class BaseLensCommand implements ExecutionProcessor { protected DefaultPrettyPrinter pp; /** The is connection active. */ - protected static boolean isConnectionActive; + protected boolean isConnectionActive; + public static final String DATE_FMT = "yyyy-MM-dd'T'HH:mm:ss:SSS"; private LensClient lensClient = null; @@ -74,7 +75,7 @@ public class BaseLensCommand implements ExecutionProcessor { return DATE_PARSER.get().format(dt); } - static { + private void registerShutDownHook() { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { closeClientConnection(); @@ -85,10 +86,10 @@ public class BaseLensCommand implements ExecutionProcessor { /** * Close client connection. */ - protected static synchronized void closeClientConnection() { + protected synchronized void closeClientConnection() { if (isConnectionActive) { log.debug("Request for stopping lens cli received"); - getClientWrapper().getClient().closeConnection(); + lensClient.closeConnection(); isConnectionActive = false; } } @@ -97,6 +98,7 @@ public class BaseLensCommand implements ExecutionProcessor { * Instantiates a new base lens command. */ public BaseLensCommand() { + registerShutDownHook(); mapper = new ObjectMapper(); mapper.setSerializationInclusion(Inclusion.NON_NULL); mapper.setSerializationInclusion(Inclusion.NON_DEFAULT); @@ -118,13 +120,13 @@ public class BaseLensCommand implements ExecutionProcessor { } public void setClient(LensClient client) { + isConnectionActive = true; lensClient = client; } public LensClient getClient() { if (lensClient == null) { setClient(getClientWrapper().getClient()); - isConnectionActive = true; } return lensClient; } http://git-wip-us.apache.org/repos/asf/lens/blob/b7773d6c/lens-cli/src/test/java/org/apache/lens/cli/TestLensConnectionCliCommands.java ---------------------------------------------------------------------- diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensConnectionCliCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensConnectionCliCommands.java index 3c4d320..d1ec94e 100644 --- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensConnectionCliCommands.java +++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensConnectionCliCommands.java @@ -195,7 +195,6 @@ public class TestLensConnectionCliCommands extends LensCliApplicationTest { } } - /** * Test jar commands. */ http://git-wip-us.apache.org/repos/asf/lens/blob/b7773d6c/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java ---------------------------------------------------------------------- diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java index 97e5512..616bf5d 100644 --- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java +++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensQueryCommands.java @@ -92,6 +92,10 @@ public class TestLensQueryCommands extends LensCliApplicationTest { return qCom; } + private void closeClientConnection(LensQueryCommands queryCommands) { + queryCommands.getClient().closeConnection(); + } + /** * Test execute sync query */ @@ -101,7 +105,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest { String sql = "cube select id,name from test_dim"; String result = qCom.executeQuery(sql, false, "testQuery2"); assertTrue(result.contains("1\tfirst"), result); - + closeClientConnection(qCom); } /** @@ -167,6 +171,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest { assertFalse(handles2.contains(qh), handles2); result = qCom.destroyPreparedQuery(handles); assertEquals("Successfully destroyed " + handles, result); + closeClientConnection(qCom); } /** @@ -199,6 +204,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest { log.debug(result); assertTrue(result.contains(explainPlan)); + closeClientConnection(qCom); } /** @@ -310,6 +316,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest { } System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); + closeClientConnection(qCom); } private String readFile(String path) throws FileNotFoundException { @@ -363,6 +370,9 @@ public class TestLensQueryCommands extends LensCliApplicationTest { LensDimensionTableCommands dimTableCmd = new LensDimensionTableCommands(); dimTableCmd.setClient(client); dimTableCmd.dropDimensionTable("dim_table", true); + + // close client connection + client.closeConnection(); } /** @@ -391,6 +401,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest { downloadResult(qCom, qCom.getClient().getStatement().getQueryHandleString(), "testQuery3", "\"1\",\"first\""); System.out.println("@@END_PERSISTENT_RESULT_TEST-------------"); qCom.getClient().setConnectionParam("lens.query.enable.persistent.resultset.indriver", "false"); + closeClientConnection(qCom); } private void downloadResult(LensQueryCommands qCom, String qHandle, String qName, String expected) @@ -412,6 +423,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest { String qh = qCom.executeQuery(sql, true, "testQuery4"); String result = qCom.getQueryResults(qh, null, false); assertTrue(result.contains("1\tfirst"), result); + closeClientConnection(qCom); } /** @@ -438,6 +450,7 @@ public class TestLensQueryCommands extends LensCliApplicationTest { assertFalse(result.contains("(-")); System.out.println("@@END_FINISHED_PURGED_RESULT_TEST-------------"); qCom.getClient().setConnectionParam("lens.query.enable.persistent.resultset", "false"); + closeClientConnection(qCom); } } http://git-wip-us.apache.org/repos/asf/lens/blob/b7773d6c/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java ---------------------------------------------------------------------- diff --git a/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java b/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java index 0daa286..568b416 100644 --- a/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java +++ b/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java @@ -121,6 +121,7 @@ public class SessionResource { try { sessionService.closeSession(sessionid); } catch (LensException e) { + log.error("Got an exception while closing {} session: ", sessionid, e); return new APIResult(Status.FAILED, e.getMessage()); } return new APIResult(Status.SUCCEEDED, "Close session with id" + sessionid + "succeeded");