Search in sources :

Example 1 with TBinaryProtocol

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

the class HttpDoAsClient method run.

private void run() throws Exception {
    TTransport transport = new TSocket(host, port);
    transport.open();
    String url = "http://" + host + ":" + port;
    THttpClient httpClient = new THttpClient(url);
    httpClient.open();
    TProtocol protocol = new TBinaryProtocol(httpClient);
    Hbase.Client client = new Hbase.Client(protocol);
    byte[] t = bytes("demo_table");
    //
    // Scan all tables, look for the demo table and delete it.
    //
    System.out.println("scanning tables...");
    for (ByteBuffer name : refresh(client, httpClient).getTableNames()) {
        System.out.println("  found: " + utf8(name.array()));
        if (utf8(name.array()).equals(utf8(t))) {
            if (refresh(client, httpClient).isTableEnabled(name)) {
                System.out.println("    disabling table: " + utf8(name.array()));
                refresh(client, httpClient).disableTable(name);
            }
            System.out.println("    deleting table: " + utf8(name.array()));
            refresh(client, httpClient).deleteTable(name);
        }
    }
    //
    // Create the demo table with two column families, entry: and unused:
    //
    ArrayList<ColumnDescriptor> columns = new ArrayList<>(2);
    ColumnDescriptor col;
    col = new ColumnDescriptor();
    col.name = ByteBuffer.wrap(bytes("entry:"));
    col.timeToLive = Integer.MAX_VALUE;
    col.maxVersions = 10;
    columns.add(col);
    col = new ColumnDescriptor();
    col.name = ByteBuffer.wrap(bytes("unused:"));
    col.timeToLive = Integer.MAX_VALUE;
    columns.add(col);
    System.out.println("creating table: " + utf8(t));
    try {
        refresh(client, httpClient).createTable(ByteBuffer.wrap(t), columns);
    } catch (AlreadyExists ae) {
        System.out.println("WARN: " + ae.message);
    }
    System.out.println("column families in " + utf8(t) + ": ");
    Map<ByteBuffer, ColumnDescriptor> columnMap = refresh(client, httpClient).getColumnDescriptors(ByteBuffer.wrap(t));
    for (ColumnDescriptor col2 : columnMap.values()) {
        System.out.println("  column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions));
    }
    transport.close();
    httpClient.close();
}
Also used : ColumnDescriptor(org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor) ArrayList(java.util.ArrayList) THttpClient(org.apache.thrift.transport.THttpClient) ByteBuffer(java.nio.ByteBuffer) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) THttpClient(org.apache.thrift.transport.THttpClient) AlreadyExists(org.apache.hadoop.hbase.thrift.generated.AlreadyExists) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) TSocket(org.apache.thrift.transport.TSocket)

Example 2 with TBinaryProtocol

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

the class TestThriftHttpServer method talkToThriftServer.

private void talkToThriftServer(int customHeaderSize) throws Exception {
    THttpClient httpClient = new THttpClient("http://" + HConstants.LOCALHOST + ":" + port);
    httpClient.open();
    if (customHeaderSize > 0) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < customHeaderSize; i++) {
            sb.append("a");
        }
        httpClient.setCustomHeader("User-Agent", sb.toString());
    }
    try {
        TProtocol prot;
        prot = new TBinaryProtocol(httpClient);
        Hbase.Client client = new Hbase.Client(prot);
        if (!tableCreated) {
            TestThriftServer.createTestTables(client);
            tableCreated = true;
        }
        TestThriftServer.checkTableList(client);
    } finally {
        httpClient.close();
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase)

Example 3 with TBinaryProtocol

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

