Example #1
0
    def __init__(self,
                 keyspace,
                 server,
                 framed_transport=True,
                 timeout=None,
                 credentials=None,
                 api_version=None):
        self.keyspace = None
        self.server = server
        server = server.split(':')
        if len(server) <= 1:
            port = 9160
        else:
            port = server[1]
        host = server[0]
        socket = TSocket.TSocket(host, int(port))
        if timeout is not None:
            socket.setTimeout(timeout * 1000.0)
        if framed_transport:
            self.transport = TTransport.TFramedTransport(socket)
        else:
            self.transport = TTransport.TBufferedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)
        Cassandra.Client.__init__(self, protocol)
        self.transport.open()

        self.set_keyspace(keyspace)

        if credentials is not None:
            request = AuthenticationRequest(credentials=credentials)
            self.login(request)
Example #2
0
    def __init__(self, keyspace, server, framed_transport=True, timeout=None,
                 credentials=None,
                 socket_factory=default_socket_factory,
                 transport_factory=default_transport_factory):
        self.keyspace = None
        self.server = server
        server = server.split(':')
        if len(server) <= 1:
            port = 9160
        else:
            port = server[1]
        host = server[0]
        socket = socket_factory(host, int(port))
        if timeout is not None:
            socket.setTimeout(timeout * 1000.0)
        self.transport = transport_factory(socket, host, port)
        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)
        Cassandra.Client.__init__(self, protocol)
        self.transport.open()

        self.set_keyspace(keyspace)

        if credentials is not None:
            request = AuthenticationRequest(credentials=credentials)
            self.login(request)
Example #3
0
    def __init__(self, keyspace, server, framed_transport, timeout,
                 credentials, recycle):
        host, port = server.split(":")
        socket = TSocket.TSocket(host, int(port))
        if timeout is not None:
            socket.setTimeout(timeout * 1000.0)
        if framed_transport:
            transport = TTransport.TFramedTransport(socket)
        else:
            transport = TTransport.TBufferedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
        client = Cassandra.Client(protocol)
        transport.open()

        server_api_version = client.describe_version().split('.', 1)
        assert server_api_version[0] == API_VERSION[0], \
                "Thrift API version mismatch. " \
                 "(Client: %s, Server: %s)" % (API_VERSION[0], server_api_version[0])

        client.set_keyspace(keyspace)

        if credentials is not None:
            request = AuthenticationRequest(credentials=credentials)
            client.login(request)

        self.keyspace = keyspace
        self.client = client
        self.transport = transport

        if recycle:
            self.recycle = time.time() + recycle + random.uniform(
                0, recycle * 0.1)
        else:
            self.recycle = None
Example #4
0
    def __init__(self,
                 keyspace,
                 server,
                 framed_transport=True,
                 timeout=None,
                 credentials=None,
                 api_version=None):
        self.keyspace = None
        self.server = server
        server = server.split(':')
        if len(server) <= 1:
            port = 9160
        else:
            port = server[1]
        host = server[0]
        socket = TSocket.TSocket(host, int(port))
        if timeout is not None:
            socket.setTimeout(timeout * 1000.0)
        if framed_transport:
            self.transport = TTransport.TFramedTransport(socket)
        else:
            self.transport = TTransport.TBufferedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)
        Cassandra.Client.__init__(self, protocol)
        self.transport.open()

        if api_version is None:
            server_api_version = self.describe_version()
            if compatible(CASSANDRA_10, server_api_version):
                self.version = CASSANDRA_10
            if compatible(CASSANDRA_08, server_api_version):
                self.version = CASSANDRA_08
            elif compatible(CASSANDRA_07, server_api_version):
                self.version = CASSANDRA_07
            else:
                raise ApiMismatch("Thrift API version incompatibility: " \
                                  "server version %s is not Cassandra 0.7, 0.8, or 1.0" %
                                  (server_api_version))
        else:
            self.version = api_version

        self.set_keyspace(keyspace)

        if credentials is not None:
            request = AuthenticationRequest(credentials=credentials)
            self.login(request)
Example #5
0
    def __init__(self,
                 keyspace,
                 server,
                 framed_transport=True,
                 timeout=None,
                 credentials=None):
        self.server = server
        server = server.split(':')
        if len(server) <= 1:
            port = 9160
        else:
            port = server[1]
        host = server[0]
        socket = TSocket.TSocket(host, int(port))
        if timeout is not None:
            socket.setTimeout(timeout * 1000.0)
        if framed_transport:
            self.transport = TTransport.TFramedTransport(socket)
        else:
            self.transport = TTransport.TBufferedTransport(socket)
        protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)
        super(Connection, self).__init__(protocol)
        self.transport.open()

        server_api_version = int(self.describe_version().split('.', 1)[0])
        assert (server_api_version >= LOWEST_COMPATIBLE_VERSION), \
                "Thrift API version incompatibility. " \
                 "(Server: %s, Lowest compatible version: %d)" % (server_api_version, LOWEST_COMPATIBLE_VERSION)

        if keyspace is not None:
            self.set_keyspace(keyspace)
        self.keyspace = keyspace

        if credentials is not None:
            request = AuthenticationRequest(credentials=credentials)
            self.login(request)