Search in sources :

Example 41 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project hbase by apache.

the class DemoClient method run.

public void run() throws Exception {
    int timeout = 10000;
    boolean framed = false;
    TTransport transport = new TSocket(host, port, timeout);
    if (framed) {
        transport = new TFramedTransport(transport);
    } else if (secure) {
        /**
       * The Thrift server the DemoClient is trying to connect to
       * must have a matching principal, and support authentication.
       *
       * The HBase cluster must be secure, allow proxy user.
       */
        Map<String, String> saslProperties = new HashMap<>();
        saslProperties.put(Sasl.QOP, "auth-conf,auth-int,auth");
        transport = new TSaslClientTransport("GSSAPI", null, // Thrift server user name, should be an authorized proxy user
        user != null ? user : "hbase", // Thrift server domain
        host, saslProperties, null, transport);
    }
    TProtocol protocol = new TBinaryProtocol(transport);
    // This is our thrift client.
    THBaseService.Iface client = new THBaseService.Client(protocol);
    // open the transport
    transport.open();
    ByteBuffer table = ByteBuffer.wrap("example".getBytes());
    TPut put = new TPut();
    put.setRow("row1".getBytes());
    TColumnValue columnValue = new TColumnValue();
    columnValue.setFamily("family1".getBytes());
    columnValue.setQualifier("qualifier1".getBytes());
    columnValue.setValue("value1".getBytes());
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(columnValue);
    put.setColumnValues(columnValues);
    client.put(table, put);
    TGet get = new TGet();
    get.setRow("row1".getBytes());
    TResult result = client.get(table, get);
    System.out.print("row = " + new String(result.getRow()));
    for (TColumnValue resultColumnValue : result.getColumnValues()) {
        System.out.print("family = " + new String(resultColumnValue.getFamily()));
        System.out.print("qualifier = " + new String(resultColumnValue.getFamily()));
        System.out.print("value = " + new String(resultColumnValue.getValue()));
        System.out.print("timestamp = " + resultColumnValue.getTimestamp());
    }
    transport.close();
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TSaslClientTransport(org.apache.thrift.transport.TSaslClientTransport) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) HashMap(java.util.HashMap) Map(java.util.Map) TSocket(org.apache.thrift.transport.TSocket) THBaseService(org.apache.hadoop.hbase.thrift2.generated.THBaseService)

Example 42 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project whirr by apache.

the class CassandraServiceTest method waitForCassandra.

private void waitForCassandra() {
    for (Instance instance : cluster.getInstances()) {
        while (true) {
            try {
                TSocket socket = new TSocket(instance.getPublicAddress().getHostAddress(), CassandraService.CLIENT_PORT);
                socket.open();
                TBinaryProtocol protocol = new TBinaryProtocol(socket);
                Cassandra.Client client = new Cassandra.Client(protocol);
                client.describe_cluster_name();
                socket.close();
                break;
            } catch (TException e) {
                System.out.print(".");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                    break;
                }
            }
        }
    }
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) Instance(org.apache.whirr.service.Cluster.Instance) Cassandra(org.apache.cassandra.thrift.Cassandra) TSocket(org.apache.thrift.transport.TSocket)

Example 43 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project whirr by apache.

the class CassandraServiceTest method testInstances.

@Test
public void testInstances() throws Exception {
    Set<String> endPoints = new HashSet<String>();
    for (Instance instance : cluster.getInstances()) {
        TSocket socket = new TSocket(instance.getPublicAddress().getHostAddress(), CassandraService.CLIENT_PORT);
        socket.open();
        TBinaryProtocol protocol = new TBinaryProtocol(socket);
        Cassandra.Client client = new Cassandra.Client(protocol);
        List<TokenRange> tr = client.describe_ring(KEYSPACE);
        for (TokenRange tokenRange : tr) {
            endPoints.addAll(tokenRange.endpoints);
        }
        socket.close();
    }
    for (Instance instance : cluster.getInstances()) {
        String address = instance.getPrivateAddress().getHostAddress();
        assertTrue(address + " not in cluster!", endPoints.remove(address));
    }
    assertTrue("Unknown node returned: " + endPoints.toString(), endPoints.isEmpty());
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) Instance(org.apache.whirr.service.Cluster.Instance) Cassandra(org.apache.cassandra.thrift.Cassandra) TokenRange(org.apache.cassandra.thrift.TokenRange) HashSet(java.util.HashSet) TSocket(org.apache.thrift.transport.TSocket) Test(org.junit.Test)

Example 44 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project lucida by claritylab.

the class QADaemon method connectToCMD.

private static void connectToCMD() {
    String LUCID = "QA";
    QuerySpec spec = new QuerySpec();
    spec.name = "" + 8083;
    // Initialize thrift objects.
    TTransport transport = new TSocket("localhost", 8080);
    TProtocol protocol = new TBinaryProtocol(new TFramedTransport(transport));
    LucidaService.Client client = new LucidaService.Client(protocol);
    try {
        transport.open();
        System.out.println("Connecting to CMD at port " + 8080);
        // Register itself to CMD.
        client.create(LUCID, spec);
        transport.close();
        System.out.println("Successfully connected to CMD");
    } catch (TException x) {
        x.printStackTrace();
    }
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 45 with TBinaryProtocol

use of org.apache.thrift.protocol.TBinaryProtocol in project lucida by claritylab.

the class CalendarClient method main.

public static void main(String[] args) {
    // Collect the port number.
    int port = 8084;
    if (args.length == 1) {
        port = Integer.parseInt(args[0]);
    } else {
        System.out.println("Using default port for Calendar Client: " + port);
    }
    // Query.
    String LUCID = "Clinc";
    String query_input_data = "What is on my Google calendar for last week?";
    QueryInput query_input = new QueryInput();
    query_input.type = "query";
    query_input.data = new ArrayList<String>();
    query_input.data.add(query_input_data);
    QuerySpec query_spec = new QuerySpec();
    query_spec.content = new ArrayList<QueryInput>();
    query_spec.content.add(query_input);
    // Initialize thrift objects.
    // TTransport transport = new TSocket("clarity08.eecs.umich.edu", port);
    TTransport transport = new TSocket("localhost", port);
    TProtocol protocol = new TBinaryProtocol(new TFramedTransport(transport));
    LucidaService.Client client = new LucidaService.Client(protocol);
    try {
        // Talk to the Calendar server.
        transport.open();
        System.out.println(query_input_data);
        System.out.println("///// Connecting to Calendar... /////");
        String results = client.infer(LUCID, query_spec);
        System.out.println("///// Result: /////");
        System.out.println(results);
        transport.close();
    } catch (TException e) {
        e.printStackTrace();
    }
    return;
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)59 TSocket (org.apache.thrift.transport.TSocket)41 TProtocol (org.apache.thrift.protocol.TProtocol)32 TTransport (org.apache.thrift.transport.TTransport)32 TFramedTransport (org.apache.thrift.transport.TFramedTransport)22 TException (org.apache.thrift.TException)18 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)11 IOException (java.io.IOException)10 TTransportException (org.apache.thrift.transport.TTransportException)9 TMessage (org.apache.thrift.protocol.TMessage)8 Test (org.junit.Test)7 Request (com.alibaba.dubbo.remoting.exchange.Request)6 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)6 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)5 RpcResult (com.alibaba.dubbo.rpc.RpcResult)5 RandomAccessByteArrayOutputStream (com.alibaba.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream)5 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)5 ImageDatasetService (org.vcell.imagedataset.ImageDatasetService)5 URL (com.alibaba.dubbo.common.URL)4 Channel (com.alibaba.dubbo.remoting.Channel)4