Skip to content

Commit 096d27e

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 d7deafa commit 096d27e

File tree

11 files changed

+253
-108
lines changed

11 files changed

+253
-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
@@ -1772,23 +1772,36 @@ public static ServerName toServerName(final byte [] data) throws Deserialization
17721772
return ServerName.valueOf(hostname, port, -1L);
17731773
}
17741774

1775+
public static HBaseProtos.TimeRange toTimeRange(TimeRange timeRange) {
1776+
if (timeRange == null) {
1777+
timeRange = TimeRange.allTime();
1778+
}
1779+
return HBaseProtos.TimeRange.newBuilder().setFrom(timeRange.getMin()).setTo(timeRange.getMax())
1780+
.build();
1781+
}
1782+
17751783
public static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) {
17761784
RSGroupInfo RSGroupInfo = new RSGroupInfo(proto.getName());
1777-
for(HBaseProtos.ServerName el: proto.getServersList()) {
1785+
for (HBaseProtos.ServerName el : proto.getServersList()) {
17781786
RSGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort()));
17791787
}
1780-
for(HBaseProtos.TableName pTableName: proto.getTablesList()) {
1788+
for (HBaseProtos.TableName pTableName : proto.getTablesList()) {
17811789
RSGroupInfo.addTable(ProtobufUtil.toTableName(pTableName));
17821790
}
17831791
return RSGroupInfo;
17841792
}
17851793

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

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import org.apache.hadoop.hbase.filter.ByteArrayComparable;
9393
import org.apache.hadoop.hbase.filter.Filter;
9494
import org.apache.hadoop.hbase.io.TimeRange;
95+
import org.apache.hadoop.hbase.net.Address;
9596
import org.apache.hadoop.hbase.protobuf.ProtobufMagic;
9697
import org.apache.hadoop.hbase.protobuf.ProtobufMessageConverter;
9798
import org.apache.hadoop.hbase.quotas.QuotaScope;
@@ -100,6 +101,7 @@
100101
import org.apache.hadoop.hbase.quotas.ThrottleType;
101102
import org.apache.hadoop.hbase.replication.ReplicationLoadSink;
102103
import org.apache.hadoop.hbase.replication.ReplicationLoadSource;
104+
import org.apache.hadoop.hbase.rsgroup.RSGroupInfo;
103105
import org.apache.hadoop.hbase.security.visibility.Authorizations;
104106
import org.apache.hadoop.hbase.security.visibility.CellVisibility;
105107
import org.apache.hadoop.hbase.util.Addressing;
@@ -176,6 +178,7 @@
176178
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MajorCompactionTimestampResponse;
177179
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
178180
import org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos;
181+
import org.apache.hadoop.hbase.shaded.protobuf.generated.RSGroupProtos;
179182
import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerReportRequest;
180183
import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest;
181184
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos;
@@ -3348,4 +3351,28 @@ public static RegionStatesCount toTableRegionStatesCount(
33483351
.build();
33493352
}
33503353

3354+
public static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) {
3355+
RSGroupInfo RSGroupInfo = new RSGroupInfo(proto.getName());
3356+
for (HBaseProtos.ServerName el : proto.getServersList()) {
3357+
RSGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort()));
3358+
}
3359+
for (HBaseProtos.TableName pTableName : proto.getTablesList()) {
3360+
RSGroupInfo.addTable(ProtobufUtil.toTableName(pTableName));
3361+
}
3362+
return RSGroupInfo;
3363+
}
3364+
3365+
public static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) {
3366+
List<HBaseProtos.TableName> tables = new ArrayList<>(pojo.getTables().size());
3367+
for (TableName arg : pojo.getTables()) {
3368+
tables.add(ProtobufUtil.toProtoTableName(arg));
3369+
}
3370+
List<HBaseProtos.ServerName> hostports = new ArrayList<>(pojo.getServers().size());
3371+
for (Address el : pojo.getServers()) {
3372+
hostports.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
3373+
.setPort(el.getPort()).build());
3374+
}
3375+
return RSGroupProtos.RSGroupInfo.newBuilder().setName(pojo.getName()).addAllServers(hostports)
3376+
.addAllTables(tables).build();
3377+
}
33513378
}
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)