forked from rmaruthiyodan/docker-hdp-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_json.sh
executable file
·183 lines (150 loc) · 4.4 KB
/
generate_json.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
########
# Author: Kuldeep Kulkarni
# Description: This script does the Magic of automating HDP install using Ambari Blueprints
#set -x
#Globals
LOC=`pwd`
PROPS=$1
#Source props
source $LOC/$PROPS 2>/dev/null
STACK_VERSION=`echo $CLUSTER_VERSION|cut -c1-3`
AMBARI_HOST=$2
NUMBER_OF_HOSTS=`grep HOST $LOC/$PROPS|grep -v SERVICES|wc -l`
LAST_HOST=`grep HOST $LOC/$PROPS|grep -v SERVICES|head -n $NUMBER_OF_HOSTS|tail -1|cut -d'=' -f2`
grep HOST $LOC/$PROPS|grep -v SERVICES|grep -v $LAST_HOST|cut -d'=' -f2 > $LOC/list
#Generate hostmap function#
hostmap()
{
#Start of function
echo "{
\"blueprint\" : \"$CLUSTERNAME\",
\"default_password\" : \"$DEFAULT_PASSWORD\",
\"host_groups\" :["
for HOST in `cat list`
do
echo "{
\"name\" : \"$HOST\",
\"hosts\" : [
{
\"fqdn\" : \"$HOST.$DOMAIN_NAME\"
}
]
},"
done
echo "{
\"name\" : \"$LAST_HOST\",
\"hosts\" : [
{
\"fqdn\" : \"$LAST_HOST.$DOMAIN_NAME\"
}
]
}
]
}"
#End of function
}
clustermap()
{
#Start of function
LAST_HST_NAME=`grep 'HOST[0-9]*' $LOC/$PROPS|grep -v SERVICES|tail -1|cut -d'=' -f1`
echo "{
\"configurations\" : [ ],
\"host_groups\" : ["
for HOST in `grep -w 'HOST[0-9]*' $LOC/$PROPS|tr '\n' ' '`
do
HST_NAME_VAR=`echo $HOST|cut -d'=' -f1`
echo "{
\"name\" : \"`grep $HST_NAME_VAR $PROPS |head -1|cut -d'=' -f2|cut -d'.' -f1`\",
\"components\" : ["
LAST_SVC=`grep $HST_NAME_VAR"_SERVICES" $LOC/$PROPS|cut -d'=' -f2|tr ',' ' '|rev|cut -d' ' -f1|rev|cut -d'"' -f1`
for SVC in `grep $HST_NAME_VAR"_SERVICES" $LOC/$PROPS|cut -d'=' -f2|tr ',' ' '|cut -d'"' -f2|cut -d'"' -f1`
do
echo "{
\"name\" : \"$SVC\""
if [ "$SVC" == "$LAST_SVC" ]
then
echo "}
],
\"cardinality\" : "1""
if [ "$HST_NAME_VAR" == "$LAST_HST_NAME" ]
then
echo "}"
else
echo "},"
fi
else
echo "},"
fi
done
done
echo " ],
\"Blueprints\" : {
\"blueprint_name\" : \"$CLUSTERNAME\",
\"stack_name\" : \"HDP\",
\"stack_version\" : \"$STACK_VERSION\"
}
}"
#End of function
}
repobuilder()
{
#Start of function
BASE_URL=`grep $CLUSTER_VERSION $LOC/$PROPS|grep BASE|cut -d'=' -f2|sed -e 's/^"//' -e 's/"$//'|sort -n|tail -1`
if [ -z "$BASE_URL" ]
then
BASE_URL=`grep $CLUSTER_VERSION /opt/docker_cluster/local_repo |grep BASE|cut -d'=' -f2|sed -e 's/^"//' -e 's/"$//'|sort -n|tail -1`
fi
echo "{
\"Repositories\" : {
\"base_url\" : \"$BASE_URL\",
\"verify_base_url\" : true
}
}" > $LOC/repo.json
BASE_URL_UTILS=`grep UTILS $LOC/$PROPS|cut -d'=' -f2|sed -e 's/^"//' -e 's/"$//'|sort -n|tail -1`
if [ -z "$BASE_URL_UTILS" ]
then
BASE_URL_URILS=`grep UTILS /opt/docker_cluster/local_repo |cut -d'=' -f2|sed -e 's/^"//' -e 's/"$//'|sort -n|tail -1`
fi
export BASE_URL_UTILS;
echo "{
\"Repositories\" : {
\"base_url\" : \"$BASE_URL_UTILS\",
\"verify_base_url\" : true
}
}" > $LOC/repo-utils.json
#End of function
}
timestamp()
{
#Function to print timestamp
echo "`date +%Y-%m-%d-%H:%M:%S`"
}
installhdp()
{
#Install hdp using Ambari Blueprints
HDP_UTILS_VERSION=`echo $BASE_URL_UTILS|cut -d'/' -f5`
curl -H "X-Requested-By: ambari" -X POST -u admin:admin http://$AMBARI_HOST:8080/api/v1/blueprints/$CLUSTERNAME -d @"$LOC"/cluster_config.json
sleep 1
curl -H "X-Requested-By: ambari" -X PUT -u admin:admin http://$AMBARI_HOST:8080/api/v1/stacks/HDP/versions/$STACK_VERSION/operating_systems/redhat6/repositories/HDP-$STACK_VERSION -d @$LOC/repo.json
sleep 1
curl -H "X-Requested-By: ambari" -X PUT -u admin:admin http://$AMBARI_HOST:8080/api/v1/stacks/HDP/versions/$STACK_VERSION/operating_systems/redhat6/repositories/$HDP_UTILS_VERSION -d @$LOC/repo-utils.json
sleep 1
curl -H "X-Requested-By: ambari" -X POST -u admin:admin http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTERNAME -d @$LOC/hostmap.json
}
#################
# Main function #
################
#Generate hostmap
echo -e "`timestamp` Generating hostmap json.."
hostmap > $LOC/hostmap.json
echo "`timestamp` Saved $LOC/hostmap.json"
#Generate cluster config json
echo -e "`timestamp` Generating cluster configuration json"
clustermap > $LOC/cluster_config.json
echo "`timestamp` Saved $LOC/cluster_config.json"
#Create internal repo json
repobuilder
echo -e "`timestamp` Generating internal repositories json..\n`timestamp` Saved $LOC/repo.json & $LOC/repo-utils.json"
#Start hdp installation
installhdp