Search in sources :

Example 1 with ThriftCLIServiceClient

use of org.apache.hive.service.cli.thrift.ThriftCLIServiceClient in project hive by apache.

the class TestEmbeddedThriftBinaryCLIService method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    service = new EmbeddedThriftBinaryCLIService();
    HiveConf conf = new HiveConf();
    conf.setBoolean("datanucleus.schema.autoCreateTables", true);
    conf.setVar(HiveConf.ConfVars.HIVEMAPREDMODE, "nonstrict");
    UtilsForTest.expandHiveConfParams(conf);
    service.init(conf);
    client = new ThriftCLIServiceClient(service);
}
Also used : EmbeddedThriftBinaryCLIService(org.apache.hive.service.cli.thrift.EmbeddedThriftBinaryCLIService) HiveConf(org.apache.hadoop.hive.conf.HiveConf) ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) BeforeClass(org.junit.BeforeClass)

Example 2 with ThriftCLIServiceClient

use of org.apache.hive.service.cli.thrift.ThriftCLIServiceClient in project hive by apache.

the class TestPluggableHiveSessionImpl method testSessionImplWithUGI.

@Test
public void testSessionImplWithUGI() 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_WITH_UGI_CLASSNAME, SampleHiveSessionImplWithUGI.class.getName());
    hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS, true);
    CLIService cliService = new CLIService(null, true);
    cliService.init(hiveConf);
    ThriftBinaryCLIService service = new ThriftBinaryCLIService(cliService);
    service.init(hiveConf);
    ThriftCLIServiceClient client = new ThriftCLIServiceClient(service);
    SessionHandle sessionHandle = null;
    sessionHandle = client.openSession("tom", "password");
    assertEquals(SampleHiveSessionImplWithUGI.class.getName(), service.getHiveConf().getVar(HiveConf.ConfVars.HIVE_SESSION_IMPL_WITH_UGI_CLASSNAME));
    HiveSession session = cliService.getSessionManager().getSession(sessionHandle);
    assertEquals(SampleHiveSessionImplWithUGI.MAGIC_RETURN_VALUE, session.getNoOperationTime());
    client.closeSession(sessionHandle);
}
Also used : ThriftBinaryCLIService(org.apache.hive.service.cli.thrift.ThriftBinaryCLIService) HiveConf(org.apache.hadoop.hive.conf.HiveConf) SessionHandle(org.apache.hive.service.cli.SessionHandle) CLIService(org.apache.hive.service.cli.CLIService) ThriftBinaryCLIService(org.apache.hive.service.cli.thrift.ThriftBinaryCLIService) ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) Test(org.junit.Test)

Example 3 with ThriftCLIServiceClient

use of org.apache.hive.service.cli.thrift.ThriftCLIServiceClient in project hive by apache.

the class TestSessionGlobalInitFile method setUp.

@Before
public void setUp() throws Exception {
    // create and put .hiverc sample file to default directory
    initFile = File.createTempFile("test", "hive");
    tmpDir = initFile.getParentFile().getAbsoluteFile() + File.separator + "TestSessionGlobalInitFile";
    initFile.delete();
    FileUtils.deleteDirectory(new File(tmpDir));
    initFile = new File(tmpDir + File.separator + SessionManager.HIVERCFILE);
    initFile.getParentFile().mkdirs();
    initFile.createNewFile();
    String[] fileContent = new String[] { "-- global init hive file for test", "set a=1;", "set hiveconf:b=1;", "set hivevar:c=1;", "set d\\", "      =1;", "add jar " + initFile.getAbsolutePath() };
    FileUtils.writeLines(initFile, Arrays.asList(fileContent));
    // set up service and client
    hiveConf = new HiveConf();
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_GLOBAL_INIT_FILE_LOCATION, initFile.getParentFile().getAbsolutePath());
    hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    service = new FakeEmbeddedThriftBinaryCLIService(hiveConf);
    service.init(new HiveConf());
    client = new ThriftCLIServiceClient(service);
}
Also used : HiveConf(org.apache.hadoop.hive.conf.HiveConf) File(java.io.File) ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) Before(org.junit.Before)

