-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathambari_util.sh
executable file
·61 lines (47 loc) · 2.07 KB
/
ambari_util.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
#!/bin/bash
source user-env.sh
function start(){
curl -u $user:$pass -i -H 'X-Requested-By: ambari' -X PUT -d \
'{"RequestInfo": {"context" :"Turn off maintenance mode for '"$1"' "}, "Body": {"ServiceInfo": {"maintenance_state": "OFF"}}}' http://$host/api/v1/clusters/$cluster/services/$1
curl -s -u $user:$pass -H 'X-Requested-By: ambari' -X PUT -d \
'{"RequestInfo": {"context" :"Start '"$1"' via REST"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}' \
http://$host/api/v1/clusters/$cluster/services/$1
}
function startWait(){
curl -u $user:$pass -i -H 'X-Requested-By: ambari' -X PUT -d \
'{"RequestInfo": {"context" :"Turn off maintenance mode for '"$1"' "}, "Body": {"ServiceInfo": {"maintenance_state": "OFF"}}}' http://$host/api/v1/clusters/$cluster/services/$1
curl -s -u $user:$pass -H 'X-Requested-By: ambari' -X PUT -d \
'{"RequestInfo": {"context" :"Start '"$1"' via REST"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}' \
http://$host/api/v1/clusters/$cluster/services/$1
wait $1 "STARTED"
}
function stop(){
curl -u $user:$pass -i -H 'X-Requested-By: ambari' -X PUT -d \
'{"RequestInfo": {"context" :"Turn off maintenance mode for '"$1"' "}, "Body": {"ServiceInfo": {"maintenance_state": "OFF"}}}' http://$host/api/v1/clusters/$cluster/services/$1
sleep 3
curl -s -u $user:$pass -H 'X-Requested-By: ambari' -X PUT -d \
'{"RequestInfo": {"context" :"Stop '"$1"' via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' \
http://$host/api/v1/clusters/$cluster/services/$1
wait $1 "INSTALLED"
}
function wait(){
finished=0
while [ $finished -ne 1 ]
do
str=$(curl -s -u $user:$pass http://{$host}/api/v1/clusters/$cluster/services/$1)
if [[ $str == *"$2"* ]] || [[ $str == *"Service not found"* ]]
then
finished=1
fi
sleep 3
done
}
function check() {
str=$(curl -s -u $user:$pass http://{$host}/api/v1/clusters/$cluster/services/$1)
if [[ $str == *"$2"* ]]
then
echo 1
else
echo 0
fi
}