Skip to content

Commit 124fed6

Browse files
committed
HBASE-22664 Move protobuf stuff in hbase-rsgroup to hbase-protocol-shaded (#362)
Signed-off-by: Guanghao Zhang <zghao@apache.org>
1 parent c9293b0 commit 124fed6

File tree

11 files changed

+254
-108
lines changed

11 files changed

+254
-108
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,23 +1768,36 @@ public static ServerName toServerName(final byte [] data) throws Deserialization
17681768
return ServerName.valueOf(hostname, port, -1L);
17691769
}
17701770

1771+
public static HBaseProtos.TimeRange toTimeRange(TimeRange timeRange) {
1772+
if (timeRange == null) {
1773+
timeRange = TimeRange.allTime();
1774+
}
1775+
return HBaseProtos.TimeRange.newBuilder().setFrom(timeRange.getMin()).setTo(timeRange.getMax())
1776+
.build();
1777+
}
1778+
17711779
public static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) {
17721780
RSGroupInfo RSGroupInfo = new RSGroupInfo(proto.getName());
1773-
for(HBaseProtos.ServerName el: proto.getServersList()) {
1781+
for (HBaseProtos.ServerName el : proto.getServersList()) {
17741782
RSGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort()));
17751783
}
1776-
for(HBaseProtos.TableName pTableName: proto.getTablesList()) {
1784+
for (HBaseProtos.TableName pTableName : proto.getTablesList()) {
17771785
RSGroupInfo.addTable(ProtobufUtil.toTableName(pTableName));
17781786
}
17791787
return RSGroupInfo;
17801788
}
17811789

1782-
public static HBaseProtos.TimeRange toTimeRange(TimeRange timeRange) {
1783-
if (timeRange == null) {
1784-
timeRange = TimeRange.allTime();
1790+
public static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) {
1791+
List<HBaseProtos.TableName> tables = new ArrayList<>(pojo.getTables().size());
1792+
for (TableName arg : pojo.getTables()) {
1793+
tables.add(ProtobufUtil.toProtoTableName(arg));
1794+
}
1795+
List<HBaseProtos.ServerName> hostports = new ArrayList<>(pojo.getServers().size());
1796+
for (Address el : pojo.getServers()) {
1797+
hostports.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
1798+
.setPort(el.getPort()).build());
17851799
}
1786-
return HBaseProtos.TimeRange.newBuilder().setFrom(timeRange.getMin())
1787-
.setTo(timeRange.getMax())
1788-
.build();
1800+
return RSGroupProtos.RSGroupInfo.newBuilder().setName(pojo.getName()).addAllServers(hostports)
1801+
.addAllTables(tables).build();
17891802
}
17901803
}

hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import org.apache.hadoop.hbase.filter.ByteArrayComparable;
9191
import org.apache.hadoop.hbase.filter.Filter;
9292
import org.apache.hadoop.hbase.io.TimeRange;
93+
import org.apache.hadoop.hbase.net.Address;
9394
import org.apache.hadoop.hbase.protobuf.ProtobufMagic;
9495
import org.apache.hadoop.hbase.protobuf.ProtobufMessageConverter;
9596
import org.apache.hadoop.hbase.quotas.QuotaScope;
@@ -98,6 +99,7 @@
9899
import org.apache.hadoop.hbase.quotas.ThrottleType;
99100
import org.apache.hadoop.hbase.replication.ReplicationLoadSink;
100101
import org.apache.hadoop.hbase.replication.ReplicationLoadSource;
102+
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
101103
import org.apache.hadoop.hbase.security.visibility.Authorizations;
102104
import org.apache.hadoop.hbase.security.visibility.CellVisibility;
103105
import org.apache.hadoop.hbase.util.Addressing;
@@ -175,6 +177,7 @@
175177
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
176178
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
177179
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos;
180+
import org.apache.hadoop.hbase.shaded.protobuf.generated.RSGroupProtos;
178181
import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerReportRequest;
179182
import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest;
180183
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos;
@@ -3292,4 +3295,29 @@ public static Set<String> toCompactedStoreFiles(byte[] bytes) throws IOException
32923295
}
32933296
return Collections.emptySet();
32943297
}
3298+
3299+
public static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) {
3300+
RSGroupInfo RSGroupInfo = new RSGroupInfo(proto.getName());
3301+
for (HBaseProtos.ServerName el : proto.getServersList()) {
3302+
RSGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort()));
3303+
}
3304+
for (HBaseProtos.TableName pTableName : proto.getTablesList()) {
3305+
RSGroupInfo.addTable(ProtobufUtil.toTableName(pTableName));
3306+
}
3307+
return RSGroupInfo;
3308+
}
3309+
3310+
public static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) {
3311+
List<HBaseProtos.TableName> tables = new ArrayList<>(pojo.getTables().size());
3312+
for (TableName arg : pojo.getTables()) {
3313+
tables.add(ProtobufUtil.toProtoTableName(arg));
3314+
}
3315+
List<HBaseProtos.ServerName> hostports = new ArrayList<>(pojo.getServers().size());
3316+
for (Address el : pojo.getServers()) {
3317+
hostports.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
3318+
.setPort(el.getPort()).build());
3319+
}
3320+
return RSGroupProtos.RSGroupInfo.newBuilder().setName(pojo.getName()).addAllServers(hostports)
3321+
.addAllTables(tables).build();
3322+
}
32953323
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package hbase.pb;
20+
21+
option java_package = "org.apache.hadoop.hbase.shaded.protobuf.generated";
22+
option java_outer_classname = "RSGroupProtos";
23+
option java_generic_services = true;
24+
option java_generate_equals_and_hash = true;
25+
option optimize_for = SPEED;
26+
27+
import "HBase.proto";
28+
29+
message RSGroupInfo {
30+
required string name = 1;
31+
repeated ServerName servers = 4;
32+
repeated TableName tables = 3;
33+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package hbase.pb;
20+
21+
option java_package = "org.apache.hadoop.hbase.shaded.protobuf.generated";
22+
option java_outer_classname = "RSGroupAdminProtos";
23+
option java_generic_services = true;
24+
option java_generate_equals_and_hash = true;
25+
option optimize_for = SPEED;
26+
27+
import "HBase.proto";
28+
import "RSGroup.proto";
29+
30+
/** Group level protobufs */
31+
32+
message ListTablesOfRSGroupRequest {
33+
required string r_s_group_name = 1;
34+
}
35+
36+
message ListTablesOfRSGroupResponse {
37+
repeated TableName table_name = 1;
38+
}
39+
40+
message GetRSGroupInfoRequest {
41+
required string r_s_group_name = 1;
42+
}
43+
44+
message GetRSGroupInfoResponse {
45+
optional RSGroupInfo r_s_group_info = 1;
46+
}
47+
48+
message GetRSGroupInfoOfTableRequest {
49+
required TableName table_name = 1;
50+
}
51+
52+
message GetRSGroupInfoOfTableResponse {
53+
optional RSGroupInfo r_s_group_info = 1;
54+
}
55+
56+
message MoveServersRequest {
57+
required string target_group = 1;
58+
repeated ServerName servers = 3;
59+
}
60+
61+
message MoveServersResponse {
62+
}
63+
64+
message MoveTablesRequest {
65+
required string target_group = 1;
66+
repeated TableName table_name = 2;
67+
}
68+
69+
message MoveTablesResponse {
70+
}
71+
72+
message AddRSGroupRequest {
73+
required string r_s_group_name = 1;
74+
}
75+
76+
message AddRSGroupResponse {
77+
}
78+
79+
message RemoveRSGroupRequest {
80+
required string r_s_group_name = 1;
81+
}
82+
83+
message RemoveRSGroupResponse {
84+
}
85+
86+
message BalanceRSGroupRequest {
87+
required string r_s_group_name = 1;
88+
}
89+
90+
message BalanceRSGroupResponse {
91+
required bool balanceRan = 1;
92+
}
93+
94+
message ListRSGroupInfosRequest {
95+
}
96+
97+
message ListRSGroupInfosResponse {
98+
repeated RSGroupInfo r_s_group_info = 1;
99+
}
100+
101+
message GetRSGroupInfoOfServerRequest {
102+
required ServerName server = 2;
103+
}
104+
105+
message GetRSGroupInfoOfServerResponse {
106+
optional RSGroupInfo r_s_group_info = 1;
107+
}
108+
109+
message MoveServersAndTablesRequest {
110+
required string target_group = 1;
111+
repeated ServerName servers = 2;
112+
repeated TableName table_name = 3;
113+
}
114+
115+
message MoveServersAndTablesResponse {
116+
}
117+
118+
message RemoveServersRequest {
119+
repeated ServerName servers = 1;
120+
}
121+
122+
message RemoveServersResponse {
123+
}
124+
125+
service RSGroupAdminService {
126+
rpc GetRSGroupInfo(GetRSGroupInfoRequest)
127+
returns (GetRSGroupInfoResponse);
128+
129+
rpc GetRSGroupInfoOfTable(GetRSGroupInfoOfTableRequest)
130+
returns (GetRSGroupInfoOfTableResponse);
131+
132+
rpc GetRSGroupInfoOfServer(GetRSGroupInfoOfServerRequest)
133+
returns (GetRSGroupInfoOfServerResponse);
134+
135+
rpc MoveServers(MoveServersRequest)
136+
returns (MoveServersResponse);
137+
138+
rpc MoveTables(MoveTablesRequest)
139+
returns (MoveTablesResponse);
140+
141+
rpc AddRSGroup(AddRSGroupRequest)
142+
returns (AddRSGroupResponse);
143+
144+
rpc RemoveRSGroup(RemoveRSGroupRequest)
145+
returns (RemoveRSGroupResponse);
146+
147+
rpc BalanceRSGroup(BalanceRSGroupRequest)
148+
returns (BalanceRSGroupResponse);
149+
150+
rpc ListRSGroupInfos(ListRSGroupInfosRequest)
151+
returns (ListRSGroupInfosResponse);
152+
153+
rpc MoveServersAndTables(MoveServersAndTablesRequest)
154+
returns (MoveServersAndTablesResponse);
155+
156+
rpc RemoveServers(RemoveServersRequest)
157+
returns (RemoveServersResponse);
158+
}

hbase-rsgroup/pom.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,6 @@
4343
<groupId>org.apache.maven.plugins</groupId>
4444
<artifactId>maven-source-plugin</artifactId>
4545
</plugin>
46-
<plugin>
47-
<groupId>org.xolstice.maven.plugins</groupId>
48-
<artifactId>protobuf-maven-plugin</artifactId>
49-
<executions>
50-
<execution>
51-
<id>compile-protoc</id>
52-
<phase>generate-sources</phase>
53-
<goals>
54-
<goal>compile</goal>
55-
</goals>
56-
<configuration>
57-
<additionalProtoPathElements>
58-
<additionalProtoPathElement>${basedir}/../hbase-protocol/src/main/protobuf</additionalProtoPathElement>
59-
</additionalProtoPathElements>
60-
</configuration>
61-
</execution>
62-
</executions>
63-
</plugin>
6446
<plugin>
6547
<groupId>org.apache.maven.plugins</groupId>
6648
<artifactId>maven-checkstyle-plugin</artifactId>

hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminClient.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
package org.apache.hadoop.hbase.rsgroup;
1919

2020
import com.google.protobuf.ServiceException;
21-
2221
import java.io.IOException;
2322
import java.util.ArrayList;
2423
import java.util.List;
2524
import java.util.Set;
26-
2725
import org.apache.hadoop.hbase.TableName;
2826
import org.apache.hadoop.hbase.TableNotFoundException;
2927
import org.apache.hadoop.hbase.client.Admin;
@@ -70,7 +68,7 @@ public RSGroupInfo getRSGroupInfo(String groupName) throws IOException {
7068
GetRSGroupInfoResponse resp = stub.getRSGroupInfo(null,
7169
GetRSGroupInfoRequest.newBuilder().setRSGroupName(groupName).build());
7270
if(resp.hasRSGroupInfo()) {
73-
return RSGroupProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
71+
return ProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
7472
}
7573
return null;
7674
} catch (ServiceException e) {
@@ -85,7 +83,7 @@ public RSGroupInfo getRSGroupInfoOfTable(TableName tableName) throws IOException
8583
try {
8684
GetRSGroupInfoOfTableResponse resp = stub.getRSGroupInfoOfTable(null, request);
8785
if (resp.hasRSGroupInfo()) {
88-
return RSGroupProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
86+
return ProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
8987
}
9088
return null;
9189
} catch (ServiceException e) {
@@ -167,7 +165,7 @@ public List<RSGroupInfo> listRSGroups() throws IOException {
167165
ListRSGroupInfosRequest.getDefaultInstance()).getRSGroupInfoList();
168166
List<RSGroupInfo> result = new ArrayList<>(resp.size());
169167
for(RSGroupProtos.RSGroupInfo entry : resp) {
170-
result.add(RSGroupProtobufUtil.toGroupInfo(entry));
168+
result.add(ProtobufUtil.toGroupInfo(entry));
171169
}
172170
return result;
173171
} catch (ServiceException e) {
@@ -186,7 +184,7 @@ public RSGroupInfo getRSGroupOfServer(Address hostPort) throws IOException {
186184
try {
187185
GetRSGroupInfoOfServerResponse resp = stub.getRSGroupInfoOfServer(null, request);
188186
if (resp.hasRSGroupInfo()) {
189-
return RSGroupProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
187+
return ProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
190188
}
191189
return null;
192190
} catch (ServiceException e) {

0 commit comments

Comments
 (0)