Yikun commented on code in PR #15: URL: https://github.com/apache/spark-docker/pull/15#discussion_r1000456477
########## Dockerfile.template: ########## @@ -95,4 +95,6 @@ RUN chmod g+w /opt/spark/work-dir RUN chmod a+x /opt/decom.sh RUN chmod a+x /opt/entrypoint.sh +EXPOSE 7077 Review Comment: Add some note for this? Like ```suggestion # Expose port for spark master service to listen on EXPOSE 7077 ``` ########## testing/testing.sh: ########## @@ -0,0 +1,158 @@ +#!/bin/bash -e + +# +# 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. +# + +CURL_TIMEOUT=1 +CURL_COOLDOWN=1 +CURL_MAX_TRIES=30 + +NETWORK_NAME=spark-net-bridge + +SUBMIT_CONTAINER_NAME=spark-submit +MASTER_CONTAINER_NAME=spark-master +WORKER_CONTAINER_NAME=spark-work Review Comment: ```suggestion WORKER_CONTAINER_NAME=spark-worker ``` ########## testing/testing.sh: ########## @@ -0,0 +1,158 @@ +#!/bin/bash -e + +# +# 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. +# + +CURL_TIMEOUT=1 +CURL_COOLDOWN=1 +CURL_MAX_TRIES=30 + +NETWORK_NAME=spark-net-bridge + +SUBMIT_CONTAINER_NAME=spark-submit +MASTER_CONTAINER_NAME=spark-master +WORKER_CONTAINER_NAME=spark-work +SPARK_MASTER_PORT=7077 +SPARK_MASTER_WEBUI_CONTAINER_PORT=8080 +SPARK_MASTER_WEBUI_HOST_PORT=8080 +SPARK_WORKER_WEBUI_CONTAINER_PORT=8081 +SPARK_WORKER_WEBUI_HOST_PORT=8081 + +# Create a new docker bridge network +function create_network() { + docker network create --driver bridge "$NETWORK_NAME" > /dev/null +} + +# Remove docker network +function remove_network() { + docker network remove "$NETWORK_NAME" > /dev/null +} + +# Find and kill any remaining containers attached to the network +function cleanup() { + local containers + containers="$(docker ps --quiet --filter network="$NETWORK_NAME")" + + if [ -n "$containers" ]; then + echo >&2 -n "==> Killing $(echo -n "$containers" | grep -c '^') orphaned container(s)..." + echo "$containers" | xargs docker kill > /dev/null + echo >&2 " done." + fi +} + +function docker_run() { + local container_name="$1" + local docker_run_command="$2" + local args="$3" + + echo >&2 "===> Starting ${container_name}" + if [ "$container_name" = "$MASTER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + elif [ "$container_name" = "$WORKER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + else + eval "docker run --rm --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + fi +} + +function start_spark_master() { + docker_run \ + "$MASTER_CONTAINER_NAME" \ + "--publish $SPARK_MASTER_WEBUI_HOST_PORT:$SPARK_MASTER_WEBUI_CONTAINER_PORT $1" \ + "/opt/spark/bin/spark-class org.apache.spark.deploy.master.Master" > /dev/null +} + +function start_spark_worker() { + docker_run \ + "$WORKER_CONTAINER_NAME" \ + "--publish $SPARK_WORKER_WEBUI_HOST_PORT:$SPARK_WORKER_WEBUI_CONTAINER_PORT $1" \ + "/opt/spark/bin/spark-class org.apache.spark.deploy.worker.Worker spark://$MASTER_CONTAINER_NAME:$SPARK_MASTER_PORT" > /dev/null +} + +function wait_container_ready() { + local container_name="$1" + local host_port="$2" + i=0 + echo >&2 "===> Waiting for ${container_name} to be ready..." + while true; do + i=$((i+1)) + + set +e + + curl \ + --silent \ + --max-time "$CURL_TIMEOUT" \ + localhost:"${host_port}" \ + > /dev/null + + result=$? + + set -e + + if [ "$result" -eq 0 ]; then + break + fi + + if [ "$i" -gt "$CURL_MAX_TRIES" ]; then + echo >&2 "===> \$CURL_MAX_TRIES exceeded waiting for ${container_name} to be ready" + return 1 + fi + + sleep "$CURL_COOLDOWN" + done + + echo >&2 "===> ${container_name} is ready." +} + +function run_spark_pi() { + docker_run \ + "$SUBMIT_CONTAINER_NAME" \ + "$1" \ + "/opt/spark/bin/spark-submit --master spark://$MASTER_CONTAINER_NAME:$SPARK_MASTER_PORT --class org.apache.spark.examples.SparkPi /opt/spark/examples/jars/spark-examples_${scala_spark_version}.jar 20" +} + +# Run smoke test +function run_smoke_test() { + local docker_run_command=$1 + + create_network + cleanup + + start_spark_master "${docker_run_command}" + start_spark_worker "${docker_run_command}" + + wait_container_ready "$MASTER_CONTAINER_NAME" "$SPARK_MASTER_WEBUI_HOST_PORT" + wait_container_ready "$WORKER_CONTAINER_NAME" "$SPARK_WORKER_WEBUI_HOST_PORT" + + run_spark_pi "${docker_run_command}" + + cleanup + remove_network +} + +# Run a master and work and verify they start up and connect to each other successfully. Review Comment: ```suggestion # Run a master and worker and verify they start up and connect to each other successfully. ``` ########## .github/workflows/main.yml: ########## @@ -155,6 +155,9 @@ jobs: path: ~/.cache/coursier key: build-${{ matrix.spark_version }}-scala${{ matrix.scala_version }}-java${{ matrix.java_version }}-coursier + - name : Test - Run spark application for standalone cluster on docker Review Comment: Move this test before `Test - Checkout Spark repository`. It seems we don't need spark code, becasue it's completely docker based ########## testing/testing.sh: ########## @@ -0,0 +1,158 @@ +#!/bin/bash -e + +# +# 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. +# + +CURL_TIMEOUT=1 +CURL_COOLDOWN=1 +CURL_MAX_TRIES=30 + +NETWORK_NAME=spark-net-bridge + +SUBMIT_CONTAINER_NAME=spark-submit +MASTER_CONTAINER_NAME=spark-master +WORKER_CONTAINER_NAME=spark-work +SPARK_MASTER_PORT=7077 +SPARK_MASTER_WEBUI_CONTAINER_PORT=8080 +SPARK_MASTER_WEBUI_HOST_PORT=8080 +SPARK_WORKER_WEBUI_CONTAINER_PORT=8081 +SPARK_WORKER_WEBUI_HOST_PORT=8081 + +# Create a new docker bridge network +function create_network() { + docker network create --driver bridge "$NETWORK_NAME" > /dev/null +} + +# Remove docker network +function remove_network() { + docker network remove "$NETWORK_NAME" > /dev/null +} + +# Find and kill any remaining containers attached to the network +function cleanup() { + local containers + containers="$(docker ps --quiet --filter network="$NETWORK_NAME")" + + if [ -n "$containers" ]; then + echo >&2 -n "==> Killing $(echo -n "$containers" | grep -c '^') orphaned container(s)..." + echo "$containers" | xargs docker kill > /dev/null + echo >&2 " done." + fi +} + +function docker_run() { + local container_name="$1" + local docker_run_command="$2" + local args="$3" + + echo >&2 "===> Starting ${container_name}" + if [ "$container_name" = "$MASTER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + elif [ "$container_name" = "$WORKER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + else + eval "docker run --rm --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + fi +} + +function start_spark_master() { + docker_run \ + "$MASTER_CONTAINER_NAME" \ + "--publish $SPARK_MASTER_WEBUI_HOST_PORT:$SPARK_MASTER_WEBUI_CONTAINER_PORT $1" \ + "/opt/spark/bin/spark-class org.apache.spark.deploy.master.Master" > /dev/null +} + +function start_spark_worker() { + docker_run \ + "$WORKER_CONTAINER_NAME" \ + "--publish $SPARK_WORKER_WEBUI_HOST_PORT:$SPARK_WORKER_WEBUI_CONTAINER_PORT $1" \ + "/opt/spark/bin/spark-class org.apache.spark.deploy.worker.Worker spark://$MASTER_CONTAINER_NAME:$SPARK_MASTER_PORT" > /dev/null +} + +function wait_container_ready() { + local container_name="$1" + local host_port="$2" + i=0 + echo >&2 "===> Waiting for ${container_name} to be ready..." + while true; do + i=$((i+1)) + + set +e + + curl \ + --silent \ + --max-time "$CURL_TIMEOUT" \ + localhost:"${host_port}" \ + > /dev/null + + result=$? + + set -e + + if [ "$result" -eq 0 ]; then + break + fi + + if [ "$i" -gt "$CURL_MAX_TRIES" ]; then + echo >&2 "===> \$CURL_MAX_TRIES exceeded waiting for ${container_name} to be ready" + return 1 + fi + + sleep "$CURL_COOLDOWN" + done + + echo >&2 "===> ${container_name} is ready." +} + +function run_spark_pi() { + docker_run \ + "$SUBMIT_CONTAINER_NAME" \ + "$1" \ + "/opt/spark/bin/spark-submit --master spark://$MASTER_CONTAINER_NAME:$SPARK_MASTER_PORT --class org.apache.spark.examples.SparkPi /opt/spark/examples/jars/spark-examples_${scala_spark_version}.jar 20" +} + +# Run smoke test +function run_smoke_test() { Review Comment: nit: maybe `run_standalone_test` or `run_smoke_standalone_test`? We will add some more other test besides standalone ########## .github/workflows/main.yml: ########## @@ -155,6 +155,9 @@ jobs: path: ~/.cache/coursier key: build-${{ matrix.spark_version }}-scala${{ matrix.scala_version }}-java${{ matrix.java_version }}-coursier + - name : Test - Run spark application for standalone cluster on docker + run: testing/run_tests.sh ${{ matrix.scala_version }}-${{ matrix.spark_version }} Review Comment: Would mind adding version for `--scala-version` and `--spark-version`, you can reference this: https://github.com/apache/spark/blob/0643d02e4f03cdadb53efc05af0b6533d22db297/resource-managers/kubernetes/integration-tests/dev/dev-run-integration-tests.sh#L54 Because we might also prepare adding more test about `pyspark`/ `spark-shell` in future. ########## testing/testing.sh: ########## @@ -0,0 +1,158 @@ +#!/bin/bash -e + +# +# 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. +# + +CURL_TIMEOUT=1 +CURL_COOLDOWN=1 +CURL_MAX_TRIES=30 + +NETWORK_NAME=spark-net-bridge + +SUBMIT_CONTAINER_NAME=spark-submit +MASTER_CONTAINER_NAME=spark-master +WORKER_CONTAINER_NAME=spark-work +SPARK_MASTER_PORT=7077 +SPARK_MASTER_WEBUI_CONTAINER_PORT=8080 +SPARK_MASTER_WEBUI_HOST_PORT=8080 +SPARK_WORKER_WEBUI_CONTAINER_PORT=8081 +SPARK_WORKER_WEBUI_HOST_PORT=8081 + +# Create a new docker bridge network +function create_network() { + docker network create --driver bridge "$NETWORK_NAME" > /dev/null +} + +# Remove docker network +function remove_network() { + docker network remove "$NETWORK_NAME" > /dev/null Review Comment: nit: it works but better to: ```suggestion docker network rm "$NETWORK_NAME" > /dev/null ``` https://docs.docker.com/engine/reference/commandline/network_rm/ ########## testing/testing.sh: ########## @@ -0,0 +1,158 @@ +#!/bin/bash -e + +# +# 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. +# + +CURL_TIMEOUT=1 +CURL_COOLDOWN=1 +CURL_MAX_TRIES=30 + +NETWORK_NAME=spark-net-bridge + +SUBMIT_CONTAINER_NAME=spark-submit +MASTER_CONTAINER_NAME=spark-master +WORKER_CONTAINER_NAME=spark-work +SPARK_MASTER_PORT=7077 +SPARK_MASTER_WEBUI_CONTAINER_PORT=8080 +SPARK_MASTER_WEBUI_HOST_PORT=8080 +SPARK_WORKER_WEBUI_CONTAINER_PORT=8081 +SPARK_WORKER_WEBUI_HOST_PORT=8081 + +# Create a new docker bridge network +function create_network() { + docker network create --driver bridge "$NETWORK_NAME" > /dev/null +} + +# Remove docker network +function remove_network() { + docker network remove "$NETWORK_NAME" > /dev/null +} + +# Find and kill any remaining containers attached to the network +function cleanup() { + local containers + containers="$(docker ps --quiet --filter network="$NETWORK_NAME")" + + if [ -n "$containers" ]; then + echo >&2 -n "==> Killing $(echo -n "$containers" | grep -c '^') orphaned container(s)..." + echo "$containers" | xargs docker kill > /dev/null + echo >&2 " done." + fi +} + +function docker_run() { + local container_name="$1" + local docker_run_command="$2" + local args="$3" + + echo >&2 "===> Starting ${container_name}" + if [ "$container_name" = "$MASTER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + elif [ "$container_name" = "$WORKER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + else + eval "docker run --rm --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + fi +} + +function start_spark_master() { + docker_run \ + "$MASTER_CONTAINER_NAME" \ + "--publish $SPARK_MASTER_WEBUI_HOST_PORT:$SPARK_MASTER_WEBUI_CONTAINER_PORT $1" \ + "/opt/spark/bin/spark-class org.apache.spark.deploy.master.Master" > /dev/null +} + +function start_spark_worker() { + docker_run \ + "$WORKER_CONTAINER_NAME" \ + "--publish $SPARK_WORKER_WEBUI_HOST_PORT:$SPARK_WORKER_WEBUI_CONTAINER_PORT $1" \ + "/opt/spark/bin/spark-class org.apache.spark.deploy.worker.Worker spark://$MASTER_CONTAINER_NAME:$SPARK_MASTER_PORT" > /dev/null +} + +function wait_container_ready() { + local container_name="$1" + local host_port="$2" + i=0 + echo >&2 "===> Waiting for ${container_name} to be ready..." + while true; do + i=$((i+1)) + + set +e + + curl \ + --silent \ + --max-time "$CURL_TIMEOUT" \ + localhost:"${host_port}" \ + > /dev/null + + result=$? + + set -e + + if [ "$result" -eq 0 ]; then + break + fi + + if [ "$i" -gt "$CURL_MAX_TRIES" ]; then + echo >&2 "===> \$CURL_MAX_TRIES exceeded waiting for ${container_name} to be ready" + return 1 + fi + + sleep "$CURL_COOLDOWN" + done + + echo >&2 "===> ${container_name} is ready." +} + +function run_spark_pi() { + docker_run \ + "$SUBMIT_CONTAINER_NAME" \ + "$1" \ + "/opt/spark/bin/spark-submit --master spark://$MASTER_CONTAINER_NAME:$SPARK_MASTER_PORT --class org.apache.spark.examples.SparkPi /opt/spark/examples/jars/spark-examples_${scala_spark_version}.jar 20" +} + +# Run smoke test +function run_smoke_test() { + local docker_run_command=$1 + + create_network + cleanup + + start_spark_master "${docker_run_command}" + start_spark_worker "${docker_run_command}" + + wait_container_ready "$MASTER_CONTAINER_NAME" "$SPARK_MASTER_WEBUI_HOST_PORT" + wait_container_ready "$WORKER_CONTAINER_NAME" "$SPARK_WORKER_WEBUI_HOST_PORT" + + run_spark_pi "${docker_run_command}" Review Comment: Do we want to validate the output contains `Pi is roughly 3`? ########## testing/testing.sh: ########## @@ -0,0 +1,158 @@ +#!/bin/bash -e + +# +# 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. +# + +CURL_TIMEOUT=1 +CURL_COOLDOWN=1 +CURL_MAX_TRIES=30 + +NETWORK_NAME=spark-net-bridge + +SUBMIT_CONTAINER_NAME=spark-submit +MASTER_CONTAINER_NAME=spark-master +WORKER_CONTAINER_NAME=spark-work +SPARK_MASTER_PORT=7077 +SPARK_MASTER_WEBUI_CONTAINER_PORT=8080 +SPARK_MASTER_WEBUI_HOST_PORT=8080 +SPARK_WORKER_WEBUI_CONTAINER_PORT=8081 +SPARK_WORKER_WEBUI_HOST_PORT=8081 + +# Create a new docker bridge network +function create_network() { + docker network create --driver bridge "$NETWORK_NAME" > /dev/null +} + +# Remove docker network +function remove_network() { + docker network remove "$NETWORK_NAME" > /dev/null +} + +# Find and kill any remaining containers attached to the network +function cleanup() { + local containers + containers="$(docker ps --quiet --filter network="$NETWORK_NAME")" + + if [ -n "$containers" ]; then + echo >&2 -n "==> Killing $(echo -n "$containers" | grep -c '^') orphaned container(s)..." + echo "$containers" | xargs docker kill > /dev/null + echo >&2 " done." + fi +} + +function docker_run() { + local container_name="$1" + local docker_run_command="$2" + local args="$3" + + echo >&2 "===> Starting ${container_name}" + if [ "$container_name" = "$MASTER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + elif [ "$container_name" = "$WORKER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" Review Comment: 1. Looks like these two branches are same, maybe could merge them into one? 2. Mind to add note about `--detach`? ########## testing/testing.sh: ########## @@ -0,0 +1,158 @@ +#!/bin/bash -e + +# +# 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. +# + Review Comment: Add some usage notes ########## testing/testing.sh: ########## @@ -0,0 +1,158 @@ +#!/bin/bash -e + +# +# 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. +# + +CURL_TIMEOUT=1 +CURL_COOLDOWN=1 +CURL_MAX_TRIES=30 + +NETWORK_NAME=spark-net-bridge + +SUBMIT_CONTAINER_NAME=spark-submit +MASTER_CONTAINER_NAME=spark-master +WORKER_CONTAINER_NAME=spark-work +SPARK_MASTER_PORT=7077 +SPARK_MASTER_WEBUI_CONTAINER_PORT=8080 +SPARK_MASTER_WEBUI_HOST_PORT=8080 +SPARK_WORKER_WEBUI_CONTAINER_PORT=8081 +SPARK_WORKER_WEBUI_HOST_PORT=8081 + +# Create a new docker bridge network +function create_network() { + docker network create --driver bridge "$NETWORK_NAME" > /dev/null +} + +# Remove docker network +function remove_network() { + docker network remove "$NETWORK_NAME" > /dev/null +} + +# Find and kill any remaining containers attached to the network +function cleanup() { + local containers + containers="$(docker ps --quiet --filter network="$NETWORK_NAME")" + + if [ -n "$containers" ]; then + echo >&2 -n "==> Killing $(echo -n "$containers" | grep -c '^') orphaned container(s)..." + echo "$containers" | xargs docker kill > /dev/null + echo >&2 " done." + fi +} + +function docker_run() { + local container_name="$1" + local docker_run_command="$2" + local args="$3" + + echo >&2 "===> Starting ${container_name}" + if [ "$container_name" = "$MASTER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + elif [ "$container_name" = "$WORKER_CONTAINER_NAME" ]; then + eval "docker run --rm --detach --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + else + eval "docker run --rm --network $NETWORK_NAME --name ${container_name} ${docker_run_command} $image_url ${args}" + fi +} + +function start_spark_master() { + docker_run \ + "$MASTER_CONTAINER_NAME" \ + "--publish $SPARK_MASTER_WEBUI_HOST_PORT:$SPARK_MASTER_WEBUI_CONTAINER_PORT $1" \ + "/opt/spark/bin/spark-class org.apache.spark.deploy.master.Master" > /dev/null +} + +function start_spark_worker() { + docker_run \ + "$WORKER_CONTAINER_NAME" \ + "--publish $SPARK_WORKER_WEBUI_HOST_PORT:$SPARK_WORKER_WEBUI_CONTAINER_PORT $1" \ + "/opt/spark/bin/spark-class org.apache.spark.deploy.worker.Worker spark://$MASTER_CONTAINER_NAME:$SPARK_MASTER_PORT" > /dev/null +} + +function wait_container_ready() { + local container_name="$1" + local host_port="$2" + i=0 + echo >&2 "===> Waiting for ${container_name} to be ready..." + while true; do + i=$((i+1)) + + set +e + + curl \ + --silent \ + --max-time "$CURL_TIMEOUT" \ + localhost:"${host_port}" \ + > /dev/null + + result=$? + + set -e + + if [ "$result" -eq 0 ]; then + break + fi + + if [ "$i" -gt "$CURL_MAX_TRIES" ]; then + echo >&2 "===> \$CURL_MAX_TRIES exceeded waiting for ${container_name} to be ready" + return 1 + fi + + sleep "$CURL_COOLDOWN" + done + + echo >&2 "===> ${container_name} is ready." +} + +function run_spark_pi() { + docker_run \ + "$SUBMIT_CONTAINER_NAME" \ + "$1" \ + "/opt/spark/bin/spark-submit --master spark://$MASTER_CONTAINER_NAME:$SPARK_MASTER_PORT --class org.apache.spark.examples.SparkPi /opt/spark/examples/jars/spark-examples_${scala_spark_version}.jar 20" +} + +# Run smoke test +function run_smoke_test() { + local docker_run_command=$1 + + create_network + cleanup + + start_spark_master "${docker_run_command}" + start_spark_worker "${docker_run_command}" + + wait_container_ready "$MASTER_CONTAINER_NAME" "$SPARK_MASTER_WEBUI_HOST_PORT" + wait_container_ready "$WORKER_CONTAINER_NAME" "$SPARK_WORKER_WEBUI_HOST_PORT" + + run_spark_pi "${docker_run_command}" + + cleanup + remove_network +} + +# Run a master and work and verify they start up and connect to each other successfully. +# And run a Spark Pi to complete smoke test. +function smoke_test() { + local scala_spark_version="$1" + local image_url=$TEST_REPO/$IMAGE_NAME:$UNIQUE_IMAGE_TAG + + echo >&2 "===> Smoke test for $image_url" + run_smoke_test "" Review Comment: nit: ```suggestion run_smoke_test ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
