Skip to content

Commit

Permalink
Style / indentation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
etejedor committed Apr 5, 2023
1 parent 09f7895 commit 6628258
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions scripts/private/webhdfs_token.sh
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
Expand All @@ -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)
Expand Down

0 comments on commit 6628258

Please sign in to comment.