Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
andistorm committed Sep 29, 2023
1 parent 288082e commit 0faf862
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 123 deletions.
6 changes: 2 additions & 4 deletions include/framework/ModuleAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <iomanip>
#include <iostream>

#include <boost/uuid/uuid.hpp>

namespace Everest {

// FIXME (aw): does the standard library already has something like this?
Expand Down Expand Up @@ -76,9 +74,9 @@ struct ModuleAdapter {
using SubscribeFunc = std::function<void(const Requirement&, const std::string&, ValueCallback)>;
using SubscribeErrorFunc = std::function<void(const Requirement&, const std::string&, error::ErrorCallback)>;
using SubscribeErrorClearedFunc = std::function<void(const Requirement&, const std::string&, error::ErrorCallback)>;
using RaiseErrorFunc = std::function<boost::uuids::uuid(const std::string&, const std::string&, const std::string&, const error::Severity&)>;
using RaiseErrorFunc = std::function<error::ErrorHandle(const std::string&, const std::string&, const std::string&, const error::Severity&)>;
using RequestClearAllErrorsFunc = std::function<Result(const std::string)>;
using RequestClearErrorFunc = std::function<Result(const std::string&, const boost::uuids::uuid&)>;
using RequestClearErrorFunc = std::function<Result(const std::string&, const error::ErrorHandle&)>;
using ExtMqttPublishFunc = std::function<void(const std::string&, const std::string&)>;
using ExtMqttSubscribeFunc = std::function<void(const std::string&, StringHandler)>;
using TelemetryPublishFunc =
Expand Down
2 changes: 1 addition & 1 deletion include/framework/everest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Everest {
/// \brief Raises an given \p error of the given \p impl_id, with the given \p error_type. Returns the uuid of the
/// raised error
///
boost::uuids::uuid raise_error(
std::string raise_error(
const std::string& impl_id,
const std::string& error_type,
const std::string& message,
Expand Down
15 changes: 11 additions & 4 deletions include/utils/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <filesystem>
#include <fmt/format.h>

#include <boost/uuid/uuid.hpp>

#include <utils/date.hpp>
#include <utils/types.hpp>

Expand Down Expand Up @@ -37,6 +35,15 @@ enum class Severity {
std::string severity_to_string(const Severity& s);
Severity string_to_severity(const std::string& s);

struct UUID {
UUID();
UUID(const std::string& uuid);

Check notice on line 40 in include/utils/error.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/utils/error.hpp#L40

Struct 'UUID' has a constructor with 1 argument that is not explicit.
bool operator<(const UUID& other) const;

std::string uuid;

Check notice on line 43 in include/utils/error.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/utils/error.hpp#L43

struct member 'UUID::uuid' is never used.
};

using ErrorHandle = UUID;
struct Error {
using time_point = date::utc_clock::time_point;
Error(
Expand All @@ -47,7 +54,7 @@ struct Error {
const bool persistent,
const Severity& severity,
const time_point& timestamp,
const boost::uuids::uuid& uuid
const UUID& uuid
);
Error(
const std::string& type,
Expand All @@ -72,7 +79,7 @@ struct Error {
Severity severity;

Check notice on line 79 in include/utils/error.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/utils/error.hpp#L79

struct member 'Error::severity' is never used.
ImplementationIdentifier from;
time_point timestamp;
boost::uuids::uuid uuid;
UUID uuid;
};

class ErrorTypeMap {
Expand Down
30 changes: 17 additions & 13 deletions lib/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@
#include <fstream>

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/uuid_io.hpp>

namespace Everest {
namespace error {

UUID::UUID() {
uuid = boost::uuids::to_string(boost::uuids::random_generator()());
}

UUID::UUID(const std::string& uuid_) : uuid(uuid_) {}

bool UUID::operator<(const UUID& other) const {
return uuid < other.uuid;
}

Error::Error(
const std::string& type_,
const std::string& message_,
Expand All @@ -26,7 +36,7 @@ Error::Error(
const bool persistent_,
const Severity& severity_,
const time_point& timestamp_,
const boost::uuids::uuid& uuid_
const UUID& uuid_
) :
type(type_),
message(message_),
Expand All @@ -52,7 +62,7 @@ Error::Error(
false,
severity_,
date::utc_clock::now(),
boost::uuids::random_generator()()
UUID()
) {}

Error::Error(
Expand Down Expand Up @@ -83,14 +93,8 @@ Error json_to_error(const json& j) {
bool persistent = j.at("persistent");
Severity severity = string_to_severity(j.at("severity"));
Error::time_point timestamp = Date::from_rfc3339(j.at("timestamp"));
boost::uuids::uuid uuid;
try {
uuid = boost::lexical_cast<boost::uuids::uuid>((std::string) j.at("uuid"));
} catch (boost::bad_lexical_cast e) {
EVLOG_error << "Error while parsing uuid " << j.at("uuid");
EVLOG_debug << "uuid source_type: " << e.source_type().name();
throw e;
}
UUID uuid(j.at("uuid"));

return Error(
type,
message,
Expand All @@ -113,7 +117,7 @@ json error_to_json(const Error& e) {
j["persistent"] = e.persistent;
j["severity"] = severity_to_string(e.severity);
j["timestamp"] = Date::to_rfc3339(e.timestamp);
j["uuid"] = boost::uuids::to_string(e.uuid);
j["uuid"] = e.uuid.uuid;
return j;
}

Expand Down
33 changes: 14 additions & 19 deletions lib/everest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <utils/date.hpp>
#include <utils/formatter.hpp>
#include <utils/error.hpp>
#include <utils/error_json.hpp>

namespace Everest {
const auto remote_cmd_res_timeout_seconds = 300;
Expand Down Expand Up @@ -482,32 +483,26 @@ void Everest::subscribe_error_cleared(const Requirement& req, const std::string&
this->mqtt_abstraction.register_handler(error_cleared_topic, token, QOS::QOS2);
}

boost::uuids::uuid Everest::raise_error(
std::string Everest::raise_error(
const std::string& impl_id,
const std::string& error_type,
const std::string& message,
const std::string& severity
) {
BOOST_LOG_FUNCTION();

std::string now_str = Date::to_rfc3339(date::utc_clock::now());
std::string description = this->error_map.get_description(error_type);
bool persistent = false;

Check notice on line 495 in lib/everest.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest.cpp#L495

Variable 'persistent' is assigned a value that is never used.
boost::uuids::uuid uuid = boost::uuids::random_generator()();

json data = json::object({
{"type", error_type},
{"description", description},
{"message", message},
{"persistent", persistent},
{"from", {
{"module", this->module_id},
{"implementation", impl_id}
}},
{"timestamp", now_str},
{"uuid", boost::uuids::to_string(uuid)},
{"severity", severity}
});

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

json data = error::error_to_json(error);

const auto error_topic = fmt::format(
"{}/error/{}",
Expand All @@ -516,13 +511,13 @@ boost::uuids::uuid Everest::raise_error(
);

this->mqtt_abstraction.publish(error_topic, data, QOS::QOS2);
return uuid;
return error.uuid.uuid;
}

json Everest::request_clear_error(const std::string& impl_id, const std::string& uuid, const bool clear_all) {
BOOST_LOG_FUNCTION();

std::string request_id = boost::uuids::to_string(boost::uuids::random_generator()());
std::string request_id = error::UUID().uuid;

std::promise<json> res_promise;
std::future<json> res_future = res_promise.get_future();
Expand Down
6 changes: 2 additions & 4 deletions lib/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <cstdlib>

#include <boost/program_options.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>

namespace Everest {

Expand Down Expand Up @@ -435,9 +433,9 @@ int ModuleLoader::initialize() {
};
module_adapter.request_clear_error = [&everest](
const std::string& impl_id,
const boost::uuids::uuid& error_uuid
const error::UUID& error_uuid
) {
return everest.request_clear_error(impl_id, boost::uuids::to_string(error_uuid));
return everest.request_clear_error(impl_id, error_uuid.uuid);
};

// NOLINTNEXTLINE(modernize-avoid-bind): prefer bind here for readability
Expand Down
2 changes: 1 addition & 1 deletion schemas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ install(
config.yaml
manifest.yaml
type.yaml
error.yaml
error-declaration-list.yaml
error-object.yaml
DESTINATION "${CMAKE_INSTALL_DATADIR}/everest/schemas"
)
35 changes: 35 additions & 0 deletions schemas/error-declaration-list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
$schema: http://json-schema.org/draft-07/schema#
$id: /everest/schemas/error-declaration-list.yaml
description: Json schema for EVerest error definition files
$defs:
error_list_subschema:
description: This describes a list of errors of this unit
type: array
items:
$ref: '#/$defs/error_subschema'
default: []
error_subschema:
type: object
description: json schema declaring the error
required:
- name
- description
properties:
name:
type: string
minLength: 2
pattern: ^[A-Z][A-Za-z0-9]*$
description:
type: string
minLength: 2
additionalProperties: false
type: object
required:
- description
properties:
description:
type: string
minLength: 2
errors:
$ref: '#/$defs/error_list_subschema'
additionalProperties: false
29 changes: 0 additions & 29 deletions schemas/error.yaml

This file was deleted.

11 changes: 3 additions & 8 deletions schemas/interface.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,11 @@ properties:
# add empty vars if not already present
default: {}
errors:
description: This describes a list of exported errors of this unit
description: This describes a list of error list allowed to be raised by this unit
type: array
items:
anyOf:
- type: string
description: This includes a single error with the given name
pattern: ^[a-z][a-z0-9_]*/[A-Z][a-zA-Z0-9]*$
- type: string
description: This includes all errors with the given prefix
pattern: ^[a-z][a-z0-9_]*/\*$
# add empty errors if not already present
- $ref: './error-declaration-list.yaml#/$defs/error_list_subschema'
- $ref: './error-declaration-list.yaml#/$defs/error_subschema'
default: []
additionalProperties: false
Loading

0 comments on commit 0faf862

Please sign in to comment.