Beispiel #1
0
def connect(host, port, timeout=None, use_ssl=False, ca_cert=None,
            user=None, password=None, kerberos_service_name='impala',
            auth_mechanism=None):
    log.debug('Connecting to HiveServer2 %s:%s with %s authentication '
             'mechanism', host, port, auth_mechanism)
    sock = get_socket(host, port, use_ssl, ca_cert)
    if timeout is not None:
        timeout = timeout * 1000.  # TSocket expects millis
    if six.PY2:
        sock.setTimeout(timeout)
    elif six.PY3:
        try:
            # thriftpy has a release where set_timeout is missing
            sock.set_timeout(timeout)
        except AttributeError:
            sock.socket_timeout = timeout
            sock.connect_timeout = timeout
    transport = get_transport(sock, host, kerberos_service_name,
                              auth_mechanism, user, password)
    transport.open()
    protocol = TBinaryProtocol(transport)
    if six.PY2:
        # ThriftClient == ImpalaHiveServer2Service.Client
        service = ThriftClient(protocol)
    elif six.PY3:
        # ThriftClient == TClient
        service = ThriftClient(ImpalaHiveServer2Service, protocol)
    log.debug('sock=%s transport=%s protocol=%s service=%s', sock, transport,
              protocol, service)

    return HS2Service(service)
Beispiel #2
0
 def connect(self):
     self.transport.open()
     protocol = TBinaryProtocol(self.transport)
     service = None
     if six.PY2:
         # ThriftClient == ImpalaHiveServer2Service.Client
         service = ThriftClient(protocol)
     elif six.PY3:
         # ThriftClient == TClient
         # service = ThriftClient(protocol)
         service = ThriftClient(ImpalaHiveServer2Service, protocol)
     service = HS2Service(service, retries=3)
     return hs2.HiveServer2Connection(service, default_db=None)
Beispiel #3
0
def connect(host,
            port,
            timeout=None,
            use_ssl=False,
            ca_cert=None,
            user=None,
            password=None,
            kerberos_service_name='impala',
            auth_mechanism=None,
            krb_host=None,
            use_http_transport=False,
            http_path=''):
    log.debug(
        'Connecting to HiveServer2 %s:%s with %s authentication '
        'mechanism', host, port, auth_mechanism)

    if use_http_transport:
        # TODO(#362): Add server authentication with thrift 0.12.
        if ca_cert:
            raise NotSupportedError("Server authentication is not supported " +
                                    "with HTTP endpoints")
        if krb_host:
            raise NotSupportedError("Kerberos authentication is not " +
                                    "supported with HTTP endpoints")
        transport = get_http_transport(host,
                                       port,
                                       http_path=http_path,
                                       use_ssl=use_ssl,
                                       ca_cert=ca_cert,
                                       user=user,
                                       password=password,
                                       auth_mechanism=auth_mechanism)
    else:
        sock = get_socket(host, port, use_ssl, ca_cert)

        if krb_host:
            kerberos_host = krb_host
        else:
            kerberos_host = host

        if timeout is not None:
            timeout = timeout * 1000.  # TSocket expects millis
        if six.PY2:
            sock.setTimeout(timeout)
        elif six.PY3:
            try:
                # thriftpy has a release where set_timeout is missing
                sock.set_timeout(timeout)
            except AttributeError:
                sock.socket_timeout = timeout
                sock.connect_timeout = timeout
        log.debug('sock=%s', sock)
        transport = get_transport(sock, kerberos_host, kerberos_service_name,
                                  auth_mechanism, user, password)

    transport.open()
    protocol = TBinaryProtocol(transport)
    if six.PY2:
        # ThriftClient == ImpalaHiveServer2Service.Client
        service = ThriftClient(protocol)
    elif six.PY3:
        # ThriftClient == TClient
        service = ThriftClient(ImpalaHiveServer2Service, protocol)
    log.debug('transport=%s protocol=%s service=%s', transport, protocol,
              service)

    return HS2Service(service)