Skip to content

Commit

Permalink
Merge pull request #10 from sile16/master
Browse files Browse the repository at this point in the history
Ability to append cluster name to all service accounts and remove isi_run depdency.  Spoke with contributor about additions and changes accepted.
  • Loading branch information
Brian Radwanski authored Jun 21, 2016
2 parents 4d14a35 + 01aaa97 commit 5419011
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
47 changes: 35 additions & 12 deletions onefs/isilon_create_directories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare -a ERRORLIST=()
DIST=""
FIXPERM="n"
ZONE="System"
CLUSTER_NAME=""

#set -x

Expand All @@ -26,7 +27,7 @@ function banner() {
}

function usage() {
echo "$0 --dist <cdh|hwx|phd|phd3|bi> [--zone <ZONE>] [--fixperm]"
echo "$0 --dist <cdh|hwx|phd|phd3|bi> [--zone <ZONE>] [--fixperm] [--append-cluster-name <clustername>]"
exit 1
}

Expand All @@ -53,17 +54,19 @@ function makedir() {
if [ "z$1" == "z" ] ; then
echo "ERROR -- function makedir needs directory as an argument"
else
mkdir $1
mkdir -p $1
fi
}

function fixperm() {
if [ "z$1" == "z" ] ; then
echo "ERROR -- function fixperm needs directory owner group perm as an argument"
else
isi_run -z $ZONEID chown $2 $1
isi_run -z $ZONEID chown :$3 $1
isi_run -z $ZONEID chmod $4 $1
uid=$(getUserUid $2)
gid=$(getGroupGid $3)
chown $uid $1
chown :$gid $1
chmod $4 $1
fi
}

Expand All @@ -78,12 +81,23 @@ function getHdfsRoot() {
echo $hdfsroot
}

function getAccessZoneId() {
local zoneid
hdfsroot=$(isi zone zones view $1 | grep "Zone ID:" | cut -f2 -d :)
echo $hdfsroot
#Params: Username
#returns: UID
function getUserUid() {
local uid
uid=$(isi auth users view --zone $ZONE $1 | grep " UID" | cut -f2 -d :)
echo $uid
}

#Params: GroupName
#returns: GID
function getGroupGid() {
local gid
gid=$(isi auth groups view --zone $ZONE $1 | grep " GID:" | cut -f2 -d :)
echo $gid
}


if [ "`uname`" != "Isilon OneFS" ]; then
fatal "Script must be run on Isilon cluster as root."
fi
Expand Down Expand Up @@ -111,6 +125,11 @@ while [ "z$1" != "z" ] ; do
echo "Info: will fix permissions and owners on existing directories"
FIXPERM="y"
;;
"--append-cluster-name")
shift
CLUSTER_NAME="-$1"
echo "Info: will add clustername to end of usernames: $CLUSTER_NAME"
;;
*) echo "ERROR -- unknown arg $1"
usage
;;
Expand Down Expand Up @@ -279,9 +298,6 @@ case "$DIST" in
;;
esac

ZONEID=$(getAccessZoneId $ZONE)
echo "Info: Access Zone ID is $ZONEID"

HDFSROOT=$(getHdfsRoot $ZONE)
echo "Info: HDFS root dir is $HDFSROOT"

Expand All @@ -300,6 +316,13 @@ prefix=0

for direntry in ${dirList[*]}; do
read -a specs <<<"$(echo $direntry | sed 's/#/ /g')"

