-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
#!/bin/bash | ||
# Located at [/srv/jupyterhub/private/webhdfs-token.sh] | ||
|
||
#Get the namenodes for the cluster. We need to convert from the cluster name to the HDFS namespace name for nxcals and hdpqa | ||
# Get the namenodes for the cluster. We need to convert from the cluster name to the HDFS namespace name for nxcals and hdpqa | ||
function get_namenodes { | ||
if [ "$1" == "hadoop-nxcals" ]; then HDFSNAMESPACE='nxcals' | ||
elif [ "$1" == "hadoop-qa" ]; then HDFSNAMESPACE='hdpqa' | ||
else HDFSNAMESPACE=$1 | ||
fi | ||
NAMENODES=$(xmllint --xpath '/configuration//property[name="dfs.ha.namenodes.'"$HDFSNAMESPACE"'"]/value/text()' /cvmfs/sft.cern.ch/lcg/etc/hadoop-confext/conf/etc/$1/hadoop.$1/hdfs-site.xml) | ||
echo "$NAMENODES" | ||
if [ "$1" == "hadoop-nxcals" ] | ||
then | ||
HDFSNAMESPACE='nxcals' | ||
elif [ "$1" == "hadoop-qa" ] | ||
then | ||
HDFSNAMESPACE='hdpqa' | ||
else | ||
HDFSNAMESPACE=$1 | ||
fi | ||
|
||
NAMENODES=$(xmllint --xpath '/configuration//property[name="dfs.ha.namenodes.'"$HDFSNAMESPACE"'"]/value/text()' /cvmfs/sft.cern.ch/lcg/etc/hadoop-confext/conf/etc/$1/hadoop.$1/hdfs-site.xml) | ||
echo "$NAMENODES" | ||
} | ||
|
||
CLUSTER=$1 | ||
USER=$2 | ||
|
||
if [ $SWAN_DEV = "true" ]; then | ||
if [ $SWAN_DEV = "true" ] | ||
then | ||
# For dev purposes, just generate some dummy string | ||
echo $(echo "dummy" | base64 -w 0) | ||
exit 0 | ||
|
@@ -25,21 +32,23 @@ export KRB5CCNAME=$(mktemp /tmp/hswan.XXXXXXXXX) | |
kinit -V -kt /srv/jupyterhub/private/hadoop.cred [email protected] -c $KRB5CCNAME >/dev/null 2>&1 | ||
|
||
# Generate web-hdfs tokens | ||
if [ "$1" == "hadoop-qa" ]; | ||
then HTTP='https' | ||
else HTTP='http' | ||
if [ "$1" == "hadoop-qa" ] | ||
then | ||
HTTP='https' | ||
else | ||
HTTP='http' | ||
fi | ||
|
||
NAMENODES=$(get_namenodes $1) | ||
OIFS=$IFS | ||
IFS=',' | ||
for namenode in $NAMENODES | ||
do | ||
#to detect active NN. we cannot use jmx, we have to rely on the exit code of the list action | ||
if [ $(curl -s --negotiate -u : "$HTTP://$namenode:50070/webhdfs/v1/?op=LISTSTATUS" -o /dev/null -s -w "%{http_code}") -eq 200 ]; | ||
then | ||
WEBHDFS_TOKEN=$(curl -s --negotiate -u : "$HTTP://$namenode:50070/webhdfs/v1/?doas=$2&op=GETDELEGATIONTOKEN&renewer=yarn" | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["Token"]["urlString"])') | ||
fi | ||
# to detect active NN. we cannot use jmx, we have to rely on the exit code of the list action | ||
if [ $(curl -s --negotiate -u : "$HTTP://$namenode:50070/webhdfs/v1/?op=LISTSTATUS" -o /dev/null -s -w "%{http_code}") -eq 200 ] | ||
then | ||
WEBHDFS_TOKEN=$(curl -s --negotiate -u : "$HTTP://$namenode:50070/webhdfs/v1/?doas=$2&op=GETDELEGATIONTOKEN&renewer=yarn" | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["Token"]["urlString"])') | ||
fi | ||
done | ||
|
||
echo $(echo $WEBHDFS_TOKEN | base64 -w 0) | ||
|