import-hive.sh 3.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/bin/bash
#
# 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. See accompanying LICENSE file.
#

# resolve links - $0 may be a softlink
PRG="${0}"

19 20
[[ `uname -s` == *"CYGWIN"* ]] && CYGWIN=true

21 22 23 24 25 26 27 28 29 30 31 32 33
while [ -h "${PRG}" ]; do
  ls=`ls -ld "${PRG}"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "${PRG}"`/"$link"
  fi
done

BASEDIR=`dirname ${PRG}`
BASEDIR=`cd ${BASEDIR}/..;pwd`

34 35
if [ -z "$ATLAS_CONF" ]; then
  ATLAS_CONF=${BASEDIR}/conf
36
fi
37
export ATLAS_CONF
38

39 40
if [ -f "${ATLAS_CONF}/atlas-env.sh" ]; then
  . "${ATLAS_CONF}/atlas-env.sh"
41 42
fi

43
if test -z "${JAVA_HOME}"
44 45 46 47
then
    JAVA_BIN=`which java`
    JAR_BIN=`which jar`
else
48 49
    JAVA_BIN="${JAVA_HOME}/bin/java"
    JAR_BIN="${JAVA_HOME}/bin/jar"
50 51 52
fi
export JAVA_BIN

53
if [ ! -e "${JAVA_BIN}" ] || [ ! -e "${JAR_BIN}" ]; then
54 55 56 57
  echo "$JAVA_BIN and/or $JAR_BIN not found on the system. Please make sure java and jar commands are available."
  exit 1
fi

58 59
# Construct classpath using Atlas conf directory
# and jars from bridge/hive and hook/hive directories.
60
ATLASCPPATH="$ATLAS_CONF"
61

62
for i in "${BASEDIR}/bridge/hive/"*.jar; do
63
  ATLASCPPATH="${ATLASCPPATH}:$i"
64 65 66
done

for i in "${BASEDIR}/hook/hive/"*.jar; do
67
  ATLASCPPATH="${ATLASCPPATH}:$i"
68 69
done

70
# log dir for applications
71 72 73
ATLAS_LOG_DIR="${ATLAS_LOG_DIR:-$BASEDIR/logs}"
export ATLAS_LOG_DIR
LOGFILE="$ATLAS_LOG_DIR/import-hive.log"
74 75 76

TIME=`date +%Y%m%d%H%M%s`

77
#Add hive conf in classpath
78 79 80 81
if [ ! -z "$HIVE_CONF_DIR" ]; then
    HIVE_CP=$HIVE_CONF_DIR
elif [ ! -z "$HIVE_HOME" ]; then
    HIVE_CP="$HIVE_HOME/conf"
82
elif [ -e /etc/hive/conf ]; then
83
    HIVE_CP="/etc/hive/conf"
84 85 86 87 88 89
else
    echo "Could not find a valid HIVE configuration"
    exit 1
fi
export HIVE_CP

90
CP="${HIVE_CP}:${ATLASCPPATH}"
91 92 93 94

# If running in cygwin, convert pathnames and classpath to Windows format.
if [ "${CYGWIN}" == "true" ]
then
95
   ATLAS_LOG_DIR=`cygpath -w ${ATLAS_LOG_DIR}`
96 97 98 99 100
   LOGFILE=`cygpath -w ${LOGFILE}`
   HIVE_CP=`cygpath -w ${HIVE_CP}`
   CP=`cygpath -w -p ${CP}`
fi

101 102
JAVA_PROPERTIES="$ATLAS_OPTS -Datlas.log.dir=$ATLAS_LOG_DIR -Datlas.log.file=import-hive.log
-Dlog4j.configuration=atlas-log4j.xml"
103 104 105 106 107 108 109 110 111 112 113
shift

while [[ ${1} =~ ^\-D ]]; do
  JAVA_PROPERTIES="${JAVA_PROPERTIES} ${1}"
  shift
done

echo Using Hive configuration directory ["$HIVE_CP"]
echo "Log file for import is $LOGFILE"

"${JAVA_BIN}" ${JAVA_PROPERTIES} -cp "${CP}" org.apache.atlas.hive.bridge.HiveMetaStoreBridge
114 115

RETVAL=$?
116 117
[ $RETVAL -eq 0 ] && echo Hive Data Model imported successfully!!!
[ $RETVAL -ne 0 ] && echo Failed to import Hive Data Model!!!