Example 4 with ThriftCLIServiceClient

use of org.apache.hive.service.cli.thrift.ThriftCLIServiceClient in project hive by apache.

the class TestSessionCleanup method testTempSessionFileCleanup.

@Test
public // This is to test session temporary files are cleaned up after HIVE-11768
void testTempSessionFileCleanup() throws Exception {
    MyEmbeddedThriftBinaryCLIService service = new MyEmbeddedThriftBinaryCLIService();
    HiveConf hiveConf = new HiveConf();
    hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    // NOTES: Apply a random tmp directory to avoid default location conflicting with other tests
    hiveConf.setVar(HiveConf.ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION, TEST_DATA_DIR + File.separator + "operation_logs");
    service.init(hiveConf);
    ThriftCLIServiceClient client = new ThriftCLIServiceClient(service);
    Set<String> existingPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles(hiveConf)));
    SessionHandle sessionHandle = client.openSession("user1", "foobar", Collections.<String, String>emptyMap());
    OperationHandle opHandle1 = client.executeStatement(sessionHandle, "set a=b", null);
    String queryId1 = service.getCliService().getQueryId(opHandle1.toTOperationHandle());
    Assert.assertNotNull(queryId1);
    OperationHandle opHandle2 = client.executeStatement(sessionHandle, "set b=c", null);
    String queryId2 = service.getCliService().getQueryId(opHandle2.toTOperationHandle());
    Assert.assertNotNull(queryId2);
    File operationLogRootDir = new File(hiveConf.getVar(HiveConf.ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION));
    Assert.assertNotEquals(0, operationLogRootDir.list().length);
    client.closeSession(sessionHandle);
    // Check if session files are removed
    Assert.assertEquals(0, operationLogRootDir.list().length);
    // Check if the pipeout files are removed
    Set<String> finalPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles(hiveConf)));
    finalPipeoutFiles.removeAll(existingPipeoutFiles);
    Assert.assertTrue(finalPipeoutFiles.isEmpty());
    // Verify both operationHandles are no longer held by the OperationManager
    Assert.assertEquals(0, service.getCliService().getSessionManager().getOperations().size());
    // Verify both queryIds are no longer held by the OperationManager
    Assert.assertNull(service.getCliService().getSessionManager().getOperationManager().getOperationByQueryId(queryId2));
    Assert.assertNull(service.getCliService().getSessionManager().getOperationManager().getOperationByQueryId(queryId1));
}
Also used : HiveConf(org.apache.hadoop.hive.conf.HiveConf) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) File(java.io.File) ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ThriftCLIServiceClient

use of org.apache.hive.service.cli.thrift.ThriftCLIServiceClient in project hive by apache.

the class TestOperationLogManager method testOperationLogManager.

