forked from HariSekhon/DevOps-Python-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathambari_cancel_all_requests.sh
executable file
·43 lines (37 loc) · 1.39 KB
/
ambari_cancel_all_requests.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
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2016-09-27 17:25:36 +0100 (Tue, 27 Sep 2016)
#
# https://github.com/harisekhon/pytools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
AMBARI_HOST="${1:-${AMBARI_HOST:-localhost}}"
AMBARI_PORT="${2:-${AMBARI_PORT:-8080}}"
AMBARI_USER="${3:-${AMBARI_USER:-admin}}"
AMBARI_PASSWORD="${4:-${AMBARI_PASSWORD:-admin}}"
AMBARI_CLUSTER="${5:-${AMBARI_CLUSTER:-Sandbox}}"
usage(){
echo "Very simple script to cancel all Ambari op requests
usage: ${0##*/} <ambari_host> <ambari_port> <username> <password> <cluster_name>"
exit 1
}
if [ $# -gt 0 ]; then
usage
fi
echo "querying Ambari for request IDs"
curl -u "$AMBARI_USER:$AMBARI_PASSWORD" "http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$AMBARI_CLUSTER/requests" |
grep id |
awk '{print $3}' |
while read id; do
echo "requesting cancellation of request $id"
curl -u "$AMBARI_USER:$AMBARI_PASSWORD" -i -H "X-Requested-By: $AMBARI_USER ($USER)" -X PUT -d '{"Requests":{"request_status":"ABORTED","abort_reason":"Aborted by user"}}' "http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/$AMBARI_CLUSTER/requests/$id"
done