-
Notifications
You must be signed in to change notification settings - Fork 33
/
playground.sh
executable file
·225 lines (204 loc) · 5 KB
/
playground.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
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
set -x
playground_dir="$(dirname "${BASH_SOURCE-$0}")"
playground_dir="$(
cd "${playground_dir}" >/dev/null
pwd
)"
testDocker() {
echo "INFO: Testing Docker environment by running hello-world..."
docker run --pull always hello-world >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "INFO: Docker is working correctly!"
else
echo "ERROR: There was an issue running the hello-world container. Please check your Docker installation."
exit 1
fi
}
testK8s() {
echo "Testing K8s environment ..."
kubectl cluster-info
if [ $? -eq 0 ]; then
echo "INFO: K8s is working correctly!"
else
echo "ERROR: There was an issue running kubectl cluster-info, please check you K8s cluster."
exit 1
fi
}
checkCompose() {
isExist=$(which docker-compose)
if [ $isExist ]; then
true # Placeholder, do nothing
else
echo "ERROR: No docker service environment found. Please install docker-compose."
exit
fi
}
checkHelm() {
isExist=$(which helm)
if [ $isExist ]; then
true # Placeholder, do nothing
else
echo "ERROR: Helm command not found, Please install helm v3."
exit
fi
# check version
# version will be like:
# Version:"v3.15.2"
regex="Version:\"(v[0-9]\.[0-9]+\.[0-9])\""
version=$(helm version)
echo "$version"
if [[ $version =~ $regex ]]; then
major_version="${BASH_REMATCH[1]}"
echo "$major_version"
if [[ $major_version =~ "v3" ]]; then
echo "INFO: helm check PASS."
return
else
echo "ERROR: Please install helm v3"
exit
fi
fi
}
checkPortInUse() {
local port=$1
if [[ "$(uname)" == "Darwin" ]]; then
openPort=$(lsof -i :$port -sTCP:LISTEN)
elif [[ "$(uname)" == "Linux" ]]; then
openPort=$(sudo lsof -i :$port -sTCP:LISTEN)
fi
if [ -z "${openPort}" ]; then
echo "INFO: Port $port is ok."
else
echo "ERROR: Port $port is in use. Please check it."
exit 1
fi
}
start() {
echo "INFO: Starting the playground..."
case "$runtime" in
k8s)
testK8s
checkHelm
;;
docker)
testDocker
checkCompose
ports=(8090 9001 3307 19000 19083 60070 13306 15342 18080 18888 19090 13000)
for port in "${ports[@]}"; do
checkPortInUse ${port}
done
;;
esac
cd ${playground_dir}
echo "Preparing packages..."
./init/spark/spark-dependency.sh
./init/gravitino/gravitino-dependency.sh
./init/jupyter/jupyter-dependency.sh
case "$runtime" in
k8s)
helm upgrade --install gravitino-playground ./helm-chart/ \
--create-namespace --namespace gravitino-playground \
--set projectRoot=$(pwd)
;;
docker)
logSuffix=$(date +%Y%m%d%H%m%s)
if [ "$enableRanger" == true ]; then
docker-compose -f docker-compose.yaml -f docker-enable-ranger-hive-override.yaml up --detach
else
docker-compose up --detach
fi
docker compose logs -f >${playground_dir}/playground-${logSuffix}.log 2>&1 &
echo "Check log details: ${playground_dir}/playground-${logSuffix}.log"
;;
esac
}
status() {
case "$runtime" in
k8s)
kubectl -n gravitino-playground get pods -o wide
;;
docker)
docker-compose ps -a
;;
esac
}
stop() {
echo "INFO: Stopping the playground..."
case "$runtime" in
k8s)
helm uninstall --namespace gravitino-playground gravitino-playground
;;
docker)
docker-compose down
if [ $? -eq 0 ]; then
echo "INFO: Playground stopped!"
fi
;;
esac
}
runtime=""
case "$1" in
k8s)
runtime="k8s";
;;
docker)
runtime="docker";
;;
*)
echo "ERROR: please specify which runtime you want to use, available runtime: [docker|k8s]"
esac
case "$2" in
start)
if [[ "$3" == "-y" ]]; then
input="y"
else
echo "The playground requires 2 CPU cores, 8 GB of RAM, and 25 GB of disk storage to operate efficiently."
read -r -p "Confirm the requirement is available in your OS [Y/n]:" input
fi
if [[ "$4" == "--enable-ranger" || "$3" == "--enable-ranger" ]]; then
enableRanger=true
else
enableRanger=false
fi
case $input in
[yY][eE][sS] | [yY]) ;;
[nN][oO] | [nN])
exit 0
;;
*)
echo "ERROR: Invalid input!"
exit 1
;;
esac
start
;;
status)
status
;;
stop)
stop
;;
*)
echo "Usage: $0 [k8s|docker] [start | status | stop]"
exit 1
;;
esac