Skip to content

Commit 19179ea

Browse files
committed
added job wait and log parsing
1 parent cf4a305 commit 19179ea

File tree

4 files changed

+91
-7
lines changed

4 files changed

+91
-7
lines changed

docs/modules/getting_started/examples/code/getting_started.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,23 @@ exit 1
4242
;;
4343
esac
4444

45-
echo "Creating a Spark Application"
45+
echo "Creating a Spark Application..."
4646
# tag::install-sparkapp[]
4747
kubectl apply -f pyspark-pi.yaml
4848
# end::install-sparkapp[]
4949

50+
echo "Waiting for job to complete ..."
51+
# tag::wait-for-job[]
52+
kubectl wait pods -l 'job-name=pyspark-pi' \
53+
--for jsonpath='{.status.phase}'=Succeeded \
54+
--timeout 300s
55+
# end::wait-for-job[]
5056

57+
result=$(kubectl logs -l 'spark-role=driver' --tail=-1 | grep "Pi is roughly")
58+
59+
if [ "$result" == "" ]; then
60+
echo "Log result was not found!"
61+
exit 1
62+
else
63+
echo "Job result:" $result
64+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# This script contains all the code snippets from the guide, as well as some assert tests
5+
# to test if the instructions in the guide work. The user *could* use it, but it is intended
6+
# for testing only.
7+
# The script will install the operators, create a superset instance and briefly open a port
8+
# forward and connect to the superset instance to make sure it is up and running.
9+
# No running processes are left behind (i.e. the port-forwarding is closed at the end)
10+
11+
if [ $# -eq 0 ]
12+
then
13+
echo "Installation method argument ('helm' or 'stackablectl') required."
14+
exit 1
15+
fi
16+
17+
case "$1" in
18+
"helm")
19+
echo "Adding 'stackable-dev' Helm Chart repository"
20+
# tag::helm-add-repo[]
21+
helm repo add stackable-dev https://repo.stackable.tech/repository/helm-dev/
22+
# end::helm-add-repo[]
23+
echo "Installing Operators with Helm"
24+
# tag::helm-install-operators[]
25+
helm install --wait commons-operator stackable-dev/commons-operator --version {{ versions.commons }}
26+
helm install --wait secret-operator stackable-dev/secret-operator --version {{ versions.secret }}
27+
helm install --wait spark-k8s-operator stackable-dev/spark-k8s-operator --version {{ versions.spark }}
28+
# end::helm-install-operators[]
29+
;;
30+
"stackablectl")
31+
echo "installing Operators with stackablectl"
32+
# tag::stackablectl-install-operators[]
33+
stackablectl operator install \
34+
commons={{ versions.commons }} \
35+
secret={{ versions.secret }} \
36+
spark-k8s={{ versions.spark }}
37+
# end::stackablectl-install-operators[]
38+
;;
39+
*)
40+
echo "Need to give 'helm' or 'stackablectl' as an argument for which installation method to use!"
41+
exit 1
42+
;;
43+
esac
44+
45+
echo "Creating a Spark Application..."
46+
# tag::install-sparkapp[]
47+
kubectl apply -f pyspark-pi.yaml
48+
# end::install-sparkapp[]
49+
50+
echo "Waiting for job to complete ..."
51+
# tag::wait-for-job[]
52+
kubectl wait pods -l 'job-name=pyspark-pi' \
53+
--for jsonpath='{.status.phase}'=Succeeded \
54+
--timeout 300s
55+
# end::wait-for-job[]
56+
57+
result=$(kubectl logs -l 'spark-role=driver' --tail=-1 | grep "Pi is roughly")
58+
59+
if [ "$result" == "" ]; then
60+
echo "Log result was not found!"
61+
exit 1
62+
else
63+
echo "Job result:" $result
64+
fi

docs/modules/getting_started/pages/first_steps.adoc

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
Once you have followed the steps in the xref:installation.adoc[] section to install the Operator and its dependencies, you will now create a Spark job. Afterwards you can <<_verify_that_it_works, verify that it works>> by looking at the logs from the driver pod.
44

5-
=== Airflow
5+
=== Starting a Spark job
66

7-
An Airflow cluster is made of up three components:
7+
A SparkApplication is made of up three components:
88

9-
- `webserver`: this provides the main UI for user-interaction
10-
- `workers`: the nodes over which the job workload will be distributed by the scheduler
11-
- `scheduler`: responsible for triggering jobs and persisting their metadata to the backend database
9+
- Job: this will build a spark-submit command from the resource, passing this to internal spark code together with templates for building the driver and executor pods
10+
- Driver: the driver starts the designated number of executors and removes them when the job is completed.
11+
- Executor(s): responsible for executing the job itself
1212

1313
Create a file named `pyspark-pi.yaml` with the following contents:
1414

@@ -50,6 +50,12 @@ image::spark_running.png[Spark job]
5050
- `pyspark-pi-xxxxxxx-driver`: the driver pod that drives the execution
5151
- `pythonpi-xxxxxxxxx-exec-x`: the set of executors started by the driver (in our example `spec.executor.instances` was set to 3 which is why we have 3 executors)
5252

53+
Job progress can be followed by issuing this command:
54+
55+
----
56+
include::example$code/getting_started.sh[tag=wait-for-job]
57+
----
58+
5359
When the job completes the driver cleans up the executor. The initial job is persisted for several minutes before being removed. The completed state will look like this:
5460

5561
image::spark_complete.png[Completed job]

docs/templating_vars.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ helm:
55
versions:
66
commons: 0.3.0-nightly
77
secret: 0.6.0-nightly
8-
airflow: 0.5.0-nightly
8+
spark: 0.5.0-nightly

0 commit comments

Comments
 (0)