@Override public String toString() { return "LensConnection{" + "sessionHandle=" + sessionHandle.getPublicId() + '}'; } }
@Override public String toString() { return "LensConnection{" + "sessionHandle=" + sessionHandle.getPublicId() + '}'; } }
/** * Checks for lens session. * * @param session the session * @return true, if successful */ public boolean hasLensSession(LensSessionHandle session) { return lensToHiveSession.containsKey(session.getPublicId().toString()); } }
/** * Checks for lens session. * * @param session the session * @return true, if successful */ public boolean hasLensSession(LensSessionHandle session) { return lensToHiveSession.containsKey(session.getPublicId().toString()); } }
@Override public boolean isOpen(LensSessionHandle sessionHandle) { return SESSION_MAP.containsKey(sessionHandle.getPublicId().toString()); }
protected void registerPredictUdf(LensSessionHandle sessionHandle, QueryRunner queryRunner) throws LensException { if (isUdfRegisterd(sessionHandle)) { // Already registered, nothing to do return; } log.info("Registering UDF for session " + sessionHandle.getPublicId().toString()); String regUdfQuery = "CREATE TEMPORARY FUNCTION " + HiveMLUDF.UDF_NAME + " AS '" + HiveMLUDF.class .getCanonicalName() + "'"; queryRunner.setQueryName("register_predict_udf_" + sessionHandle.getPublicId().toString()); QueryHandle udfQuery = queryRunner.runQuery(regUdfQuery); log.info("udf query handle is " + udfQuery); predictUdfStatus.put(sessionHandle, true); log.info("Predict UDF registered for session " + sessionHandle.getPublicId().toString()); }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { int numSessions = in.readInt(); restorableSessions = new ArrayList<LensSessionImpl.LensSessionPersistInfo>(); for (int i = 0; i < numSessions; i++) { LensSessionImpl.LensSessionPersistInfo persistInfo = new LensSessionImpl.LensSessionPersistInfo(); persistInfo.readExternal(in); restorableSessions.add(persistInfo); SESSION_MAP.put(persistInfo.getSessionHandle().getPublicId().toString(), persistInfo.getSessionHandle()); } log.info("Session service recovered " + SESSION_MAP.size() + " sessions"); }
/** * Release. * * @param sessionHandle the session handle */ public void release(LensSessionHandle sessionHandle) { if (sessionHandle != null) { getSession(sessionHandle).release(); log.debug("Released lens session:{}", sessionHandle.getPublicId()); } }
/** * Acquire. * * @param sessionHandle the session handle */ public void acquire(LensSessionHandle sessionHandle) { if (sessionHandle != null) { log.debug("Acquiring lens session:{}", sessionHandle.getPublicId()); getSession(sessionHandle).acquire(); } }
protected void resotreSessionIfRequired(final LensSessionHandle sessionHandle) { try { verifySessionInMemory(sessionHandle); } catch (LensException e) { try { restoreFromDb(sessionHandle); } catch (LensException le) { // we need to restore lens session if not present in memory, // if its not in mysql then just swallow exception here log.warn("Session " + sessionHandle.getPublicId() + " is invalid."); } } }
/** * Execute async internal. * * @param sessionHandle the session handle * @param ctx the ctx * @return the query handle * @throws LensException the lens exception */ private QueryHandle executeAsyncInternal(LensSessionHandle sessionHandle, QueryContext ctx) throws LensException { ctx.setLensSessionIdentifier(sessionHandle.getPublicId().toString()); rewriteAndSelect(ctx); return submitQuery(ctx); }
private void addSingleResourceToHive(HiveDriver driver, ResourceEntry res, LensSessionHandle sessionHandle) throws LensException { String sessionIdentifier = sessionHandle.getPublicId().toString(); String uri = res.getUri(); // Hive doesn't and URIs starting with file:/ correctly, so we have to change it to file:/// // See: org.apache.hadoop.hive.ql.exec.Utilities.addToClassPath uri = removePrefixBeforeURI(uri); String command = "add " + res.getType().toLowerCase() + " " + uri; driver.execute(createResourceQuery(command, sessionHandle, driver)); log.info("Added resource to hive driver {} for session {} cmd: {}", driver, sessionIdentifier, command); }
private void doesSessionBelongToUser(LensSessionHandle sessionHandle, String user) throws LensException { LensSessionImpl session = getSession(sessionHandle); if (!session.getLoggedInUser().equals(user)) { log.warn("Session User {} is not equal to Job owner {}", session.getLoggedInUser(), user); throw new LensException(LensSchedulerErrorCode.CURRENT_USER_IS_NOT_SAME_AS_OWNER.getLensErrorInfo(), null, session.getLoggedInUser(), sessionHandle.getPublicId().toString(), user); } }
/** * Gets the hive session handle. * * @param lensHandle the lens handle * @return the hive session handle */ public static SessionHandle getHiveSessionHandle(LensSessionHandle lensHandle) { return new SessionHandle(new HandleIdentifier(lensHandle.getPublicId(), lensHandle.getSecretId()), CLIService.SERVER_VERSION); }
/** * Get the current session handle */ @CliCommand(value = {"session"}, help = "Print the current session handle") public String getSessionHandle() { LensSessionHandle sessionHandle = getClient().getConnection().getSessionHandle(); if (sessionHandle != null) { return "Session Handle: " + sessionHandle.getPublicId(); } else { return "Session not established"; } }
/** * Get the current session handle */ @CliCommand(value = {"session"}, help = "Print the current session handle") public String getSessionHandle() { LensSessionHandle sessionHandle = getClient().getConnection().getSessionHandle(); if (sessionHandle != null) { return "Session Handle: " + sessionHandle.getPublicId(); } else { return "Session not established"; } }
private List<UserSessionInfo> getSessionsOfFoo() { List<UserSessionInfo> sessions = getSessionService().getSessionInfo(); Iterator<UserSessionInfo> iter = sessions.iterator(); while (iter.hasNext()) { UserSessionInfo session = iter.next(); assertNotEquals(session.getHandle(), lensSessionId.getPublicId(), "session not cleaned up even after queries finished"); if (!session.getUserName().equals("foo")) { iter.remove(); } } return sessions; }
public List<UserSessionInfo> getSessionInfo() { List<UserSessionInfo> userSessionInfoList = new ArrayList<>(); for (LensSessionHandle handle : SESSION_MAP.values()) { LensSessionImpl session = getSession(handle); UserSessionInfo sessionInfo = new UserSessionInfo(); sessionInfo.setHandle(handle.getPublicId().toString()); sessionInfo.setUserName(session.getLoggedInUser()); sessionInfo.setActiveQueries(session.getActiveQueries()); sessionInfo.setCreationTime(session.getCreationTime()); sessionInfo.setLastAccessTime(session.getLastAccessTime()); userSessionInfoList.add(sessionInfo); } return userSessionInfoList; }
private void restoreFromDb(final LensSessionHandle sessionHandle) throws LensException { try { LensSessionImpl.LensSessionPersistInfo persistInfo = LENS_SERVER_DAO.findActiveSessionDetails(sessionHandle); if (persistInfo == null) { throw new LensException("Unable to find session in mysql with session id : " + sessionHandle.getPublicId()); } restoreSession(sessionHandle, persistInfo.getUsername(), persistInfo.getPassword(), persistInfo.getConfig()); } catch (Exception daoE) { log.error("sql query failed with " + daoE.toString()); throw new LensException(SESSION_CLOSED.getLensErrorInfo(), sessionHandle); } throw new LensException("session not found"); }
@Test public void testPriorityOnMockQuery() throws Exception { String query = "select mock, fail from " + TEST_TABLE; QueryContext ctx = queryService.createContext(query, null, new LensConf(), new Configuration(), 5000L); ctx.setLensSessionIdentifier(lensSessionId.getPublicId().toString()); queryService.acquire(lensSessionId); try { queryService.rewriteAndSelect(ctx); } finally { queryService.release(lensSessionId); } assertNotNull(ctx.getSelectedDriver()); assertEquals(ctx.getPriority(), Priority.NORMAL); }