/** Reopens the session that was found to not be running. */ @Override public TezSessionState reopen(TezSessionState sessionState) throws Exception { HiveConf sessionConf = sessionState.getConf(); if (sessionState.getQueueName() != null && sessionConf.get(TezConfiguration.TEZ_QUEUE_NAME) == null) { sessionConf.set(TezConfiguration.TEZ_QUEUE_NAME, sessionState.getQueueName()); } reopenInternal(sessionState); return sessionState; }
@Test public void testCloseAndOpenDefault() throws Exception { poolManager = new TestTezSessionPoolManager(); TezSessionState session = Mockito.mock(TezSessionState.class); Mockito.when(session.isDefault()).thenReturn(false); Mockito.when(session.getConf()).thenReturn(conf); poolManager.reopen(session); Mockito.verify(session).close(false); Mockito.verify(session).open(Mockito.<TezSessionState.HiveResources>any()); }
@Override public void applyAction(final Map<TezSessionState, Trigger> queriesViolated) { for (Map.Entry<TezSessionState, Trigger> entry : queriesViolated.entrySet()) { switch (entry.getValue().getAction().getType()) { case KILL_QUERY: TezSessionState sessionState = entry.getKey(); String queryId = sessionState.getWmContext().getQueryId(); try { SessionState ss = new SessionState(new HiveConf()); ss.setIsHiveServerQuery(true); SessionState.start(ss); KillQuery killQuery = sessionState.getKillQuery(); // if kill query is null then session might have been released to pool or closed already if (killQuery != null) { sessionState.getKillQuery().killQuery(queryId, entry.getValue().getViolationMsg(), sessionState.getConf()); } } catch (HiveException e) { LOG.warn("Unable to kill query {} for trigger violation", queryId); } break; default: throw new RuntimeException("Unsupported action: " + entry.getValue()); } } } }
if (doAsEnabled != session.getConf().getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS)) { return false;
if (doAsEnabled != session.getConf().getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS)) { return false;
/** Reopens the session that was found to not be running. */ public void reopenSession(TezSessionState sessionState, HiveConf conf, String[] additionalFiles, boolean keepTmpDir) throws Exception { HiveConf sessionConf = sessionState.getConf(); if (sessionConf != null && sessionConf.get(TezConfiguration.TEZ_QUEUE_NAME) != null) { // user has explicitly specified queue name conf.set(TezConfiguration.TEZ_QUEUE_NAME, sessionConf.get(TezConfiguration.TEZ_QUEUE_NAME)); } else { // default queue name when the initial session was created if (sessionState.getQueueName() != null) { conf.set(TezConfiguration.TEZ_QUEUE_NAME, sessionState.getQueueName()); } } // TODO: close basically resets the object to a bunch of nulls. // We should ideally not reuse the object because it's pointless and error-prone. sessionState.close(keepTmpDir); // Clean up stuff. sessionState.open(conf, additionalFiles); }
@Test(timeout = 10000) public void testReuse() throws Exception { HiveConf conf = createConf(); MockQam qam = new MockQam(); WorkloadManager wm = new WorkloadManagerForTest("test", conf, 1, qam); wm.start(); TezSessionState nonPool = mock(TezSessionState.class); when(nonPool.getConf()).thenReturn(conf); doNothing().when(nonPool).close(anyBoolean()); TezSessionState session = wm.getSession(nonPool, mappingInput("user"), conf); verify(nonPool).close(anyBoolean()); assertNotSame(nonPool, session); session.returnToSessionManager(); TezSessionPoolSession diffPool = mock(TezSessionPoolSession.class); when(diffPool.getConf()).thenReturn(conf); doNothing().when(diffPool).returnToSessionManager(); session = wm.getSession(diffPool, mappingInput("user"), conf); verify(diffPool).returnToSessionManager(); assertNotSame(diffPool, session); TezSessionState session2 = wm.getSession(session, mappingInput("user"), conf); assertSame(session, session2); }
Mockito.when(session.getQueueName()).thenReturn("default"); Mockito.when(session.isDefault()).thenReturn(false); Mockito.when(session.getConf()).thenReturn(conf);
public void closeAndOpen(TezSessionState sessionState, HiveConf conf, String[] additionalFiles, boolean keepTmpDir) throws Exception { HiveConf sessionConf = sessionState.getConf(); if (sessionConf != null && sessionConf.get("tez.queue.name") != null) { conf.set("tez.queue.name", sessionConf.get("tez.queue.name")); } close(sessionState, keepTmpDir); sessionState.open(conf, additionalFiles); openSessions.add(sessionState); }