the class TestHCatHiveThriftCompatibility method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    if (setUpComplete) {
        return;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    TIOStreamTransport transport = new TIOStreamTransport(out);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    IntString intString = new IntString(1, "one", 1);
    intString.write(protocol);
    BytesWritable bytesWritable = new BytesWritable(out.toByteArray());
    intStringSeq = new Path(TEST_DATA_DIR + "/data/intString.seq");
    LOG.info("Creating data file: " + intStringSeq);
    SequenceFile.Writer seqFileWriter = SequenceFile.createWriter(intStringSeq.getFileSystem(hiveConf), hiveConf, intStringSeq, NullWritable.class, BytesWritable.class);
    seqFileWriter.append(NullWritable.get(), bytesWritable);
    seqFileWriter.close();
    setUpComplete = true;
}
Also used : Path(org.apache.hadoop.fs.Path) IntString(org.apache.hadoop.hive.serde2.thrift.test.IntString) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) SequenceFile(org.apache.hadoop.io.SequenceFile) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) BytesWritable(org.apache.hadoop.io.BytesWritable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 4 with TBinaryProtocol

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

the class ClientFactory method create.

@Override
public Client create() throws Exception {
    TSocket transport = new TSocket(host, port);
    try {
        transport.open();
    } catch (TTransportException e) {
        throw new InterpreterException(e);
    }
    TProtocol protocol = new TBinaryProtocol(transport);
    Client client = new RemoteInterpreterService.Client(protocol);
    synchronized (clientSocketMap) {
        clientSocketMap.put(client, transport);
    }
    return client;
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) TTransportException(org.apache.thrift.transport.TTransportException) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TSocket(org.apache.thrift.transport.TSocket)

Example 5 with TBinaryProtocol

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

the class QAClient method main.

public static void main(String[] args) {
    // Collect the port number.
    int port = 8083;
    if (args.length >= 1) {
        port = Integer.parseInt(args[0]);
    }
    // User.
    String LUCID = "Clinc";
    QuerySpec create_spec = new QuerySpec();
    // Knowledge.
    final QueryInput knowledge_text = createQueryInput("text", "Clinc is created by Jason and Lingjia.", "1234567");
    final QueryInput knowledge_url = createQueryInput("url", "https://en.wikipedia.org/wiki/Apple_Inc.", "abcdefg");
    final QuerySpec knowledge = createQuerySpec("knowledge", new ArrayList<QueryInput>() {

        {
            add(knowledge_text);
            add(knowledge_url);
        }
    });
    // Unlearn.
    final QueryInput knowledge_unlearn_input = createQueryInput("unlearn", "", "abcdefg");
    final QuerySpec knowledge_unlearn_spec = createQuerySpec("unlearn knowledge", new ArrayList<QueryInput>() {

        {
            add(knowledge_unlearn_input);
        }
    });
    // Query.
    final QueryInput query_input = createQueryInput("text", "Who created Clinc?", "");
    final QuerySpec query = createQuerySpec("query", new ArrayList<QueryInput>() {

        {
            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 server.
        transport.open();
        System.out.println("///// Connecting to OpenEphyra at port " + port + " ... /////");
        // Learn and ask.
        client.create(LUCID, create_spec);
        client.learn(LUCID, knowledge);
        System.out.println("///// Query input: /////");
        System.out.println(query_input.data.get(0));
        String answer = client.infer(LUCID, query);
        // Print the answer.
        System.out.println("///// Answer: /////");
        System.out.println(answer);
        // Unlearn and ask again.
        client.learn(LUCID, knowledge_unlearn_spec);
        System.out.println("///// Query input: /////");
        System.out.println(query_input.data.get(0));
        answer = client.infer(LUCID, query);
        // Print the answer.
        System.out.println("///// Answer: /////");
        System.out.println(answer);
        transport.close();
    } 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)

Aggregations

TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)52 TSocket (org.apache.thrift.transport.TSocket)34 TProtocol (org.apache.thrift.protocol.TProtocol)26 TTransport (org.apache.thrift.transport.TTransport)25 TFramedTransport (org.apache.thrift.transport.TFramedTransport)21 TException (org.apache.thrift.TException)16 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)11 IOException (java.io.IOException)10 TMessage (org.apache.thrift.protocol.TMessage)8 TTransportException (org.apache.thrift.transport.TTransportException)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 URL (com.alibaba.dubbo.common.URL)4 Channel (com.alibaba.dubbo.remoting.Channel)4 Response (com.alibaba.dubbo.remoting.exchange.Response)4