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(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:
        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 #3
0
def connect(
    host,
    port,
    timeout=45,
    use_ssl=False,
    ca_cert=None,
    user=None,
    password=None,
    kerberos_service_name="impala",
    auth_mechanism=None,
):
    sock = get_socket(host, port, use_ssl, ca_cert)
    if six.PY2:
        sock.setTimeout(timeout * 1000.0)
    elif six.PY3:
        sock.set_timeout(timeout * 1000.0)
    transport = get_transport(sock, host, kerberos_service_name, auth_mechanism, user, password)
    transport.open()
    protocol = TBinaryProtocol(transport)
    if six.PY2:
        # ThriftClient == ImpalaService.Client
        service = ThriftClient(protocol)
    elif six.PY3:
        # ThriftClient == TClient
        service = ThriftClient(ImpalaService, protocol)
    return service
Beispiel #4
0
def connect(host,
            port,
            timeout=45,
            use_ssl=False,
            ca_cert=None,
            user=None,
            password=None,
            kerberos_service_name='impala',
            auth_mechanism=None):
    log.info(
        'Connecting to HiveServer2 %s:%s with %s authentication '
        'mechanism', host, port, auth_mechanism)
    sock = get_socket(host, port, use_ssl, ca_cert)
    if six.PY2:
        sock.setTimeout(timeout * 1000.)
    elif six.PY3:
        sock.set_timeout(timeout * 1000.)
    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 service
Beispiel #5
0
def connect(host,
            port,
            timeout=45,
            use_ssl=False,
            ca_cert=None,
            user=None,
            password=None,
            kerberos_service_name='impala',
            auth_mechanism=None):
    sock = get_socket(host, port, use_ssl, ca_cert)
    if six.PY2:
        sock.setTimeout(timeout * 1000.)
    elif six.PY3:
        sock.set_timeout(timeout * 1000.)
    transport = get_transport(sock, host, kerberos_service_name,
                              auth_mechanism, user, password)
    transport.open()
    protocol = TBinaryProtocol(transport)
    if six.PY2:
        # ThriftClient == ImpalaService.Client
        service = ThriftClient(protocol)
    elif six.PY3:
        # ThriftClient == TClient
        service = ThriftClient(ImpalaService, protocol)
    return service
Beispiel #6
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.0  # 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 #7
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)