HBASE-26920 Fix missing braces warnings in TestProcedureMember (#4315)
[hbase.git] / dev-support / hbase_nightly_pseudo-distributed-test.sh
blob1267a85a71ad1cc0be38fce61da605bb13be2e46
1 #!/usr/bin/env bash
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
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
19 set -e
20 function usage {
21 echo "Usage: ${0} [options] /path/to/component/bin-install /path/to/hadoop/executable /path/to/share/hadoop/yarn/timelineservice /path/to/hadoop/hadoop-yarn-server-tests-tests.jar /path/to/hadoop/hadoop-mapreduce-client-jobclient-tests.jar /path/to/mapred/executable"
22 echo ""
23 echo " --zookeeper-data /path/to/use Where the embedded zookeeper instance should write its data."
24 echo " defaults to 'zk-data' in the working-dir."
25 echo " --working-dir /path/to/use Path for writing configs and logs. must exist."
26 echo " defaults to making a directory via mktemp."
27 echo " --hadoop-client-classpath /path/to/some.jar:/path/to/another.jar classpath for hadoop jars."
28 echo " defaults to 'hadoop classpath'"
29 echo " --hbase-client-install /path/to/unpacked/client/tarball if given we'll look here for hbase client jars instead of the bin-install"
30 echo " --force-data-clean Delete all data in HDFS and ZK prior to starting up hbase"
31 echo " --single-process Run as single process instead of pseudo-distributed"
32 echo ""
33 exit 1
35 # if no args specified, show usage
36 if [ $# -lt 5 ]; then
37 usage
40 # Get arguments
41 declare component_install
42 declare hadoop_exec
43 declare working_dir
44 declare zk_data_dir
45 declare clean
46 declare distributed="true"
47 declare hadoop_jars
48 declare hbase_client
49 while [ $# -gt 0 ]
51 case "$1" in
52 --working-dir) shift; working_dir=$1; shift;;
53 --force-data-clean) shift; clean="true";;
54 --zookeeper-data) shift; zk_data_dir=$1; shift;;
55 --single-process) shift; distributed="false";;
56 --hadoop-client-classpath) shift; hadoop_jars="$1"; shift;;
57 --hbase-client-install) shift; hbase_client="$1"; shift;;
58 --) shift; break;;
59 -*) usage ;;
60 *) break;; # terminate while loop
61 esac
62 done
64 # should still have where component checkout is.
65 if [ $# -lt 5 ]; then
66 usage
68 component_install="$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"
69 hadoop_exec="$(cd "$(dirname "$2")"; pwd)/$(basename "$2")"
70 timeline_service_dir="$(cd "$(dirname "$3")"; pwd)/$(basename "$3")"
71 yarn_server_tests_test_jar="$(cd "$(dirname "$4")"; pwd)/$(basename "$4")"
72 mapred_jobclient_test_jar="$(cd "$(dirname "$5")"; pwd)/$(basename "$5")"
73 mapred_exec="$(cd "$(dirname "$6")"; pwd)/$(basename "$6")"
75 if [ ! -x "${hadoop_exec}" ]; then
76 echo "hadoop cli does not appear to be executable." >&2
77 exit 1
80 if [ ! -x "${mapred_exec}" ]; then
81 echo "mapred cli does not appear to be executable." >&2
82 exit 1
85 if [ ! -d "${component_install}" ]; then
86 echo "Path to HBase binary install should be a directory." >&2
87 exit 1
90 if [ ! -f "${yarn_server_tests_test_jar}" ]; then
91 echo "Specified YARN server tests test jar is not a file." >&2
92 exit 1
95 if [ ! -f "${mapred_jobclient_test_jar}" ]; then
96 echo "Specified MapReduce jobclient test jar is not a file." >&2
97 exit 1
100 if [ -z "${working_dir}" ]; then
101 if ! working_dir="$(mktemp -d -t hbase-pseudo-dist-test)" ; then
102 echo "Failed to create temporary working directory. Please specify via --working-dir" >&2
103 exit 1
105 else
106 # absolutes please
107 working_dir="$(cd "$(dirname "${working_dir}")"; pwd)/$(basename "${working_dir}")"
108 if [ ! -d "${working_dir}" ]; then
109 echo "passed working directory '${working_dir}' must already exist." >&2
110 exit 1
114 if [ -z "${zk_data_dir}" ]; then
115 zk_data_dir="${working_dir}/zk-data"
116 mkdir "${zk_data_dir}"
117 else
118 # absolutes please
119 zk_data_dir="$(cd "$(dirname "${zk_data_dir}")"; pwd)/$(basename "${zk_data_dir}")"
120 if [ ! -d "${zk_data_dir}" ]; then
121 echo "passed directory for unpacking the source tarball '${zk_data_dir}' must already exist."
122 exit 1
126 if [ -z "${hbase_client}" ]; then
127 hbase_client="${component_install}"
128 else
129 echo "Using HBase client-side artifact"
130 # absolutes please
131 hbase_client="$(cd "$(dirname "${hbase_client}")"; pwd)/$(basename "${hbase_client}")"
132 if [ ! -d "${hbase_client}" ]; then
133 echo "If given hbase client install should be a directory with contents of the client tarball." >&2
134 exit 1
138 if [ -n "${hadoop_jars}" ]; then
139 declare -a tmp_jars
140 for entry in $(echo "${hadoop_jars}" | tr ':' '\n'); do
141 tmp_jars=("${tmp_jars[@]}" "$(cd "$(dirname "${entry}")"; pwd)/$(basename "${entry}")")
142 done
143 hadoop_jars="$(IFS=:; echo "${tmp_jars[*]}")"
147 echo "You'll find logs and temp files in ${working_dir}"
149 function redirect_and_run {
150 log_base=$1
151 shift
152 echo "$*" >"${log_base}.err"
153 "$@" >"${log_base}.out" 2>>"${log_base}.err"
156 (cd "${working_dir}"
158 echo "Hadoop version information:"
159 "${hadoop_exec}" version
160 hadoop_version=$("${hadoop_exec}" version | head -n 1)
161 hadoop_version="${hadoop_version#Hadoop }"
162 if [ "${hadoop_version%.*.*}" -gt 2 ]; then
163 "${hadoop_exec}" envvars
164 else
165 echo "JAVA_HOME: ${JAVA_HOME}"
168 # Ensure that if some other Hadoop install happens to be present in the environment we ignore it.
169 HBASE_DISABLE_HADOOP_CLASSPATH_LOOKUP="true"
170 export HBASE_DISABLE_HADOOP_CLASSPATH_LOOKUP
172 if [ -n "${clean}" ]; then
173 echo "Cleaning out ZooKeeper..."
174 rm -rf "${zk_data_dir:?}/*"
177 echo "HBase version information:"
178 "${component_install}/bin/hbase" version 2>/dev/null
179 hbase_version=$("${component_install}/bin/hbase" version 2>&1 | grep ^HBase | head -n 1)
180 hbase_version="${hbase_version#HBase }"
182 if [ ! -s "${hbase_client}/lib/shaded-clients/hbase-shaded-mapreduce-${hbase_version}.jar" ]; then
183 echo "HBase binary install doesn't appear to include a shaded mapreduce artifact." >&2
184 exit 1
187 if [ ! -s "${hbase_client}/lib/shaded-clients/hbase-shaded-client-${hbase_version}.jar" ]; then
188 echo "HBase binary install doesn't appear to include a shaded client artifact." >&2
189 exit 1
192 if [ ! -s "${hbase_client}/lib/shaded-clients/hbase-shaded-client-byo-hadoop-${hbase_version}.jar" ]; then
193 echo "HBase binary install doesn't appear to include a shaded client artifact." >&2
194 exit 1
197 echo "Writing out configuration for HBase."
198 rm -rf "${working_dir}/hbase-conf"
199 mkdir "${working_dir}/hbase-conf"
201 if [ -f "${component_install}/conf/log4j2.properties" ]; then
202 cp "${component_install}/conf/log4j2.properties" "${working_dir}/hbase-conf/log4j2.properties"
203 else
204 cat >"${working_dir}/hbase-conf/log4j2.properties" <<EOF
205 status = debug
206 dest = err
207 name = PropertiesConfig
209 appender.console.type = Console
210 appender.console.target = SYSTEM_ERR
211 appender.console.name = Console
212 appender.console.layout.type = PatternLayout
213 appender.console.layout.pattern = %d{ISO8601} %-5p [%t] %c{2}: %.1000m%n
215 rootLogger = ${sys:hbase.root.logger:-INFO,console}
219 cat >"${working_dir}/hbase-conf/hbase-site.xml" <<EOF
220 <?xml version="1.0"?>
221 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
222 <!--
225 * Licensed to the Apache Software Foundation (ASF) under one
226 * or more contributor license agreements. See the NOTICE file
227 * distributed with this work for additional information
228 * regarding copyright ownership. The ASF licenses this file
229 * to you under the Apache License, Version 2.0 (the
230 * "License"); you may not use this file except in compliance
231 * with the License. You may obtain a copy of the License at
233 * http://www.apache.org/licenses/LICENSE-2.0
235 * Unless required by applicable law or agreed to in writing, software
236 * distributed under the License is distributed on an "AS IS" BASIS,
237 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
238 * See the License for the specific language governing permissions and
239 * limitations under the License.
242 <configuration>
243 <property>
244 <name>hbase.rootdir</name>
245 <!-- We rely on the defaultFS being set in our hadoop confs -->
246 <value>/hbase</value>
247 </property>
248 <property>
249 <name>hbase.zookeeper.property.dataDir</name>
250 <value>${zk_data_dir}</value>
251 </property>
252 <property>
253 <name>hbase.cluster.distributed</name>
254 <value>${distributed}</value>
255 </property>
256 </configuration>
259 if [ "true" = "${distributed}" ]; then
260 cat >"${working_dir}/hbase-conf/regionservers" <<EOF
261 localhost
265 function cleanup {
267 echo "Shutting down HBase"
268 HBASE_CONF_DIR="${working_dir}/hbase-conf/" "${component_install}/bin/stop-hbase.sh"
270 if [ -f "${working_dir}/hadoop.pid" ]; then
271 echo "Shutdown: listing HDFS contents"
272 redirect_and_run "${working_dir}/hadoop_listing_at_end" \
273 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" fs -ls -R /
275 echo "Shutting down Hadoop"
276 kill -6 "$(cat "${working_dir}/hadoop.pid")"
280 trap cleanup EXIT SIGQUIT
282 echo "Starting up Hadoop"
284 if [ "${hadoop_version%.*.*}" -gt 2 ]; then
285 "${mapred_exec}" minicluster -format -writeConfig "${working_dir}/hbase-conf/core-site.xml" -writeDetails "${working_dir}/hadoop_cluster_info.json" >"${working_dir}/hadoop_cluster_command.out" 2>"${working_dir}/hadoop_cluster_command.err" &
286 else
287 HADOOP_CLASSPATH="${timeline_service_dir}/*:${timeline_service_dir}/lib/*:${yarn_server_tests_test_jar}" "${hadoop_exec}" jar "${mapred_jobclient_test_jar}" minicluster -format -writeConfig "${working_dir}/hbase-conf/core-site.xml" -writeDetails "${working_dir}/hadoop_cluster_info.json" >"${working_dir}/hadoop_cluster_command.out" 2>"${working_dir}/hadoop_cluster_command.err" &
290 echo "$!" > "${working_dir}/hadoop.pid"
292 # 2 + 4 + 8 + .. + 256 ~= 8.5 minutes.
293 max_sleep_time=512
294 sleep_time=2
295 until [[ -s "${working_dir}/hbase-conf/core-site.xml" || "${sleep_time}" -ge "${max_sleep_time}" ]]; do
296 printf '\twaiting for Hadoop to finish starting up.\n'
297 sleep "${sleep_time}"
298 sleep_time="$((sleep_time*2))"
299 done
301 if [ "${sleep_time}" -ge "${max_sleep_time}" ] ; then
302 echo "time out waiting for Hadoop to startup" >&2
303 exit 1
306 if [ "${hadoop_version%.*.*}" -gt 2 ]; then
307 echo "Verifying configs"
308 hadoop_conf_files=""
309 for f in "${working_dir}"/hbase-conf/*-site.xml; do
310 hadoop_conf_files="$hadoop_conf_files -conffile $f"
311 done
312 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" conftest $hadoop_conf_files
315 if [ -n "${clean}" ]; then
316 echo "Cleaning out HDFS..."
317 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" fs -rm -r /hbase
318 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" fs -rm -r example/
319 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" fs -rm -r example-region-listing.data
322 echo "Listing HDFS contents"
323 redirect_and_run "${working_dir}/hadoop_cluster_smoke" \
324 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" fs -ls -R /
326 echo "Starting up HBase"
327 HBASE_CONF_DIR="${working_dir}/hbase-conf/" "${component_install}/bin/start-hbase.sh"
329 sleep_time=2
330 until "${component_install}/bin/hbase" --config "${working_dir}/hbase-conf/" shell --noninteractive >"${working_dir}/waiting_hbase_startup.log" 2>&1 <<EOF
331 count 'hbase:meta'
334 printf '\tretry waiting for hbase to come up.\n'
335 sleep "${sleep_time}"
336 sleep_time="$((sleep_time*2))"
337 done
339 echo "Setting up table 'test:example' with 1,000 regions"
340 "${hbase_client}/bin/hbase" --config "${working_dir}/hbase-conf/" shell --noninteractive >"${working_dir}/table_create.log" 2>&1 <<EOF
341 create_namespace 'test'
342 create 'test:example', 'family1', 'family2', {NUMREGIONS => 1000, SPLITALGO => 'UniformSplit'}
345 echo "writing out example TSV to example.tsv"
346 cat >"${working_dir}/example.tsv" <<EOF
347 row1 value8 value8
348 row3 value2
349 row2 value9
350 row10 value1
351 pow1 value8 value8
352 pow3 value2
353 pow2 value9
354 pow10 value1
355 paw1 value8 value8
356 paw3 value2
357 paw2 value9
358 paw10 value1
359 raw1 value8 value8
360 raw3 value2
361 raw2 value9
362 raw10 value1
363 aow1 value8 value8
364 aow3 value2
365 aow2 value9
366 aow10 value1
367 aaw1 value8 value8
368 aaw3 value2
369 aaw2 value9
370 aaw10 value1
371 how1 value8 value8
372 how3 value2
373 how2 value9
374 how10 value1
375 zow1 value8 value8
376 zow3 value2
377 zow2 value9
378 zow10 value1
379 zaw1 value8 value8
380 zaw3 value2
381 zaw2 value9
382 zaw10 value1
383 haw1 value8 value8
384 haw3 value2
385 haw2 value9
386 haw10 value1
387 low1 value8 value8
388 low3 value2
389 low2 value9
390 low10 value1
391 law1 value8 value8
392 law3 value2
393 law2 value9
394 law10 value1
397 echo "uploading example.tsv to HDFS"
398 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" fs -mkdir example
399 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" fs -copyFromLocal "${working_dir}/example.tsv" "example/"
401 echo "Importing TSV via shaded client artifact for HBase - MapReduce integration."
402 # hbase_thirdparty_jars=("${component_install}"/lib/htrace-core4*.jar \
403 # "${component_install}"/lib/slf4j-api-*.jar \
404 # "${component_install}"/lib/commons-logging-*.jar \
405 # "${component_install}"/lib/slf4j-log4j12-*.jar \
406 # "${component_install}"/lib/log4j-1.2.*.jar \
407 # "${working_dir}/hbase-conf/log4j.properties")
408 # hbase_dep_classpath=$(IFS=:; echo "${hbase_thirdparty_jars[*]}")
409 hbase_dep_classpath="$("${hbase_client}/bin/hbase" --config "${working_dir}/hbase-conf/" mapredcp)"
410 HADOOP_CLASSPATH="${hbase_dep_classpath}" redirect_and_run "${working_dir}/mr-importtsv" \
411 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" jar "${hbase_client}/lib/shaded-clients/hbase-shaded-mapreduce-${hbase_version}.jar" importtsv -Dimporttsv.columns=HBASE_ROW_KEY,family1:column1,family1:column4,family1:column3 test:example example/ -libjars "${hbase_dep_classpath}"
412 "${hbase_client}/bin/hbase" --config "${working_dir}/hbase-conf/" shell --noninteractive >"${working_dir}/scan_import.out" 2>"${working_dir}/scan_import.err" <<EOF
413 scan 'test:example'
416 echo "Verifying row count from import."
417 import_rowcount=$(echo 'count "test:example"' | "${hbase_client}/bin/hbase" --config "${working_dir}/hbase-conf/" shell --noninteractive 2>/dev/null | tail -n 1)
418 if [ ! "${import_rowcount}" -eq 48 ]; then
419 echo "ERROR: Instead of finding 48 rows, we found ${import_rowcount}."
420 exit 2
423 if [ -z "${hadoop_jars}" ]; then
424 echo "Hadoop client jars not given; getting them from 'hadoop classpath' for the example."
425 hadoop_jars=$("${hadoop_exec}" --config "${working_dir}/hbase-conf/" classpath)
428 echo "Building shaded client example."
429 cat >"${working_dir}/HBaseClientReadWriteExample.java" <<EOF
430 import org.apache.hadoop.conf.Configuration;
431 import org.apache.hadoop.fs.FileSystem;
432 import org.apache.hadoop.fs.FSDataInputStream;
433 import org.apache.hadoop.fs.FSDataOutputStream;
434 import org.apache.hadoop.fs.Path;
435 import org.apache.hadoop.hbase.Cell;
436 import org.apache.hadoop.hbase.CellBuilder;
437 import org.apache.hadoop.hbase.CellBuilderFactory;
438 import org.apache.hadoop.hbase.CellBuilderType;
439 import org.apache.hadoop.hbase.ClusterMetrics;
440 import org.apache.hadoop.hbase.HBaseConfiguration;
441 import org.apache.hadoop.hbase.RegionMetrics;
442 import org.apache.hadoop.hbase.ServerMetrics;
443 import org.apache.hadoop.hbase.TableName;
444 import org.apache.hadoop.hbase.client.Admin;
445 import org.apache.hadoop.hbase.client.Connection;
446 import org.apache.hadoop.hbase.client.ConnectionFactory;
447 import org.apache.hadoop.hbase.client.Put;
448 import org.apache.hadoop.hbase.client.Table;
449 import org.apache.hadoop.hbase.util.Bytes;
451 import java.util.LinkedList;
452 import java.util.List;
455 public class HBaseClientReadWriteExample {
456 private static final byte[] FAMILY_BYTES = Bytes.toBytes("family2");
458 public static void main(String[] args) throws Exception {
459 Configuration hbase = HBaseConfiguration.create();
460 Configuration hadoop = new Configuration();
461 try (Connection connection = ConnectionFactory.createConnection(hbase)) {
462 System.out.println("Generating list of regions");
463 final List<String> regions = new LinkedList<>();
464 try (Admin admin = connection.getAdmin()) {
465 final ClusterMetrics cluster = admin.getClusterMetrics();
466 System.out.println(String.format("\tCluster reports version %s, ave load %f, region count %d", cluster.getHBaseVersion(), cluster.getAverageLoad(), cluster.getRegionCount()));
467 for (ServerMetrics server : cluster.getLiveServerMetrics().values()) {
468 for (RegionMetrics region : server.getRegionMetrics().values()) {
469 regions.add(region.getNameAsString());
473 final Path listing = new Path("example-region-listing.data");
474 System.out.println("Writing list to HDFS");
475 try (FileSystem fs = FileSystem.newInstance(hadoop)) {
476 final Path path = fs.makeQualified(listing);
477 try (FSDataOutputStream out = fs.create(path)) {
478 out.writeInt(regions.size());
479 for (String region : regions) {
480 out.writeUTF(region);
482 out.hsync();
485 final List<Put> puts = new LinkedList<>();
486 final Put marker = new Put(new byte[] { (byte)0 });
487 System.out.println("Reading list from HDFS");
488 try (FileSystem fs = FileSystem.newInstance(hadoop)) {
489 final Path path = fs.makeQualified(listing);
490 final CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
491 try (FSDataInputStream in = fs.open(path)) {
492 final int count = in.readInt();
493 marker.addColumn(FAMILY_BYTES, Bytes.toBytes("count"), Bytes.toBytes(count));
494 for(int i = 0; i < count; i++) {
495 builder.clear();
496 final byte[] row = Bytes.toBytes(in.readUTF());
497 final Put put = new Put(row);
498 builder.setRow(row);
499 builder.setFamily(FAMILY_BYTES);
500 builder.setType(Cell.Type.Put);
501 put.add(builder.build());
502 puts.add(put);
506 System.out.println("Writing list into HBase table");
507 try (Table table = connection.getTable(TableName.valueOf("test:example"))) {
508 table.put(marker);
509 table.put(puts);
515 redirect_and_run "${working_dir}/hbase-shaded-client-compile" \
516 javac -cp "${hbase_client}/lib/shaded-clients/hbase-shaded-client-byo-hadoop-${hbase_version}.jar:${hadoop_jars}" "${working_dir}/HBaseClientReadWriteExample.java"
517 echo "Running shaded client example. It'll fetch the set of regions, round-trip them to a file in HDFS, then write them one-per-row into the test table."
518 # The order of classpath entries here is important. if we're using non-shaded Hadoop 3 / 2.9.0 jars, we have to work around YARN-2190.
519 redirect_and_run "${working_dir}/hbase-shaded-client-example" \
520 java -cp "${working_dir}/hbase-conf/:${hbase_client}/lib/shaded-clients/hbase-shaded-client-byo-hadoop-${hbase_version}.jar:${hbase_dep_classpath}:${working_dir}:${hadoop_jars}" HBaseClientReadWriteExample
522 echo "Checking on results of example program."
523 "${hadoop_exec}" --config "${working_dir}/hbase-conf/" fs -copyToLocal "example-region-listing.data" "${working_dir}/example-region-listing.data"
525 "${hbase_client}/bin/hbase" --config "${working_dir}/hbase-conf/" shell --noninteractive >"${working_dir}/scan_example.out" 2>"${working_dir}/scan_example.err" <<EOF
526 scan 'test:example'
529 echo "Verifying row count from example."
530 example_rowcount=$(echo 'count "test:example"' | "${hbase_client}/bin/hbase" --config "${working_dir}/hbase-conf/" shell --noninteractive 2>/dev/null | tail -n 1)
531 if [ "${example_rowcount}" -gt "1049" ]; then
532 echo "Found ${example_rowcount} rows, which is enough to cover 48 for import, 1000 example's use of user table regions, 1 for example's use of meta region, and 1 for example's count record"
533 else
534 echo "ERROR: Only found ${example_rowcount} rows."