use of org.apache.hive.service.rpc.thrift.TOpenSessionResp in project hive by apache.
the class TestThriftHttpCLIServiceFeatures method verifyForwardedHeaders.
private void verifyForwardedHeaders(ArrayList<String> headerIPs, String cmd) throws Exception {
TTransport transport;
DefaultHttpClient hClient = new DefaultHttpClient();
String httpUrl = getHttpUrl();
// add an interceptor that adds the X-Forwarded-For header with given ips
if (!headerIPs.isEmpty()) {
Header xForwardHeader = new BasicHeader("X-Forwarded-For", Joiner.on(",").join(headerIPs));
RequestDefaultHeaders headerInterceptor = new RequestDefaultHeaders(Arrays.asList(xForwardHeader));
hClient.addRequestInterceptor(headerInterceptor);
}
// interceptor for adding username, pwd
HttpBasicAuthInterceptor authInt = new HttpBasicAuthInterceptor(ThriftCLIServiceTest.USERNAME, ThriftCLIServiceTest.PASSWORD, null, null, false, null, null);
hClient.addRequestInterceptor(authInt);
transport = new THttpClient(httpUrl, hClient);
TCLIService.Client httpClient = getClient(transport);
// Create a new open session request object
TOpenSessionReq openReq = new TOpenSessionReq();
TOpenSessionResp openResp = httpClient.OpenSession(openReq);
// execute a query
TExecuteStatementReq execReq = new TExecuteStatementReq(openResp.getSessionHandle(), "show tables");
httpClient.ExecuteStatement(execReq);
// capture arguments to authorizer impl call and verify ip addresses passed
ArgumentCaptor<HiveAuthzContext> contextCapturer = ArgumentCaptor.forClass(HiveAuthzContext.class);
verify(mockedAuthorizer).checkPrivileges(any(HiveOperationType.class), Matchers.anyListOf(HivePrivilegeObject.class), Matchers.anyListOf(HivePrivilegeObject.class), contextCapturer.capture());
HiveAuthzContext context = contextCapturer.getValue();
System.err.println("Forwarded IP Addresses " + context.getForwardedAddresses());
List<String> auditIPAddresses = new ArrayList<String>(context.getForwardedAddresses());
Collections.sort(auditIPAddresses);
Collections.sort(headerIPs);
Assert.assertEquals("Checking forwarded IP Address", headerIPs, auditIPAddresses);
}
use of org.apache.hive.service.rpc.thrift.TOpenSessionResp in project hive by apache.
the class TestHs2ConnectionMetricsHttp method testOpenConnectionMetrics.
@Test
public void testOpenConnectionMetrics() throws Exception {
CodahaleMetrics metrics = (CodahaleMetrics) MetricsFactory.getInstance();
TCLIService.Client httpClient = getHttpClient();
TOpenSessionReq openSessionReq = new TOpenSessionReq();
TOpenSessionResp tOpenSessionResp = httpClient.OpenSession(openSessionReq);
// wait a couple of sec to make sure the connection is closed
TimeUnit.SECONDS.sleep(3);
verifyConnectionMetrics(metrics.dumpJson(), 0, 1);
TSessionHandle sessionHandle = tOpenSessionResp.getSessionHandle();
TCloseSessionReq closeSessionReq = new TCloseSessionReq(sessionHandle);
httpClient.CloseSession(closeSessionReq);
TimeUnit.SECONDS.sleep(3);
verifyConnectionMetrics(metrics.dumpJson(), 0, 2);
tOpenSessionResp = httpClient.OpenSession(openSessionReq);
TimeUnit.SECONDS.sleep(3);
verifyConnectionMetrics(metrics.dumpJson(), 0, 3);
sessionHandle = tOpenSessionResp.getSessionHandle();
closeSessionReq = new TCloseSessionReq(sessionHandle);
httpClient.CloseSession(closeSessionReq);
TimeUnit.SECONDS.sleep(3);
verifyConnectionMetrics(metrics.dumpJson(), 0, 4);
}
use of org.apache.hive.service.rpc.thrift.TOpenSessionResp in project hive by apache.
the class ThriftCLIService method OpenSession.
@Override
public TOpenSessionResp OpenSession(TOpenSessionReq req) throws TException {
LOG.info("Client protocol version: " + req.getClient_protocol());
TOpenSessionResp resp = new TOpenSessionResp();
String userName = null;
try {
userName = getUserName(req);
final SessionHandle sessionHandle = getSessionHandle(req, resp, userName);
final int fetchSize = hiveConf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_DEFAULT_FETCH_SIZE);
Map<String, String> map = new HashMap<>();
map.put(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_DEFAULT_FETCH_SIZE.varname, Integer.toString(fetchSize));
map.put(HiveConf.ConfVars.HIVE_DEFAULT_NULLS_LAST.varname, String.valueOf(hiveConf.getBoolVar(ConfVars.HIVE_DEFAULT_NULLS_LAST)));
resp.setSessionHandle(sessionHandle.toTSessionHandle());
resp.setConfiguration(map);
resp.setStatus(OK_STATUS);
ThriftCLIServerContext context = (ThriftCLIServerContext) currentServerContext.get();
if (context != null) {
context.setSessionHandle(sessionHandle);
}
LOG.info("Login attempt is successful for user : " + userName);
} catch (Exception e) {
// Do not log request as it contains password information
LOG.error("Login attempt failed for user : {}", userName, e);
resp.setStatus(HiveSQLException.toTStatus(e));
}
return resp;
}
use of org.apache.hive.service.rpc.thrift.TOpenSessionResp 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.rpc.thrift.TOpenSessionResp in project hive by apache.
the class TestThriftCliServiceWithInfoMessage method testExecuteReturnWithInfoMessage.
@Test
public void testExecuteReturnWithInfoMessage() throws Exception {
TTransport transport = HiveAuthUtils.getSocketTransport(host, cliPort, 0);
try {
transport.open();
TCLIService.Iface client = new TCLIService.Client(new TBinaryProtocol(transport));
TOpenSessionReq openReq = new TOpenSessionReq();
openReq.setClient_protocol(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11);
TOpenSessionResp sessionResp = client.OpenSession(openReq);
Map<String, String> serverHiveConf = sessionResp.getConfiguration();
assertNotNull(serverHiveConf);
assertTrue(Boolean.parseBoolean(serverHiveConf.get(ConfVars.HIVE_DEFAULT_NULLS_LAST.varname)));
TSessionHandle sessHandle = sessionResp.getSessionHandle();
TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, "select 1");
execReq.setRunAsync(true);
TExecuteStatementResp execResp = client.ExecuteStatement(execReq);
TStatus status = execResp.getStatus();
assertTrue(status.getStatusCode() == TStatusCode.SUCCESS_WITH_INFO_STATUS);
assertNotNull(status.getInfoMessages());
assertTrue(status.getInfoMessages().size() > 0);
Pattern pattern = Pattern.compile("http://.*:(\\d+)/query_page\\.html\\?operationId=(.+)$");
Matcher matcher = pattern.matcher(status.getInfoMessages().get(0));
assertTrue(matcher.find());
assertEquals(webuiPort + "", matcher.group(1));
OperationHandle operationHandle = new OperationHandle(execResp.getOperationHandle());
assertEquals(operationHandle.getHandleIdentifier().toString(), matcher.group(2));
// Cancel the operation
TCancelOperationReq cancelReq = new TCancelOperationReq();
cancelReq.setOperationHandle(execResp.getOperationHandle());
client.CancelOperation(cancelReq);
// Disable showing the link
Map<String, String> overlayConf = new HashMap<>();
overlayConf.put(ConfVars.HIVE_SERVER2_SHOW_OPERATION_DRILLDOWN_LINK.varname, "false");
execReq = new TExecuteStatementReq(sessHandle, "select 1");
execReq.setRunAsync(true);
execReq.setConfOverlay(overlayConf);
execResp = client.ExecuteStatement(execReq);
status = execResp.getStatus();
assertTrue(status.getStatusCode() == TStatusCode.SUCCESS_STATUS);
assertTrue(status.getInfoMessages() == null);
} finally {
transport.close();
}
}
Aggregations