|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright 2025 Google LLC and contributors |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS-IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# This initialization script installs the required |
| 18 | +# jars and sets the hive conf to enable lineage. |
| 19 | + |
| 20 | +set -euxo pipefail |
| 21 | + |
| 22 | +function prepare_env() { |
| 23 | + export HIVE_HOME="/usr/lib/hive" |
| 24 | + export HIVE_CONF_DIR="/etc/hive/conf" |
| 25 | + export HIVE_CONF_FILE="$HIVE_CONF_DIR/hive-site.xml" |
| 26 | + export HIVE_LIB_DIR="$HIVE_HOME/lib" |
| 27 | + export INSTALLATION_SOURCE="gs://hadoop-lib/hive-lineage" |
| 28 | + export HIVE_OL_HOOK_VERSION="1.0.0-preview" |
| 29 | + export HIVE_OL_HOOK="io.openlineage.hive.hooks.HiveOpenLineageHook" |
| 30 | +} |
| 31 | + |
| 32 | +function set_hive_lineage_conf() { |
| 33 | + declare -A properties=( |
| 34 | + ["hive.exec.post.hooks"]="$HIVE_OL_HOOK" |
| 35 | + ["hive.exec.failure.hooks"]="$HIVE_OL_HOOK" |
| 36 | + ["hive.openlineage.transport.type"]="gcplineage" |
| 37 | + ["hive.conf.validation"]="false" # to allow custom properties, like hive.openlineage.namespace |
| 38 | + ) |
| 39 | + echo "Setting hive conf to enable lineage" |
| 40 | + for key in "${!properties[@]}"; do |
| 41 | + bdconfig set_property \ |
| 42 | + --configuration_file="$HIVE_CONF_FILE" \ |
| 43 | + --name "$key" \ |
| 44 | + --value "${properties[$key]}" |
| 45 | + done |
| 46 | +} |
| 47 | + |
| 48 | +function install_jars() { |
| 49 | + echo "Installing openlineage-hive hook" |
| 50 | + gsutil cp -P "$INSTALLATION_SOURCE/hive-openlineage-hook-$HIVE_OL_HOOK_VERSION.jar" "$HIVE_LIB_DIR/hive-openlineage-hook.jar" |
| 51 | +} |
| 52 | + |
| 53 | +function restart_hive_server2_master() { |
| 54 | + ROLE=$(curl -f -s -H Metadata-Flavor:Google http://metadata/computeMetadata/v1/instance/attributes/dataproc-role) |
| 55 | + if [[ "${ROLE}" == 'Master' ]]; then |
| 56 | + echo "Restarting hive-server2" |
| 57 | + sudo systemctl restart hive-server2.service |
| 58 | + fi |
| 59 | +} |
| 60 | + |
| 61 | +prepare_env |
| 62 | +install_jars |
| 63 | +set_hive_lineage_conf |
| 64 | +restart_hive_server2_master |
0 commit comments