-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathplayground.sh
executable file
·237 lines (204 loc) · 7.02 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
226
227
228
229
230
231
232
233
234
235
236
237
#!/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.
#
playground_dir="$(dirname "${BASH_SOURCE-$0}")"
playground_dir="$(
cd "${playground_dir}" >/dev/null || exit 1
pwd
)"
playgroundRuntimeName="gravitino-playground"
requiredDiskSpaceGB=25
requiredRamGB=8
requiredCpuCores=2
requiredPorts=(6080 8090 9001 3307 19000 19083 60070 13306 15342 18080 18888 19090 13000)
dockerComposeCommand=""
testDocker() {
echo "[INFO] Testing Docker environment by running hello-world..."
# Use `always` to test network connection
docker run --rm --pull always hello-world:linux >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "[INFO] Docker check passed: Docker is working correctly!"
else
echo "[ERROR] Docker check failed: There was an issue running the hello-world container. Please check your Docker installation."
exit 1
fi
for containerId in $(docker ps -a | grep hello-world | awk '{print $1}'); do
docker rm $containerId
done
for imageTag in $(docker images | grep hello-world | awk '{print $2}'); do
docker rmi hello-world:$imageTag
done
}
checkDockerCompose() {
dockerComposeCommand=""
if command -v docker >/dev/null 2>&1 && command -v docker compose >/dev/null 2>&1; then
dockerComposeCommand="docker compose"
elif command -v docker-compose >/dev/null 2>&1; then
dockerComposeCommand="docker-compose"
else
echo "[ERROR] Docker compose check failed: There was an issue running the docker compose command. Please check your docker compose installation."
exit 1
fi
echo "[INFO] Docker compose check passed: Docker compose is working correctly using ${dockerComposeCommand} command!"
}
checkPlaygroundNotRunning() {
if ${dockerComposeCommand} ls | grep -q "${playgroundRuntimeName}"; then
echo "[ERROR] Playground runtime is already running. Please stop it first."
exit 1
fi
}
checkPlaygroundRunning() {
if ! ${dockerComposeCommand} ls | grep -q "${playgroundRuntimeName}"; then
echo "[ERROR] Playground runtime is not running. Please start it first."
exit 1
fi
}
checkDockerDisk() {
# Step 1: Get Docker Root Directory
local dockerRootDir="$(docker info 2>/dev/null | grep "Docker Root Dir" | awk '{print $NF}')"
# Step 2: Check if the Docker directory exists
if [ -z "${dockerRootDir}" ]; then
echo "[ERROR] Docker disk check failed: Docker is not running or Docker Root Directory not found."
exit 1
fi
local availableSpaceKB
if [ -d "${dockerRootDir}" ]; then
# Check available space in the Docker directory's partition
availableSpaceKB=$(df -k "${dockerRootDir}" | awk 'NR==2 {print $4}')
else
# Check available space in the root partition if the directory doesn't exist (special case for WSL)
availableSpaceKB=$(df -k / | awk 'NR==2 {print $4}')
fi
# Step 3: Check if available space is greater than required
local availableSpaceGB=$((${availableSpaceKB} / 1024 / 1024))
if [ "${availableSpaceGB}" -ge "${requiredDiskSpaceGB}" ]; then
echo "[INFO] Docker disk check passed: ${availableSpaceGB} GB available."
else
echo "[ERROR] Docker disk check failed: Only ${availableSpaceGB} GB available, required ${requiredDiskSpaceGB} GB or more."
exit 1
fi
}
checkDockerRam() {
local totalRamBytes=$(docker info --format '{{.MemTotal}}')
# Convert from bytes to GB
local totalRamGB=$((totalRamBytes / 1024 / 1024 / 1024))
if [ "${totalRamGB}" -ge "${requiredRamGB}" ]; then
echo "[INFO] Docker RAM check passed: ${totalRamGB} GB available."
else
echo "[ERROR] Docker RAM check failed: Only ${totalRamGB} GB available, required ${requiredRamGB} GB or more."
exit 1
fi
}
checkDockerCpu() {
local cpuCores=$(docker info --format '{{.NCPU}}')
if [ "${cpuCores}" -ge "${requiredCpuCores}" ]; then
echo "[INFO] Docker CPU check passed: ${cpuCores} cores available."
else
echo "[ERROR] Docker CPU check failed: Only ${cpuCores} cores available, required ${requiredCpuCores} cores or more."
exit 1
fi
}
checkPortsInUse() {
local usedPorts=()
local availablePorts=()
for port in "${requiredPorts[@]}"; do
if [[ "$(uname)" == "Darwin" ]]; then
openPort=$(lsof -i :${port} -sTCP:LISTEN)
# Use sudo only when necessary
elif [[ "$(uname)" == "Linux" ]]; then
openPort=$(sudo lsof -i :${port} -sTCP:LISTEN)
fi
if [ -z "${openPort}" ]; then
availablePorts+=("${port}")
else
usedPorts+=("${port}")
fi
done
echo "[INFO] Port status check results:"
if [ ${#availablePorts[@]} -gt 0 ]; then
echo "[INFO] Available ports: ${availablePorts[*]}"
fi
if [ ${#usedPorts[@]} -gt 0 ]; then
echo "[ERROR] Ports in use: ${usedPorts[*]}"
echo "[ERROR] Please check these ports."
exit 1
fi
}
start() {
if [ "${enableRanger}" == true ]; then
echo "[INFO] Starting the playground with Ranger..."
else
echo "[INFO] Starting the playground..."
fi
echo "[INFO] The playground requires ${requiredCpuCores} CPU cores, ${requiredRamGB} GB of RAM, and ${requiredDiskSpaceGB} GB of disk storage to operate efficiently."
checkPortsInUse
testDocker
checkDockerCompose
checkPlaygroundNotRunning
checkDockerDisk
checkDockerRam
checkDockerCpu
cd ${playground_dir}
echo "[INFO] Preparing packages..."
./init/spark/spark-dependency.sh
./init/gravitino/gravitino-dependency.sh
./init/jupyter/jupyter-dependency.sh
logSuffix=$(date +%Y%m%d%H%M%s)
if [ "${enableRanger}" == true ]; then
${dockerComposeCommand} -f docker-compose.yaml -f docker-enable-ranger-hive-override.yaml -p ${playgroundRuntimeName} up --detach
else
${dockerComposeCommand} -p ${playgroundRuntimeName} up --detach
fi
${dockerComposeCommand} -p ${playgroundRuntimeName} logs -f >${playground_dir}/playground-${logSuffix}.log 2>&1 &
echo "[INFO] Check log details: ${playground_dir}/playground-${logSuffix}.log"
}
status() {
checkDockerCompose
checkPlaygroundRunning
${dockerComposeCommand} ps -a
}
stop() {
checkDockerCompose
checkPlaygroundRunning
echo "[INFO] Stopping the playground..."
${dockerComposeCommand} down
if [ $? -eq 0 ]; then
echo "[INFO] Playground stopped!"
fi
}
case "$1" in
start)
if [[ "$2" == "--enable-ranger" ]]; then
enableRanger=true
else
enableRanger=false
fi
start
;;
status)
status
;;
stop)
stop
;;
*)
echo "Usage: $0 <start|status|stop> [--enable-ranger]"
exit 1
;;
esac