HBASE-24119 Polish the protobuf usage in hbase-examples (#1438)

Move the proto files only used by hbase-examples to hbase-examples, to show users how to make use of shaded hbase protos when implementing coprocessor.

Signed-off-by: Jan Hentschel <jan.hentschel@ultratendency.com>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Duo Zhang 2020-04-06 22:14:55 +08:00 committed by GitHub
parent 1784938af7
commit 6452396187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 20 deletions

View File

@ -29,7 +29,12 @@
<artifactId>hbase-examples</artifactId>
<name>Apache HBase - Examples</name>
<description>Examples of HBase usage</description>
<!--REMOVE-->
<properties>
<!--Version of protobuf that hbase uses internally (we shade our pb)
Must match what is out in hbase-thirdparty include.
-->
<internal.protobuf.version>3.11.4</internal.protobuf.version>
</properties>
<build>
<plugins>
<plugin>
@ -62,9 +67,50 @@
<goals>
<goal>compile</goal>
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${internal.protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
<checkStaleness>true</checkStaleness>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${basedir}/target/generated-sources/</basedir>
<includes>
<include>**/*.java</include>
</includes>
<!-- Ignore errors when missing files, because it means this build
was run with -Dprotoc.skip and there is no -Dreplacer.skip -->
<ignoreErrors>true</ignoreErrors>
<replacements>
<replacement>
<token>([^\.])com.google.protobuf</token>
<value>$1org.apache.hbase.thirdparty.com.google.protobuf</value>
</replacement>
<replacement>
<token>(public)(\W+static)?(\W+final)?(\W+class)</token>
<value>@javax.annotation.Generated("proto") $1$2$3$4</value>
</replacement>
<!-- replacer doesn't support anchoring or negative lookbehind -->
<replacement>
<token>(@javax.annotation.Generated\("proto"\) ){2}</token>
<value>$1</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>warbucks-maven-plugin</artifactId>
@ -87,6 +133,10 @@
<groupId>org.apache.hbase.thirdparty</groupId>
<artifactId>hbase-shaded-netty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-protocol-shaded</artifactId>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>

View File

@ -17,13 +17,14 @@
*/
package org.apache.hadoop.hbase.types;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import java.io.IOException;
import org.apache.hadoop.hbase.example.protobuf.generated.CellMessage;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream;
import org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream;
/**
* An example for using protobuf objects with {@link DataType} API.
*/

View File

@ -17,15 +17,19 @@
*/
package org.apache.hadoop.hbase.types;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.Message;
import org.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream;
import org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream;
import org.apache.hbase.thirdparty.com.google.protobuf.Message;
/**
* A base-class for {@link DataType} implementations backed by protobuf. See {@link PBCell}.
* <p/>
* Notice that, in hbase we always uses our own shaded version of protobuf, but you are free to use
* the original version of protobuf in your own project.
*/
@InterfaceAudience.Private
public abstract class PBType<T extends Message> implements DataType<T> {
@ -59,6 +63,7 @@ public abstract class PBType<T extends Message> implements DataType<T> {
* {@code src}'s position after consuming from the stream.
* <p/>
* For example:
*
* <pre>
* Foo.Builder builder = ...
* CodedInputStream is = inputStreamFromByteRange(src);
@ -76,6 +81,7 @@ public abstract class PBType<T extends Message> implements DataType<T> {
* {@code dst}'s position after writing to the stream.
* <p/>
* For example:
*
* <pre>
* CodedOutputStream os = outputStreamFromByteRange(dst);
* int before = os.spaceLeft(), after, written;

View File

@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.types;
import static org.junit.Assert.assertEquals;
import com.google.protobuf.ByteString;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.example.protobuf.generated.CellMessage;
import org.apache.hadoop.hbase.testclassification.MiscTests;
@ -30,6 +29,8 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.hbase.thirdparty.com.google.protobuf.ByteString;
@Category({ SmallTests.class, MiscTests.class })
public class TestPBCell {

View File

@ -33,20 +33,10 @@
<maven.javadoc.skip>true</maven.javadoc.skip>
<!--Version of protobuf that hbase uses internally (we shade our pb)
Must match what is out in hbase-thirdparty include.
3.5.1-1 is the same as 3.5.1 except includes corrected binaries for el6
to work around https://github.com/google/protobuf/issues/4109
-->
<internal.protobuf.version>3.5.1-1</internal.protobuf.version>
-->
<internal.protobuf.version>3.11.4</internal.protobuf.version>
</properties>
<build>
<resources>
<resource>
<directory>src/main/</directory>
<includes>
<include>**/*.proto</include>
</includes>
</resource>
</resources>
<plugins>
<!-- Make a jar and put the sources in the jar -->
<plugin>
@ -88,7 +78,6 @@
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${internal.protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
<attachProtoSources>false</attachProtoSources>
<checkStaleness>true</checkStaleness>
</configuration>
</execution>