hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [2/2] hbase git commit: HBASE-17612 [C++] Set client version info in RPC header
Date Tue, 14 Feb 2017 02:52:16 GMT
HBASE-17612 [C++] Set client version info in RPC header


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/d308e0d3
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/d308e0d3
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/d308e0d3

Branch: refs/heads/HBASE-14850
Commit: d308e0d358207f7fc53db5fef5d706daefbde2ab
Parents: 8b3954f
Author: Enis Soztutar <enis@apache.org>
Authored: Mon Feb 13 18:52:04 2017 -0800
Committer: Enis Soztutar <enis@apache.org>
Committed: Mon Feb 13 18:52:04 2017 -0800

----------------------------------------------------------------------
 hbase-common/pom.xml                    |  3 +--
 hbase-common/src/saveVersion.sh         | 24 ++++++++++++++++++++++
 hbase-native-client/.gitignore          |  3 +++
 hbase-native-client/Makefile            |  8 +++++---
 hbase-native-client/bin/copy-version.sh | 25 +++++++++++++++++++++++
 hbase-native-client/bin/start-docker.sh |  3 +++
 hbase-native-client/serde/BUCK          |  5 +----
 hbase-native-client/serde/rpc.cc        | 30 +++++++++++++++++++++++++++-
 hbase-native-client/serde/rpc.h         |  2 ++
 hbase-native-client/utils/BUCK          |  2 +-
 10 files changed, 94 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-common/pom.xml
----------------------------------------------------------------------
diff --git a/hbase-common/pom.xml b/hbase-common/pom.xml
index 5b43553..da9eb6b 100644
--- a/hbase-common/pom.xml
+++ b/hbase-common/pom.xml
@@ -84,7 +84,6 @@
               <goal>run</goal>
             </goals>
           </execution>
-                <!-- Generate web app sources -->
                 <execution>
                     <id>generate</id>
                     <phase>generate-sources</phase>
@@ -93,7 +92,7 @@
                             <property name="generated.sources" location="${project.build.directory}/generated-sources"/>
 
                             <exec executable="bash">
-                                <arg line="${basedir}/src/saveVersion.sh ${project.version}
${generated.sources}/java"/>
+                                <arg line="${basedir}/src/saveVersion.sh ${project.version}
${generated.sources}/java ${generated.sources}/native"/>
                             </exec>
                         </target>
                     </configuration>

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-common/src/saveVersion.sh
----------------------------------------------------------------------
diff --git a/hbase-common/src/saveVersion.sh b/hbase-common/src/saveVersion.sh
index 890dc5a..771c282 100644
--- a/hbase-common/src/saveVersion.sh
+++ b/hbase-common/src/saveVersion.sh
@@ -23,6 +23,7 @@ unset LC_CTYPE
 
 version=$1
 outputDirectory=$2
+cppOutputDirectory=$3
 
 pushd .
 cd ..
@@ -65,3 +66,26 @@ cat >"$outputDirectory/org/apache/hadoop/hbase/package-info.java" <<EOF
 package org.apache.hadoop.hbase;
 EOF
 
