Skip to content

Commit 459c5c5

Browse files
committed
HBASE-21002 make an assembly for hbase-connectors
1 parent 1455f78 commit 459c5c5

File tree

15 files changed

+1366
-57
lines changed

15 files changed

+1366
-57
lines changed

bin/hbase-connectors

+292
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
#! /usr/bin/env bash
2+
#
3+
#/**
4+
# * Licensed to the Apache Software Foundation (ASF) under one
5+
# * or more contributor license agreements. See the NOTICE file
6+
# * distributed with this work for additional information
7+
# * regarding copyright ownership. The ASF licenses this file
8+
# * to you under the Apache License, Version 2.0 (the
9+
# * "License"); you may not use this file except in compliance
10+
# * with the License. You may obtain a copy of the License at
11+
# *
12+
# * http://www.apache.org/licenses/LICENSE-2.0
13+
# *
14+
# * Unless required by applicable law or agreed to in writing, software
15+
# * distributed under the License is distributed on an "AS IS" BASIS,
16+
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# * See the License for the specific language governing permissions and
18+
# * limitations under the License.
19+
# */
20+
#
21+
# The hbase command script. Based on the hadoop command script putting
22+
# in hbase classes, libs and configurations ahead of hadoop's.
23+
#
24+
# TODO: Narrow the amount of duplicated code.
25+
#
26+
# Environment Variables:
27+
#
28+
# JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
29+
# HBASE_CONNECTOR_CLASSPATH_PREFIX Extra Java CLASSPATH entries that should be
30+
# prefixed to the system classpath.
31+
#
32+
# HBASE_CONNECTOR_HEAPSIZE The maximum amount of heap to use.
33+
# Default is unset and uses the JVMs default setting
34+
# (usually 1/4th of the available memory).
35+
#
36+
# HBASE_CONNECTOR_LIBRARY_PATH HBase additions to JAVA_LIBRARY_PATH for adding
37+
# native libraries.
38+
#
39+
# HBASE_CONNECTOR_OPTS Extra Java runtime options.
40+
#
41+
# HBASE_CONNECTOR_CONF_DIR Alternate conf dir. Default is ${HBASE_CONNECTOR_HOME}/conf.
42+
#
43+
# HBASE_CONNECTOR_ROOT_LOGGER The root appender. Default is INFO,console
44+
#
45+
46+
47+
bin=`dirname "$0"`
48+
bin=`cd "$bin">/dev/null; pwd`
49+
50+
# This will set HBASE_CONNECTOR_HOME etc.
51+
. "$bin"/hbase-connectors-config.sh
52+
53+
54+
cygwin=false
55+
case "`uname`" in
56+
CYGWIN*) cygwin=true;;
57+
esac
58+
59+
# Detect if we are in hbase sources dir
60+
in_dev_env=false
61+
if [ -d "${HBASE_CONNECTOR_HOME}/target" ]; then
62+
in_dev_env=true
63+
fi
64+
65+
# Detect if we are in the omnibus tarball
66+
in_omnibus_tarball="false"
67+
if [ -f "${HBASE_CONNECTOR_HOME}/bin/hbase-connectors-daemon.sh" ]; then
68+
in_omnibus_tarball="true"
69+
fi
70+
71+
# if no args specified, show usage
72+
if [ $# = 0 ]; then
73+
echo "Usage: hbase-connectors [<options>] <command> [<args>]"
74+
echo ""
75+
echo "Commands:"
76+
77+
if [ "${in_omnibus_tarball}" = "true" ]; then
78+
echo " kafkaproxy Run the HBase Kafka Proxy server"
79+
echo " kafkaproxytest Run the HBase Kafka Proxy sample kafka listener"
80+
fi
81+
82+
echo " CLASSNAME Run the class named CLASSNAME"
83+
exit 1
84+
fi
85+
86+
# get arguments
87+
COMMAND=$1
88+
shift
89+
90+
JAVA=$JAVA_HOME/bin/java
91+
92+
# override default settings for this command, if applicable
93+
if [ -f "$HBASE_CONNECTOR_HOME/conf/hbase-connector-env-$COMMAND.sh" ]; then
94+
. "$HBASE_CONNECTOR_HOME/conf/hbase-connector-env-$COMMAND.sh"
95+
fi
96+
97+
add_size_suffix() {
98+
# add an 'm' suffix if the argument is missing one, otherwise use whats there
99+
local val="$1"
100+
local lastchar=${val: -1}
101+
if [[ "mMgG" == *$lastchar* ]]; then
102+
echo $val
103+
else
104+
echo ${val}m
105+
fi
106+
}
107+
108+
109+
110+
#if [[ -n "$HBASE_CONNECTOR_HEAPSIZE" ]]; then
111+
# JAVA_HEAP_MAX="-Xmx$(add_size_suffix $HBASE_CONNECTOR_HEAPSIZE)"
112+
#fi
113+
#
114+
#if [[ -n "$HBASE_CONNECTOR_OFFHEAPSIZE" ]]; then
115+
# JAVA_OFFHEAP_MAX="-XX:MaxDirectMemorySize=$(add_size_suffix $HBASE_OFFHEAPSIZE)"
116+
#fi
117+
118+
119+
120+
121+
122+
# so that filenames w/ spaces are handled correctly in loops below
123+
ORIG_IFS=$IFS
124+
IFS=
125+
126+
# CLASSPATH initially contains $HBASE_CONNECTOR_CONF_DIR
127+
PASS_CLASSPATH="${HBASE_CONNECTOR_CONF_DIR}"
128+
129+
#CLASSPATH=${PASS_CLASSPATH}:$JAVA_HOME/lib/tools.jar
130+
131+
132+
HBASE_IN_PATH=$(which hbase 2>/dev/null)
133+
134+
# default log directory & file
135+
if [ "$HBASE_CONNECTOR_LOG_DIR" = "" ]; then
136+
HBASE_CONNECTOR_LOG_DIR="$HBASE_CONNECTOR_HOME/logs"
137+
fi
138+
if [ "$HBASE_CONNECTOR_LOGFILE" = "" ]; then
139+
HBASE_CONNECTOR_LOGFILE='hbase-connector.log'
140+
fi
141+
142+
function append_path() {
143+
if [ -z "$1" ]; then
144+
echo "$2"
145+
else
146+
echo "$1:$2"
147+
fi
148+
}
149+
150+
JAVA_PLATFORM=""
151+
152+
# if HBASE_CONNECTOR_LIBRARY_PATH is defined lets use it as first or second option
153+
if [ "$HBASE_CONNECTOR_LIBRARY_PATH" != "" ]; then
154+
JAVA_LIBRARY_PATH=$(append_path "$JAVA_LIBRARY_PATH" "$HBASE_CONNECTOR_LIBRARY_PATH")
155+
fi
156+
157+
158+
# Add user-specified CLASSPATH last
159+
if [ "$HBASE_CONNECTOR_CLASSPATH" != "" ]; then
160+
PASS_CLASSPATH=${PASS_CLASSPATH}:${HBASE_CONNECTOR_CLASSPATH}
161+
fi
162+
163+
# Add user-specified CLASSPATH prefix first
164+
if [ "$HBASE_CONNECTOR_CLASSPATH_PREFIX" != "" ]; then
165+
PASS_CLASSPATH=${HBASE_CONNECTOR_CLASSPATH_PREFIX}:${PASS_CLASSPATH}
166+
fi
167+
168+
# cygwin path translation
169+
if $cygwin; then
170+
PASS_CLASSPATH=`cygpath -p -w "$PASS_CLASSPATH"`
171+
HBASE_CONNECTOR_HOME=`cygpath -d "$HBASE_CONNECTOR_HOME"`
172+
HBASE_CONNECTOR_LOG_DIR=`cygpath -d "$HBASE_CONNECTOR_LOG_DIR"`
173+
fi
174+
175+
# cygwin path translation
176+
if $cygwin; then
177+
JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"`
178+
fi
179+
180+
# restore ordinary behaviour
181+
unset IFS
182+
183+
#Set the right GC options based on the what we are running
184+
declare -a server_cmds=("kafkaproxy")
185+
for cmd in ${server_cmds[@]}; do
186+
if [[ $cmd == $COMMAND ]]; then
187+
server=true
188+
break
189+
fi
190+
done
191+
192+
if [[ $server ]]; then
193+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS $SERVER_GC_OPTS"
194+
else
195+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS $CLIENT_GC_OPTS"
196+
fi
197+
198+
if [ "$AUTH_AS_SERVER" == "true" ]; then
199+
if [ -n "$HBASE_CONNECTOR_SERVER_JAAS_OPTS" ]; then
200+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS $HBASE_CONNECTOR_SERVER_JAAS_OPTS"
201+
fi
202+
fi
203+
204+
205+
add_maven_deps_to_classpath() {
206+
f="${HBASE_CONNECTOR_HOME}/target/$1"
207+
208+
if [ ! -f "${f}" ]; then
209+
echo "As this is a development environment, we need ${f} to be generated from maven (command: mvn install -DskipTests)"
210+
exit 1
211+
fi
212+
PASS_CLASSPATH=${PASS_CLASSPATH}:$(cat "${f}")
213+
}
214+
215+
216+
add_connector_jars_to_classpath() {
217+
connector_dir="${HBASE_CONNECTOR_HOME}/$1"
218+
219+
if [ -d "${connector_dir}" ]; then
220+
for f in $connector_dir/*.jar; do
221+
PASS_CLASSPATH="${PASS_CLASSPATH}:${f}"
222+
done
223+
fi
224+
}
225+
226+
227+
#Add the development env class path stuff
228+
if $in_dev_env; then
229+
add_maven_deps_to_classpath "cached_classpath.txt"
230+
fi
231+
232+
# figure out which class to run
233+
if [ "$COMMAND" = "kafkaproxy" ] ; then
234+
CLASS='org.apache.hadoop.hbase.kafka.KafkaProxy'
235+
if [ "$1" != "stop" ] ; then
236+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS $HBASE_KAFKA_OPTS"
237+
fi
238+
239+
# add the kafka proxy jars
240+
add_connector_jars_to_classpath "hbase-kafka-proxy"
241+
242+
elif [ "$COMMAND" = "kafkaproxytest" ] ; then
243+
CLASS='org.apache.hadoop.hbase.kafka.DumpToStringListener'
244+
if [ "$1" != "stop" ] ; then
245+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS $HBASE_KAFKA_TEST_OPTS"
246+
fi
247+
248+
# add the kafka proxy jars
249+
add_connector_jars_to_classpath "hbase-kafka-proxy"
250+
251+
else
252+
CLASS=$COMMAND
253+
fi
254+
255+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS -Dhbase.connector.log.dir=$HBASE_CONNECTOR_LOG_DIR"
256+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS -Dhbase.connector.log.file=$HBASE_CONNECTOR_LOGFILE"
257+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS -Dhbase.connector.home.dir=$HBASE_CONNECTOR_HOME"
258+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS -Dhbase.connector.id.str=$HBASE_CONNECTOR_IDENT_STRING"
259+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS -Dhbase.connector.root.logger=${HBASE_CONNECTOR_ROOT_LOGGER:-INFO,console}"
260+
261+
262+
if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
263+
HBASE_CONNECTOR_OPTS="$HBASE_CONNECTOR_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
264+
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$JAVA_LIBRARY_PATH"
265+
fi
266+
267+
#HEAP_SETTINGS="$JAVA_HEAP_MAX $JAVA_OFFHEAP_MAX"
268+
269+
270+
271+
272+
273+
# by now if we're running a command it means we need logging
274+
for f in ${HBASE_CONNECTOR_HOME}/lib/client-facing-thirdparty/slf4j-*.jar; do
275+
if [ -f "${f}" ]; then
276+
PASS_CLASSPATH="${PASS_CLASSPATH}:${f}"
277+
break
278+
fi
279+
done
280+
281+
282+
283+
CLASSPATH=$PASS_CLASSPATH:`$HBASE_IN_PATH classpath`
284+
285+
export CLASSPATH
286+
287+
288+
if [ "${HBASE_CONNECTOR_NOEXEC}" != "" ]; then
289+
"$JAVA" -Dproc_$COMMAND -XX:OnOutOfMemoryError="kill -9 %p" $HEAP_SETTINGS $HBASE_CONNECTOR_OPTS $CLASS "$@"
290+
else
291+
exec "$JAVA" -Dproc_$COMMAND -XX:OnOutOfMemoryError="kill -9 %p" $HEAP_SETTINGS $HBASE_CONNECTOR_OPTS $CLASS "$@"
292+
fi

0 commit comments

Comments
 (0)