-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config restructure: distribute module configs via MQTT (#201)
Changes to reduce configuration parsing effort by parsing it once by the manager and then distribute it to the modules via MQTT. This is achieved by first parsing the MQTT settings from the config, passing these to the modules whilst spawning them. The modules themselves then ask for their module config via MQTT, which is in turn provided to them from the manager. schemas, manifests, types, interfaces, error definitions are published as retained topics that modules can access when needed. * Enable code coverage * Update clang-format lint job to use v1.3.1 of run-clang-format * Add additional Config tests * Add user-config test * Add test for module that has an interface using types that implements a cmd and a var * Add simple config serialization test * Add test for config file in legacy json format * Add test for config file that does not exist * Exit early if parse_command_line returned false This is for example the case in the --help and --version parameters * Log an error if a wrong module is started for a given module id This can happen if the wrong binary is manually selected for a standalone module * Update clang-tidy config * Add RuntimeSettings as member to ManagerSettings to avoid code duplication * Move filesystem helper functions into their own header * Move BootException to the types header * Use a shared MQTTAbstraction for config getting and EVerest afterwards * Add misc-const-correctness check to clang-tidy config Reorder checks so enabled checks come first, followed by checks that are deactivated * Use std::size_t to avoid narrowing conversions * Use int64_t instead of int in return value to avoid narrowing conversion * Use constexpr instead of define for MQTT_BUF_SIZE * Fix config not being checked in check_config command * Move version_information.txt filename to constant * Move MQTT get timeout to constant * Use std::size_t everywhere * re-order member ConfigBase, ManagerConfig and Config implementations this now better reflects the order from the config header file that got shuffled around during breaking up into different classes * Add ImplementationInfo struct replacing json * Add build* to .gitignore * Make extract_implementation_info into a free function Add create_printable_identifier free function and use it in the member function * Move MQTTSettings into its own files * Use factory method create_mqtt_client to initialize MQTTAbstractionImpl based on MQTTSettings * Remove lcov coverage, add gcovr xml coverage report Move this configuration to tests/CMakeLists.txt * Reduce usage of using for nlohmann::json in headers * Re-introduce functionality to RuntimeSession ctor with config file param This prevents everest-testing from breaking until it is refactored to use the new ctor + environment variables * Updated catch2 to latest stable release 3.7.1 * Move testing logic to tests subdir Set coverage flags directly on the appropriate targets To make this work from the tests directory set CMake policy CMP0079 * Re-use the config that's already loaded in the ManagerSettings Don't load the same yaml file twice * Bump version to 0.19.0 * Add documentation with sequence and class diagrams about MQTT config feature Signed-off-by: Kai-Uwe Hermann <[email protected]> * refactor(tests): dry Signed-off-by: aw <[email protected]> --------- Signed-off-by: Kai-Uwe Hermann <[email protected]> Signed-off-by: aw <[email protected]> Co-authored-by: aw <[email protected]>
- Loading branch information
1 parent
09fb55f
commit 72dec12
Showing
82 changed files
with
3,314 additions
and
1,561 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
Checks: > | ||
*, | ||
bugprone*, | ||
misc-const-correctness, | ||
-llvmlibc*, | ||
-fuchsia-default-arguments-calls, | ||
-fuchsia-overloaded-operator, | ||
-fuchsia-statically-constructed-objects, | ||
-readability-function-cognitive-complexity, | ||
-modernize-use-trailing-return-type, | ||
-abseil-string-find-startswith, | ||
-abseil-string-find-str-contains | ||
HeaderFilterRegex: ".*" | ||
-abseil-string-find-str-contains, | ||
-readability-identifier-length, | ||
-fuchsia-default-arguments-calls, | ||
-fuchsia-default-arguments-declarations, | ||
-altera-struct-pack-align, | ||
-performance-enum-size, | ||
-altera*, | ||
-misc-non-private-member-variables-in-classes, | ||
-cppcoreguidelines-non-private-member-variables-in-classes, | ||
-bugprone-easily-swappable-parameters | ||
HeaderFilterRegex: ".*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
*build | ||
*build-cross | ||
build* | ||
!everestrs-build | ||
target | ||
bazel-bin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Module configuration distributed via MQTT | ||
|
||
Since everest-framework 0.19.0 the module configuration is parsed once | ||
by the manager and then distributed to the modules via MQTT. | ||
This is achieved by parsing the MQTT settings from the config, | ||
spawning the modules and passing these MQTT settings to them. | ||
The modules themselves then ask for their module config via MQTT, | ||
which is in turn provided to them from the manager. | ||
After the modules have received their config, their init() function is called. | ||
Afterwards they signal ready to the manager. | ||
The manager sends out the global ready signal | ||
once it has received all Module ready signals. | ||
|
||
The following sequence diagram illustrates this startup process | ||
|
||
```mermaid | ||
sequenceDiagram | ||
create participant manager | ||
create participant ManagerSettings | ||
manager-)ManagerSettings: ManagerSettings(prefix, config_path) | ||
ManagerSettings-->>manager: return ms | ||
create participant ManagerConfig | ||
manager-)ManagerConfig: ManagerConfig(ms) | ||
create participant MQTTAbstraction | ||
manager-)MQTTAbstraction: MQTTAbstraction(ms.mqtt_settings) | ||
MQTTAbstraction-->>manager: return mqtt_abstraction | ||
activate manager | ||
manager->>manager: start_modules() | ||
manager->>ManagerConfig: serialize() | ||
ManagerConfig-->>manager: serialized_config | ||
manager->>MQTTAbstraction: publish(interfaces, types, schemas, manifests, settings, retain=true) | ||
loop For every module | ||
manager->>manager: spawn_modules(Module) | ||
create participant Module | ||
manager->>Module: spawn Module | ||
Module->>MQTTAbstraction: get(Config) | ||
MQTTAbstraction->>manager: get(Config of Module) | ||
manager-->>MQTTAbstraction: publish(module configs, mappings) | ||
MQTTAbstraction-->>Module: publish(module configs, mappings) | ||
Module->>Module: init | ||
Module->>MQTTAbstraction: publish(ready) | ||
MQTTAbstraction->>manager: publish(ready of Module) | ||
end | ||
manager->>MQTTAbstraction: publish global ready | ||
``` | ||
|
||
Class diagram | ||
|
||
```mermaid | ||
classDiagram | ||
ConfigBase <|-- ManagerConfig | ||
ConfigBase <|-- Config | ||
MQTTSettings *-- ConfigBase | ||
ManagerSettings *-- ManagerConfig | ||
note for ConfigBase " | ||
Baseclass containing json config, manifests, interfaces, | ||
types and functions to access this information which | ||
needs to be available in all derived classes | ||
" | ||
class ManagerSettings{ | ||
+fs::path configs_dir | ||
+fs::path schemas_dir | ||
+fs::path interfaces_dir | ||
+fs::path types_dir | ||
+fs::path errors_dir | ||
+fs::path config_file | ||
+fs::path www_dir | ||
+int controller_port | ||
+int controller_rpc_timeout_ms | ||
+std::string run_as_user | ||
+std::string version_information | ||
+nlohmann::json config | ||
+MQTTSettings mqtt_settings | ||
+std::unique_ptr<RuntimeSettings> runtime_settings | ||
+ManagerSettings(const std::string& prefix, const std::string& config) | ||
+const RuntimeSettings& get_runtime_settings() | ||
} | ||
class MQTTSettings{ | ||
+std::string broker_socket_path | ||
+std::string broker_host | ||
+int broker_port | ||
+std::string everest_prefix | ||
+std::string external_prefix | ||
+bool uses_socket() | ||
} | ||
class ConfigBase{ | ||
#const MQTTSettings mqtt_settings | ||
+ConfigBase(const MQTTSettings& mqtt_settings) | ||
} | ||
class ManagerConfig{ | ||
-const ManagerSettings& ms | ||
+ManagerConfig(const ManagerSettings& ms) | ||
+nlohmann::json serialize() | ||
-load_and_validate_manifest(const std::string& module_id, const nlohmann::json& module_config) | ||
-std::tuple~nlohmann::json, int64_t~ load_and_validate_with_schema(const fs::path& file_path, const nlohmann::json& schema) | ||
-nlohmann::json resolve_interface(const std::string& intf_name) | ||
-nlohmann::json load_interface_file(const std::string& intf_name) | ||
-resolve_all_requirements() | ||
-parse(nlohmann::json config) | ||
} | ||
class Config{ | ||
+Config(const MQTTSettings& mqtt_settings, nlohmann::json config) | ||
+bool module_provides(const std::string& module_name, const std::string& impl_id); | ||
+nlohmann::json get_module_cmds(const std::string& module_name, const std::string& impl_id) | ||
+nlohmann::json resolve_requirement(const std::string& module_id, const std::string& requirement_id) | ||
+std::list~Requirement~ get_requirements(const std::string& module_id) | ||
+RequirementInitialization get_requirement_initialization(const std::string& module_id) | ||
+ModuleConfigs get_module_configs(const std::string& module_id) | ||
+nlohmann::json get_module_json_config(const std::string& module_id) | ||
+ModuleInfo get_module_info(const std::string& module_id) | ||
+std::optional~<~TelemetryConfig~ get_telemetry_config() | ||
+nlohmann::json get_interface_definition(const std::string& interface_name) const; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Additional documentation about the inner workings of EVerest Framework | ||
|
||
[MQTT Config distribution](MQTTConfigDistribution.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.