#!/bin/bash
# Copyright (c) 2013 Cloudera, Inc. All rights reserved.

# Time marker for both stderr and stdout
date; date 1>&2

cloudera_config=`dirname $0`
cloudera_config=`cd "$cloudera_config/../common"; pwd`
. ${cloudera_config}/cloudera-config.sh

# load the parcel environment
source_parcel_environment

# attempt to find java
locate_cdh_java_home

# simulate /etc/default/hadoop if necessary
. ${cloudera_config}/cdh-default-hadoop

export HADOOP_OPTS="-Djava.net.preferIPv4Stack=true $HADOOP_OPTS"

echo "using $JAVA_HOME as JAVA_HOME"
echo "using $CONF_DIR as CONF_DIR"

set_hadoop_classpath

export HADOOP_HOME=$CDH_HADOOP_HOME

export HADOOP_CONF_DIR=$CONF_DIR/yarn-conf
export HADOOP_MAPRED_HOME=$CDH_MR2_HOME
perl -pi -e "s#{{CDH_MR2_HOME}}#$CDH_MR2_HOME#g" $HADOOP_CONF_DIR/*

# Search-replace {{CMF_CONF_DIR}} in files
replace_conf_dir

acquire_kerberos_tgt impala.keytab

export LLAMA_AM_SERVER_HOME=$CONF_DIR
export LLAMA_AM_SERVER_CONF=$CONF_DIR

# Add LLAMA jars to classpath.  This probably ought to be
# in $CDH_LLAMA_HOME/bin/llama itself.
export HADOOP_CLASSPATH=$(JARS=($CDH_LLAMA_HOME/*.jar /usr/lib/llama/lib/*.jar); IFS=:; echo "${JARS[*]}:${HADOOP_CLASSPATH}")

exec $CDH_LLAMA_HOME/bin/llama "$@"