if [[ ${specs[0]} == /user/* ]] ; then
specs[0]="${specs[0]}$CLUSTER_NAME"
fi
specs[2]="${specs[2]}$CLUSTER_NAME"
specs[3]="${specs[3]}$CLUSTER_NAME"

echo "DEBUG: specs dirname ${specs[0]}; perm ${specs[1]}; owner ${specs[2]}; group ${specs[3]}"
ifspath=$HDFSROOT${specs[0]}
# echo "DEBUG: ifspath = $ifspath"
Expand Down
22 changes: 16 additions & 6 deletions onefs/isilon_create_users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DIST=""
STARTUID=1000
STARTGID=1000
ZONE="System"
CLUSTER_NAME=""

#set -x

Expand All @@ -27,7 +28,7 @@ function banner() {
}

function usage() {
echo "$0 --dist <cdh|hwx|phd|phd3|bi> [--startgid <GID>] [--startuid <UID>] [--zone <ZONE>]"
echo "$0 --dist <cdh|hwx|phd|phd3|bi> [--startgid <GID>] [--startuid <UID>] [--zone <ZONE>] [--append-cluster-name <clustername>]"
exit 1
}

Expand All @@ -50,7 +51,7 @@ function yesno() {
[ -n "$1" ] || myPrompt=">>> Please enter yes/no: "
read -rp "$myPrompt" yn
[ "z${yn:0:1}" = "zy" -o "z${yn:0:1}" = "zY" ] && return 0
# exit "DEBUG: returning false from function yesno"
# exit ": returning false from function yesno"
return 1
}

Expand Down Expand Up @@ -140,6 +141,11 @@ while [ "z$1" != "z" ] ; do
ZONE="$1"
echo "Info: will put users in zone: $ZONE"
;;
"--append-cluster-name")
shift
CLUSTER_NAME="-$1"
echo "Info: will add clustername to end of usernames: $CLUSTER_NAME"
;;
*)
echo "ERROR -- unknown arg $1"
usage
Expand Down Expand Up @@ -193,6 +199,7 @@ echo "Info: HDFS root: $HDFSROOT"
gid=$STARTGID
for group in $REQUIRED_GROUPS; do
# echo "DEBUG: GID=$gid"
group="$group$CLUSTER_NAME"
if groupExists $group $ZONE ; then
gid=$(getGidFromGroup $group $ZONE)
addError "Group $group already exists at gid $gid in zone $ZONE"
Expand All @@ -210,6 +217,7 @@ done
uid=$STARTUID
for user in $REQUIRED_USERS; do
# echo "DEBUG: UID=$uid"
user="$user$CLUSTER_NAME"
if userExists $user $ZONE ; then
uid=$(getUidFromUser $user $ZONE)
addError "User $user already exists at uid $uid in zone $ZONE"
Expand All @@ -224,7 +232,9 @@ for user in $REQUIRED_USERS; do
done

for user in $SUPER_USERS; do
user="$user$CLUSTER_NAME"
for group in $SUPER_GROUPS; do
group="$group$CLUSTER_NAME"
isi auth groups modify $group --add-user $user --zone $ZONE
[ $? -ne 0 ] && addError "Could not add user $user to $group group in zone $ZONE"
done
Expand All @@ -233,15 +243,15 @@ done
# Special cases
case "$DIST" in
"cdh")
isi auth groups modify sqoop --add-user sqoop2 --zone $ZONE
isi auth groups modify sqoop$CLUSTER_NAME --add-user sqoop2$CLUSTER_NAME --zone $ZONE
[ $? -ne 0 ] && addError "Could not add user sqoop2 to sqoop group in zone $ZONE"
;;
"bi")
isi auth groups modify users --add-user hive --zone $ZONE
isi auth groups modify users$CLUSTER_NAME --add-user hive$CLUSTER_NAME --zone $ZONE
[ $? -ne 0 ] && addError "Could not add user hive to users group in zone $ZONE"
isi auth groups modify hcat --add-user hive --zone $ZONE
isi auth groups modify hcat$CLUSTER_NAME --add-user hive$CLUSTER_NAME --zone $ZONE
[ $? -ne 0 ] && addError "Could not add user hive to hcat group in zone $ZONE"
isi auth groups modify knox --add-user kafka --zone $ZONE
isi auth groups modify knox$CLUSTER_NAME --add-user kafka$CLUSTER_NAME --zone $ZONE
[ $? -ne 0 ] && addError "Could not add user kafka to knox group in zone $ZONE"
;;
esac
Expand Down

0 comments on commit 5419011

Please sign in to comment.