Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Heinrich <andreas.heinrich@rwth-aachen.de>
  • Loading branch information
andistorm committed Nov 3, 2023
1 parent b5950b6 commit 94a5eb7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion everestjs/everestjs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ static Napi::Value boot_module(const Napi::CallbackInfo& info) {
// connect to mqtt server and start mqtt mainloop thread
auto everest_handle = std::make_unique<Everest::Everest>(
module_id, *config, validate_schema, rs->mqtt_broker_host, rs->mqtt_broker_port, rs->mqtt_everest_prefix,
rs->mqtt_external_prefix, rs->telemetry_prefix, rs->telemetry_enabled, rs->errors_dir);
rs->mqtt_external_prefix, rs->telemetry_prefix, rs->telemetry_enabled);

ctx = new EvModCtx(std::move(everest_handle), module_manifest, env);

Expand Down
6 changes: 3 additions & 3 deletions everestpy/src/everest/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
std::unique_ptr<Everest::Everest> Module::create_everest_instance(const std::string& module_id,
const RuntimeSession& session) {
const auto& rs = session.get_runtime_settings();
return std::make_unique<Everest::Everest>(
module_id, session.get_config(), rs->validate_schema, rs->mqtt_broker_host, rs->mqtt_broker_port,
rs->mqtt_everest_prefix, rs->mqtt_external_prefix, rs->telemetry_prefix, rs->telemetry_enabled, rs->errors_dir);
return std::make_unique<Everest::Everest>(module_id, session.get_config(), rs->validate_schema,
rs->mqtt_broker_host, rs->mqtt_broker_port, rs->mqtt_everest_prefix,
rs->mqtt_external_prefix, rs->telemetry_prefix, rs->telemetry_enabled);
}

static std::string get_ev_module_from_env() {
Expand Down
4 changes: 1 addition & 3 deletions include/framework/everest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class Everest {
public:
Everest(std::string module_id, const Config& config, bool validate_data_with_schema,
const std::string& mqtt_server_address, int mqtt_server_port, const std::string& mqtt_everest_prefix,
const std::string& mqtt_external_prefix, const std::string& telemetry_prefix, bool telemetry_enabled,
const fs::path& errors_dir);
const std::string& mqtt_external_prefix, const std::string& telemetry_prefix, bool telemetry_enabled);

// forbid copy assignment and copy construction
// NOTE (aw): move assignment and construction are also not supported because we're creating explicit references to
Expand Down Expand Up @@ -185,7 +184,6 @@ class Everest {
std::string telemetry_prefix;
std::optional<TelemetryConfig> telemetry_config;
bool telemetry_enabled;
error::ErrorTypeMap error_map;

void handle_ready(json data);

Expand Down
4 changes: 4 additions & 0 deletions include/utils/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <nlohmann/json-schema.hpp>

#include <utils/config_cache.hpp>
#include <utils/error.hpp>
#include <utils/types.hpp>

namespace Everest {
Expand Down Expand Up @@ -105,7 +106,10 @@ class Config {

void load_and_validate_manifest(const std::string& module_id, const json& module_config);

error::ErrorTypeMap error_map;

public:
error::ErrorTypeMap get_error_map() const;
std::string get_module_name(const std::string& module_id);
bool module_provides(const std::string& module_name, const std::string& impl_id);
json get_module_cmds(const std::string& module_name, const std::string& impl_id);
Expand Down
5 changes: 5 additions & 0 deletions lib/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ Config::Config(std::shared_ptr<RuntimeSettings> rs, bool manager) : rs(rs), mana
this->types = json({});
this->errors = json({});
this->_schemas = Config::load_schemas(this->rs->schemas_dir);
this->error_map = error::ErrorTypeMap(this->rs->errors_dir);

// load and process config file
fs::path config_path = rs->config_file;
Expand Down Expand Up @@ -542,6 +543,10 @@ Config::Config(std::shared_ptr<RuntimeSettings> rs, bool manager) : rs(rs), mana
resolve_all_requirements();
}

error::ErrorTypeMap Config::get_error_map() const {
return this->error_map;
}

std::string Config::get_module_name(const std::string& module_id) {
return this->module_names.at(module_id);
}
Expand Down
8 changes: 2 additions & 6 deletions lib/everest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ const std::array<std::string, 3> TELEMETRY_RESERVED_KEYS = {{"connector_id"}};

Everest::Everest(std::string module_id_, const Config& config_, bool validate_data_with_schema,
const std::string& mqtt_server_address, int mqtt_server_port, const std::string& mqtt_everest_prefix,
const std::string& mqtt_external_prefix, const std::string& telemetry_prefix, bool telemetry_enabled,
const fs::path& errors_dir) :
const std::string& mqtt_external_prefix, const std::string& telemetry_prefix, bool telemetry_enabled) :
mqtt_abstraction(mqtt_server_address, std::to_string(mqtt_server_port), mqtt_everest_prefix, mqtt_external_prefix),
config(std::move(config_)),
module_id(std::move(module_id_)),
Expand Down Expand Up @@ -55,8 +54,6 @@ Everest::Everest(std::string module_id_, const Config& config_, bool validate_da
this->ready_received = false;
this->on_ready = nullptr;

this->error_map = error::ErrorTypeMap(errors_dir);

// register handler for global ready signal
Handler handle_ready_wrapper = [this](json data) { this->handle_ready(data); };
std::shared_ptr<TypedHandler> everest_ready =
Expand Down Expand Up @@ -480,8 +477,7 @@ std::string Everest::raise_error(const std::string& impl_id, const std::string&
const std::string& severity) {
BOOST_LOG_FUNCTION();

std::string description = this->error_map.get_description(error_type);
bool persistent = false;
std::string description = this->config.get_error_map().get_description(error_type);

error::Error error(error_type, message, description, this->module_id, impl_id);

Expand Down
6 changes: 3 additions & 3 deletions lib/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ int ModuleLoader::initialize() {
}
Logging::update_process_name(module_identifier);

auto everest = Everest(this->module_id, config, rs->validate_schema, rs->mqtt_broker_host, rs->mqtt_broker_port,
rs->mqtt_everest_prefix, rs->mqtt_external_prefix, rs->telemetry_prefix,
rs->telemetry_enabled, rs->errors_dir);
auto everest =
Everest(this->module_id, config, rs->validate_schema, rs->mqtt_broker_host, rs->mqtt_broker_port,
rs->mqtt_everest_prefix, rs->mqtt_external_prefix, rs->telemetry_prefix, rs->telemetry_enabled);

// module import
EVLOG_debug << fmt::format("Initializing module {}...", module_identifier);
Expand Down

0 comments on commit 94a5eb7

Please sign in to comment.