Skip to content

Commit

Permalink
Merge pull request #104 from aiven/fwu-flink-stock
Browse files Browse the repository at this point in the history
flink stock demo - terraform updates
  • Loading branch information
runwuf authored Jan 11, 2024
2 parents dc31937 + 322f67a commit 578881b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
31 changes: 6 additions & 25 deletions solutions/flink-kafka/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,14 @@ This demo uses Aiven Flink and Kafka to simulate processing stock data.

## Usage

- run terraform to create `stockdata-kafka` and `stockdata-flink` services in aiven console under the project you created.
- Update `aiven_project` in `terraform/variables.tf` to your project name.

```bash
terraform init
terraform plan
terraform apply"
```
- after terraform completed successfully, the follwing would be in `stockdata-flink`
* `flinkdemo-flink`: flink job to prcoess stock data
* `stock_source` : source table for data feeded from kafka `source_topic`
* `stock_sink`: target table for flink processed data into kafka `sink_topic`
- Run the following to call terraform to create flink and kafka services and download certificates.

- install the following demo code in virtualenv:
```bash
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
```
- download `ca.pem` `service.cert` `service.key` into `src/` from `flinkdemo-kafka`
```
./lab.sh setup
```

- Go to aiven console, stockdata-flink service -> Applications -> stock-data -> Create deployment
- open two terminals to send messages to kafka `source_topic` and consume messages from `sink_topic`.
these are running in an infinite loop, press `ctrl` + `c` to stop at anytime.

Expand Down Expand Up @@ -110,6 +89,8 @@ Received: b'{"symbol":"GRAFANA","change_bid_price":6.04,"change_ask_price":6.28,
Received: b'{"symbol":"AVN","change_bid_price":4.23,"change_ask_price":3.86,"min_bid_price":999.49,"max_bid_price":1003.72,"min_ask_price":1000.24,"max_ask_price":1004.1,"time_interval":6,"time_stamp":"2021-11-27 01:52:42.359"}'
```

- Run ./lab.sh teardown to delete all the resources created from this demo. Note: this would cause terraform.tfstate out of sync which would have to be deleted after.
- Run `./lab.sh teardown` to delete all the resources created from this demo.

./lab.sh teardown
```
./lab.sh teardown
```
18 changes: 15 additions & 3 deletions solutions/flink-kafka/lab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ set -e
source ./lab.env

lab_setup() {
cd terraform
terraform init
terraform plan
terraform apply \
&& printf "" || echo ""
echo "services created successfully."
cd ..

avn service user-creds-download ${SERVICE_KAFKA} --username avnadmin -d src/ \
&& printf "" || echo ""
echo "certificates and keys downloaded from ${SERVICE_KAFKA}"
Expand All @@ -29,9 +37,13 @@ cd ..
}

lab_teardown() {
rm -f ca.pem service.cert service.key os-connector.json kcat.config
echo ${SERVICE_KAFKA} | avn service terminate ${SERVICE_KAFKA}
echo ${SERVICE_FLINK} | avn service terminate ${SERVICE_FLINK}
rm -f src/ca.pem src/service.cert src/service.key
cd terraform
terraform destroy \
&& printf "" || echo ""
echo "services deleted successfully."
cd ..

}

lab_producer() {
Expand Down
7 changes: 7 additions & 0 deletions solutions/flink-kafka/terraform/stockdata.tf
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ resource "aiven_flink_application_version" "stock-data-version" {
integration_id = aiven_service_integration.flink_to_kafka.integration_id
}
}

resource "aiven_flink_application_deployment" "stock-data-version" {
project = aiven_flink.flink.project
service_name = aiven_flink.flink.service_name
application_id = aiven_flink_application.stock-data.application_id
version_id = aiven_flink_application_version.stock-data-version.application_version_id
}
6 changes: 1 addition & 5 deletions solutions/flink-kafka/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
variable "aiven_api_token" {
type = string
default = ""
}
variable "aiven_project" {
type = string
default = "felixwu-demo"
default = "myproject"
}

variable "cloud_name" {
Expand Down

0 comments on commit 578881b

Please sign in to comment.