Skip to content

Instantly share code, notes, and snippets.

@azurecube
Created December 25, 2015 07:58
Show Gist options
  • Save azurecube/040aa92d8da605e68a28 to your computer and use it in GitHub Desktop.
Save azurecube/040aa92d8da605e68a28 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Setup
CMNODE=`hostname -A | cut -d' ' -f1`
BASE=http://$CMNODE:7180/api/v8
USERNAME="admin"
USERPASS="admin"
CLUSTER=$(curl -X GET -u "$USERNAME:$USERPASS" -i $BASE/clusters | grep '"name"' | awk -F'"' '{print $4}')
nodes=$(curl -X GET -u "$USERNAME:$USERPASS" -i $BASE/hosts | grep hostname | awk -F'"' '{print $4}')
installjq(){
# http://qiita.com/wnoguchi/items/70a808a68e60651224a4
curl -o /usr/local/bin/jq http://stedolan.github.io/jq/download/linux64/jq && sudo chmod +x /usr/local/bin/jq
}
jq > /dev/null 2>&1
if [ $? -eq 127 ]; then installjq; fi
services_json=`curl -u "$USERNAME:$USERPASS" "$BASE/clusters/$CLUSTER/services" | jq '[.items[]|{name, type}]'`
num_services=`echo $services_json | jq 'length'`
cm_wait() {
while [ 1 ]; do
sleep 5
curl -s -u "$USERNAME:$USERPASS" $BASE/cm/service/commands | grep id > /dev/null
if [ $? -ne 0 ]; then break; fi
done
}
cluster_wait () {
while [ 1 ]; do
sleep 5
curl -s -u "$USERNAME:$USERPASS" $BASE/clusters/$CLUSTER/commands | grep id > /dev/null
if [ $? -ne 0 ]; then break; fi
done
}
service_wait() {
while [ 1 ]; do
sleep 5
curl -s -u "$USERNAME:$USERPASS" $BASE/clusters/$CLUSTER/services/$1/commands | grep id > /dev/null
if [ $? -ne 0 ]; then break; fi
done
}
zk(){
curl -s -X PUT -H 'Content-type:application/json' \
-d '{"items":[{"name":"enableSecurity","value":"true"}]}' \
-u "$USERNAME:$USERPASS" \
$BASE/clusters/$CLUSTER/services/$1/config
}
hdfs(){
curl -s -X PUT -H 'Content-type:application/json' \
-d '{"items":[{"name":"hadoop_security_authentication","value":"kerberos"},
{"name":"hadoop_security_authorization","value":"true"}]}' \
-u "$USERNAME:$USERPASS" \
$BASE/clusters/$CLUSTER/services/$1/config
curl -s -X PUT -H 'Content-type:application/json' \
-d '{"items":[{"name":"dfs_datanode_http_port","value":"1006"},
{"name":"dfs_datanode_port","value":"1004"},
{"name":"dfs_datanode_data_dir_perm","value":"700"}]}' \
-u "$USERNAME:$USERPASS" \
$BASE/clusters/$CLUSTER/services/$1/roleConfigGroups/$1-DATANODE-BASE/config
}
mr(){
[ -n "mr1" ]; curl -s -X PUT -H 'Content-type:application/json' \
-d '{"items":[{"name":"taskcontroller_min_user_id","value":"0"}]}' \
-u "$USERNAME:$USERPASS" \
$BASE/clusters/$CLUSTER/services/$1/roleConfigGroups/$1-TASKTRACKER-BASE/config
[ -n "yarn" ]; curl -s -X PUT -H 'Content-type:application/json' \
-d '{"items":[{"name":"container_executor_min_user_id","value":"0"}]}' \
-u "$USERNAME:$USERPASS" \
$BASE/clusters/$CLUSTER/services/$1/roleConfigGroups/$1-NODEMANAGER-BASE/config
}
hbase(){
[ -n "hbase" ]; curl -s -X PUT -H 'Content-type:application/json' \
-d '{"items":[{"name":"hbase_security_authentication","value":"kerberos"},
{"name":"hbase_security_authorization","value":"true"}]}' \
-u "$USERNAME:$USERPASS" \
$BASE/clusters/$CLUSTER/services/$1/config
}
# Kerberos
krb(){
curl -X PUT -u "$USERNAME:$USERPASS" -H "content-type:application/json" \
-d '{ "items": [{"name": "KDC_HOST", "value": "'$CMNODE'"},
{"name": "KDC_TYPE", "value": "MIT KDC"},
{"name": "KRB_MANAGE_KRB5_CONF", "value": "true"},
{"name": "SECURITY_REALM", "value": "HADOOP"}]}' \
$BASE/cm/config
cm_wait
}
# Admin User
other(){
curl -X POST -u "$USERNAME:$USERPASS" -i \
-G --data-urlencode 'username=cloudera-scm/admin@HADOOP' \
--data-urlencode 'password=cloudera' \
$BASE/cm/commands/importAdminCredentials
cm_wait
}
krb
other
index=0
while [ $index -lt $num_services ]; do
dictionary=`echo $services_json | jq ".[$index]"`
name=`echo $dictionary | jq -r '.name'`
type=`echo $dictionary | jq -r '.type'`
case $type in
HBASE)
hbase $name
;;
HDFS)
hdfs $name
;;
YARN)
mr $name
;;
ZOOKEEPER)
zk $name
;;
esac
service_wait $name
let index=index+1
done
# Deploy Client Config
curl -X POST -u "$USERNAME:$USERPASS" -i $BASE/clusters/$CLUSTER/commands/deployClientConfig
cluster_wait
# Restart Cluster
curl -X POST -u "$USERNAME:$USERPASS" -i \
-H "Content-Type:application/json" \
-d '{"redeployClientConfiguration": true, "restartOnlyStaleServices": null}' \
$BASE/clusters/$CLUSTER/commands/restart
cluster_wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment