Search in sources :

Example 1 with TBinaryProtocol

use of org.apache.cassandra.thrift.TBinaryProtocol in project eiger by wlloyd.

the class ColumnFamilyRecordReader method initialize.

@Override
public void initialize(InputSplit split, TaskAttemptContext context) throws IOException {
    this.split = (ColumnFamilySplit) split;
    Configuration conf = context.getConfiguration();
    predicate = ConfigHelper.getInputSlicePredicate(conf);
    isEmptyPredicate = isEmptyPredicate(predicate);
    totalRowCount = ConfigHelper.getInputSplitSize(conf);
    batchRowCount = ConfigHelper.getRangeBatchSize(conf);
    cfName = ConfigHelper.getInputColumnFamily(conf);
    consistencyLevel = ConsistencyLevel.valueOf(ConfigHelper.getReadConsistencyLevel(conf));
    keyspace = ConfigHelper.getInputKeyspace(conf);
    try {
        // only need to connect once
        if (socket != null && socket.isOpen())
            return;
        // create connection using thrift
        String location = getLocation();
        socket = new TSocket(location, ConfigHelper.getInputRpcPort(conf));
        TBinaryProtocol binaryProtocol = new TBinaryProtocol(new TFramedTransport(socket));
        client = new Cassandra.Client(binaryProtocol);
        socket.open();
        // log in
        client.set_keyspace(keyspace, LamportClock.COPS_UNSUPPORTED);
        if (ConfigHelper.getInputKeyspaceUserName(conf) != null) {
            Map<String, String> creds = new HashMap<String, String>();
            creds.put(IAuthenticator.USERNAME_KEY, ConfigHelper.getInputKeyspaceUserName(conf));
            creds.put(IAuthenticator.PASSWORD_KEY, ConfigHelper.getInputKeyspacePassword(conf));
            AuthenticationRequest authRequest = new AuthenticationRequest(creds);
            client.login(authRequest, LamportClock.COPS_UNSUPPORTED);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    iter = new RowIterator();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) Cassandra(org.apache.cassandra.thrift.Cassandra) SocketException(java.net.SocketException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) AuthenticationRequest(org.apache.cassandra.thrift.AuthenticationRequest) TSocket(org.apache.thrift.transport.TSocket)

Example 2 with TBinaryProtocol

use of org.apache.cassandra.thrift.TBinaryProtocol in project eiger by wlloyd.

the class ConfigHelper method createConnection.

public static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws IOException {
    TSocket socket = new TSocket(host, port);
    TTransport trans = framed ? new TFramedTransport(socket) : socket;
    try {
        trans.open();
    } catch (TTransportException e) {
        throw new IOException("unable to connect to server", e);
    }
    return new Cassandra.Client(new TBinaryProtocol(trans));
}
Also used : TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Example 3 with TBinaryProtocol

use of org.apache.cassandra.thrift.TBinaryProtocol in project brisk by riptano.

the class BriskTool method getConnection.

private Brisk.Iface getConnection() throws IOException {
    TTransport trans = new TFramedTransport(new TSocket(host, port));
    try {
        trans.open();
    } catch (TTransportException e) {
        throw new IOException("unable to connect to brisk server");
    }
    Brisk.Iface client = new Brisk.Client(new TBinaryProtocol(trans));
    return client;
}
Also used : TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) Brisk(org.apache.cassandra.thrift.Brisk) Iface(org.apache.cassandra.thrift.Brisk.Iface) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

IOException (java.io.IOException)3 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)3 TFramedTransport (org.apache.thrift.transport.TFramedTransport)3 TSocket (org.apache.thrift.transport.TSocket)3 TTransport (org.apache.thrift.transport.TTransport)2 TTransportException (org.apache.thrift.transport.TTransportException)2 SocketException (java.net.SocketException)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 ConfigurationException (org.apache.cassandra.config.ConfigurationException)1 AuthenticationRequest (org.apache.cassandra.thrift.AuthenticationRequest)1 Brisk (org.apache.cassandra.thrift.Brisk)1 Iface (org.apache.cassandra.thrift.Brisk.Iface)1 Cassandra (org.apache.cassandra.thrift.Cassandra)1 Configuration (org.apache.hadoop.conf.Configuration)1 TException (org.apache.thrift.TException)1