forked from broadinstitute/gatk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataproc-cluster-ui
executable file
·112 lines (90 loc) · 2.14 KB
/
dataproc-cluster-ui
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
#!/usr/bin/env bash
port=1080
DARWIN_CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
LINUX_CHROME="/usr/bin/google-chrome"
SSH_OUTPUT_TO_GREP="Entering interactive session"
##############################################################
# Script to easily open a gcs dataproc cluster's spark UI #
##############################################################
#################################
# Stuff to make and cleanup tmp files
TMPFILELIST=''
GCLOUD_PID=''
function makeTemp()
{
local f
f=$( mktemp )
TMPFILELIST="${TMPFILELIST} $f"
echo $f
}
function cleanTempVars()
{
rm -f ${TMPFILELIST}
}
function error()
{
echo "$1" 2>&1
}
function at_exit()
{
cleanTempVars
}
trap at_exit EXIT
####################################
cluster=$1
if [[ -z "${cluster}" ]]; then
echo ""
echo "Usage: $0 <gcs-cluster-name>"
echo "Open the spark ui for a dataproc cluster in a new chrome window"
echo ""
exit 1
fi
echo "Connecting to ${cluster} on port ${port}"
echo ""
tmp=makeTemp
gcloud compute ssh ${cluster}-m -- \
-D ${port} -N -n -v &>${tmp} &
GCLOUD_PID=$!
x=0
echo "Waiting for ssh connection to be established."
while ! grep -q "${SSH_OUTPUT_TO_GREP}" ${tmp}; do
if ! ps -p ${GCLOUD_PID} >&-; then
error ""
error "ssh exited unexpectedly"
error ""
exit 1
fi
x=$(( x + 1 ))
if [ $x -gt 300 ]; then
error ""
error "Exiting because ssh took too long to connect."
error ""
fi
if [ $(( $x % 10 )) -eq 0 ]; then
echo -n "."
fi
sleep .1
done
echo ""
echo "Opening new chrome instance, it doesn't always open on top so you may have to look for it."
if [[ $( uname -s ) == "Darwin" ]]; then
chrome=${DARWIN_CHROME}
else
chrome=${LINUX_CHROME}
fi
"${chrome}" \
--proxy-server="socks5://localhost:${port}" \
--host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE localhost" \
--user-data-dir=/tmp/${cluster}-m \
--disable-logging \
--new-window http://${cluster}-m:8088 &>/dev/null &
function lurkAndMurder(){
local gcloudPID=$1
local chromePID=$2
while ps -p ${chromePID} >&-; do
sleep .1
done
kill ${gcloudPID} &>/dev/null
exit 0
}
lurkAndMurder $GCLOUD_PID $! &