def setup(self): host, port = IMPALAD_HS2_HOST_PORT.split(":") self.socket = TSocket(host, port) self.transport = TBufferedTransport(self.socket) self.transport.open() self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport) self.hs2_client = TCLIService.Client(self.protocol)
from cli_service import TCLIService from thrift.transport import TTransport, TSocket from thrift.protocol import TBinaryProtocol parser = OptionParser() parser.add_option("--hs2_hostport", dest="hs2_hostport", default="localhost:11050", help="HiveServer2 hostport to wait for.") parser.add_option("--use_kerberos", action="store_true", default=False, help="Indicates whether the cluster is kerberized.") options, args = parser.parse_args() hs2_host, hs2_port = options.hs2_hostport.split(':') hs2_transport = create_transport(use_kerberos=options.use_kerberos, host=hs2_host, port=hs2_port, service="hiveserver2") protocol = TBinaryProtocol.TBinaryProtocol(hs2_transport) hs2_client = TCLIService.Client(protocol) # Try to connect to the HiveServer2 service and create a session now = time.time() TIMEOUT_SECONDS = 30.0 while time.time() - now < TIMEOUT_SECONDS: try: hs2_transport.open() open_session_req = TCLIService.TOpenSessionReq() open_session_req.username = getpass.getuser() resp = hs2_client.OpenSession(open_session_req) if resp.status.statusCode == TCLIService.TStatusCode.SUCCESS_STATUS: close_session_req = TCLIService.TCloseSessionReq() close_session_req.sessionHandle = resp.sessionHandle hs2_client.CloseSession(close_session_req) print "HiveServer2 service is up at %s." % options.hs2_hostport