LENS-1527 : Fix session restore issue
authorRajitha R <rajithar@apache.org>
Fri, 10 Aug 2018 08:14:39 +0000 (13:44 +0530)
committerRajitha.R <rajithar@IM0318-L0.corp.inmobi.com>
Fri, 10 Aug 2018 08:14:39 +0000 (13:44 +0530)
lens-server-api/src/main/java/org/apache/lens/server/api/session/SessionService.java
lens-server/src/main/java/org/apache/lens/server/BaseLensService.java
lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
lens-server/src/test/resources/lens-site.xml

index d96d430..ccd2a3b 100644 (file)
@@ -56,7 +56,8 @@ public interface SessionService {
    * @throws LensException the lens exception
    */
 
-  void restoreSession(LensSessionHandle sessionHandle, String userName, String password) throws LensException;
+  void restoreSession(LensSessionHandle sessionHandle, String userName, String password,
+                      Map<String, String> configuration) throws LensException;
 
   /**
    * Close session.
index 2598c2e..ebb3a95 100644 (file)
@@ -254,21 +254,27 @@ public abstract class BaseLensService extends CompositeService implements Extern
    * @param password      the password
    * @throws LensException the lens exception
    */
-  public void restoreSession(LensSessionHandle sessionHandle, String userName, String password) throws LensException {
+  public void restoreSession(LensSessionHandle sessionHandle, String userName, String password,
+                             Map<String, String> configuration) throws LensException {
     HandleIdentifier handleIdentifier = new HandleIdentifier(sessionHandle.getPublicId(), sessionHandle.getSecretId());
     SessionHandle hiveSessionHandle = new SessionHandle(new TSessionHandle(handleIdentifier.toTHandleIdentifier()));
     try {
       cliService.createSessionWithSessionHandle(hiveSessionHandle, userName, password,
-        new HashMap<String, String>());
+        new HashMap<>());
       LensSessionHandle restoredSession = new LensSessionHandle(hiveSessionHandle.getHandleIdentifier().getPublicId(),
         hiveSessionHandle.getHandleIdentifier().getSecretId());
       SESSION_MAP.put(restoredSession.getPublicId().toString(), restoredSession);
-      SessionUser sessionUser = SESSION_USER_INSTANCE_MAP.get(userName);
+
+      String loggedinUser = userName;
+      if (configuration!= null) {
+        loggedinUser = configuration.getOrDefault(LensConfConstants.SESSION_LOGGEDIN_USER, userName);
+      }
+      SessionUser sessionUser = SESSION_USER_INSTANCE_MAP.get(loggedinUser);
       if (sessionUser == null) {
-        sessionUser = new SessionUser(userName);
-        SESSION_USER_INSTANCE_MAP.put(userName, sessionUser);
+        sessionUser = new SessionUser(loggedinUser);
+        SESSION_USER_INSTANCE_MAP.put(loggedinUser, sessionUser);
       }
-      updateSessionsPerUser(userName);
+      updateSessionsPerUser(loggedinUser);
     } catch (HiveSQLException e) {
       throw new LensException("Error restoring session " + sessionHandle, e);
     }
index d1ef716..f6d43d7 100644 (file)
@@ -364,7 +364,7 @@ public class HiveSessionService extends BaseLensService implements SessionServic
     for (LensSessionImpl.LensSessionPersistInfo persistInfo : restorableSessions) {
       try {
         LensSessionHandle sessionHandle = persistInfo.getSessionHandle();
-        restoreSession(sessionHandle, persistInfo.getUsername(), persistInfo.getPassword());
+        restoreSession(sessionHandle, persistInfo.getUsername(), persistInfo.getPassword(), persistInfo.getConfig());
         LensSessionImpl session = getSession(sessionHandle);
         session.getLensSessionPersistInfo().setLastAccessTime(persistInfo.getLastAccessTime());
         session.getLensSessionPersistInfo().setConfig(persistInfo.getConfig());
index bc1e2bc..0010889 100644 (file)
   </property>
   <property>
     <name>lens.server.max.sessions.per.user</name>
-    <value>20</value>
+    <value>100</value>
     <description>Number of sessions can be allowed for each user.</description>
   </property>
     <property>