Files
impala/testdata/bin/run-step.sh
Tim Armstrong 43de306d17 Log data loading and cluster setup to file
Log output of data loading steps to files only print to stdout
if there is an actual failure. The output of some steps is very noisy,
and some steps even have output that looks like errors.

This is implemented with a run-step helper function in bash that handles
redirection and logging. Any bash command can be prefixed with run-step
<step description> <log file name> to redirect the output to a log file.

Sample output is:

Starting Impala cluster (logging to start-impala-cluster.log)... OK
Setting up HDFS environment (logging to setup-hdfs-env.log)... OK
Skipped loading the metadata.
Loading HBase data only (logging to load-hbase-only.log)... OK
Loading Hive UDFs (logging to build-and-copy-hive-udfs.log)... OK
Running custom post-load steps (logging to custom-post-load-steps.log)... OK
Caching test tables (logging to cache-test-tables.log)... OK
Loading external data sources (logging to load-ext-data-source.log)... OK
Splitting HBase (logging to create-hbase.log)... OK

Change-Id: I6396540858c408b084039a87efc81e1004626f39
Reviewed-on: http://gerrit.cloudera.org:8080/1760
Reviewed-by: Skye Wanderman-Milne <skye@cloudera.com>
Tested-by: Internal Jenkins
2016-01-20 04:38:19 +00:00

46 lines
1.4 KiB
Bash

#!/bin/bash
# Copyright 2015 Cloudera Inc.
#
# Licensed 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.
#
# run-step helper function used by multiple scripts. To use in a bash script, just
# source this file.
# Function to run a build step that logs output to a file and only
# outputs if there is an error.
# Usage: run-step <step description> <log file name> <cmd> <arg1> <arg2> ...
# LOG_DIR must be set to a writable directory for logs.
function run-step {
local MSG=$1
shift
local LOG_FILE_NAME=$1
shift
if [ ! -d "${LOG_DIR}" ]; then
echo "LOG_DIR must be set to a valid directory: ${LOG_DIR}"
return 1
fi
local LOG=${LOG_DIR}/${LOG_FILE_NAME}
echo -n "${MSG} (logging to ${LOG_FILE_NAME})... "
echo "Log for command '$@'" > ${LOG}
if ! "$@" >> ${LOG} 2>&1 ; then
echo "FAILED"
echo "'$@' failed. Tail of log:"
tail -n50 ${LOG}
return 1
fi
echo OK
}