-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathstartDemoServices.sh
executable file
·393 lines (332 loc) · 15.5 KB
/
startDemoServices.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/bin/bash
export AMBARI_HOST=$(hostname -f)
echo "*********************************AMABRI HOST IS: $AMBARI_HOST"
serviceExists () {
SERVICE=$1
SERVICE_STATUS=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE | grep '"status" : ' | grep -Po '([0-9]+)')
if [ "$SERVICE_STATUS" == 404 ]; then
echo 0
else
echo 1
fi
}
getServiceStatus () {
SERVICE=$1
SERVICE_STATUS=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE | grep '"state" :' | grep -Po '([A-Z]+)')
echo $SERVICE_STATUS
}
waitForAmbari () {
# Wait for Ambari
LOOPESCAPE="false"
until [ "$LOOPESCAPE" == true ]; do
TASKSTATUS=$(curl -u admin:admin -I -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME | grep -Po 'OK')
if [ "$TASKSTATUS" == OK ]; then
LOOPESCAPE="true"
TASKSTATUS="READY"
else
AUTHSTATUS=$(curl -u admin:admin -I -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME | grep HTTP | grep -Po '( [0-9]+)'| grep -Po '([0-9]+)')
if [ "$AUTHSTATUS" == 403 ]; then
echo "THE AMBARI PASSWORD IS NOT SET TO: admin"
echo "RUN COMMAND: ambari-admin-password-reset, SET PASSWORD: admin"
exit 403
else
TASKSTATUS="PENDING"
fi
fi
echo "Waiting for Ambari..."
echo "Ambari Status... " $TASKSTATUS
sleep 2
done
}
getServiceStatus () {
SERVICE=$1
SERVICE_STATUS=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE | grep '"state" :' | grep -Po '([A-Z]+)')
echo $SERVICE_STATUS
}
waitForService () {
# Ensure that Service is not in a transitional state
SERVICE=$1
SERVICE_STATUS=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE | grep '"state" :' | grep -Po '([A-Z]+)')
sleep 2
echo "$SERVICE STATUS: $SERVICE_STATUS"
LOOPESCAPE="false"
if ! [[ "$SERVICE_STATUS" == STARTED || "$SERVICE_STATUS" == INSTALLED ]]; then
until [ "$LOOPESCAPE" == true ]; do
SERVICE_STATUS=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE | grep '"state" :' | grep -Po '([A-Z]+)')
if [[ "$SERVICE_STATUS" == STARTED || "$SERVICE_STATUS" == INSTALLED ]]; then
LOOPESCAPE="true"
fi
echo "*********************************$SERVICE Status: $SERVICE_STATUS"
sleep 2
done
fi
}
startService (){
SERVICE=$1
SERVICE_STATUS=$(getServiceStatus $SERVICE)
echo "*********************************Starting Service $SERVICE ..."
if [ "$SERVICE_STATUS" == INSTALLED ]; then
TASKID=$(curl -u admin:admin -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo": {"context": "Start $SERVICE" }, "ServiceInfo": {"maintenance_state" : "OFF", "state": "STARTED"}}' http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE | grep "id" | grep -Po '([0-9]+)')
echo "*********************************Start $SERVICE TaskID $TASKID"
sleep 2
LOOPESCAPE="false"
until [ "$LOOPESCAPE" == true ]; do
TASKSTATUS=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/requests/$TASKID | grep "request_status" | grep -Po '([A-Z]+)')
if [ "$TASKSTATUS" == COMPLETED ]; then
LOOPESCAPE="true"
fi
echo "*********************************Start $SERVICE Task Status $TASKSTATUS"
sleep 2
done
echo "*********************************$SERVICE Service Started..."
elif [ "$SERVICE_STATUS" == STARTED ]; then
echo "*********************************$SERVICE Service Started..."
fi
}
startNifiFlowReporter() {
sleep 1
echo "*********************************Instantiating Nifi Reporting Task..."
PAYLOAD=$(echo "{\"revision\":{\"version\":0},\"component\":{\"name\":\"AtlasFlowReportingTask\",\"type\":\"org.apache.nifi.atlas.reporting.AtlasFlowReportingTask\",\"properties\":{\"Atlas URL\":\"http://$ATLAS_HOST:21000\",\"Nifi URL\":\"http://$AMBARI_HOST:9090\"}}}")
REPORTING_TASK_ID=$(curl -d "$PAYLOAD" -H "Content-Type: application/json" -X POST http://$AMBARI_HOST:9090/nifi-api/controller/reporting-tasks|grep -Po '("component":{"id":")([0-9a-zA-z\-]+)'| grep -Po '(:"[0-9a-zA-z\-]+)'| grep -Po '([0-9a-zA-z\-]+)')
sleep 1
echo "*********************************Starting Nifi Reporting Task..."
PAYLOAD=$(echo "{\"id\":\"$REPORTING_TASK_ID\",\"revision\":{\"version\":1},\"component\":{\"id\":\"$REPORTING_TASK_ID\",\"state\":\"RUNNING\"}}")
curl -d "$PAYLOAD" -H "Content-Type: application/json" -X PUT http://$AMBARI_HOST:9090/nifi-api/reporting-tasks/$REPORTING_TASK_ID
sleep 1
}
getNameNodeHost () {
NAMENODE_HOST=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/HDFS/components/NAMENODE|grep "host_name"|grep -Po ': "([a-zA-Z0-9\-_!?.]+)'|grep -Po '([a-zA-Z0-9\-_!?.]+)')
echo $NAMENODE_HOST
}
getHiveServerHost () {
HIVESERVER_HOST=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/HIVE/components/HIVE_SERVER|grep "host_name"|grep -Po ': "([a-zA-Z0-9\-_!?.]+)'|grep -Po '([a-zA-Z0-9\-_!?.]+)')
echo $HIVESERVER_HOST
}
getHiveMetaStoreHost () {
HIVE_METASTORE_HOST=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/HIVE/components/HIVE_METASTORE|grep "host_name"|grep -Po ': "([a-zA-Z0-9\-_!?.]+)'|grep -Po '([a-zA-Z0-9\-_!?.]+)')
echo $HIVE_METASTORE_HOST
}
getKafkaBroker () {
KAFKA_BROKER=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/KAFKA/components/KAFKA_BROKER |grep "host_name"|grep -Po ': "([a-zA-Z0-9\-_!?.]+)'|grep -Po '([a-zA-Z0-9\-_!?.]+)')
echo $KAFKA_BROKER
}
getAtlasHost () {
ATLAS_HOST=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/ATLAS/components/ATLAS_SERVER |grep "host_name"|grep -Po ': "([a-zA-Z0-9\-_!?.]+)'|grep -Po '([a-zA-Z0-9\-_!?.]+)')
echo $ATLAS_HOST
}
getNifiHost () {
NIFI_HOST=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/NIFI/comonents/NIFI_MASTER|grep "host_name"|grep -Po ': "([a-zA-Z0-9\-_!?.]+)'|grep -Po '([a-zA-Z0-9\-_!?.]+)')
echo $NIFI_HOST
}
ambari-server start
waitForAmbari
export CLUSTER_NAME=$(curl -u admin:admin -X GET http://$AMBARI_HOST:8080/api/v1/clusters |grep cluster_name|grep -Po ': "(.+)'|grep -Po '[a-zA-Z0-9!$\-]+')
if [[ -z $CLUSTER_NAME ]]; then
echo "Could not connect to Ambari Server. Please run the install script on the same host where Ambari Server is installed."
exit 1
else
echo "*********************************CLUSTER NAME IS: $CLUSTER_NAME"
fi
export JAVA_HOME=/usr/jdk64
NAMENODE_HOST=$(getNameNodeHost)
export NAMENODE_HOST=$NAMENODE_HOST
HIVESERVER_HOST=$(getHiveServerHost)
export HIVESERVER_HOST=$HIVESERVER_HOST
HIVE_METASTORE_HOST=$(getHiveMetaStoreHost)
export HIVE_METASTORE_HOST=$HIVE_METASTORE_HOST
HIVE_METASTORE_URI=thrift://$HIVE_METASTORE_HOST:9083
export HIVE_METASTORE_URI=$HIVE_METASTORE_URI
ZK_HOST=$AMBARI_HOST
export ZK_HOST=$ZK_HOST
KAFKA_BROKER=$(getKafkaBroker)
export KAFKA_BROKER=$KAFKA_BROKER
ATLAS_HOST=$(getAtlasHost)
export ATLAS_HOST=$ATLAS_HOST
COMETD_HOST=$AMBARI_HOST
export COMETD_HOST=$COMETD_HOST
NIFI_HOST=$(getNifiHost)
export NIFI_HOST=$NIFI_HOST
env
mkdir /var/run/nifi
chmod 777 /var/run/nifi
chown nifi:nifi /var/run/nifi
#Start HDFS
#HDFS_STATUS=$(getServiceStatus HDFS)
#echo "*********************************Checking HDFS status..."
#if ! [[ $HDFS_STATUS == STARTED || $HDFS_STATUS == INSTALLED ]]; then
# echo "*********************************HDFS is in a transitional state, #waiting..."
# waitForService HDFS
# echo "*********************************HDFS has entered a ready state..."
#fi
#if [[ $HDFS_STATUS == INSTALLED ]]; then
# startService HDFS
#else
# echo "*********************************HDFS Service Started..."
#fi
sleep 1
#Start YARN
YARN_STATUS=$(getServiceStatus YARN)
echo "*********************************Checking YARN status..."
if ! [[ $YARN_STATUS == STARTED || $YARN_STATUS == INSTALLED ]]; then
echo "*********************************YARN is in a transitional state, waiting..."
waitForService YARN
echo "*********************************YARN has entered a ready state..."
fi
if [[ $YARN_STATUS == INSTALLED ]]; then
startService YARN
else
echo "*********************************YARN Service Started..."
fi
sleep 1
#Start ZooKeeper
ZOOKEEPER_STATUS=$(getServiceStatus ZOOKEEPER)
echo "*********************************Checking KAFKA status..."
if ! [[ $ZOOKEEPER_STATUS == STARTED || $ZOOKEEPER_STATUS == INSTALLED ]]; then
echo "*********************************ZOOKEEPER is in a transitional state, waiting..."
waitForService ZOOKEEPER
echo "*********************************ZOOKEEPER has entered a ready state..."
fi
if [[ $ZOOKEEPER_STATUS == INSTALLED ]]; then
startService ZOOKEEPER
else
echo "*********************************ZOOKEEPER Service Started..."
fi
sleep 1
#Start MAPREDUCE2
MAPREDUCE2_STATUS=$(getServiceStatus MAPREDUCE2)
echo "*********************************Checking HIVE status..."
if ! [[ $MAPREDUCE2_STATUS == STARTED || $MAPREDUCE2_STATUS == INSTALLED ]]; then
echo "*********************************MAPREDUCE2 is in a transitional state, waiting..."
waitForService MAPREDUCE2
echo "*********************************MAPREDUCE2 has entered a ready state..."
fi
if [[ $MAPREDUCE2_STATUS == INSTALLED ]]; then
startService MAPREDUCE2
else
echo "*********************************MAPREDUCE2 Service Started..."
fi
sleep 1
#Start Hive
HIVE_STATUS=$(getServiceStatus HIVE)
echo "*********************************Checking HIVE status..."
if ! [[ $HIVE_STATUS == STARTED || $HIVE_STATUS == INSTALLED ]]; then
echo "*********************************HIVE is in a transitional state, waiting..."
waitForService HIVE
echo "*********************************HIVE has entered a ready state..."
fi
if [[ $HIVE_STATUS == INSTALLED ]]; then
startService HIVE
else
echo "*********************************HIVE Service Started..."
fi
sleep 1
#Start Kafka
KAFKA_STATUS=$(getServiceStatus KAFKA)
echo "*********************************Checking KAFKA status..."
if ! [[ $KAFKA_STATUS == STARTED || $KAFKA_STATUS == INSTALLED ]]; then
echo "*********************************KAFKA is in a transitional state, waiting..."
waitForService KAFKA
echo "*********************************KAFKA has entered a ready state..."
fi
if [[ $KAFKA_STATUS == INSTALLED ]]; then
startService KAFKA
else
echo "*********************************KAFKA Service Started..."
fi
sleep 1
#Start Nifi
NIFI_STATUS=$(getServiceStatus NIFI)
echo "*********************************Checking NIFI status..."
if ! [[ $NIFI_STATUS == STARTED || $NIFI_STATUS == INSTALLED ]]; then
echo "*********************************NIFI is in a transitional state, waiting..."
waitForService NIFI
echo "*********************************NIFI has entered a ready state..."
fi
if [[ $NIFI_STATUS == INSTALLED ]]; then
startService NIFI
else
echo "*********************************NIFI Service Started..."
fi
sleep 1
#Start HBase
HBASE_STATUS=$(getServiceStatus HBASE)
echo "*********************************Checking HBASE status..."
if ! [[ $HBASE_STATUS == STARTED || $HBASE_STATUS == INSTALLED ]]; then
echo "*********************************HBASE is in a transitional state, waiting..."
waitForService HBASE
echo "*********************************HBASE has entered a ready state..."
fi
if [[ $HBASE_STATUS == INSTALLED ]]; then
startService HBASE
else
echo "*********************************HBASE Service Started..."
fi
sleep 1
AMBARI_INFRA_PRESENT=$(serviceExists AMBARI_INFRA)
if [[ "$AMBARI_INFRA_PRESENT" == 1 ]]; then
# Start AMBARI_INFRA
AMBARI_INFRA_STATUS=$(getServiceStatus AMBARI_INFRA)
echo "*********************************Checking AMBARI_INFRA status..."
if ! [[ $AMBARI_INFRA_STATUS == STARTED || $AMBARI_INFRA_STATUS == INSTALLED ]]; then
echo "*********************************AMBARI_INFRA is in a transitional state, waiting..."
waitForService AMBARI_INFRA
echo "*********************************AMBARI_INFRA has entered a ready state..."
fi
if [[ $AMBARI_INFRA_STATUS == INSTALLED ]]; then
startService AMBARI_INFRA
else
echo "*********************************AMBARI_INFRA Service Started..."
fi
else
echo "*********************************AMBARI_INFRA is not present, skipping..."
fi
sleep 1
# Start Atlas
ATLAS_STATUS=$(getServiceStatus ATLAS)
echo "*********************************Checking ATLAS status..."
if ! [[ $ATLAS_STATUS == STARTED || $ATLAS_STATUS == INSTALLED ]]; then
echo "*********************************ATLAS is in a transitional state, waiting..."
waitForService ATLAS
echo "*********************************ATLAS has entered a ready state..."
fi
if [[ $ATLAS_STATUS == INSTALLED ]]; then
startService ATLAS
else
echo "*********************************ATLAS Service Started..."
fi
sleep 1
# Start Storm
STORM_STATUS=$(getServiceStatus STORM)
echo "*********************************Checking STORM status..."
if ! [[ $STORM_STATUS == STARTED || $STORM_STATUS == INSTALLED ]]; then
echo "*********************************STORM is in a transitional state, waiting..."
waitForService STORM
echo "*********************************STORM has entered a ready state..."
fi
if [[ $STORM_STATUS == INSTALLED ]]; then
startService STORM
else
echo "*********************************STORM Service Started..."
fi
# Deploy Storm Topology
echo "*********************************Deploying Storm Topology..."
storm jar /home/storm/CreditCardTransactionMonitor-0.0.1-SNAPSHOT.jar com.hortonworks.iot.financial.topology.CreditCardTransactionMonitorTopology $CLUSTER_NAME
# Start Nifi Flow Reporter to send flow meta data to Atlas
sleep 5
startNifiFlowReporter
echo "*********************************Deploying Application Container ..."
# Ensure docker service is running
service docker start
# Clear Slider working directory
#export HADOOP_USER_NAME=hdfs
#echo "*********************************HADOOP_USER_NAME set to HDFS"
#hadoop fs -rm -R /user/root/.slider/cluster
# Start UI servlet on Yarn using Slider
#slider create transactionmonitorui --template /home/docker/dockerbuild/transactionmonitorui/appConfig.json --metainfo /home/docker/dockerbuild/transactionmonitorui/metainfo.json --resources /home/docker/dockerbuild/transactionmonitorui/resources.json
#Start UI servlet in Docker
docker run -d --net=host vvaks/cometd
docker run -d -e MAP_API_KEY=$MAP_API_KEY -e ZK_HOST=$ZK_HOST -e COMETD_HOST=$COMETD_HOST -e HTTP_HOST=$NIFI_HOST --net=host vvaks/transactionmonitorui
#echo "*********************************Wait 10 seconds for Application to Initialize..."
#sleep 10
echo "*********************************Access the UI at http://$AMBARI_HOST:8090/TransactionMonitorUI/CustomerOverview"
exit 0