@Test
public void testOperationLogManager() throws Exception {
    MyThriftBinaryCLIService service = new MyThriftBinaryCLIService();
    service.init(hiveConf);
    ThriftCLIServiceClient client = new ThriftCLIServiceClient(service);
    SessionManager sessionManager = ((CLIService) service.getService()).getSessionManager();
    SessionHandle session1 = client.openSession("user1", "foobar", Collections.<String, String>emptyMap());
    OperationHandle opHandle1 = client.executeStatement(session1, "select 1 + 1", null);
    Operation operation1 = sessionManager.getOperationManager().getOperation(opHandle1);
    String logLocation = operation1.getOperationLog().toString();
    // as the historic log is enabled, the log dir of the operation1 should be under the historic dir
    assertTrue(logLocation.startsWith(OperationLogManager.getHistoricLogDir()));
    File operationLogFile = new File(operation1.getOperationLog().toString());
    assertTrue(operationLogFile.exists());
    client.closeOperation(opHandle1);
    // now close the session1
    client.closeSession(session1);
    // check that the log of operation1 is exist even if the session1 has been closed
    assertTrue(operationLogFile.exists());
    SessionHandle session2 = client.openSession("user1", "foobar", Collections.<String, String>emptyMap());
    OperationHandle opHandle2 = client.executeStatement(session2, "select 1 + 1", null);
    Operation operation2 = sessionManager.getOperationManager().getOperation(opHandle2);
    // as the historic log is enabled, the log dir of the operation2 should be under the historic dir
    logLocation = operation2.getOperationLog().toString();
    assertTrue(logLocation.startsWith(OperationLogManager.getHistoricLogDir()));
    // remove the query info of operation1 from the cache
    client.closeOperation(opHandle2);
    // the operation1 becomes unreachable
    OperationManager operationManager = sessionManager.getOperationManager();
    assertTrue(operationManager.getAllCachedQueryIds().size() == 1 && operationManager.getLiveQueryInfos().isEmpty());
    assertNull(operationManager.getQueryInfo(opHandle1.getHandleIdentifier().toString()));
    // now the session1 is closed and has no cached query info, the historic session log dir should be returned.
    OperationLogManager logManager = sessionManager.getLogManager().get();
    List<File> expiredLogDirs = logManager.getExpiredSessionLogDirs();
    List<File> expiredOperationLogs = logManager.getExpiredOperationLogFiles();
    assertEquals(operation1.getQueryId(), expiredOperationLogs.get(0).getName());
    assertEquals(session1.getHandleIdentifier().toString(), expiredLogDirs.get(0).getName());
    logManager.removeExpiredOperationLogAndDir();
    // the historic session log dir has been cleanup
    assertFalse(operationLogFile.exists());
    assertFalse(expiredLogDirs.get(0).exists());
    // though session2 is closed, but there exists his operation(operation2) in cache and
    // log file under the historic session log dir, so the historic log dir of session2 would not be cleaned
    client.closeSession(session2);
    assertNotNull(operationManager.getQueryInfo(opHandle2.getHandleIdentifier().toString()));
    assertTrue(operationManager.getAllCachedQueryIds().size() == 1 && operationManager.getLiveQueryInfos().isEmpty());
    expiredOperationLogs = logManager.getExpiredOperationLogFiles();
    expiredLogDirs = logManager.getExpiredSessionLogDirs();
    assertTrue(expiredLogDirs.isEmpty());
    assertTrue(expiredOperationLogs.isEmpty());
    logManager.removeExpiredOperationLogAndDir();
    assertTrue(new File(logLocation).getParentFile().exists());
    FileUtils.deleteQuietly(new File(OperationLogManager.getHistoricLogDir()));
}
Also used : SessionManager(org.apache.hive.service.cli.session.SessionManager) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) File(java.io.File) CLIService(org.apache.hive.service.cli.CLIService) EmbeddedThriftBinaryCLIService(org.apache.hive.service.cli.thrift.EmbeddedThriftBinaryCLIService) ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) Test(org.junit.Test)

Aggregations

ThriftCLIServiceClient (org.apache.hive.service.cli.thrift.ThriftCLIServiceClient)8 HiveConf (org.apache.hadoop.hive.conf.HiveConf)7 SessionHandle (org.apache.hive.service.cli.SessionHandle)4 EmbeddedThriftBinaryCLIService (org.apache.hive.service.cli.thrift.EmbeddedThriftBinaryCLIService)4 Test (org.junit.Test)4 File (java.io.File)3 CLIService (org.apache.hive.service.cli.CLIService)3 Before (org.junit.Before)3 OperationHandle (org.apache.hive.service.cli.OperationHandle)2 ThriftBinaryCLIService (org.apache.hive.service.cli.thrift.ThriftBinaryCLIService)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 SessionManager (org.apache.hive.service.cli.session.SessionManager)1 BeforeClass (org.junit.BeforeClass)1