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();
}
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();
}
}
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;
}
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;
}
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();
}
}
Aggregations