Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ producer.properties
exercises/*
!exercises/exercise.sh
!exercises/exercise.bat
!exercises/README.md

/flink*

6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

## Version 0.1.0

* Initial commit of required files for a public repo.
* Initial commit of required files for a public repo.

## Version 0.2.0

* Initial implementation for Exercise 03 - Connecting to Confluent Cloud.
59 changes: 59 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

EXERCISES_DIR=exercises
SOLUTIONS_DIR=solutions
STAGING_DIR=staging

function help() {
echo "Usage:"
echo " build.sh <command>"
echo " Commands:"
echo " validate - Run through each exercise, stage the exercise, then apply the solution. Verify the exercise builds in it's final state."
}

function validate() {
WORKING_DIR=$(pwd)

EXERCISES=($(ls $SOLUTIONS_DIR/ | grep "^[0-9]*"))

TMP_DIR=target/tmp
rm -rf $TMP_DIR
mkdir -p $TMP_DIR

cp -r $EXERCISES_DIR $TMP_DIR
cp -r $SOLUTIONS_DIR $TMP_DIR
cp -r $STAGING_DIR $TMP_DIR

cd $TMP_DIR/$EXERCISES_DIR

for EXERCISE in "${EXERCISES[@]}"
do
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo $EXERCISE
./exercise.sh stage $EXERCISE
./exercise.sh solve $EXERCISE
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

if [ -f "pom.xml" ]; then
mvn clean test
fi
done

rm -rf $TMP_DIR

cd $WORKING_DIR
}

## Determine which command is being requested, and execute it.
COMMAND=${1:-"help"}
if [ "$COMMAND" = "validate" ]; then
validate
elif [ "$COMMAND" = "help" ]; then
help
else
echo "INVALID COMMAND: $COMMAND"
help
exit 1
fi
43 changes: 43 additions & 0 deletions exercises/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# A Simple Marketplace with Apache Flink

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.

## exercises

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.

### exercises/exercise.sh

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:

```bash
./exercise.sh stage <exercise number>
```

You can automatically solve an exercise by running:

```bash
./exercise.sh solve <exercise number>
```

**NOTE:** Solving an exercise will overwrite your code.

You can solve a single file by running:

```bash
./exercise.sh solve <exercise number> <file name>
```

**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).

## staging

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.

In general, you can ignore this folder.

## solutions

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.

In general, you can ignore this folder, but you might find it helpful to reference if you get stuck.
110 changes: 110 additions & 0 deletions exercises/exercise.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

EXERCISE_DIR=./
SOLUTIONS_DIR=../solutions
STAGING_DIR=../staging

if [ ! -d $STAGING_DIR ]; then
echo "$STAGING_DIR could not be found."
exit 1
fi

if [ ! -d $SOLUTIONS_DIR ]; then
echo "$SOLUTIONS_DIR could not be found."
exit 1
fi

function help() {
echo "Usage:"
echo " exercises.sh <Command>"
echo " Commands:"
echo " stage <Exercise Filter> - Setup the exercise."
echo " <Exercise Filter> - A portion of the exercise name (eg. the exercise number) that will be used to select the exercise."
echo " solve <Exercise Filter> <File Filter> - Solve the exercise."
echo " <Exercise Filter> - A portion of the exercise name (eg. the exercise number) that will be used to select the exercise."
echo " <File Filter> - (Optional) A portion of a file name that will be used to select while file to copy from the solution."
echo " list - List all exercises."
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."
}

function stage() {
EXERCISE_FILTER=$1
MATCHED_EXERCISES=($(ls $STAGING_DIR | grep ".*$EXERCISE_FILTER.*"))
EXERCISE=${MATCHED_EXERCISES[0]}

echo "STAGING $EXERCISE"

cp -r $STAGING_DIR/$EXERCISE/. $EXERCISE_DIR
}

function solve() {
EXERCISE_FILTER=$1
FILE_FILTER=${2:-""}
MATCHED_EXERCISES=($(ls $SOLUTIONS_DIR | grep ".*$EXERCISE_FILTER.*"))
EXERCISE=${MATCHED_EXERCISES[0]}
SOLUTION=$SOLUTIONS_DIR/$EXERCISE

if [ -z $FILE_FILTER ]; then
echo "SOLVING $EXERCISE"

cp -r $SOLUTION/. $EXERCISE_DIR
else
WORKING_DIR=$(pwd)
cd $SOLUTION
MATCHED_FILES=($(find . -iname "*$FILE_FILTER*"))
cd $WORKING_DIR

if [ -z ${MATCHED_FILES:-""} ]; then
echo "FILE NOT FOUND: $FILE_FILTER"
exit 1
fi

FILE_PATH=${MATCHED_FILES[0]}

echo "COPYING $FILE_PATH FROM $EXERCISE"

cp $SOLUTION/$FILE_PATH $EXERCISE_DIR/$FILE_PATH
fi

}

function list() {
EXERCISES=$(ls $SOLUTIONS_DIR)

for ex in "${EXERCISES[@]}"
do
echo "$ex"
done
}

COMMAND=${1:-"help"}

## Determine which command is being requested, and execute it.
if [ "$COMMAND" = "stage" ]; then
EXERCISE_FILTER=${2:-""}
if [ -z $EXERCISE_FILTER ]; then
echo "MISSING EXERCISE ID"
help
exit 1
fi
stage $EXERCISE_FILTER
elif [ "$COMMAND" = "solve" ]; then
EXERCISE_FILTER=${2:-""}
FILE_FILTER=${3:-""}
if [ -z $EXERCISE_FILTER ]; then
echo "MISSING EXERCISE ID"
help
exit 1
fi
solve $EXERCISE_FILTER $FILE_FILTER
elif [ "$COMMAND" = "list" ]; then
list
elif [ "$COMMAND" = "help" ]; then
help
else
echo "INVALID COMMAND: $COMMAND"
help
exit 1
fi
Loading