Skip to content

fog-computing-prototype/fog-computing-prototype

Repository files navigation

Prototype Assignment

Fog Computing - TU Berlin

Summer Semester 2022

License: MIT


Logo


Table of contents


Description

The task was to design and implement an application that can deal with various different challenges related to fog computing.

Requirements

  1. The application must comprise a local component that runs on a local machine, and a component running in the Cloud, e.g., on GCE.
  2. The local component must collect and make use of (simulated) environmental information. For this purpose, a minimum of two virtual sensors should be designed and used that continuously generate realistic data.
  3. Data has to be transmitted regularly (multiple times a minute) between the local component and the Cloud component in both directions.
  4. When disconnected and/or crashed, the local and Cloud component have to keep working while preserving data for later transmission. Upon reconnection, the queued data needs to be delivered.

Further notes

  • The application can be implemented in any standard programming language
  • It is not allowed to use any Cloud services or frameworks that take care of resolving fog-specific challenges, e.g., regarding reliable message delivery
    • (messaging libraries such as ZeroMQ are fine).
  • The goal of the prototype is to build a fog application and to manually implement the reliable delivery of messages.

Architecture

Logo

Diagram was created with diagrams.net.

Dashboard website

Website: Dashboard

Main page Settings
Logo Logo

In the Settings you can set the URL for the API.
You can only use https endpoints! Default value is: http://127.0.0.1:8000.

Because the website hosted on GitHub pages uses https, only https API endpoints can be called there.

Because our default scripts use only http to connect to the GCP instance, use the manual way or start the docker-compose file in ./dashboard/docker-compose.yaml. See: section: Frontend - Docker compose. Then you can reach the GCP compute engine over http.


Technology stack


Documentation


Start locally

Environment variables

Component Name Default Description
Local LOCAL_CLOUD_ENDPOINT_URL tcp://localhost:5556 The cloud component ZeroMQ endpoint url
LOCAL_LISTENER_ENDPOINT_URL tcp://*:5557 The local component ZeroMQ endpoint to bind to
Cloud CLOUD_LOCAL_ENDPOINT_URL tcp://localhost:5557 The local component ZeroMQ endpoint url
CLOUD_LISTENER_ENDPOINT_URL tcp://*:5556 The cloud component ZeroMQ endpoint to bind to

All: Local + Cloud + Dashboard

Docker compose

Use -d to start it in the background.

Run:

# Run service
docker compose up -d 
Description URL
Dashboard address http://localhost/
Cloud API http://localhost:8000
Cloud API docs http://localhost:8000/docs
Cloud API: GET sensor data http://localhost:8000/sensor-data
Cloud API: GET sensor data (ordered) http://localhost:8000/sensor-data/ordered

Local

Go into the: local/ folder.

Docker compose

Use -d to start it in the background.

Run:

# Run service
docker compose up -d 

Manually

Run:

# Install dependencies
poetry install

# Run service
poetry run python -m local.main

Cloud

Go into the: cloud/ folder.

Docker compose

Use -d to start it in the background.

Run:

# Run service
docker compose up -d 

Manually

Run:

# Install dependencies
poetry install

# Run service
poetry run uvicorn cloud.main:app

Addresses

Description URL
Cloud API http://localhost:8000
Cloud API docs http://localhost:8000/docs
Cloud API docs http://localhost:8000/docs
Cloud API: GET sensor data http://localhost:8000/sensor-data
Cloud API: GET sensor data (ordered) http://localhost:8000/sensor-data/ordered

Frontend

Go into the: dashboard/ folder.

Docker compose

Use -d to start it in the background.

Run:

# Run service
docker compose up -d 

Manually

Run:

# Install dependencies
pnpm install

# Run service
pnpm run dev

Addresses

Description URL
Dashboard address http://localhost/

Setup GCP

Create resources on GCP

  1. Follow the steps in section Credentials/Variables to setup the required variables.
  2. Edit the variables (or use the given values) in gcp-00-settings.sh.
  3. Setup the resources on GCP (GCP project, GCP compute engine, firewall settings):
  4. Setup Python and Poetry on the previously created GCP compute instance:
  5. Upload the cloud files to the GCP compute instance:
  6. Start the app in the cloud:

Credentials/Variables

Copy template file template.credentials.sh, rename it to credentials.sh and fill out the variables.

Variable name Description Example
CREDENTIALS_PATH Path to SSH folder /home/<username>/.ssh
CREDENTIAL_NAME Name of the SSH key fogcomputing
SSH_PW Password for the SSH key
COMMENT_SSH Comment for the SSH key fog-computing
PROJECT_ID Project ID on GCP fogcomputing
PROJECT_NAME Project name on GCP
USER_NAME Username of the GCP instance

Define sensors

You can define multiple sensors in the /local/sensors.yaml file. You can choose between two types of sensors temperature_sensors and humidity_sensors.

Below is an example of such a file:

temperature_sensors:
  # Recommended name schema: <sensor_type>-<location>-<number>
  - name: temperature-kitchen-01
    interval: 5 # in seconds

  - name: temperature-livingroom-01
    interval: 5

humidity_sensors:
  - name: humidity-bedroom-01
    interval: 5

API docs

API docs as image

Endpoints

Description HTTP Verb CRUD Endpoint
Cloud API docs GET Read /docs
Cloud API: GET sensor data GET Read /sensor-data
Cloud API: GET sensor data (ordered) GET Read /sensor-data/ordered