Skip to content

Commit

Permalink
module-2 done. Pulumi config must be added
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandruvesa committed Apr 5, 2024
1 parent f9307ab commit 7d30fd1
Show file tree
Hide file tree
Showing 189 changed files with 51 additions and 293 deletions.
1 change: 1 addition & 0 deletions course/module-2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ share/python-wheels/
*.egg
MANIFEST

data/
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
11 changes: 11 additions & 0 deletions course/module-2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
help:
@grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done

local-start: # Buil and start mongodb and mq.
docker-compose -f docker-compose.yml up --build -d

local-start-cdc: # Start CDC system
python cdc.py

local-test-cdc: #Test CDC system by inserting data to mongodb
python test_cdc.py
48 changes: 29 additions & 19 deletions course/module-2/cdc.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
import json
import logging

from bson import json_util

from data_flow.mq import publish_to_rabbitmq
from db.mongo import MongoDatabaseConnector

# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")


def stream_process():
# Setup MongoDB connection
client = MongoDatabaseConnector()
db = client["scrabble"]

# Watch changes in a specific collection
changes = db.watch([{"$match": {"operationType": {"$in": ["insert"]}}}])
for change in changes:
data_type = change["ns"]["coll"]
entry_id = str(change["fullDocument"]["_id"]) # Convert ObjectId to string
change["fullDocument"].pop("_id")
change["fullDocument"]["type"] = data_type
change["fullDocument"]["entry_id"] = entry_id

# Use json_util to serialize the document
data = json.dumps(change["fullDocument"], default=json_util.default)
print("aici")

# Send data to rabbitmq
publish_to_rabbitmq(queue_name="test_queue", data=data)
try:
# Setup MongoDB connection
client = MongoDatabaseConnector()
db = client["scrabble"]
logging.info("Connected to MongoDB.")

# Watch changes in a specific collection
changes = db.watch([{"$match": {"operationType": {"$in": ["insert"]}}}])
for change in changes:
data_type = change["ns"]["coll"]
entry_id = str(change["fullDocument"]["_id"]) # Convert ObjectId to string
change["fullDocument"].pop("_id")
change["fullDocument"]["type"] = data_type
change["fullDocument"]["entry_id"] = entry_id

# Use json_util to serialize the document
data = json.dumps(change["fullDocument"], default=json_util.default)
logging.info(f"Change detected and serialized: {data}")

# Send data to rabbitmq
publish_to_rabbitmq(queue_name="test_queue", data=data)
logging.info("Data published to RabbitMQ.")

except Exception as e:
logging.error(f"An error occurred: {e}")


if __name__ == "__main__":
Expand Down
234 changes: 0 additions & 234 deletions course/module-2/data/mongo-1/.dbshell

This file was deleted.

2 changes: 0 additions & 2 deletions course/module-2/data/mongo-1/WiredTiger

This file was deleted.

1 change: 0 additions & 1 deletion course/module-2/data/mongo-1/WiredTiger.lock

This file was deleted.

6 changes: 0 additions & 6 deletions course/module-2/data/mongo-1/WiredTiger.turtle

This file was deleted.

Binary file removed course/module-2/data/mongo-1/WiredTiger.wt
Binary file not shown.
Binary file removed course/module-2/data/mongo-1/WiredTigerHS.wt
Binary file not shown.
Binary file removed course/module-2/data/mongo-1/_mdb_catalog.wt
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion course/module-2/data/mongo-1/mongod.lock

This file was deleted.

Binary file removed course/module-2/data/mongo-1/sizeStorer.wt
Binary file not shown.
Binary file removed course/module-2/data/mongo-1/storage.bson
Binary file not shown.
2 changes: 0 additions & 2 deletions course/module-2/data/mongo-2/WiredTiger

This file was deleted.

1 change: 0 additions & 1 deletion course/module-2/data/mongo-2/WiredTiger.lock

This file was deleted.

6 changes: 0 additions & 6 deletions course/module-2/data/mongo-2/WiredTiger.turtle

This file was deleted.

Loading

0 comments on commit 7d30fd1

Please sign in to comment.