Skip to content

Commit 2b259ac

Browse files
authored
Merge pull request #214 from shenyunlong/update_readme
[Doc] modify the demo to use HBase configuration and connection factory
2 parents 0d83374 + 26c5b61 commit 2b259ac

File tree

4 files changed

+156
-90
lines changed

4 files changed

+156
-90
lines changed

README.md

Lines changed: 97 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OBKV HBase Client
2-
OBKV HBase Client is Java Library that can be used to access data from [OceanBase](https://github.com/oceanbase/oceanbase) by [HBase-0.94 API](https://svn.apache.org/repos/asf/hbase/hbase.apache.org/trunk/0.94/apidocs/index.html).
2+
OBKV HBase Client is Java Library that can be used to access data from [OceanBase](https://github.com/oceanbase/oceanbase) by [HBase-1.x API](https://javadoc.io/doc/org.apache.hbase/hbase-client/1.3.6/index.html) or [Hbase-2.x API](https://javadoc.io/doc/org.apache.hbase/hbase-client/2.1.10/index.html).
33

44
## Quick start
55

@@ -32,26 +32,19 @@ Import the dependency for your maven project:
3232

3333
The code demo:
3434
``` java
35-
import com.alipay.oceanbase.hbase.OHTableClient;
36-
import org.apache.hadoop.conf.Configuration;
37-
import org.apache.hadoop.hbase.client.Get;
38-
import org.apache.hadoop.hbase.client.Put;
39-
import org.apache.hadoop.hbase.client.Result;
35+
import org.apache.hadoop.hbase.HBaseConfiguration;
36+
import org.apache.hadoop.hbase.TableName;
37+
import org.apache.hadoop.hbase.client.*;
4038

41-
import static com.alipay.oceanbase.hbase.constants.OHConstants.*;
4239
import static org.apache.hadoop.hbase.util.Bytes.toBytes;
4340

44-
public class simpleTest {
45-
public static void main(String[] args) throws Exception {
46-
// 1. initial client for table test1
47-
Configuration conf = new Configuration();
48-
conf.set(HBASE_OCEANBASE_PARAM_URL, "PARAM_URL");
49-
conf.set(HBASE_OCEANBASE_FULL_USER_NAME, "FULL_USER_NAME");
50-
conf.set(HBASE_OCEANBASE_PASSWORD, "PASSWORD");
51-
conf.set(HBASE_OCEANBASE_SYS_USER_NAME, "SYS_USER_NAME");
52-
conf.set(HBASE_OCEANBASE_SYS_PASSWORD, "SYS_PASSWORD");
53-
OHTableClient hTable = new OHTableClient("test1", conf);
54-
hTable.init();
41+
public class SimpleHBaseClientDemo {
42+
public static void simpleTest() throws Exception {
43+
// 1. initial connection for table test1
44+
HBaseConfiguration conf = new HBaseConfiguration();
45+
Connection connection = ConnectionFactory.createConnection(conf);
46+
TableName tableName = TableName.valueOf("test1");
47+
Table hTable = connection.getTable(tableName);
5548

5649
// 2. put data like hbase
5750
byte[] family = toBytes("family1");
@@ -65,19 +58,98 @@ public class simpleTest {
6558
Get get = new Get(rowKey);
6659
get.addColumn(family, column);
6760
Result r = hTable.get(get);
68-
System.out.printf("column1: " + r.getColumn(family, column));
61+
System.out.println("column1: " + r.getColumn(family, column));
62+
63+
// 4. close
64+
hTable.close();
65+
connection.close();
66+
}
67+
68+
public static void main(String[] args) throws Exception {
69+
simpleTest();
6970
}
7071
}
7172
```
73+
74+
The Hbase Configuration in hbase-site.xml for direct-connect mode:
75+
```xml
76+
<configuration>
77+
<property>
78+
<name>hbase.client.connection.impl</name>
79+
<value>com.alipay.oceanbase.hbase.util.OHConnectionImpl</value>
80+
</property>
81+
<property>
82+
<name>hbase.oceanbase.fullUserName</name>
83+
<value></value>
84+
</property>
85+
<property>
86+
<name>hbase.oceanbase.password</name>
87+
<value></value>
88+
</property>
89+
<property>
90+
<name>hbase.oceanbase.paramURL</name>
91+
<value></value>
92+
</property>
93+
<property>
94+
<name>hbase.oceanbase.sysUserName</name>
95+
<value></value>
96+
</property>
97+
<property>
98+
<name>hbase.oceanbase.sysPassword</name>
99+
<value></value>
100+
</property>
101+
</configuration>
102+
```
103+
104+
The Hbase Configuration in hbase-site.xml for ODP mode:
105+
```xml
106+
<configuration>
107+
<property>
108+
<name>hbase.client.connection.impl</name>
109+
<value>com.alipay.oceanbase.hbase.util.OHConnectionImpl</value>
110+
</property>
111+
<property>
112+
<name>hbase.oceanbase.odpMode</name>
113+
<value>true</value>
114+
</property>
115+
<property>
116+
<name>hbase.oceanbase.fullUserName</name>
117+
<value></value>
118+
</property>
119+
<property>
120+
<name>hbase.oceanbase.password</name>
121+
<value></value>
122+
</property>
123+
<property>
124+
<name>hbase.oceanbase.odpAddr</name>
125+
<value></value>
126+
</property>
127+
<property>
128+
<name>hbase.oceanbase.odpPort</name>
129+
<value>3307</value>
130+
</property>
131+
<property>
132+
<name>hbase.oceanbase.database</name>
133+
<value></value>
134+
</property>
135+
</configuration>
136+
```
137+
72138
**NOTE:**
73-
* param_url is generated by [ConfigServer](https://ask.oceanbase.com/t/topic/35601923)
74-
* More example [TODO]
75-
* full_user_name: the user for accessing obkv, which format is user_name@tenant_name#cluster_name
76-
* sys_user_name: root@sys or proxy@sys, which have privileges to access routing system view
139+
* `hbase.client.connection.impl`: the implementation of hbase connenction, which must be set to `com.alipay.oceanbase.hbase.util.OHConnectionImpl`
140+
* `hbase.oceanbase.odpMode`: true indicate is in ODP mode, false(in default) indicate is in direct-connect mode
141+
* `hbase.oceanbase.fullUserName`: the user for accessing obkv, which format is user_name@tenant_name#cluster_name
142+
* `hbase.oceanbase.password`: the password associated with the specified user
143+
* `hbase.oceanbase.paramURL`: which is generated by [ConfigServer](https://ask.oceanbase.com/t/topic/35601923)
144+
* `hbase.oceanbase.sysUserName`: root@sys or proxy@sys, which have privileges to access routing system view
145+
* `hbase.oceanbase.sysPassword`: the password associated with the specified sys user
146+
* `hbase.oceanbase.odpAddr`: the ODP's IP address
147+
* `hbase.oceanbase.odpPort`: the ODP's OBKV port
148+
* `hbase.oceanbase.database`: the target database to operate on
149+
77150
## Documentation
78-
79151
- English [Coming soon]
80-
- Simplified Chinese (简体中文) [Coming soon]
152+
- [Simplified Chinese (简体中文)](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000002022354)
81153

82154
## Licencing
83155

example/simple-hbase-demo/src/main/java/com/oceanbase/example/LoggerFactory.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

example/simple-hbase-demo/src/main/java/com/oceanbase/example/SimpleHBaseClientDemo.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,20 @@
1717

1818
package com.oceanbase.example;
1919

20-
import com.alipay.oceanbase.hbase.OHTableClient;
21-
import org.apache.hadoop.conf.Configuration;
22-
import org.apache.hadoop.hbase.client.Get;
23-
import org.apache.hadoop.hbase.client.Put;
24-
import org.apache.hadoop.hbase.client.Result;
2520

26-
import static com.alipay.oceanbase.hbase.constants.OHConstants.*;
21+
import org.apache.hadoop.hbase.HBaseConfiguration;
22+
import org.apache.hadoop.hbase.TableName;
23+
import org.apache.hadoop.hbase.client.*;
24+
2725
import static org.apache.hadoop.hbase.util.Bytes.toBytes;
2826

2927
public class SimpleHBaseClientDemo {
30-
public static String PARAM_URL = "";
31-
public static String FULL_USER_NAME = "";
32-
public static String PASSWORD = "";
33-
public static String SYS_USER_NAME = "";
34-
public static String SYS_PASSWORD = "";
35-
3628
public static void simpleTest() throws Exception {
37-
// 1. initial client for table test1
38-
Configuration conf = new Configuration();
39-
conf.set(HBASE_OCEANBASE_PARAM_URL, PARAM_URL);
40-
conf.set(HBASE_OCEANBASE_FULL_USER_NAME, FULL_USER_NAME);
41-
conf.set(HBASE_OCEANBASE_PASSWORD, PASSWORD);
42-
conf.set(HBASE_OCEANBASE_SYS_USER_NAME, SYS_USER_NAME);
43-
conf.set(HBASE_OCEANBASE_SYS_PASSWORD, SYS_PASSWORD);
44-
OHTableClient hTable = new OHTableClient("test1", conf);
45-
hTable.init();
29+
// 1. initial connection for table test1
30+
HBaseConfiguration conf = new HBaseConfiguration();
31+
Connection connection = ConnectionFactory.createConnection(conf);
32+
TableName tableName = TableName.valueOf("test1");
33+
Table hTable = connection.getTable(tableName);
4634

4735
// 2. put data like hbase
4836
byte[] family = toBytes("family1");
@@ -56,10 +44,11 @@ public static void simpleTest() throws Exception {
5644
Get get = new Get(rowKey);
5745
get.addColumn(family, column);
5846
Result r = hTable.get(get);
59-
System.out.printf("column1: " + r.getColumn(family, column));
47+
System.out.println("column1: " + r.getColumn(family, column));
6048

6149
// 4. close
6250
hTable.close();
51+
connection.close();
6352
}
6453

6554
public static void main(String[] args) throws Exception {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<configuration>
2+
<property>
3+
<name>hbase.client.connection.impl</name>
4+
<value>com.alipay.oceanbase.hbase.util.OHConnectionImpl</value>
5+
</property>
6+
<property>
7+
<name>hbase.oceanbase.odpMode</name>
8+
<value>false</value>
9+
</property>
10+
<property>
11+
<name>hbase.oceanbase.fullUserName</name>
12+
<value></value>
13+
</property>
14+
<property>
15+
<name>hbase.oceanbase.password</name>
16+
<value></value>
17+
</property>
18+
<property>
19+
<!-- only for direct-connect mode-->
20+
<name>hbase.oceanbase.paramURL</name>
21+
<value></value>
22+
</property>
23+
<property>
24+
<!-- only for direct-connect mode-->
25+
<name>hbase.oceanbase.sysUserName</name>
26+
<value></value>
27+
</property>
28+
<property>
29+
<!-- only for direct-connect mode-->
30+
<name>hbase.oceanbase.sysPassword</name>
31+
<value></value>
32+
</property>
33+
<property>
34+
<!-- only for odp mode-->
35+
<name>hbase.oceanbase.odpAddr</name>
36+
<value></value>
37+
</property>
38+
<!-- only for odp mode-->
39+
<property>
40+
<name>hbase.oceanbase.odpPort</name>
41+
<value>3307</value>
42+
</property>
43+
<property>
44+
<!-- only for odp mode-->
45+
<name>hbase.oceanbase.database</name>
46+
<value></value>
47+
</property>
48+
</configuration>

0 commit comments

Comments
 (0)