Assignment 1 - Run the application
October 7, 2021 · View on GitHub
In this assignment, you'll run the application to make sure everything works correctly.
Assignment goals
To complete this assignment, you must reach the following goals:
- All services are running.
- The logging indicates that all services are working correctly.
As a reminder, this is how the services will interact with each other:
Step 1. Run the VehicleRegistration service
-
Open the source code folder in VS Code. This guide assumes VS Code, but feel free to use an editor or IDE you're comfortable with.
Throughout the assignment you can execute all steps in the same instance of editor or IDE window.
-
Open a terminal window.
You can do this by using the hotkey
Ctrl-`(Windows) orShift-Ctrl-`(macOS). -
Make sure the current folder is
VehicleRegistrationService. -
Run the command
pip3 install -r requirements.txt -
Start the service using
uvicorn vehicle_registration:app --port 6002
Note The
uvicorncommand may not work if you're running on Linux/Ubuntu. You can run the commandsudo apt install uvicornto makeuvicornavailable on your system.
If you receive an error here, please double-check whether or not you have installed all the prerequisites for the workshop!
Now you can test whether you can call the VehicleRegistrationService. You can do this using a browser, cURL or some other HTTP client. But there is a convenient way of testing RESTful APIs directly from VS Code (this uses the REST Client extension VS Code):
-
Open the file
VehicleRegistrationService/test.httpin your editor. The request in this file simulates retrieving the vehicle- and owner information for a certain license-number. -
Click on
Send requestin the file to send a request to the API:
-
The response of the request will be shown in a separate window on the right. It should be a response with HTTP status code
200 OKand the body should contain some random vehicle and owner-information:HTTP/1.1 200 Connection: keep-alive Content-Type: application/json Date: Wed, 16 Jun 2021 19:39:05 GMT Keep-Alive: timeout=60 Transfer-Encoding: chunked { "vehicle_id": "KZ-49-VX", "brand": "Toyota", "model": "Rav 4", "owner_name": "Angelena Fairbairn", "owner_email": "angelena.fairbairn@outlook.com" } -
Check the logging in the terminal window. It should look like this:
> uvicorn vehicle_registration:app --port 6002 INFO: Started server process [29384] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:6002 (Press CTRL+C to quit) INFO: 127.0.0.1:64855 - "GET /vehicleinfo/KZ-49-VX HTTP/1.1" 200 OK
Step 2. Run the FineCollection service
-
Make sure the VehicleRegistrationService service is running (result of step 1).
-
Open a new terminal window in VS Code.
You can do this by using the hotkey (
Ctrl-`on Windows,Shift-Ctrl-`on macOS) or clicking on the+button in the terminal window title bar:
-
Make sure the current folder is
FineCollectionService. -
Run the command
pip3 install -r requirements.txt -
Start the service using
uvicorn fine_collection:app --port 6001. -
Open the file
FineCollectionService/test.httpin VS Code. The request in this file simulates sending a detected speeding-violation to the FineCollectionService. -
Click on
Execute requestin the file to send a request to the API. -
The response of the request will be shown in a separate window on the right. It should be a response with HTTP status code
200 OKand no body. -
Check the logging in the terminal window. It should look like this:
❯ uvicorn fine_collection:app --port 6001 INFO: Started server process [3108] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:6001 (Press CTRL+C to quit) INFO: 127.0.0.1:52778 - "POST /collectfine HTTP/1.1" 200 OK
Step 3. Run the TrafficControl service
-
Make sure the VehicleRegistrationService and FineCollectionService are running (results of step 1 and 2).
-
Open a new terminal window in VS Code and make sure the current folder is
TrafficControlService. -
Run the command
pip3 install -r requirements.txt -
Start the service using
uvicorn traffic_control:app --port 6000. -
Open the
TrafficControlService/test.httpfile in VS Code. -
Click on
Execute requestfor all three requests in the file to send two requests to the API. -
The response of the requests will be shown in a separate window on the right. Both requests should yield a response with HTTP status code
200 OKand no body. -
Check the logging in the terminal window. It should look like this:
❯ uvicorn traffic_control:app --port 6000 INFO: Started server process [29680] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:6000 (Press CTRL+C to quit) INFO: 127.0.0.1:56477 - "POST /entrycam HTTP/1.1" 200 OK Vehicle XT-346-Y is over the speed limit. Collecting fine INFO: 127.0.0.1:56478 - "POST /exitcam HTTP/1.1" 200 OK -
Also inspect the logging of the FineCollectionService.
You can do this by selecting another terminal window using the dropdown in the title-bar of the terminal window:

You should see the speeding-violation being handled by the FineCollectionService:
❯ uvicorn fine_collection:app --port 6001 INFO: Started server process [8728] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:6001 (Press CTRL+C to quit) INFO: 127.0.0.1:49916 - "POST /collectfine HTTP/1.1" 200 OK
Step 4. Run the simulation
You've tested the APIs directly by using a REST client. Now you're going to run the simulation that actually simulates cars driving on the highway. The simulation will simulate 3 entry- and exit-cameras (one for each lane).
-
Open a new terminal window in VS Code and make sure the current folder is
Simulation. -
Run the command
pip3 install -r requirements.txt -
Start the service using
python3 simulation. -
In the simulation window you should see something like this:
❯ python simulation Starting agent 0... Starting agent 1... Starting agent 2... Simulation started. Press Ctrl+C to exit. Sent car 20-TK-YH into the traffic control system Sent car ZD-84-GG into the traffic control system Sent car PZ-36-FF into the traffic control system -
Also check the logging in all the other Terminal windows. You should see all entry- and exit events and any speeding-violations that were detected in the logging.
Now we know the application runs correctly. It's time to start adding Dapr to the application.
Next assignment
Make sure you stop all running processes and close all the terminal windows in VS Code before proceeding to the next
assignment. Stopping a service or the simulation is done by pressing Ctrl-C in the terminal window. To close the
terminal window, enter the exit command.
You can quickly close a terminal window by clicking on the trashcan icon in its title bar:
Go to assignment 2.
