Skip to content

Commit 82caba9

Browse files
committed
Implementing Exercise 04 - Connecting to Confluent Cloud
1 parent 1898c3b commit 82caba9

File tree

16 files changed

+719
-1
lines changed

16 files changed

+719
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ producer.properties
3131
exercises/*
3232
!exercises/exercise.sh
3333
!exercises/exercise.bat
34+
!exercises/README.md
3435

3536
/flink*
3637

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
## Version 0.1.0
44

5-
* Initial commit of required files for a public repo.
5+
* Initial commit of required files for a public repo.
6+
7+
## Version 0.2.0
8+
9+
* Initial implementation for Exercise 03 - Connecting to Confluent Cloud.

build.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
EXERCISES_DIR=exercises
6+
SOLUTIONS_DIR=solutions
7+
STAGING_DIR=staging
8+
9+
function help() {
10+
echo "Usage:"
11+
echo " build.sh <command>"
12+
echo " Commands:"
13+
echo " validate - Run through each exercise, stage the exercise, then apply the solution. Verify the exercise builds in it's final state."
14+
}
15+
16+
function validate() {
17+
WORKING_DIR=$(pwd)
18+
19+
EXERCISES=($(ls $SOLUTIONS_DIR/ | grep "^[0-9]*"))
20+
21+
TMP_DIR=target/tmp
22+
rm -rf $TMP_DIR
23+
mkdir -p $TMP_DIR
24+
25+
cp -r $EXERCISES_DIR $TMP_DIR
26+
cp -r $SOLUTIONS_DIR $TMP_DIR
27+
cp -r $STAGING_DIR $TMP_DIR
28+
29+
cd $TMP_DIR/$EXERCISES_DIR
30+
31+
for EXERCISE in "${EXERCISES[@]}"
32+
do
33+
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
34+
echo $EXERCISE
35+
./exercise.sh stage $EXERCISE
36+
./exercise.sh solve $EXERCISE
37+
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
38+
39+
if [ -f "pom.xml" ]; then
40+
mvn clean test
41+
fi
42+
done
43+
44+
rm -rf $TMP_DIR
45+
46+
cd $WORKING_DIR
47+
}
48+
49+
## Determine which command is being requested, and execute it.
50+
COMMAND=${1:-"help"}
51+
if [ "$COMMAND" = "validate" ]; then
52+
validate
53+
elif [ "$COMMAND" = "help" ]; then
54+
help
55+
else
56+
echo "INVALID COMMAND: $COMMAND"
57+
help
58+
exit 1
59+
fi

exercises/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# A Simple Marketplace with Apache Flink
2+
3+
Throughout these exercises we'll be executing a series of Flink queries that focus on an eCommerce Marketplace domain. Before you get started with the exercises, take a moment to familiarize yourself with the repository.
4+
5+
## exercises
6+
7+
Throughout this course, your work will be done in the `exercises` folder. It contains an `exercise.sh` script that will help you navigate the course.
8+
9+
### exercises/exercise.sh
10+
11+
The `exercise.sh` script is there to help you advance through the exercises. At the beginning of each exercise, you can import any new code by running:
12+
13+
```bash
14+
./exercise.sh stage <exercise number>
15+
```
16+
17+
You can automatically solve an exercise by running:
18+
19+
```bash
20+
./exercise.sh solve <exercise number>
21+
```
22+
23+
**NOTE:** Solving an exercise will overwrite your code.
24+
25+
You can solve a single file by running:
26+
27+
```bash
28+
./exercise.sh solve <exercise number> <file name>
29+
```
30+
31+
**NOTE:** We encourage you to try to solve the exercise on your own. If you get stuck, you can always look at the solution in the `solutions` folder (see below).
32+
33+
## staging
34+
35+
The `staging` folder contains the files necessary to set up each exercise. These will be copied to the `exercises` folder when you execute the `stage` command with the `exercise.sh` script.
36+
37+
In general, you can ignore this folder.
38+
39+
## solutions
40+
41+
The `solutions` folder contains the files necessary to solve each exercise. These will be copied to the `exercises` folder when you execute the `solve` command with the `exercise.sh` script.
42+
43+
In general, you can ignore this folder, but you might find it helpful to reference if you get stuck.

exercises/exercise.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
EXERCISE_DIR=./
6+
SOLUTIONS_DIR=../solutions
7+
STAGING_DIR=../staging
8+
9+
if [ ! -d $STAGING_DIR ]; then
10+
echo "$STAGING_DIR could not be found."
11+
exit 1
12+
fi
13+
14+
if [ ! -d $SOLUTIONS_DIR ]; then
15+
echo "$SOLUTIONS_DIR could not be found."
16+
exit 1
17+
fi
18+
19+
function help() {
20+
echo "Usage:"
21+
echo " exercises.sh <Command>"
22+
echo " Commands:"
23+
echo " stage <Exercise Filter> - Setup the exercise."
24+
echo " <Exercise Filter> - A portion of the exercise name (eg. the exercise number) that will be used to select the exercise."
25+
echo " solve <Exercise Filter> <File Filter> - Solve the exercise."
26+
echo " <Exercise Filter> - A portion of the exercise name (eg. the exercise number) that will be used to select the exercise."
27+
echo " <File Filter> - (Optional) A portion of a file name that will be used to select while file to copy from the solution."
28+
echo " list - List all exercises."
29+
echo " Exercise Filter: A portion of the name of the exercise. Eg. The Exercise Number. If multiple matches are found, the first one will be chosen."
30+
}
31+
32+
function stage() {
33+
EXERCISE_FILTER=$1
34+
MATCHED_EXERCISES=($(ls $STAGING_DIR | grep ".*$EXERCISE_FILTER.*"))
35+
EXERCISE=${MATCHED_EXERCISES[0]}
36+
37+
echo "STAGING $EXERCISE"
38+
39+
cp -r $STAGING_DIR/$EXERCISE/. $EXERCISE_DIR
40+
}
41+
42+
function solve() {
43+
EXERCISE_FILTER=$1
44+
FILE_FILTER=${2:-""}
45+
MATCHED_EXERCISES=($(ls $SOLUTIONS_DIR | grep ".*$EXERCISE_FILTER.*"))
46+
EXERCISE=${MATCHED_EXERCISES[0]}
47+
SOLUTION=$SOLUTIONS_DIR/$EXERCISE
48+
49+
if [ -z $FILE_FILTER ]; then
50+
echo "SOLVING $EXERCISE"
51+
52+
cp -r $SOLUTION/. $EXERCISE_DIR
53+
else
54+
WORKING_DIR=$(pwd)
55+
cd $SOLUTION
56+
MATCHED_FILES=($(find . -iname "*$FILE_FILTER*"))
57+
cd $WORKING_DIR
58+
59+
if [ -z ${MATCHED_FILES:-""} ]; then
60+
echo "FILE NOT FOUND: $FILE_FILTER"
61+
exit 1
62+
fi
63+
64+
FILE_PATH=${MATCHED_FILES[0]}
65+
66+
echo "COPYING $FILE_PATH FROM $EXERCISE"
67+
68+
cp $SOLUTION/$FILE_PATH $EXERCISE_DIR/$FILE_PATH
69+
fi
70+
71+
}
72+
73+
function list() {
74+
EXERCISES=$(ls $SOLUTIONS_DIR)
75+
76+
for ex in "${EXERCISES[@]}"
77+
do
78+
echo "$ex"
79+
done
80+
}
81+
82+
COMMAND=${1:-"help"}
83+
84+
## Determine which command is being requested, and execute it.
85+
if [ "$COMMAND" = "stage" ]; then
86+
EXERCISE_FILTER=${2:-""}
87+
if [ -z $EXERCISE_FILTER ]; then
88+
echo "MISSING EXERCISE ID"
89+
help
90+
exit 1
91+
fi
92+
stage $EXERCISE_FILTER
93+
elif [ "$COMMAND" = "solve" ]; then
94+
EXERCISE_FILTER=${2:-""}
95+
FILE_FILTER=${3:-""}
96+
if [ -z $EXERCISE_FILTER ]; then
97+
echo "MISSING EXERCISE ID"
98+
help
99+
exit 1
100+
fi
101+
solve $EXERCISE_FILTER $FILE_FILTER
102+
elif [ "$COMMAND" = "list" ]; then
103+
list
104+
elif [ "$COMMAND" = "help" ]; then
105+
help
106+
else
107+
echo "INVALID COMMAND: $COMMAND"
108+
help
109+
exit 1
110+
fi

0 commit comments

Comments
 (0)