Skip to content

Commit

Permalink
Sync github to internal FB hadoop code.
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamdamania87 committed Sep 11, 2013
1 parent 41f4b6f commit 9f1ea1b
Show file tree
Hide file tree
Showing 1,065 changed files with 115,982 additions and 35,121 deletions.
130 changes: 121 additions & 9 deletions bin/hadoop
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
# HADOOP_ROOT_LOGGER The root appender. Default is INFO,console
#

bin=`dirname "$0"`
thisfile="${BASH_SOURCE[0]}"
if [ -L "${thisfile}" ]; then
thisfile=$(readlink "${thisfile}")
fi

bin=`dirname "${thisfile}"`
bin=`cd "$bin"; pwd`

. "$bin"/hadoop-config.sh
Expand Down Expand Up @@ -157,14 +162,64 @@ for f in $HADOOP_HOME/hadoop-*-core.jar; do
done

# add libs to CLASSPATH
for f in $HADOOP_HOME/lib/*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
# the thrift library has conflicts in hdfs-nfs-proxy
# only put neccessary jars for hdfs-nfs-proxy
if [ "$COMMAND" = "hdfsnfsproxy" ] ; then
for f in $HADOOP_HOME/lib/slf4j*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/lib/zookeeper*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/lib/guava*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/lib/json*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/lib/commons*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/lib/log4j*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/lib/hadoop*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
else
for f in $HADOOP_HOME/lib/*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
fi

if [ -d "$HADOOP_HOME/build/ivy/lib/Hadoop/common" ]; then
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
if [ "$COMMAND" = "hdfsnfsproxy" ] ; then
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/slf4j*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/zookeeper*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/guava*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/json*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/commons*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/log4j*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/hadoop*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
else
for f in $HADOOP_HOME/build/ivy/lib/Hadoop/common/*.jar; do
CLASSPATH=${CLASSPATH}:$f;
done
fi
fi

for f in $HADOOP_HOME/lib/jsp-2.1/*.jar; do
Expand All @@ -187,8 +242,10 @@ for f in $HADOOP_HOME/contrib/corona/*.jar; do
CORONA_PATH=${CORONA_PATH}:$f;
done

if [ "$CORONA_PATH" != "" ]; then
CLASSPATH=${CLASSPATH}:${CORONA_PATH}
if [ "$COMMAND" != "hdfsnfsproxy" ] ; then
if [ "$CORONA_PATH" != "" ]; then
CLASSPATH=${CLASSPATH}:${CORONA_PATH}
fi
fi

for f in $HADOOP_HOME/contrib/corona/lib/*.jar; do
Expand All @@ -204,6 +261,37 @@ for f in $HADOOP_HOME/contrib/namespace-notifier/*.jar; do
NOTIFIER_PATH=${NOTIFIER_PATH}:$f;
done

# NFS_PROXY_PATH for the hdfs nfs proxy daemon
if [ -d "$HADOOP_HOME/build/contrib/hdfs-nfs-proxy/classes" ] ; then
NFS_PROXY_PATH=${NFS_PROXY_PATH}:$HADOOP_HOME/build/contrib/hdfs-nfs-proxy/classes
fi

# hdfs-nfs-proxy needs raid and configerator in classpath
# to get DistributedRaidFileSystem from configuration
if [ -d "$HADOOP_HOME/build/contrib/raid/classes" ] ; then
NFS_PROXY_PATH=${NFS_PROXY_PATH}:$HADOOP_HOME/build/contrib/raid/classes
fi

if [ -d "$HADOOP_HOME/build/contrib/configerator/classes" ] ; then
NFS_PROXY_PATH=${NFS_PROXY_PATH}:$HADOOP_HOME/build/contrib/configerator/classes
fi

for f in $HADOOP_HOME/build/contrib/hdfs-nfs-proxy/lib/*.jar; do
NFS_PROXY_PATH=${NFS_PROXY_PATH}:$f;
done

for f in $HADOOP_HOME/build/contrib/hdfs-nfs-proxy/hadoop-*-hdfs-nfs-proxy.jar; do
NFS_PROXY_PATH=${NFS_PROXY_PATH}:$f;
done

for f in $HADOOP_HOME/contrib/hdfs-nfs-proxy/*.jar; do
NFS_PROXY_PATH=${NFS_PROXY_PATH}:$f;
done

for f in $HADOOP_HOME/contrib/hdfs-nfs-proxy/lib/*.jar; do
NFS_PROXY_PATH=${NFS_PROXY_PATH}:$f;
done

# default log directory & file
if [ "$HADOOP_LOG_DIR" = "" ]; then
HADOOP_LOG_DIR="$HADOOP_HOME/logs"
Expand Down Expand Up @@ -246,6 +334,10 @@ elif [ "$COMMAND" = "avatarnode" ] ; then
CLASS='org.apache.hadoop.hdfs.server.namenode.AvatarNode'
JMX_OPTS=$HADOOP_JMX_NAMENODE_OPTS
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_GC_LOG_OPTS $HADOOP_NAMENODE_OPTS"
elif [ "$COMMAND" = "journalnode" ] ; then
CLASS='org.apache.hadoop.hdfs.qjournal.server.JournalNode'
JMX_OPTS=$HADOOP_JMX_JOURNAL_OPTS
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_GC_LOG_OPTS $HADOOP_JOURNAL_OPTS"
elif [ "$COMMAND" = "secondarynamenode" ] ; then
CLASS='org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode'
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_GC_LOG_OPTS $HADOOP_SECONDARYNAMENODE_OPTS"
Expand All @@ -259,7 +351,19 @@ elif [ "$COMMAND" = "notifier" ] ; then
if [ "$NOTIFIER_PATH" != "" ]; then
CLASSPATH=${CLASSPATH}:${NOTIFIER_PATH}
fi
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_GC_LOG_OPTS $NOTIFIER_OPTS"
JMX_OPTS="$JMX_OPTS $NOTIFIER_JMX_OPTS"
elif [ "$COMMAND" = "hdfsnfsproxy" ] ; then
CLASS='org.apache.hadoop.hdfs.nfs.nfs4.NFS4Server'
# hdfs-nfs-proxy is using log4j Rolling File Appender for
# log rotation, max log size, and how many backup logs to keep
HADOOP_LOGFILE='hdfs-nfs-proxy.log'
HADOOP_ROOT_LOGGER=INFO,RFA
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_GC_LOG_OPTS"
JMX_OPTS="$JMX_OPTS"
if [ "$NFS_PROXY_PATH" != "" ]; then
CLASSPATH=${CLASSPATH}:${NFS_PROXY_PATH}
fi
elif [ "$COMMAND" = "fsshellservice" ] ; then
CLASS='org.apache.hadoop.hdfs.fsshellservice.FsShellServiceImpl'
if [ -d "$HADOOP_HOME/build/contrib/corona/lib" ]; then
Expand Down Expand Up @@ -312,6 +416,9 @@ elif [ "$COMMAND" = "raidfsck" ] ; then
elif [ "$COMMAND" = "raidshell" ] ; then
CLASS=org.apache.hadoop.raid.RaidShell
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
elif [ "$COMMAND" = "notifiershell" ] ; then
CLASS=org.apache.hadoop.hdfs.notifier.tools.NotifierShell
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
elif [ "$COMMAND" = "balancer" ] ; then
CLASS=org.apache.hadoop.hdfs.server.balancer.Balancer
HADOOP_OPTS="$HADOOP_OPTS $HADOOP_BALANCER_OPTS"
Expand Down Expand Up @@ -460,6 +567,11 @@ if [ -d "${HADOOP_HOME}/build/native" -o -d "${HADOOP_HOME}/lib/native" ]; then
fi
fi

# use fbcode gcc in nfs proxy java.library.path
if [ "$COMMAND" = "hdfsnfsproxy" ] ; then
JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:/usr/local/fbcode/gcc-4.6.2-glibc-2.5.1/lib;
fi

# cygwin path translation
if $cygwin; then
JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"`
Expand Down
107 changes: 107 additions & 0 deletions bin/mount-hdfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash

# Mount an HDFS uri into a local directory. Start up an instance of the proxy
# if there isn't one already running.

hdfs_uri=$1
local_dir=$2

START_PORT=34550
END_PORT=34700

# Needs to be root user to restart rpcidmapd. Will sudo as hadoop later
if [ $UID -ne 0 ]; then
echo "Error: must run as root user"
exit 1
fi

# Does hadoop user exist on system?
if ! /usr/bin/getent passwd hadoop >/dev/null 2>/dev/null; then echo
echo "Error: hadoop user does not exist on system."
exit 1
fi

# Find a free port to bind to between the start and end ports
# Return 0 if nothing was free in that range
find_free_port() {
start=$1
end=$2
port=$start
while true; do
free=$(lsof -iTCP:$port | wc -l)
if [ $free == "0" ]; then
break
fi
port=$(( $port + 1))
if [ $port -gt $end ]; then
port=0
break
fi
done
echo $port
}

# Get a port of an existing NFS proxy. If there isn't one, return 0
get_existing_port() {
running_pid=$(/usr/bin/pgrep -f org.apache.hadoop.hdfs.nfs.nfs4.NFS4Server)
if [ $? != "0" ]; then
echo "0"
return
fi

if [ $(echo "${running_pid}" | wc -l) != "1" ]; then
# More than one proxy. What's going on?
exit 6
fi

port=$(/bin/awk -F'\0' '{ print $(NF-1) }' /proc/$running_pid/cmdline)
if ! echo "${port}" | /bin/egrep -q '^[0-9]+$'; then
# Command line looks weird. What's going on?
exit 7
fi

echo ${port}
}

# Start up an instance of the proxy
start_proxy() {
# Pick a free port to run on
free_port=$(find_free_port $START_PORT $END_PORT)
if [ $free_port -eq 0 ]; then
echo "Error: could not find a free port"
exit 4
fi
$(dirname ${BASH_SOURCE[0]})/start-nfs-server.sh $free_port >/dev/null 2>/dev/null
sleep 5
echo $free_port
}

if [ $# -ne 2 ]; then
echo "Usage: $0 <hdfs uri> <directory>"
echo
echo " Mounts the HDFS location into the local directory"
echo
exit 1
fi

if ! echo $1 | /bin/egrep -q "^hdfs://[^:/]+:[0-9]+/.+$"; then
echo "Error: HDFS URI '$hdfs_uri' is not valid"
exit 2
fi

short_uri=$(echo "${hdfs_uri}" | sed -e 's/^hdfs:\/\/*//' -e 's/^\([^:]*\):\([0-9]*\)/\1.\2/')

