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

Adapt to refactoring in everest-framework #678

Merged
merged 25 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:
schedule:
- cron: '37 13,1 * * *'

env:
BUILD_KIT_IMAGE: ghcr.io/everest/build-kit-alpine:v1.1.2

jobs:
build:
name: Build, Lint and Test
Expand Down Expand Up @@ -47,8 +50,8 @@ jobs:
rsync -a source/.ci/build-kit/ scripts
- name: Pull build-kit image
run: |
docker pull --quiet ghcr.io/everest/build-kit-alpine:latest
docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit
docker pull --quiet ${{ env.BUILD_KIT_IMAGE }}
docker image tag ${{ env.BUILD_KIT_IMAGE }} build-kit
- name: Compile
run: |
docker run \
Expand Down
2 changes: 1 addition & 1 deletion cmake/ev-project-bootstrap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/config-run-script.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/config-run-nodered-script.cmake)

# dependencies
require_ev_cli_version("0.0.24")
require_ev_cli_version("0.1.0")

# source generate scripts / setup
include(${CMAKE_CURRENT_LIST_DIR}/everest-generate.cmake)
16 changes: 0 additions & 16 deletions config/config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,3 @@ active_modules:
- module_id: example
implementation_id: example
module: ExampleUser
example2:
module: JsExample
example_user2:
connections:
example:
- module_id: example2
implementation_id: example
module: JsExampleUser
example3:
module: PyExample
example_user3:
connections:
example:
- module_id: example3
implementation_id: example
module: PyExampleUser
4 changes: 2 additions & 2 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---
everest-framework:
git: https://github.com/EVerest/everest-framework.git
git_tag: v0.13.0
git_tag: v0.14.0
options: ["BUILD_TESTING OFF"]
sigslot:
git: https://github.com/palacaze/sigslot
Expand Down Expand Up @@ -80,7 +80,7 @@ ext-mbedtls:
# everest-testing
everest-utils:
git: https://github.com/EVerest/everest-utils.git
git_tag: 2d7ea3e4742114cb7e3b1e71b3d1e7da566e2146
git_tag: v0.2.3
cmake_condition: "EVEREST_CORE_BUILD_TESTING"

