use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class SessionManager method startTimeoutChecker.
private void startTimeoutChecker() {
// minimum 3 seconds
final long interval = Math.max(checkInterval, 3000l);
final Runnable timeoutChecker = new Runnable() {
@Override
public void run() {
sleepFor(interval);
while (!shutdown) {
long current = System.currentTimeMillis();
for (HiveSession session : new ArrayList<HiveSession>(handleToSession.values())) {
if (shutdown) {
break;
}
if (sessionTimeout > 0 && session.getLastAccessTime() + sessionTimeout <= current && (!checkOperation || session.getNoOperationTime() > sessionTimeout)) {
SessionHandle handle = session.getSessionHandle();
LOG.warn("Session " + handle + " is Timed-out (last access : " + new Date(session.getLastAccessTime()) + ") and will be closed");
try {
closeSession(handle);
} catch (HiveSQLException e) {
LOG.warn("Exception is thrown closing session " + handle, e);
} finally {
Metrics metrics = MetricsFactory.getInstance();
if (metrics != null) {
metrics.incrementCounter(MetricsConstant.HS2_ABANDONED_SESSIONS);
}
}
} else {
session.closeExpiredOperations();
}
}
sleepFor(interval);
}
}
private void sleepFor(long interval) {
synchronized (timeoutCheckerLock) {
try {
timeoutCheckerLock.wait(interval);
} catch (InterruptedException e) {
// Ignore, and break.
}
}
}
};
backgroundOperationPool.execute(timeoutChecker);
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCLIServiceClient method openSession.
/* (non-Javadoc)
* @see org.apache.hive.service.cli.ICLIService#openSession(java.lang.String, java.lang.String, java.util.Map)
*/
@Override
public SessionHandle openSession(String username, String password, Map<String, String> configuration) throws HiveSQLException {
try {
TOpenSessionReq req = new TOpenSessionReq();
req.setUsername(username);
req.setPassword(password);
req.setConfiguration(configuration);
TOpenSessionResp resp = cliService.OpenSession(req);
checkStatus(resp.getStatus());
return new SessionHandle(resp.getSessionHandle(), resp.getServerProtocolVersion());
} catch (HiveSQLException e) {
throw e;
} catch (Exception e) {
throw new HiveSQLException(e);
}
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestHS2HttpServer method testApiServletActiveSessions.
@Test
public void testApiServletActiveSessions() throws Exception {
String sessionsRoute = "/sessions";
String initNoSessionsResponse = readFromUrl(apiBaseURL + sessionsRoute);
Assert.assertTrue("[]".equals(initNoSessionsResponse));
SessionHandle handle1 = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap());
String oneSessionResponse = readFromUrl(apiBaseURL + sessionsRoute);
List<JsonNode> sessionNodes = getListOfNodes(oneSessionResponse);
Assert.assertEquals(sessionNodes.size(), 1);
JsonNode session = sessionNodes.get(0);
Assert.assertEquals(session.path("sessionId").asText(), handle1.getSessionId().toString());
Assert.assertEquals(session.path("username").asText(), "user");
Assert.assertEquals(session.path("ipAddress").asText(), "127.0.0.1");
Assert.assertEquals(session.path("operationCount").asInt(), 0);
Assert.assertTrue(session.path("activeTime").canConvertToInt());
Assert.assertTrue(session.path("idleTime").canConvertToInt());
SessionHandle handle2 = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap());
String twoSessionsResponse = readFromUrl(apiBaseURL + sessionsRoute);
List<JsonNode> twoSessionsNodes = getListOfNodes(twoSessionsResponse);
Assert.assertEquals(twoSessionsNodes.size(), 2);
sm.closeSession(handle1);
sm.closeSession(handle2);
String endNoSessionsResponse = readFromUrl(apiBaseURL + sessionsRoute);
Assert.assertTrue("[]".equals(endNoSessionsResponse));
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestHS2HttpServer method testApiServletHistoricalQueries.
@Test
public void testApiServletHistoricalQueries() throws Exception {
String historicalQueriesRoute = "/queries/historical";
final SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap());
String queryString = "SET " + HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname + " = false";
OperationHandle opHandle = client.executeStatement(handle, queryString, new HashMap());
client.closeOperation(opHandle);
opHandle = client.executeStatement(handle, "SELECT 1", new HashMap());
client.closeOperation(opHandle);
String queriesResponse = readFromUrl(apiBaseURL + historicalQueriesRoute);
List<JsonNode> historicalQueries = getListOfNodes(queriesResponse);
Assert.assertTrue(historicalQueries.size() == 1);
JsonNode historicalQuery = historicalQueries.get(0);
Assert.assertEquals(historicalQuery.path("running").asBoolean(), false);
Assert.assertEquals(historicalQuery.path("state").asText(), "FINISHED");
Assert.assertTrue(historicalQuery.path("runtime").canConvertToInt());
Assert.assertTrue(historicalQuery.path("queryDisplay").isObject());
}
use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class TestSessionHooks method testProxyUser.
/**
* Create session with proxy user property. Verify the effective session user
* @throws Exception
*/
@Test
public void testProxyUser() throws Exception {
String connectingUser = "user1";
String proxyUser = System.getProperty("user.name");
Map<String, String> sessConf = new HashMap<String, String>();
sessConf.put(HiveAuthConstants.HS2_PROXY_USER, proxyUser);
sessionUserName = proxyUser;
SessionHandle sessionHandle = client.openSession(connectingUser, "foobar", sessConf);
Assert.assertEquals(1, SessionHookTest.runCount.get());
client.closeSession(sessionHandle);
}
Aggregations