Skip to content

Commit

Permalink
Merge pull request #2819 from didier-wenzek/refactor/improve-tedge-ap…
Browse files Browse the repository at this point in the history
…i-struct

refactor: Improve tedge_api structure
  • Loading branch information
didier-wenzek authored Apr 22, 2024
2 parents e0aba78 + 383e62e commit 2c06282
Show file tree
Hide file tree
Showing 39 changed files with 279 additions and 106 deletions.
4 changes: 2 additions & 2 deletions crates/core/c8y_api/src/json_c8y.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::collections::HashMap;
use std::fmt;
use tedge_api::alarm::ThinEdgeAlarm;
use tedge_api::alarm::ThinEdgeAlarmData;
use tedge_api::commands::SoftwareListCommand;
use tedge_api::entity_store::EntityMetadata;
use tedge_api::entity_store::EntityType;
use tedge_api::event::ThinEdgeEvent;
use tedge_api::messages::SoftwareListCommand;
use tedge_api::EntityStore;
use tedge_api::Jsonify;
use tedge_api::SoftwareModule;
Expand Down Expand Up @@ -366,11 +366,11 @@ mod tests {
use std::collections::HashSet;
use tedge_api::alarm::ThinEdgeAlarm;
use tedge_api::alarm::ThinEdgeAlarmData;
use tedge_api::commands::SoftwareListCommandPayload;
use tedge_api::entity_store::EntityExternalId;
use tedge_api::entity_store::EntityRegistrationMessage;
use tedge_api::entity_store::InvalidExternalIdError;
use tedge_api::event::ThinEdgeEventData;
use tedge_api::messages::SoftwareListCommandPayload;
use tedge_api::mqtt_topics::EntityTopicId;
use tedge_api::mqtt_topics::MqttSchema;
use test_case::test_case;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/c8y_api/src/smartrest/smartrest_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub trait OperationStatusMessage {
#[cfg(test)]
mod tests {
use super::*;
use tedge_api::messages::SoftwareListCommandPayload;
use tedge_api::commands::SoftwareListCommandPayload;
use tedge_api::mqtt_topics::EntityTopicId;
use tedge_api::Jsonify;

Expand Down
6 changes: 3 additions & 3 deletions crates/core/plugin_sm/src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use std::io::{self};
use std::path::Path;
use std::path::PathBuf;
use std::process::Stdio;
use tedge_api::messages::CommandStatus;
use tedge_api::messages::SoftwareListCommand;
use tedge_api::messages::SoftwareUpdateCommand;
use tedge_api::commands::CommandStatus;
use tedge_api::commands::SoftwareListCommand;
use tedge_api::commands::SoftwareUpdateCommand;
use tedge_api::SoftwareError;
use tedge_api::SoftwareType;
use tedge_api::DEFAULT;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/tedge_agent/src/operation_file_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use tedge_actors::RuntimeRequestSink;
use tedge_actors::Sender;
use tedge_actors::Service;
use tedge_actors::SimpleMessageBoxBuilder;
use tedge_api::messages::ConfigUpdateCmdPayload;
use tedge_api::commands::ConfigUpdateCmdPayload;
use tedge_api::mqtt_topics::Channel;
use tedge_api::mqtt_topics::ChannelFilter;
use tedge_api::mqtt_topics::EntityFilter;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/tedge_agent/src/restart_manager/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tedge_actors::RuntimeError;
use tedge_actors::RuntimeRequest;
use tedge_actors::Sender;
use tedge_actors::SimpleMessageBox;
use tedge_api::messages::CommandStatus;
use tedge_api::commands::CommandStatus;
use tedge_api::RestartCommand;
use tedge_config::system_services::SystemConfig;
use tedge_config::system_services::SystemSpecificCommands;
Expand Down
4 changes: 2 additions & 2 deletions crates/core/tedge_agent/src/restart_manager/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use tedge_actors::NoConfig;
use tedge_actors::Sender;
use tedge_actors::SimpleMessageBox;
use tedge_actors::SimpleMessageBoxBuilder;
use tedge_api::messages::CommandStatus;
use tedge_api::messages::RestartCommandPayload;
use tedge_api::commands::CommandStatus;
use tedge_api::commands::RestartCommandPayload;
use tedge_api::mqtt_topics::EntityTopicId;
use tedge_api::RestartCommand;
use tedge_config::SudoCommandBuilder;
Expand Down
8 changes: 4 additions & 4 deletions crates/core/tedge_agent/src/software_manager/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ use tedge_actors::RuntimeError;
use tedge_actors::RuntimeRequest;
use tedge_actors::Sender;
use tedge_actors::SimpleMessageBox;
use tedge_api::messages::CommandStatus;
use tedge_api::messages::SoftwareCommandMetadata;
use tedge_api::messages::SoftwareListCommand;
use tedge_api::messages::SoftwareUpdateCommand;
use tedge_api::commands::CommandStatus;
use tedge_api::commands::SoftwareCommandMetadata;
use tedge_api::commands::SoftwareListCommand;
use tedge_api::commands::SoftwareUpdateCommand;
use tedge_api::SoftwareType;
use tedge_config::TEdgeConfigError;
use tracing::error;
Expand Down
16 changes: 8 additions & 8 deletions crates/core/tedge_agent/src/software_manager/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use tedge_actors::NoConfig;
use tedge_actors::Sender;
use tedge_actors::SimpleMessageBox;
use tedge_actors::SimpleMessageBoxBuilder;
use tedge_api::messages::CommandStatus;
use tedge_api::messages::SoftwareCommandMetadata;
use tedge_api::messages::SoftwareListCommand;
use tedge_api::messages::SoftwareModuleAction;
use tedge_api::messages::SoftwareModuleItem;
use tedge_api::messages::SoftwareRequestResponseSoftwareList;
use tedge_api::messages::SoftwareUpdateCommand;
use tedge_api::messages::SoftwareUpdateCommandPayload;
use tedge_api::commands::CommandStatus;
use tedge_api::commands::SoftwareCommandMetadata;
use tedge_api::commands::SoftwareListCommand;
use tedge_api::commands::SoftwareModuleAction;
use tedge_api::commands::SoftwareModuleItem;
use tedge_api::commands::SoftwareRequestResponseSoftwareList;
use tedge_api::commands::SoftwareUpdateCommand;
use tedge_api::commands::SoftwareUpdateCommandPayload;
use tedge_api::mqtt_topics::EntityTopicId;
use tedge_config::SudoCommandBuilder;
use tedge_config::TEdgeConfigLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use tedge_actors::MessageReceiver;
use tedge_actors::RuntimeError;
use tedge_actors::Sender;
use tedge_actors::UnboundedLoggingReceiver;
use tedge_api::messages::RestartCommand;
use tedge_api::messages::SoftwareCommandMetadata;
use tedge_api::messages::SoftwareListCommand;
use tedge_api::messages::SoftwareUpdateCommand;
use tedge_api::commands::RestartCommand;
use tedge_api::commands::SoftwareCommandMetadata;
use tedge_api::commands::SoftwareListCommand;
use tedge_api::commands::SoftwareUpdateCommand;
use tedge_api::mqtt_topics::Channel;
use tedge_api::mqtt_topics::EntityTopicId;
use tedge_api::mqtt_topics::MqttSchema;
Expand Down
16 changes: 8 additions & 8 deletions crates/core/tedge_agent/src/tedge_operation_converter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use tedge_actors::RequestEnvelope;
use tedge_actors::Sender;
use tedge_actors::SimpleMessageBox;
use tedge_actors::SimpleMessageBoxBuilder;
use tedge_api::messages::CommandStatus;
use tedge_api::messages::RestartCommandPayload;
use tedge_api::messages::SoftwareCommandMetadata;
use tedge_api::messages::SoftwareListCommand;
use tedge_api::messages::SoftwareModuleAction;
use tedge_api::messages::SoftwareModuleItem;
use tedge_api::messages::SoftwareRequestResponseSoftwareList;
use tedge_api::messages::SoftwareUpdateCommandPayload;
use tedge_api::commands::CommandStatus;
use tedge_api::commands::RestartCommandPayload;
use tedge_api::commands::SoftwareCommandMetadata;
use tedge_api::commands::SoftwareListCommand;
use tedge_api::commands::SoftwareModuleAction;
use tedge_api::commands::SoftwareModuleItem;
use tedge_api::commands::SoftwareRequestResponseSoftwareList;
use tedge_api::commands::SoftwareUpdateCommandPayload;
use tedge_api::mqtt_topics::EntityTopicId;
use tedge_api::mqtt_topics::MqttSchema;
use tedge_api::workflow::WorkflowSupervisor;
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions crates/core/tedge_api/src/entity_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
// TODO: move entity business logic to its own module

use crate::entity_store;
use crate::message_log::MessageLogReader;
use crate::message_log::MessageLogWriter;
use crate::mqtt_topics::Channel;
use crate::mqtt_topics::EntityTopicId;
use crate::mqtt_topics::MqttSchema;
use crate::mqtt_topics::TopicIdError;
use crate::pending_entity_store::PendingEntityData;
use crate::pending_entity_store::PendingEntityStore;
use crate::store::message_log::MessageLogReader;
use crate::store::message_log::MessageLogWriter;
use crate::store::pending_entity_store::PendingEntityData;
use crate::store::pending_entity_store::PendingEntityStore;
use log::debug;
use log::error;
use log::info;
Expand Down
25 changes: 9 additions & 16 deletions crates/core/tedge_api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
pub mod alarm;
pub mod builder;
pub mod data;
pub mod commands;
pub mod entity_store;
pub mod error;
pub mod event;
pub mod group;
pub mod health;
pub mod measurement;
pub mod message_log;
pub mod messages;
pub mod mqtt_topics;
pub mod parser;
pub mod path;
pub mod pending_entity_store;
mod ring_buffer;
pub mod serialize;
mod software;
pub mod utils;
mod store;
pub mod workflow;

pub use commands::CommandStatus;
pub use commands::Jsonify;
pub use commands::OperationStatus;
pub use commands::RestartCommand;
pub use commands::SoftwareListCommand;
pub use commands::SoftwareUpdateCommand;
pub use download::*;
pub use entity_store::EntityStore;
pub use error::*;
pub use health::*;
pub use messages::CommandStatus;
pub use messages::Jsonify;
pub use messages::OperationStatus;
pub use messages::RestartCommand;
pub use messages::SoftwareListCommand;
pub use messages::SoftwareUpdateCommand;
pub use software::*;
pub use store::pending_entity_store;

#[cfg(test)]
mod tests {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use time::OffsetDateTime;

use crate::data::*;
use crate::measurement::data::*;
use crate::measurement::*;

/// A `MeasurementVisitor` that builds up `ThinEdgeJson`.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
use time::OffsetDateTime;

#[cfg(test)]
pub mod builder;
#[cfg(test)]
mod data;
mod group;
mod parser;
mod serialize;
pub(crate) mod utils;

pub use group::*;
pub use parser::*;
pub use serialize::*;

/// The `MeasurementVisitor` trait represents the capability to visit a series of measurements, possibly grouped.
///
/// Here is an implementation of the `MeasurementVisitor` trait that prints the measurements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn invalid_empty_measurement(key: &str) -> String {
fn map_error(error: serde_json::Error, input: &str) -> ThinEdgeJsonParserError {
const MAX_INPUT_EXCERPT: usize = 80;
let input_excerpt =
crate::utils::excerpt(input, error.line(), error.column(), MAX_INPUT_EXCERPT);
crate::measurement::utils::excerpt(input, error.line(), error.column(), MAX_INPUT_EXCERPT);
ThinEdgeJsonParserError {
error,
input_excerpt,
Expand All @@ -287,11 +287,11 @@ mod tests {
use time::macros::datetime;
use time::OffsetDateTime;

use crate::parser::parse_str;
use super::parse_str;

#[test]
fn it_deserializes_thin_edge_json() -> anyhow::Result<()> {
use crate::builder::ThinEdgeJsonBuilder;
use crate::measurement::builder::ThinEdgeJsonBuilder;
let input = r#"{
"time" : "2021-04-30T17:03:14.123+02:00",
"pressure": 123.4,
Expand Down Expand Up @@ -333,7 +333,7 @@ mod tests {

#[test]
fn it_shows_input_excerpt_on_error() {
use crate::builder::ThinEdgeJsonBuilder;
use crate::measurement::builder::ThinEdgeJsonBuilder;

let input = "{\n\"time\" : null\n}";

Expand All @@ -349,7 +349,7 @@ mod tests {

#[test]
fn it_accepts_unix_timestamps_in_place_of_iso_8601() {
use crate::builder::ThinEdgeJsonBuilder;
use crate::measurement::builder::ThinEdgeJsonBuilder;

let input = "{\n\"time\" : 1701949168,\n\"test\": 1023}";
let expected_timestamp = OffsetDateTime::parse(
Expand All @@ -367,7 +367,7 @@ mod tests {

#[test]
fn it_accepts_decimals_as_unix_timestamps() {
use crate::builder::ThinEdgeJsonBuilder;
use crate::measurement::builder::ThinEdgeJsonBuilder;

let input = "{\n\"time\" : 1701949168.001,\n\"test\": 1023}";
let expected_timestamp = OffsetDateTime::parse(
Expand All @@ -385,7 +385,7 @@ mod tests {

#[test]
fn it_produces_a_clear_error_message_when_unix_timestamp_is_out_of_range() {
use crate::builder::ThinEdgeJsonBuilder;
use crate::measurement::builder::ThinEdgeJsonBuilder;

let input = "{\n\"time\" : -377705116801,\n\"test\": 1023}";
let mut builder = ThinEdgeJsonBuilder::default();
Expand All @@ -400,7 +400,7 @@ mod tests {

#[test]
fn parse_type_as_measurement() {
use crate::builder::ThinEdgeJsonBuilder;
use crate::measurement::builder::ThinEdgeJsonBuilder;

let input = r#"{
"time" : "2021-04-30T17:03:14.123+02:00",
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2c06282

Please sign in to comment.