if [ ! -d "${local_dir}" ]; then
echo "Error: Directory '${local_dir}' does not exist"
exit 3
fi

existing_port=$(get_existing_port)

if [ $existing_port == "0" ]; then
existing_port=$(start_proxy)
fi

/bin/mount -t nfs4 "localhost:/${short_uri}" "${local_dir}" -o rw,intr,port=${existing_port}

exit $?
32 changes: 32 additions & 0 deletions bin/start-journalnode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.

usage="Usage: start-journalnode.sh"

params=$#
bin=`dirname "$0"`
bin=`cd "$bin"; pwd`

. "$bin"/hadoop-config.sh
. "$bin"/../conf/hadoop-env.sh

# get arguments
if [ $# -ge 1 ]; then
echo $usage
fi

"$bin"/hadoop-daemon.sh --config $HADOOP_CONF_DIR start journalnode
24 changes: 19 additions & 5 deletions bin/start-namespace-notifier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

usage="Usage: start-namespace-notifier.sh"
usage="Usage: start-namespace-notifier.sh [-service service_id]"

params=$#
bin=`dirname "$0"`
Expand All @@ -26,12 +26,26 @@ bin=`cd "$bin"; pwd`

# get arguments
if [ $# -ge 1 ]; then
echo $usage
startArg=$1
case $startArg in
(-service)
if [ $# -ge 2 ]; then
service_id=$2
else
echo $usage
exit 1
fi
;;
(*)
echo $usage
exit 1
;;
esac
fi

export NOTIFIER_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=$NOTIFIER_JMX_PORT -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

# use the thrift 0.7.0 jar in the class path
export HADOOP_CLASSPATH=${HADOOP_HOME}/contrib/namespace-notifier/lib/libthrift-0.7.0.jar:${HADOOP_CLASSPATH}
# use the thrift 0.9.0 jar in the class path
export HADOOP_CLASSPATH=${HADOOP_HOME}/contrib/namespace-notifier/lib/libthrift-0.9.0.jar:${HADOOP_CLASSPATH}

"$bin"/hadoop-daemon.sh --config $HADOOP_CONF_DIR start notifier
"$bin"/hadoop-daemon.sh --config $HADOOP_CONF_DIR start notifier $startArg $service_id
Loading

0 comments on commit 9f1ea1b

Please sign in to comment.