Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baf 849/fleet management #35

Merged
merged 23 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4ab18c1
added fleet management and integration layer
MarioIvancik May 7, 2024
65ef57f
added fleet init script
MarioIvancik May 9, 2024
ae3be64
update module gateway
MarioIvancik May 10, 2024
4fe8301
update components
MarioIvancik May 14, 2024
90968e1
add necessary requirements for fleet-init
MarioIvancik May 20, 2024
413bb25
adjust ES mqtt timeout
MarioIvancik May 20, 2024
1847e8e
added common issues to readme
MarioIvancik May 20, 2024
7fcd99e
updated components
MarioIvancik May 31, 2024
d4682c2
update fleet init to 3.1.0
MarioIvancik May 31, 2024
48fa3e4
update API configs
MarioIvancik May 31, 2024
1d7aa83
revert to 2.3.2 management
MarioIvancik May 31, 2024
bdf6a0d
added virtual fleet management
Melky-Phoe Jun 4, 2024
18dca77
Merge remote-tracking branch 'origin/BAF-849/fleet_management' into B…
Melky-Phoe Jun 4, 2024
c38d5ea
added scenario dir ovverride for env argument
Melky-Phoe Jun 4, 2024
1ca0a2e
fleet init for management 3.1.0
MarioIvancik Jun 4, 2024
ecfc0cf
updated component tags
MarioIvancik Jun 14, 2024
f647e53
fix fleet-init readme
MarioIvancik Jun 14, 2024
26a1cbc
BAF-686 add statesmurf scenarios (#36)
Melky-Phoe Jun 17, 2024
69c0aac
Add volume for integration layer logs (#37)
jiristrouhal Jun 17, 2024
25efb33
Virtual Fleet Management documentation
Melky-Phoe Jun 21, 2024
6555dda
redo old info about mosquitto
Melky-Phoe Jun 21, 2024
80a33af
fleet management api v3.1.6; integration layer v2.0.1
MarioIvancik Jun 21, 2024
8d4a224
Merge branch 'BAF-849/fleet_management' of github.com:bringauto/etna …
MarioIvancik Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "fleet-protocol"]
path = fleet-protocol
url = https://github.com/bringauto/fleet-protocol.git
[submodule "scripts/fleet-init"]
path = scripts/fleet-init
url = https://github.com/bringauto/fleet-init.git
105 changes: 86 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# BringAuto virtual development platform

It's intended to simplify development for [Fleet] and The Autonomy developers.
Expand All @@ -8,16 +7,21 @@ The system can be used by docker compose stored at the git root of this reposito
There are multiple containers

- VerneMQ MQTT broker (bringauto/vernemq)
- Virtual Vehicle Utility - Mission module client implementation (it connects to Module Gateway and simulates an Mission module's autonomy device)
- Virtual Vehicle Utility - Mission module client implementation (it connects to Module Gateway and simulates a Mission
module's autonomy device)
- Virtual PLC - IO module client
- Module Gateway - cpp implementation of Module Gateway with Mission, IO and example module support
- External server - server implementation with Mission, IO and example module support
- HTTP API Server - tool for communication with final endpoint, used by mission module
- Integration layer - a bridge between the HTTP API and the Fleet Management API
- Fleet Management API - an API that handles creating orders for cars and displaying their state
- Virtual Fleet Management - application simulating Fleet Management. It creates orders for cars.
- PostgreSQL database - storage of the HTTP API api keys and the messages sent via the API

## Fleet Protocol

To read more about the system architecture look at Fleet Protocol v2 documentation:

- [Summary]
- [Fleet Protocol Requirements]
- [Internal Client]
Expand All @@ -31,7 +35,7 @@ To read more about the system architecture look at Fleet Protocol v2 documentati
- [HTTP API]
- [HTTP API Wait Mechanism]

To use Fleet Protocol v1, use the latest release on [GitHub](https://github.com/bringauto/etna/tree/v1.2.2).
To use Fleet Protocol v1, use the latest v1 release on [GitHub](https://github.com/bringauto/etna/tree/v1.2.2).

## Requirements

Expand All @@ -40,63 +44,109 @@ To use Fleet Protocol v1, use the latest release on [GitHub](https://github.com/

## Usage


Docker compose file has multiple profiles so the developer can disable/enable parts of the system he needs

- all - start all containers including MQTT, virtual vehicle, daemon, and virtual fleet
- without-module-gateway - do not start Module Gateway
- without-external-server - do not start External Server
- without-devices - do not start internal clients
- without-fleet-management - do not start Virtual Fleet Management
- core - start only internal clients and Module Gateway
- virtual-vehicle-utility - start only Virtual Vehicle Utility
- virtual-plc - start only Virtual PLC
- mqtt - start only MQTT vernemq broker
- module-gateway - start only Module Gateway
- http-api - start HTTP API server and the related PostgreSQL database
- http-api - start HTTP API server and the related PostgreSQL database

Now you can run `docker-compose --profile=<profile> up` where `profile` is the name of the profile above.
Now you can run `docker compose --profile <profile> up` where `profile` is the name of the profile above.

To run components with different arguments you can edit the configuration files placed under configuration/<component>

### HTTP API
To show the OpenAPI specification (the service must be running), visit http://localhost:8080/openapi.json.
To explore the API endpoints and entities, visit http://localhost:8080/ui. More on Swagger UI is [here](https://swagger.io/tools/swagger-ui/).

The HTTP API requires authentication via API keys. To access all its endpoints, you can use the key `StaticAccessKeyToBeUsedByDevelopersOnEtna`.
To show the OpenAPI specification (the service must be running), visit http://localhost:8080/v2/protocol/openapi.json.
To explore the API endpoints and entities, visit http://localhost:8080/v2/protocol/ui. More on Swagger UI
is [here](https://swagger.io/tools/swagger-ui/).

The HTTP API requires authentication via API keys. To access all its endpoints, you can use the
key `ProtocolStaticAccessKey`.

The database access information and message cleanup can be set in the `configuration/http-api/config.json` (this config
overwrites the original config from the http-api image).

### Fleet Management API

To show the OpenAPI specification (the service must be running), visit http://localhost:8081/v2/management/openapi.json.
To explore the API endpoints and entities, visit http://localhost:8081/v2/management/ui. More on Swagger UI
is [here](https://swagger.io/tools/swagger-ui/).

The Fleet Management API requires authentication via API keys. To access all its endpoints, you can use the
key `ManagementStaticAccessKey`.

The database access information and the number of stored states and orders can be set
in `configuration/management-api/config.json` (this config overwrites the original config from the management-api
image).

The database access information and message cleanup can be set in the `configuration/http-api/config.json` (this config overwrites the original config from the http-api image).
### Virtual Fleet Management

Simulates the Fleet Management ([documentation](https://github.com/bringauto/virtual-fleet-management/blob/main/README.md).

The Virtual Fleet Management uses `env` variables to set:
- **ETNA_VFM_SCENARIO** : Changes the scenario that the Virtual Fleet Management will use.
- **ETNA_VFM_CONFIG** : Changes the configuration of the Virtual Fleet Management.

All the scenarios and configurations must be stored in the `configuration/virtual-fleet-management` directory, so the docker container has access to it.
Both variables have default values, so the Virtual Fleet Management can be started without setting them.

### Common Issues

- external-server and module-gateway connect sequence
- mqtt tends to be unstable in some cases, which could lead to problems in ES and MG communication. Consider
changing the mqtt_timeout in ES config if there are connection problems (numbers greater than 15 and no multiples
of 15 should be used)
- postgresql databases
- databases are created only on container creation (if you have an old container, it needs to be deleted)
- http APIs
- by default API containers wait for the postgresql database to be available. If the database fails to initialize,
the containers won't start

## MQTT IP and Port

The MQTT uses a standard plain (not encrypted) connection on port 1883 and an SSL encrypted connection on port 8883.

There are [pregenerated certificate files] for both, server and client, however, it is not recommended to use those, and they are there for Etna to work out-of-box.
There are [pregenerated certificate files] for both, server and client, however, it is not recommended to use those, and
they are there for Etna to work out-of-box.

If you generate new certificate files they must have the same name as the original, otherwise, you have to change the paths in file `configuration/mosquitto/mosquitto.conf`.
If you generate new certificate files they must have the same name as the original, otherwise, you have to change the
paths in file `configuration/mosquitto/mosquitto.conf`.

> Directory `configuration/mosquitto/certs`, include files `cacert.pem` (certificate authority), `server.crt` (signed certificate for the server) and `server.key` (servers private key).
> Directory `configuration/mosquitto/certs`, include files `cacert.pem` (certificate authority), `server.crt` (signed
> certificate for the server) and `server.key` (servers private key).

## Topics to listen

Each MQTT topic consist from `company_name` and `car_name`.

BringAuto has the following MQTT topics

- \<company_name>/\<vehicle_name>/module_gateway
- \<company_name>/\<vehicle_name>/external_server

where each variable can be changed by the .env file, variable names to be saved there are in parentheses.

- `company_name` is by default set to "bringauto" (COMPANY)
- `vehicle_name` is by default set to "virtual_vehicle" (VEHICLE_NAME)


Actual MQTT topics to which developers can connect by default settings are:

- bringauto/virtual_vehicle/module_gateway
- bringauto/virtual_vehicle/external_server


## Logs

Logs for each component can be found in the `docker_volumes` directory.
> The component directories are pre-created in the repository to avoid permission problems associated with docker volumes.
Logs for each component can be found in the `docker_volumes` directory.
> The component directories are pre-created in the repository to avoid permission problems associated with docker
> volumes.

In case of a problem please attach the `docker_volumes` directory to the Bug report.

Expand All @@ -105,25 +155,42 @@ In case of a problem please attach the `docker_volumes` directory to the Bug rep
There are example scripts for sniffing communication and seeing the basics [scripts/]

## Bug solving
If your mosquitto logs contain lines as below, make sure mosquitto.conf file uses LF line ending. (CRLF doesn't work)

Docker container can have error similar to this:
```
Error: Invalid require_certificate value (false
Error found at /mosquitto/config/mosquitto.conf:2.
```
If this happens, make sure the mentioned file uses LF line ending. (CRLF doesn't work)

[Fleet]: https://github.com/bringauto/fleet

[Google Artifacts Registry]: https://console.cloud.google.com/artifacts/docker/bringauto-infrastructure/europe-west1/virtual-platform?hl=cs&project=bringauto-infrastructure

[pregenerated certificate files]: configuration/mosquitto/certs

[scripts/]: scripts/

[Summary]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/summary

[Fleet Protocol Requirements]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/protocol-requirements

[Internal Client]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client

[Module Gateway]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/module-gateway

[External Server]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/external-server

[Modules]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/modules

[Message Structure]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/message-structure
[Internal Client design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client-design

[Internal Client design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client-design

[Module Gateway design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/module-gateway-design

[External Server design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/external-server-design

[HTTP API]: https://ref.bringautofleet.com/r/protocol/http-api/1.0.0/http-api

[HTTP API Wait Mechanism]: https://ref.bringautofleet.com/r/protocol/http-api/1.0.0/wait-mechanism
6 changes: 3 additions & 3 deletions configuration/external-server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"car_name": "virtual_vehicle",
"mqtt_address": "172.17.0.1",
"mqtt_port": 1883,
"mqtt_timeout": 60,
"mqtt_timeout": 20,
"timeout": 60,
"send_invalid_command": false,
"sleep_duration_after_connection_refused": 0.5,
Expand All @@ -15,7 +15,7 @@
"lib_path": "/home/bringauto/modules/mission_module/lib/libmission-external-server-shared.so",
"config": {
"api_url": "http://http-api:8080/v2/protocol",
"api_key": "StaticAccessKeyToBeUsedByDevelopersOnEtna",
"api_key": "ProtocolStaticAccessKey",
"max_requests_threshold_count": "5",
"max_requests_threshold_period_ms": "1000",
"delay_after_threshold_reached_ms": "500",
Expand All @@ -26,7 +26,7 @@
"lib_path": "/home/bringauto/modules/io_module/lib/libio-external-server-shared.so",
"config": {
"api_url": "http://http-api:8080/v2/protocol",
"api_key": "StaticAccessKeyToBeUsedByDevelopersOnEtna",
"api_key": "ProtocolStaticAccessKey",
"max_requests_threshold_count": "5",
"max_requests_threshold_period_ms": "1000",
"delay_after_threshold_reached_ms": "500",
Expand Down
5 changes: 2 additions & 3 deletions configuration/http-api/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"port": 5432,
"username": "postgres",
"password": "1234",
"database_name": "postgres"
"database_name": "protocol_api"
},
"cleanup": {
"timing_in_seconds": {
Expand All @@ -26,7 +26,6 @@
"client_id": "",
"client_secret_key": "",
"scope": "",
"realm": "",
"keycloak_public_key_file": "config/keycloak.pem"
"realm": ""
}
}
16 changes: 16 additions & 0 deletions configuration/integration-layer/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"protocol": {
"host": "http://http-api:8080/v2/protocol",
"api_key": "ProtocolStaticAccessKey",
"autonomy_device_id":
{
"module_id": 1,
"type": 1,
"role": "autonomy"
}
},
"management": {
"host": "http://management-api:8081/v2/management",
"api_key": "ManagementStaticAccessKey"
}
}
89 changes: 89 additions & 0 deletions configuration/integration-layer/logging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "[%(asctime)s.%(msecs)03d] [integration-layer] [%(levelname)s]\t %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "simple",
"filename": "/usr/src/app/log/fleet-management-integration-layer.log"
}
},
"loggers": {
"fleetman_integration.protocol.checker": {
"level": "DEBUG",
"handlers": [
"console",
"file"
],
"propagate": false
},
"fleetman_integration.layer": {
"level": "DEBUG",
"handlers": [
"console",
"file"
],
"propagate": false
},
"fleetman_integration.protocol.handler": {
"level": "DEBUG",
"handlers": [
"console",
"file"
],
"propagate": false
},
"fleetman_integration.protocol.api_adapter": {
"level": "DEBUG",
"handlers": [
"console",
"file"
],
"propagate": false
},
"fleetman_integration.management.checker": {
"level": "DEBUG",
"handlers": [
"console",
"file"
],
"propagate": false
},
"fleetman_integration.management.handler": {
"level": "DEBUG",
"handlers": [
"console",
"file"
],
"propagate": false
},
"fleetman_integration.management.api_adapter": {
"level": "DEBUG",
"handlers": [
"console",
"file"
],
"propagate": false
}
},
"root": {
"level": "DEBUG",
"handlers": [
"console",
"file"
]
}
}
Loading