Search in sources :

Example 6 with TOpenSessionReq

use of org.apache.hive.service.rpc.thrift.TOpenSessionReq in project hive by apache.

the class TestThriftHttpCLIServiceFeatures method testAdditionalHttpHeaders.

/**
 * Test additional http headers passed to request interceptor.
 * @throws Exception
 */
@Test
public void testAdditionalHttpHeaders() throws Exception {
    TTransport transport;
    DefaultHttpClient hClient = new DefaultHttpClient();
    String httpUrl = getHttpUrl();
    Map<String, String> additionalHeaders = new HashMap<String, String>();
    additionalHeaders.put("key1", "value1");
    additionalHeaders.put("key2", "value2");
    HttpBasicAuthInterceptorWithLogging authInt = new HttpBasicAuthInterceptorWithLogging(ThriftCLIServiceTest.USERNAME, ThriftCLIServiceTest.PASSWORD, null, null, false, additionalHeaders, 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();
    httpClient.OpenSession(openReq).getSessionHandle();
    ArrayList<String> headers = authInt.getRequestHeaders();
    for (String h : headers) {
        assertTrue(h.contains("key1:value1"));
        assertTrue(h.contains("key2:value2"));
    }
}
Also used : HashMap(java.util.HashMap) THttpClient(org.apache.thrift.transport.THttpClient) TTransport(org.apache.thrift.transport.TTransport) TOpenSessionReq(org.apache.hive.service.rpc.thrift.TOpenSessionReq) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) TCLIService(org.apache.hive.service.rpc.thrift.TCLIService) Test(org.junit.Test)

Example 7 with TOpenSessionReq

use of org.apache.hive.service.rpc.thrift.TOpenSessionReq in project hive by apache.

the class TestThriftCLIServiceSecurity method testPasswordNotInLogs.

/**
 * Ensures password isn't printed to logs from TOpenSessionReq.toString().
 * See maven-replacer-plugin code in service-rpc/pom.xml.
 *
 * @throws Exception
 */
@Test
public void testPasswordNotInLogs() throws Exception {
    String PASSWORD = "testpassword";
    TOpenSessionReq tOpenSessionReq = new TOpenSessionReq();
    tOpenSessionReq.setPassword(PASSWORD);
    assertFalse(tOpenSessionReq.toString().contains(PASSWORD));
}
Also used : TOpenSessionReq(org.apache.hive.service.rpc.thrift.TOpenSessionReq) Test(org.junit.Test)

Example 8 with TOpenSessionReq

use of org.apache.hive.service.rpc.thrift.TOpenSessionReq 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();
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) TExecuteStatementReq(org.apache.hive.service.rpc.thrift.TExecuteStatementReq) OperationHandle(org.apache.hive.service.cli.OperationHandle) TCLIService(org.apache.hive.service.rpc.thrift.TCLIService) TSessionHandle(org.apache.hive.service.rpc.thrift.TSessionHandle) TCancelOperationReq(org.apache.hive.service.rpc.thrift.TCancelOperationReq) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TStatus(org.apache.hive.service.rpc.thrift.TStatus) TTransport(org.apache.thrift.transport.TTransport) TOpenSessionReq(org.apache.hive.service.rpc.thrift.TOpenSessionReq) TOpenSessionResp(org.apache.hive.service.rpc.thrift.TOpenSessionResp) TExecuteStatementResp(org.apache.hive.service.rpc.thrift.TExecuteStatementResp) Test(org.junit.Test)

Example 9 with TOpenSessionReq

use of org.apache.hive.service.rpc.thrift.TOpenSessionReq 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);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) TOpenSessionReq(org.apache.hive.service.rpc.thrift.TOpenSessionReq) TOpenSessionResp(org.apache.hive.service.rpc.thrift.TOpenSessionResp) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Aggregations

TOpenSessionReq (org.apache.hive.service.rpc.thrift.TOpenSessionReq)9 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 TOpenSessionResp (org.apache.hive.service.rpc.thrift.TOpenSessionResp)4 TTransport (org.apache.thrift.transport.TTransport)4 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)3 THttpClient (org.apache.thrift.transport.THttpClient)3 IOException (java.io.IOException)2 TExecuteStatementReq (org.apache.hive.service.rpc.thrift.TExecuteStatementReq)2 TSessionHandle (org.apache.hive.service.rpc.thrift.TSessionHandle)2 TException (org.apache.thrift.TException)2 InterruptedIOException (java.io.InterruptedIOException)1 SQLException (java.sql.SQLException)1 Savepoint (java.sql.Savepoint)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CodahaleMetrics (org.apache.hadoop.hive.common.metrics.metrics2.CodahaleMetrics)1