# unit testing
Expand Down
2 changes: 0 additions & 2 deletions interfaces/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ vars:
max_current:
description: Provides maximum current of this supply in ampere
type: number
errors:
- reference: /errors/example
7 changes: 7 additions & 0 deletions interfaces/example_error_framework.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: >-
This is an example interface used for the error framework example modules.
errors:
- reference: /errors/example#/ExampleErrorA
- reference: /errors/example#/ExampleErrorB
- reference: /errors/example#/ExampleErrorC
- reference: /errors/example#/ExampleErrorD
5 changes: 0 additions & 5 deletions interfaces/example_user.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
description: >-
This interface defines an example_user interface that uses the example
interface
errors:
- reference: /errors/example#/ExampleErrorA
- reference: /errors/example#/ExampleErrorB
- reference: /errors/example#/ExampleErrorC
- reference: /errors/example#/ExampleErrorD
39 changes: 23 additions & 16 deletions modules/ErrorHistory/ErrorDatabaseSqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ void ErrorDatabaseSqlite::reset_database() {
"type TEXT NOT NULL,"
"description TEXT NOT NULL,"
"message TEXT NOT NULL,"
"from_module TEXT NOT NULL,"
"from_implementation TEXT NOT NULL,"
"origin_module TEXT NOT NULL,"
"origin_implementation TEXT NOT NULL,"
"timestamp TEXT NOT NULL,"
"severity TEXT NOT NULL,"
"state TEXT NOT NULL);";
"state TEXT NOT NULL,"
"sub_type TEXT NOT NULL);";
db.exec(sql);
} catch (std::exception& e) {
EVLOG_error << "Error creating database: " << e.what();
Expand All @@ -100,19 +101,20 @@ void ErrorDatabaseSqlite::add_error_without_mutex(Everest::error::ErrorPtr error
BOOST_LOG_FUNCTION();
try {
SQLite::Database db(this->db_path.string(), SQLite::OPEN_READWRITE);
std::string sql = "INSERT INTO errors(uuid, type, description, message, from_module, from_implementation, "
"timestamp, severity, state) VALUES(";
sql += "?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9);";
std::string sql = "INSERT INTO errors(uuid, type, description, message, origin_module, origin_implementation, "
"timestamp, severity, state, sub_type) VALUES(";
sql += "?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10);";
SQLite::Statement stmt(db, sql);
stmt.bind(1, error->uuid.to_string());
stmt.bind(2, error->type);
stmt.bind(3, error->description);
stmt.bind(4, error->message);
stmt.bind(5, error->from.module_id);
stmt.bind(6, error->from.implementation_id);
stmt.bind(5, error->origin.module_id);
stmt.bind(6, error->origin.implementation_id);
stmt.bind(7, Everest::Date::to_rfc3339(error->timestamp));
stmt.bind(8, Everest::error::severity_to_string(error->severity));
stmt.bind(9, Everest::error::state_to_string(error->state));
stmt.bind(10, error->sub_type);
stmt.exec();
} catch (std::exception& e) {
EVLOG_error << "Error adding error to database: " << e.what();
Expand All @@ -127,11 +129,11 @@ std::string ErrorDatabaseSqlite::filter_to_sql_condition(const Everest::error::E
condition = "(state = '" + Everest::error::state_to_string(filter.get_state_filter()) + "')";
} break;
case Everest::error::FilterType::Origin: {
condition = "(from_module = '" + filter.get_origin_filter().module_id + "' AND " + "from_implementation = '" +
filter.get_origin_filter().implementation_id + "')";
condition = "(origin_module = '" + filter.get_origin_filter().module_id + "' AND " +
"origin_implementation = '" + filter.get_origin_filter().implementation_id + "')";
} break;
case Everest::error::FilterType::Type: {
condition = "(type = '" + filter.get_type_filter() + "')";
condition = "(type = '" + filter.get_type_filter().value + "')";
} break;
case Everest::error::FilterType::Severity: {
switch (filter.get_severity_filter()) {
Expand All @@ -156,6 +158,9 @@ std::string ErrorDatabaseSqlite::filter_to_sql_condition(const Everest::error::E
case Everest::error::FilterType::Handle: {
condition = "(uuid = '" + filter.get_handle_filter().to_string() + "')";
} break;
case Everest::error::FilterType::SubType: {
condition = "(sub_type = '" + filter.get_sub_type_filter().value + "')";
} break;
}
return condition;
}
Expand Down Expand Up @@ -196,17 +201,19 @@ std::list<Everest::error::ErrorPtr> ErrorDatabaseSqlite::get_errors(const std::o
const Everest::error::ErrorType err_type(stmt.getColumn("type").getText());
const std::string err_description = stmt.getColumn("description").getText();
const std::string err_msg = stmt.getColumn("message").getText();
const std::string err_from_module_id = stmt.getColumn("from_module").getText();
const std::string err_from_impl_id = stmt.getColumn("from_implementation").getText();
const ImplementationIdentifier err_from(err_from_module_id, err_from_impl_id);
const std::string err_origin_module_id = stmt.getColumn("origin_module").getText();
const std::string err_origin_impl_id = stmt.getColumn("origin_implementation").getText();
const ImplementationIdentifier err_origin(err_origin_module_id, err_origin_impl_id);
const Everest::error::Error::time_point err_timestamp =
Everest::Date::from_rfc3339(stmt.getColumn("timestamp").getText());
const Everest::error::Severity err_severity =
Everest::error::string_to_severity(stmt.getColumn("severity").getText());
const Everest::error::State err_state = Everest::error::string_to_state(stmt.getColumn("state").getText());
const Everest::error::ErrorHandle err_handle(Everest::error::ErrorHandle(stmt.getColumn("uuid").getText()));
Everest::error::ErrorPtr error = std::make_shared<Everest::error::Error>(
err_type, err_msg, err_description, err_from, err_severity, err_timestamp, err_handle, err_state);
const Everest::error::ErrorSubType err_sub_type(stmt.getColumn("sub_type").getText());
Everest::error::ErrorPtr error =
std::make_shared<Everest::error::Error>(err_type, err_sub_type, err_msg, err_description, err_origin,
err_severity, err_timestamp, err_handle, err_state);
result.push_back(error);
}
} catch (std::exception& e) {
Expand Down
3 changes: 2 additions & 1 deletion modules/ErrorHistory/ErrorDatabaseSqlite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class ErrorDatabaseSqlite : public Everest::error::ErrorDatabase {
public:
explicit ErrorDatabaseSqlite(const fs::path& db_path_, const bool reset_ = false);

void add_error(Everest::error::ErrorPtr error) override;
std::list<Everest::error::ErrorPtr>
get_errors(const std::list<Everest::error::ErrorFilter>& filters) const override;

void add_error(Everest::error::ErrorPtr error) override;
std::list<Everest::error::ErrorPtr> edit_errors(const std::list<Everest::error::ErrorFilter>& filters,
EditErrorFunc edit_func) override;
std::list<Everest::error::ErrorPtr> remove_errors(const std::list<Everest::error::ErrorFilter>& filters) override;
Expand Down
7 changes: 4 additions & 3 deletions modules/ErrorHistory/error_history/error_historyImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ error_historyImpl::handle_get_errors(types::error_history::FilterArguments& filt
std::string string_severity = Everest::error::severity_to_string(error->severity);
error_object.severity = types::error_history::string_to_severity(string_severity);
error_object.type = error->type;
error_object.origin.module_id = error->from.module_id;
error_object.origin.implementation_id = error->from.implementation_id;
error_object.sub_type = error->sub_type;
error_object.origin.module_id = error->origin.module_id;
error_object.origin.implementation_id = error->origin.implementation_id;
error_object.message = error->message;
error_object.description = error->description;
return error_object;
Expand All @@ -105,7 +106,7 @@ error_historyImpl::handle_get_errors(types::error_history::FilterArguments& filt

void error_historyImpl::handle_global_all_errors(const Everest::error::Error& error) {
Everest::error::ErrorPtr error_ptr = std::make_shared<Everest::error::Error>(error);
this->db->add_error(error_ptr); // LTODO check if error is already in db -> write test case
this->db->add_error(error_ptr);
}

void error_historyImpl::handle_global_all_errors_cleared(const Everest::error::Error& error) {
Expand Down
2 changes: 1 addition & 1 deletion modules/ErrorHistory/error_history/error_historyImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class error_historyImpl : public error_historyImplBase {
error_historyImplBase(ev, "error_history"), mod(mod), config(config){};

// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1
// insert your public definitions here
friend class ErrorDatabaseSqlite; // for write access to db
// ev@8ea32d28-373f-4c90-ae5e-b4fcc74e2a61:v1

protected:
Expand Down
28 changes: 15 additions & 13 deletions modules/ErrorHistory/tests/error_database_sqlite_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
}
WHEN("Adding an error") {
std::vector<Everest::error::ErrorPtr> test_errors = {std::make_shared<Everest::error::Error>(
"test_type", "test_message", "test_description",
ImplementationIdentifier("test_from_module", "test_from_implementation"), Everest::error::Severity::Low,
date::utc_clock::now(), Everest::error::UUID(), Everest::error::State::Active)};
"test_type", "test_sub_type", "test_message", "test_description",
ImplementationIdentifier("test_origin_module", "test_origin_implementation"),
Everest::error::Severity::Low, date::utc_clock::now(), Everest::error::UUID(),
Everest::error::State::Active)};
db.add_error(test_errors.at(0));
THEN("The error should be in the database") {
check_expected_errors_in_list(test_errors, db.get_errors(std::list<Everest::error::ErrorFilter>()));
Expand All @@ -30,13 +31,13 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
WHEN("Adding multiple errors") {
std::vector<Everest::error::ErrorPtr> test_errors = {
std::make_shared<Everest::error::Error>(
"test_type_a", "test_message_a", "test_description_a",
ImplementationIdentifier("test_from_module_a", "test_from_implementation_a"),
"test_type_a", "test_sub_type_a", "test_message_a", "test_description_a",
ImplementationIdentifier("test_origin_module_a", "test_origin_implementation_a"),
Everest::error::Severity::High, date::utc_clock::now(), Everest::error::UUID(),
Everest::error::State::ClearedByModule),
std::make_shared<Everest::error::Error>(
"test_type_b", "test_message_b", "test_description_b",
ImplementationIdentifier("test_from_module_b", "test_from_implementation_b"),
"test_type_b", "test_sub_type_b", "test_message_b", "test_description_b",
ImplementationIdentifier("test_origin_module_b", "test_origin_implementation_b"),
Everest::error::Severity::Medium, date::utc_clock::now(), Everest::error::UUID(),
Everest::error::State::ClearedByReboot)};
for (Everest::error::ErrorPtr error : test_errors) {
Expand Down Expand Up @@ -71,7 +72,7 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
}
WHEN("Getting all errors with OriginFilter") {
auto errors = db.get_errors({Everest::error::ErrorFilter(
Everest::error::OriginFilter("test_from_module_a", "test_from_implementation_a"))});
Everest::error::OriginFilter("test_origin_module_a", "test_origin_implementation_a"))});
THEN("The result should contain specific errors") {
std::vector<Everest::error::ErrorPtr> expected_errors(
{test_errors[0], test_errors[2], test_errors[4], test_errors[6], test_errors[8], test_errors[10]});
Expand Down Expand Up @@ -115,7 +116,7 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
WHEN("Getting all errors with multiple filters") {
auto errors = db.get_errors({Everest::error::ErrorFilter(Everest::error::StateFilter::Active),
Everest::error::ErrorFilter(Everest::error::OriginFilter(
"test_from_module_a", "test_from_implementation_a"))});
"test_origin_module_a", "test_origin_implementation_a"))});
THEN("The result should contain specific errors") {
std::vector<Everest::error::ErrorPtr> expected_errors({test_errors[4]});
check_expected_errors_in_list(expected_errors, errors);
Expand All @@ -125,7 +126,7 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
auto errors = db.get_errors({
Everest::error::ErrorFilter(Everest::error::StateFilter::ClearedByModule),
Everest::error::ErrorFilter(
Everest::error::OriginFilter("test_from_module_a", "test_from_implementation_a")),
Everest::error::OriginFilter("test_origin_module_a", "test_origin_implementation_a")),
Everest::error::ErrorFilter(Everest::error::TypeFilter("test_type_c")),
Everest::error::ErrorFilter(Everest::error::SeverityFilter::HIGH_GE),
});
Expand Down Expand Up @@ -208,14 +209,15 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
std::list<Everest::error::ErrorFilter> filters = {
Everest::error::ErrorFilter(Everest::error::HandleFilter(test_errors[4]->uuid))};
Everest::error::ErrorDatabase::EditErrorFunc edit_func = [](Everest::error::ErrorPtr error) {
error->from = ImplementationIdentifier("new_from_module", "new_from_implementation");
error->origin = ImplementationIdentifier("new_origin_module", "new_origin_implementation");
};
REQUIRE(db.get_errors(filters).size() > 0);
db.edit_errors(filters, edit_func);
THEN("The error should be edited") {
auto errors = db.get_errors(filters);
REQUIRE(errors.size() == 1);
REQUIRE(errors.front()->from == ImplementationIdentifier("new_from_module", "new_from_implementation"));
REQUIRE(errors.front()->origin ==
ImplementationIdentifier("new_origin_module", "new_origin_implementation"));
}
}
WHEN("Edit error timestamp") {
Expand Down Expand Up @@ -265,7 +267,7 @@ SCENARIO("Check ErrorDatabaseSqlite class", "[!throws]") {
std::list<Everest::error::ErrorFilter> filters = {
Everest::error::ErrorFilter(Everest::error::StateFilter::Active),
Everest::error::ErrorFilter(
Everest::error::OriginFilter("test_from_module_c", "test_from_implementation_c"))};
Everest::error::OriginFilter("test_origin_module_c", "test_origin_implementation_c"))};
REQUIRE(db.get_errors(filters).size() > 0);
db.remove_errors(filters);
THEN("The errors should be removed") {
Expand Down
Loading
Loading