Skip to content

Instantly share code, notes, and snippets.

@azurecube
Last active October 27, 2015 04:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azurecube/ee88c330d6d4883de95d to your computer and use it in GitHub Desktop.
Save azurecube/ee88c330d6d4883de95d to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script checked on CM5.2.1 and CDH5.2.1
# Properties
CMNODE="node1.cloudera.com"
TARGET="node1.cloudera.com node2.cloudera.com node3.cloudera.com"
CLUSTER="Cluster1"
ROOT_PASS="cloudera"
BASE=http://$CMNODE:7180/api/v8
CDH_VER=5
# Start Trial
curl -X POST -u "admin:admin" -i $BASE/cm/trial/begin
# Setup Hosts
## Arrange host_list
host_list=""
for i in $TARGET
do
host_list=$host_list'"'$i'"',
done
host_list=${host_list/%?/}
## Install agent and Assign hosts to deployment
curl -X POST -u "admin:admin" -i \
-H "content-type:application/json" \
-d '{ "hostNames": ['$host_list'],
"userName" : "root",
"password" : "'$ROOT_PASS'"}' \
$BASE/cm/commands/hostInstall
## wait for finish installation
echo "Waiting for setup nodes"
while [ 1 ]
do
target_size=$(expr 1 + `echo $TARGET | grep -o " " | wc -l`)
installed_hosts=`curl -sS -X GET -u "admin:admin" -i $BASE/hosts | grep '"hostname" :' | wc -l`
test $target_size -eq $installed_hosts && break
echo -e "setuped:" $installed_hosts"/"$target_size"\c"
echo -e "\r\c"
sleep 10
done
# Setting MGMT
## Create mgmt service
curl -X PUT -u "admin:admin" -i \
-H "content-type:application/json" \
-d '{ "name": "mgmt" }' \
$BASE/cm/service
## Assign and Configure Roles
curl -X PUT -u "admin:admin" -i $BASE/cm/service/autoAssignRoles
curl -X PUT -u "admin:admin" -i $BASE/cm/service/autoConfigure
## Setting Report Manager DB
### Report Manager password
rman_pass=`sudo grep com.cloudera.cmf.REPORTSMANAGER.db.password /etc/cloudera-scm-server/db.mgmt.properties | cut -d= -f2`
### Configuration
curl -X PUT -u "admin:admin" -i \
-H "content-type:application/json" \
-d '{ "items": [{"name": "headlamp_database_host", "value": "'$CMNODE':7432"},
{"name": "headlamp_database_name", "value": "rman"},
{"name": "headlamp_database_password", "value": "'$rman_pass'"},
{"name": "headlamp_database_user", "value": "rman"},
{"name": "headlamp_database_type", "value": "postgresql"}
]}' \
$BASE/cm/service/roleConfigGroups/mgmt-REPORTSMANAGER-BASE/config
## Delete Navigator Entry
curl -X DELETE -u "admin:admin" -i \
$BASE/cm/service/roles/`curl -sS -X GET -u "admin:admin" -i $BASE/cm/service/roles | grep -B1 '"type" : "NAVIGATORMETASERVER"' | grep name | cut -d'"' -f4`
curl -X DELETE -u "admin:admin" -i \
$BASE/cm/service/roles/`curl -sS -X GET -u "admin:admin" -i $BASE/cm/service/roles | grep -B1 '"type" : "NAVIGATOR"' | grep name | cut -d'"' -f4`
# Startup
curl -X POST -u "admin:admin" -i $BASE/cm/service/commands/start
# Setting Cluster
## Create Cluster
curl -X POST -u "admin:admin" -i \
-H "content-type:application/json" \
-d '{ "items": [
{
"name": "'$CLUSTER'",
"version": "CDH'$CDH_VER'"
}
] }' \
$BASE/clusters
## Assign Hosts
host_ids=`curl -sS -X GET -u "admin:admin" -i $BASE/hosts | grep '"hostId" :' | cut -d'"' -f 4`
for i in $host_ids
do
curl -X POST -u "admin:admin" -i \
-H "content-type:application/json" \
-d '{ "items": [ {"hostId": "'$i'"} ]}' \
$BASE/clusters/$CLUSTER/hosts
done
## Assign Service
curl -X POST -u "admin:admin" -i \
-H "content-type:application/json" \
-d '{ "items": [ {"name": "zookeeper", "type": "ZOOKEEPER"},
{"name": "hive" , "type": "HIVE"},
{"name": "sqoop" , "type": "SQOOP"},
{"name": "yarn" , "type": "YARN"},
{"name": "hdfs" , "type": "HDFS"}
] }' \
$BASE/clusters/$CLUSTER/services
## Assign and Configure Roles
curl -X PUT -u "admin:admin" -i $BASE/clusters/$CLUSTER/autoAssignRoles
curl -X PUT -u "admin:admin" -i $BASE/clusters/$CLUSTER/autoConfigure
## Parcel Operation
### Getting CDH Parcel name
CDH=`curl -sS -X GET -u "admin:admin" -i $BASE/clusters/$CLUSTER/parcels | grep -A1 '"product" : "CDH"' | grep '"version" : "'$CDH_VER | cut -d'"' -f4`
### short function to wait previous operation
parcel_wait_for () {
while [ 1 ]
do
curl -sS -X GET -u "admin:admin" -i $BASE/clusters/$CLUSTER/parcels/products/CDH/versions/$CDH | grep '"stage" : "'$1'"' && break
sleep 5
done
}
### Download Parcel
curl -X POST -u "admin:admin" -i $BASE/clusters/$CLUSTER/parcels/products/CDH/versions/$CDH/commands/startDownload
parcel_wait_for DOWNLOADED
### Distribute Parcel
curl -X POST -u "admin:admin" -i $BASE/clusters/$CLUSTER/parcels/products/CDH/versions/$CDH/commands/startDistribution
parcel_wait_for DISTRIBUTED
### Activate Parcel
curl -X POST -u "admin:admin" -i $BASE/clusters/$CLUSTER/parcels/products/CDH/versions/$CDH/commands/activate
parcel_wait_for ACTIVATED
## Configuring Hive metastore DB
curl -X PUT -u "admin:admin" -i \
-H "content-type:application/json" \
-d '{ "items": [{"name": "hive_metastore_database_host", "value": "'$CMNODE'"},
{"name": "hive_metastore_database_name", "value": "hive"},
{"name": "hive_metastore_database_password", "value": "hive"},
{"name": "hive_metastore_database_port", "value": "7432"},
{"name": "hive_metastore_database_type", "value": "postgresql"}
]}' \
$BASE/clusters/$CLUSTER/services/hive/config
## FirstRun
curl -X POST -u "admin:admin" -i $BASE/clusters/$CLUSTER/commands/firstRun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment