static ThriftCLIServiceClient getServiceClientInternal() { for (Service service : hiveServer2.getServices()) { if (service instanceof ThriftBinaryCLIService) { return new ThriftCLIServiceClient((ThriftBinaryCLIService) service); } if (service instanceof ThriftHttpCLIService) { return new ThriftCLIServiceClient((ThriftHttpCLIService) service); } } throw new IllegalStateException("HiveServer2 not running Thrift service"); }
protected static ThriftCLIServiceClient getServiceClientInternal() { for (Service service : hiveServer2.getServices()) { if (service instanceof ThriftBinaryCLIService) { return new ThriftCLIServiceClient((ThriftBinaryCLIService) service); } if (service instanceof ThriftHttpCLIService) { return new ThriftCLIServiceClient((ThriftHttpCLIService) service); } } throw new IllegalStateException("HiveServer2 not running Thrift service"); }
protected synchronized TTransport connect(HiveConf conf) throws HiveSQLException, TTransportException { if (transport != null && transport.isOpen()) { transport.close(); } String host = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST); int port = conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT); LOG.info("Connecting to " + host + ":" + port); transport = new TSocket(host, port); ((TSocket) transport).setTimeout((int) conf.getTimeVar(HiveConf.ConfVars.SERVER_READ_SOCKET_TIMEOUT, TimeUnit.SECONDS) * 1000); try { ((TSocket) transport).getSocket().setKeepAlive(conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE)); } catch (SocketException e) { LOG.error("Error setting keep alive to " + conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE), e); } String userName = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_USER); String passwd = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_PASSWORD); try { transport = PlainSaslHelper.getPlainTransport(userName, passwd, transport); } catch (SaslException e) { LOG.error("Error creating plain SASL transport", e); } TProtocol protocol = new TBinaryProtocol(transport); transport.open(); base = new ThriftCLIServiceClient(new TCLIService.Client(protocol), conf); LOG.info("Connected!"); return transport; }
@Override @Before public void setUp() throws Exception { super.setUp(); SessionHookTest.runCount.set(0); System.setProperty(ConfVars.HIVE_SERVER2_SESSION_HOOK.varname, TestSessionHooks.SessionHookTest.class.getName()); service = new EmbeddedThriftBinaryCLIService(); HiveConf hiveConf = new HiveConf(); hiveConf .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); service.init(hiveConf); client = new ThriftCLIServiceClient(service); }
@Before public void setUp() throws Exception { super.setUp(); // 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); }
@Test // This is to test session temporary files are cleaned up after HIVE-11768 public void testTempSessionFileCleanup() throws Exception { EmbeddedThriftBinaryCLIService service = new EmbeddedThriftBinaryCLIService(); HiveConf hiveConf = new HiveConf(); hiveConf .setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); service.init(hiveConf); ThriftCLIServiceClient client = new ThriftCLIServiceClient(service); Set<String> existingPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles())); SessionHandle sessionHandle = client.openSession("user1", "foobar", Collections.<String, String>emptyMap()); client.executeStatement(sessionHandle, "set a=b", null); File operationLogRootDir = new File( new HiveConf().getVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LOG_LOCATION)); Assert.assertNotEquals(operationLogRootDir.list().length, 0); client.closeSession(sessionHandle); // Check if session files are removed Assert.assertEquals(operationLogRootDir.list().length, 0); // Check if the pipeout files are removed Set<String> finalPipeoutFiles = new HashSet<String>(Arrays.asList(getPipeoutFiles())); finalPipeoutFiles.removeAll(existingPipeoutFiles); Assert.assertTrue(finalPipeoutFiles.isEmpty()); }
@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, null); 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); }
@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, true); 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); }
public CLIServiceClient getServiceClientInternal() { for (Service service : hiveServer2.getServices()) { if (service instanceof ThriftBinaryCLIService) { return new ThriftCLIServiceClient((ThriftBinaryCLIService) service); } if (service instanceof ThriftHttpCLIService) { return new ThriftCLIServiceClient((ThriftHttpCLIService) service); } } throw new IllegalStateException("HiveServer2 not running Thrift service"); }
base = new ThriftCLIServiceClient(new TCLIService.Client(protocol)); return transport;
protected synchronized TTransport connect(HiveConf conf) throws HiveSQLException, TTransportException { if (transport != null && transport.isOpen()) { transport.close(); } String host = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_BIND_HOST); int port = conf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_PORT); LOG.info("Connecting to " + host + ":" + port); transport = new TSocket(host, port); ((TSocket) transport).setTimeout((int) conf.getTimeVar(HiveConf.ConfVars.SERVER_READ_SOCKET_TIMEOUT, TimeUnit.SECONDS) * 1000); try { ((TSocket) transport).getSocket().setKeepAlive(conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE)); } catch (SocketException e) { LOG.error("Error setting keep alive to " + conf.getBoolVar(HiveConf.ConfVars.SERVER_TCP_KEEP_ALIVE), e); } String userName = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_USER); String passwd = conf.getVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_CLIENT_PASSWORD); try { transport = PlainSaslHelper.getPlainTransport(userName, passwd, transport); } catch (SaslException e) { LOG.error("Error creating plain SASL transport", e); } TProtocol protocol = new TBinaryProtocol(transport); transport.open(); base = new ThriftCLIServiceClient(new TCLIService.Client(protocol), conf); LOG.info("Connected!"); return transport; }