The assignment repository for the "Fog Computing course (SS2023)" course at TU Berlin.
The code includes a sensor simulation, a Broker that can receive messages from sensors and a ReplayBroker that can synchronize with another broker through periodical replay requests.
A replay request is either a "replay all" request or a "replay_by_timestamp" request that contains timestamp of the last received message. If a broker receives a replay request, it responds with messages of the requested type. It sends all messages of given type if received "replay all" and in case of "replay_by_timestamp", it sends all messages that have timestamp > timestamp in request.
This way we ensure reliable message delivery and asynchronous data synchronization even if one of brokers goes offline.
Authors:
- Alexander Guttenberger
- Maxim Popov
The assignment deliveries can be found at root of the repository.
- Demo Video -> demo_presentation_video.mp4
- Documentation -> documentation.pdf
The repository is organized as follows:
├── README.md # Documentation file for the repository
├── LICENSE # License file
├── demo_presentation_video.mp4 # Demo video of the working solution
├── documentation.pdf # Documentation of the solution
├── deploy # Folder containing deployment files
│ ├── firewall.tf # Terraform configuration for the firewall
│ ├── output.tf # Terraform configuration for output variables
│ ├── provider.tf # Terraform configuration for the provider
│ ├── setup.sh # Shell script for setup
│ ├── ssh_into_vm.sh # Shell script for SSH into VM
│ ├── ssh_key.tf # Terraform configuration for SSH key
│ └── vm.tf # Terraform configuration for virtual machine
├── docker-compose.cloud.yml # Docker Compose configuration for cloud environment
├── prototyping_assignment.pdf # PDF file for prototyping assignment
├── requirements.txt # File listing the required Python packages
└── src # Source code folder
├── cloud_components.py # Python file for cloud components
├── fog_components.py # Python file for fog components
├── replay_broker # Folder for replay broker
│ ├── Dockerfile # Dockerfile for replay broker
│ ├── __init__.py # Initialization file for replay broker
│ ├── broker.py # Python file for broker
│ ├── configs # Folder containing configuration files
│ │ ├── broker.yaml # YAML configuration file for broker
│ │ ├── cloud_broker.yaml # YAML configuration file for cloud broker
│ │ └── fog_broker.yaml # YAML configuration file for fog broker
│ ├── logging_formatter.py # Python file for logging formatter
│ ├── persistance.py # Python file for persistence
│ ├── replaybroker.py # Python file for replay broker
│ ├── requirements.txt # File listing the required Python packages for replay broker
│ ├── serialization.py # Python file for serialization
│ ├── start_brokers.py # Python file for starting brokers
│ ├── start_cloud.py # Python file for starting cloud
│ └── start_fog.py # Python file for starting fog
├── sensor # Folder for sensor
│ ├── Dockerfile # Dockerfile for sensor
│ ├── configs # Folder containing configuration files
│ │ ├── sensor_cloud.yaml # YAML configuration file for sensor in cloud
│ │ └── sensor_fog.yaml # YAML configuration file for sensor in fog
│ ├── requirements.txt # File listing the required Python packages for sensor
│ └── sensor.py # Python file for sensor
└── subscriber # Folder for subscriber
├── configs # Folder containing configuration files
│ └── subscriber.yaml # YAML configuration file for subscriber
├── requirements.txt # File listing the required Python packages for subscriber
└── subscriber.py # Python file for subscriber
To execute the test scenario you should follow these steps:
- Install requirements:
pip install -r requirements.txt - Install and run MongoDB
- Run fog components by executing:
python3 src/fog_components.py - Run cloud components:
python3 src/cloud_components.py
Before deploying the application, ensure you have the following:
- Terraform installed on your system.
- A Tailscale account created and Tailscale installed on your local machine.
- The Google Cloud Platform (GCP) service account key downloaded from GCP. Set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to the path of the downloaded key, for example:export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/key.json.
- Change to the deployment directory:
cd deploy. - Initialize the Terraform environment:
terraform init. - Apply the infrastructure using Terraform:
terraform apply. - SSH into the VM instance using the command:
ssh -i ssh_key.pem ubuntu@vm_ip. Replacevm_ipwith the IP address of the VM (you can find the IP address inip.txt).
- Install Tailscale by running the command:
curl -fsSL https://tailscale.com/install.sh | sh, and log in to your Tailscale account. - Start Tailscale by running:
sudo tailscale up.
- Install the required Python packages:
pip install -r requirements.txt. - Change the remote server address in the
src/replay_broker/cloud_config.ymlfile to the Tailscale IP address of your fog node. - Run the Cloud Node application:
python3 src/cloud_components.py.
- Exit the application and the SSH connection.
- To clean up and destroy the infrastructure created by Terraform, run:
terraform destroy.
- Update the remote server address in the
src/replay_broker/fog_config.ymlfile to the Tailscale IP address of your cloud node. For example, changeremote_replay_socket: "tcp://127.0.0.1:4411"toremote_replay_socket: "tcp://35.246.212.91:4411". - Start MongoDB with docker:
docker run --name mongodb -d -p 27017:27017 mongo:latest - Install the required Python packages:
pip install -r requirements.txt. - Run the Fog Node application:
python3 src/fog_components.py.