+# Generate C++ code
+mkdir -p "$cppOutputDirectory/utils"
+cat >"$cppOutputDirectory/utils/version.h" <<EOF
+/*
+ * Generated by src/saveVersion.sh
+ */
+
+#pragma once
+
+namespace hbase {
+
+class Version {
+ public:
+  static constexpr const char* version = "$version";
+  static constexpr const char* revision = "$revision";
+  static constexpr const char* user = "$user";
+  static constexpr const char* date = "$date";
+  static constexpr const char* url = "$url";
+  static constexpr const char* src_checksum = "$srcChecksum";
+};
+}  // namespace hbase
+EOF
+

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-native-client/.gitignore
----------------------------------------------------------------------
diff --git a/hbase-native-client/.gitignore b/hbase-native-client/.gitignore
index c0032e4..c99ce59 100644
--- a/hbase-native-client/.gitignore
+++ b/hbase-native-client/.gitignore
@@ -24,3 +24,6 @@ buck-out
 # Thirdparty dirs
 third-party/*
 /gcc-debug/
+
+# Generated files
+utils/version.h

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-native-client/Makefile
----------------------------------------------------------------------
diff --git a/hbase-native-client/Makefile b/hbase-native-client/Makefile
index 99e38ef..84ae556 100644
--- a/hbase-native-client/Makefile
+++ b/hbase-native-client/Makefile
@@ -57,7 +57,7 @@ ARC_DEBUG=$(DEBUG_PATH)/libHbaseClient_d.a
 
 vpath %.cc $(SRC_DIR)
 
-build: checkdirs protos $(LIB_DEBUG) $(LIB_RELEASE) $(ARC_DEBUG) $(ARC_RELEASE)
+build: checkdirs copyfiles protos $(LIB_DEBUG) $(LIB_RELEASE) $(ARC_DEBUG) $(ARC_RELEASE)
 $(LIB_DEBUG): $(DEBUG_BUILD_DIR)
 define make-goal-dbg
 $1/%.o: %.cc $(DEPS) $(PROTODEPS) $(PROTOSRC)
@@ -72,10 +72,12 @@ endef
 
 .PHONY: all clean install 
 
-
-
 checkdirs: $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) $(PROTO_SRC_DIR)
 
+copyfiles:
+	bin/copy-protobuf.sh
+	bin/copy-version.sh
+
 protos: createprotosrc
 	@make all -f Makefile.protos
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-native-client/bin/copy-version.sh
----------------------------------------------------------------------
diff --git a/hbase-native-client/bin/copy-version.sh b/hbase-native-client/bin/copy-version.sh
new file mode 100755
index 0000000..b33db7a
--- /dev/null
+++ b/hbase-native-client/bin/copy-version.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+##
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+set -euo pipefail
+IFS=$'\n\t'
+
+# Copy the version.h generated from hbase-common/src/saveVersion.sh script via the mvn build
+BIN_DIR=$(dirname "$0")
+VERSION_SOURCE_DIR="${BIN_DIR}/../../hbase-common/target/generated-sources/native/utils/"
+VERSION_DEST_DIR="${BIN_DIR}/../utils/"
+cp $VERSION_SOURCE_DIR/* $VERSION_DEST_DIR/

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-native-client/bin/start-docker.sh
----------------------------------------------------------------------
diff --git a/hbase-native-client/bin/start-docker.sh b/hbase-native-client/bin/start-docker.sh
index 38affa0..1380cdf 100755
--- a/hbase-native-client/bin/start-docker.sh
+++ b/hbase-native-client/bin/start-docker.sh
@@ -26,7 +26,10 @@ eval "$(docker-machine env dinghy)"
 BIN_DIR=$(pushd `dirname "$0"` 2>&1 > /dev/null && pwd && popd
 2>&1 > /dev/null)
 BASE_DIR=$(pushd "${BIN_DIR}/../" 2>&1 > /dev/null && pwd && popd
 2>&1 > /dev/null)
 
+# TODO: this is wrong. These should be called from BUCK, but I could not find a
+# way to execute scripts in BUCK that are in under bin/.
 ${BIN_DIR}/copy-protobuf.sh
+${BIN_DIR}/copy-version.sh
 
 # Go into the base dir. This just makes things cleaner.
 pushd ${BASE_DIR}

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-native-client/serde/BUCK
----------------------------------------------------------------------
diff --git a/hbase-native-client/serde/BUCK b/hbase-native-client/serde/BUCK
index c6809a8..38e7b4d 100644
--- a/hbase-native-client/serde/BUCK
+++ b/hbase-native-client/serde/BUCK
@@ -31,10 +31,7 @@ cxx_library(
         "rpc.cc",
         "zk.cc",
     ],
-    deps=[
-        "//if:if",
-        "//third-party:folly",
-    ],
+    deps=["//if:if", "//third-party:folly", "//utils:utils"],
     tests=[
         ":client-deserializer-test",
         ":client-serializer-test",

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-native-client/serde/rpc.cc
----------------------------------------------------------------------
diff --git a/hbase-native-client/serde/rpc.cc b/hbase-native-client/serde/rpc.cc
index d5bca62..e657a64 100644
--- a/hbase-native-client/serde/rpc.cc
+++ b/hbase-native-client/serde/rpc.cc
@@ -19,16 +19,18 @@
 
 #include "serde/rpc.h"
 
+#include <folly/Conv.h>
 #include <folly/Logging.h>
 #include <folly/io/Cursor.h>
 #include <google/protobuf/io/coded_stream.h>
 #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
 #include <google/protobuf/message.h>
+#include <boost/algorithm/string.hpp>
 
 #include <utility>
 
-#include "if/HBase.pb.h"
 #include "if/RPC.pb.h"
+#include "utils/version.h"
 
 using namespace hbase;
 
@@ -111,12 +113,38 @@ unique_ptr<IOBuf> RpcSerde::Header(const string &user) {
   // TODO: send the service name and user from the RpcClient
   h.set_service_name(INTERFACE);
 
+  std::unique_ptr<pb::VersionInfo> version_info = CreateVersionInfo();
+
+  h.set_allocated_version_info(version_info.release());
+
   if (codec_ != nullptr) {
     h.set_cell_block_codec_class(codec_->java_class_name());
   }
   return PrependLength(SerializeMessage(h));
 }
 
+std::unique_ptr<pb::VersionInfo> RpcSerde::CreateVersionInfo() {
+  std::unique_ptr<pb::VersionInfo> version_info = std::make_unique<pb::VersionInfo>();
+  version_info->set_user(Version::user);
+  version_info->set_revision(Version::revision);
+  version_info->set_url(Version::url);
+  version_info->set_date(Version::date);
+  version_info->set_src_checksum(Version::src_checksum);
+  version_info->set_version(Version::version);
+
+  std::string version{Version::version};
+  std::vector<std::string> version_parts;
+  boost::split(version_parts, version, boost::is_any_of("."), boost::token_compress_on);
+  uint32_t major_version = 0, minor_version = 0;
+  if (version_parts.size() >= 2) {
+    version_info->set_version_major(folly::to<uint32_t>(version_parts[0]));
+    version_info->set_version_minor(folly::to<uint32_t>(version_parts[1]));
+  }
+
+  VLOG(1) << "Client VersionInfo:" << version_info->ShortDebugString();
+  return version_info;
+}
+
 unique_ptr<IOBuf> RpcSerde::Request(const uint32_t call_id, const string &method,
                                     const Message *msg) {
   pb::RequestHeader rq;

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-native-client/serde/rpc.h
----------------------------------------------------------------------
diff --git a/hbase-native-client/serde/rpc.h b/hbase-native-client/serde/rpc.h
index c59f903..abebe94 100644
--- a/hbase-native-client/serde/rpc.h
+++ b/hbase-native-client/serde/rpc.h
@@ -21,6 +21,7 @@
 #include <memory>
 #include <string>
 
+#include "if/HBase.pb.h"
 #include "serde/cell-scanner.h"
 #include "serde/codec.h"
 
@@ -120,5 +121,6 @@ class RpcSerde {
   /* data */
   uint8_t auth_type_;
   std::shared_ptr<Codec> codec_;
+  std::unique_ptr<pb::VersionInfo> CreateVersionInfo();
 };
 }  // namespace hbase

http://git-wip-us.apache.org/repos/asf/hbase/blob/d308e0d3/hbase-native-client/utils/BUCK
----------------------------------------------------------------------
diff --git a/hbase-native-client/utils/BUCK b/hbase-native-client/utils/BUCK
index 120331a..796f2f5 100644
--- a/hbase-native-client/utils/BUCK
+++ b/hbase-native-client/utils/BUCK
@@ -17,7 +17,7 @@
 
 cxx_library(
     name="utils",
-    exported_headers=["user-util.h",],
+    exported_headers=["user-util.h", "version.h"],
     srcs=["user-util.cc",],
     deps=['//third-party:folly',],
     tests=[":user-util-test"],


Mime
View raw message