Skip to content

Commit

Permalink
simplified the cluster_name append, applied to folder paths that begi…
Browse files Browse the repository at this point in the history
…n with /user/
  • Loading branch information
sile16 committed Jun 14, 2016
1 parent 357bb95 commit 01aaa97
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
32 changes: 14 additions & 18 deletions onefs/isilon_create_directories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare -a ERRORLIST=()
DIST=""
FIXPERM="n"
ZONE="System"
CLUSTERNAME=""
CLUSTER_NAME=""

#set -x

Expand Down Expand Up @@ -67,10 +67,6 @@ function fixperm() {
chown $uid $1
chown :$gid $1
chmod $4 $1

#isi_run -z $ZONEIDchown $2 $1
#isi_run -z $ZONEID chown :$3 $1
#isi_run -z $ZONEID chmod $4 $1
fi
}

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

function getAccessZoneId() {
local zoneid
zoneid=$(isi zone zones view $1 | grep "Zone ID:" | cut -f2 -d :)
echo $zoneid
}

#Params: Username
#returns: UID
function getUserUid() {
local uid
uid=$(isi auth users view --zone $ZONE $1$CLUSTERNAME | grep " UID" | cut -f2 -d :)
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$CLUSTERNAME | grep " GID:" | cut -f2 -d :)
gid=$(isi auth groups view --zone $ZONE $1 | grep " GID:" | cut -f2 -d :)
echo $gid
}

Expand Down Expand Up @@ -135,8 +127,8 @@ while [ "z$1" != "z" ] ; do
;;
"--append-cluster-name")
shift
CLUSTERNAME="-$1"
echo "Info: will add clustername to end of usernames: $CLUSTERNAME"
CLUSTER_NAME="-$1"
echo "Info: will add clustername to end of usernames: $CLUSTER_NAME"
;;
*) echo "ERROR -- unknown arg $1"
usage
Expand Down Expand Up @@ -306,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 @@ -327,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
44 changes: 24 additions & 20 deletions onefs/isilon_create_users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DIST=""
STARTUID=1000
STARTGID=1000
ZONE="System"
CLUSTERNAME=""
CLUSTER_NAME=""

#set -x

Expand Down Expand Up @@ -51,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 All @@ -60,11 +60,11 @@ function uidInUse() {
}

function userExists() {
isi auth users view $1$CLUSTERNAME --zone $2 > /dev/null 2>&1
isi auth users view $1 --zone $2 > /dev/null 2>&1
}

function groupExists() {
isi auth groups view $1$CLUSTERNAME --zone $2 > /dev/null 2>&1
isi auth groups view $1 --zone $2 > /dev/null 2>&1
}

function gidInUse() {
Expand All @@ -73,7 +73,7 @@ function gidInUse() {

function getUidFromUser() {
local uid
uid=$(isi auth users view $1$CLUSTERNAME --zone $2 | awk '/^ *UID:/ {print $2}')
uid=$(isi auth users view $1 --zone $2 | awk '/^ *UID:/ {print $2}')
echo $uid
}

Expand All @@ -85,7 +85,7 @@ function getUserFromUid() {

function getGidFromGroup() {
local gid
gid=$(isi auth groups view $1$CLUSTERNAME --zone $2 | awk '/^ *GID:/ {print $2}')
gid=$(isi auth groups view $1 --zone $2 | awk '/^ *GID:/ {print $2}')
echo $gid
}

Expand Down Expand Up @@ -143,8 +143,8 @@ while [ "z$1" != "z" ] ; do
;;
"--append-cluster-name")
shift
CLUSTERNAME="-$1"
echo "Info: will add clustername to end of usernames: $CLUSTERNAME"
CLUSTER_NAME="-$1"
echo "Info: will add clustername to end of usernames: $CLUSTER_NAME"
;;
*)
echo "ERROR -- unknown arg $1"
Expand Down Expand Up @@ -199,15 +199,16 @@ 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"
elif gidInUse $gid $ZONE ; then
group=$(getGroupFromGid $gid $ZONE)
addError "GID $gid already in use by group $group in zone $ZONE"
else
isi auth groups create $group$CLUSTERNAME --gid $gid --zone $ZONE
[ $? -ne 0 ] && addError "Could not create group $group$CLUSTERNAME with gid $gid in zone $ZONE"
isi auth groups create $group --gid $gid --zone $ZONE
[ $? -ne 0 ] && addError "Could not create group $group with gid $gid in zone $ZONE"
fi
gid=$(( $gid + 1 ))
done
Expand All @@ -216,38 +217,41 @@ 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$CLUSTERNAME already exists at uid $uid in zone $ZONE"
addError "User $user already exists at uid $uid in zone $ZONE"
elif uidInUse $uid $ZONE ; then
user=$(getUserFromUid $uid $ZONE)
addError "UID $uid already in use by user $user$CLUSTERNAME in zone $ZONE"
addError "UID $uid already in use by user $user in zone $ZONE"
else
isi auth users create $user$CLUSTERNAME --uid $uid --primary-group $user$CLUSTERNAME --zone $ZONE --provider local --home-directory $HDFSROOT/user/$user$CLUSTERNAME
[ $? -ne 0 ] && addError "Could not create user $user$CLUSTERNAME with uid $uid in zone $ZONE"
isi auth users create $user --uid $uid --primary-group $user --zone $ZONE --provider local --home-directory $HDFSROOT/user/$user
[ $? -ne 0 ] && addError "Could not create user $user with uid $uid in zone $ZONE"
fi
uid=$(( $uid + 1 ))
done

for user in $SUPER_USERS; do
user="$user$CLUSTER_NAME"
for group in $SUPER_GROUPS; do
isi auth groups modify $group$CLUSTERNAME --add-user $user$CLUSTERNAME --zone $ZONE
[ $? -ne 0 ] && addError "Could not add user $user$CLUSTERNAME to $group$CLUSTERNAME group in zone $ZONE"
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
done

# Special cases
case "$DIST" in
"cdh")
isi auth groups modify sqoop$CLUSTERNAME --add-user sqoop2$CLUSTERNAME --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$CLUSTERNAME --add-user hive$CLUSTERNAME --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$CLUSTERNAME --add-user hive$CLUSTERNAME --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$CLUSTERNAME --add-user kafka$CLUSTERNAME --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 01aaa97

Please sign in to comment.