use of org.apache.hive.service.cli.SessionHandle in project hive by apache.
the class ThriftCLIService method GetCrossReference.
@Override
public TGetCrossReferenceResp GetCrossReference(TGetCrossReferenceReq req) throws TException {
TGetCrossReferenceResp resp = new TGetCrossReferenceResp();
try {
OperationHandle opHandle = cliService.getCrossReference(new SessionHandle(req.getSessionHandle()), req.getParentCatalogName(), req.getParentSchemaName(), req.getParentTableName(), req.getForeignCatalogName(), req.getForeignSchemaName(), req.getForeignTableName());
resp.setOperationHandle(opHandle.toTOperationHandle());
resp.setStatus(OK_STATUS);
} catch (Exception e) {
LOG.warn("Error getting functions: ", e);
resp.setStatus(HiveSQLException.toTStatus(e));
}
return resp;
}
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 TestPluggableHiveSessionImpl method testSessionImpl.
@Test
public void testSessionImpl() throws Exception {
HiveConf hiveConf = new HiveConf();
hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER.getDefaultValue());
hiveConf.setVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME, SampleHiveSessionImpl.class.getName());
hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, false);
CLIService cliService = new CLIService(null);
cliService.init(hiveConf);
ThriftBinaryCLIService service = new ThriftBinaryCLIService(cliService, null);
service.init(hiveConf);
ThriftCLIServiceClient client = new ThriftCLIServiceClient(service);
SessionHandle sessionHandle = null;
sessionHandle = client.openSession("tom", "password");
assertEquals(SampleHiveSessionImpl.class.getName(), service.getHiveConf().getVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_CLASSNAME));
HiveSession session = cliService.getSessionManager().getSession(sessionHandle);
assertEquals(SampleHiveSessionImpl.MAGIC_RETURN_VALUE, session.getNoOperationTime());
client.closeSession(sessionHandle);
}
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 ThriftCLIService method CloseSession.
@Override
public TCloseSessionResp CloseSession(TCloseSessionReq req) throws TException {
TCloseSessionResp resp = new TCloseSessionResp();
try {
SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle());
cliService.closeSession(sessionHandle);
resp.setStatus(OK_STATUS);
ThriftCLIServerContext context = (ThriftCLIServerContext) currentServerContext.get();
if (context != null) {
context.setSessionHandle(null);
}
} catch (Exception e) {
LOG.warn("Error closing session: ", e);
resp.setStatus(HiveSQLException.toTStatus(e));
}
return resp;
}
Aggregations