Skip to content

Commit

Permalink
Merge pull request #2818 from didier-wenzek/refactor/deprecate-get_ch…
Browse files Browse the repository at this point in the history
…ild_id_from_child_topic

Deprecate tedge topic parsing method
  • Loading branch information
didier-wenzek authored Apr 9, 2024
2 parents 41b80d3 + 7478800 commit e80b0ce
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 46 deletions.
1 change: 0 additions & 1 deletion crates/core/tedge_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod pending_entity_store;
mod ring_buffer;
pub mod serialize;
mod software;
pub mod topic;
pub mod utils;
pub mod workflow;

Expand Down
29 changes: 0 additions & 29 deletions crates/core/tedge_api/src/topic.rs

This file was deleted.

12 changes: 2 additions & 10 deletions crates/extensions/c8y_firmware_manager/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use tedge_actors::LoggingReceiver;
use tedge_actors::MessageReceiver;
use tedge_actors::RuntimeError;
use tedge_actors::Sender;
use tedge_api::topic::get_child_id_from_child_topic;
use tedge_mqtt_ext::MqttMessage;

fan_in_message_type!(FirmwareInput[MqttMessage, OperationOutcome] : Debug);
Expand Down Expand Up @@ -208,13 +207,6 @@ impl FirmwareManagerActor {
&mut self,
message: MqttMessage,
) -> Result<(), FirmwareManagementError> {
let topic_name = &message.topic.name;
let child_id = get_child_id_from_child_topic(topic_name).ok_or(
FirmwareManagementError::InvalidTopicFromChildOperation {
topic: topic_name.to_string(),
},
)?;

match FirmwareOperationResponse::try_from(&message) {
Ok(response) => {
if let Err(err) =
Expand All @@ -224,7 +216,7 @@ impl FirmwareManagerActor {
.await
{
self.fail_operation_in_cloud(
&child_id,
&response.get_child_id(),
Some(response.get_payload().operation_id.as_str()),
&err.to_string(),
)
Expand All @@ -233,7 +225,7 @@ impl FirmwareManagerActor {
}
Err(err) => {
// Ignore bad responses. Eventually, timeout will fail an operation.
error!("Received a firmware update response with invalid payload for child {child_id}. Error: {err}");
error!("Received a firmware update response with invalid payload: {err}");
}
}
Ok(())
Expand Down
17 changes: 11 additions & 6 deletions crates/extensions/c8y_firmware_manager/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use c8y_api::smartrest::smartrest_serializer::CumulocitySupportedOperations;
use c8y_api::smartrest::smartrest_serializer::CumulocitySupportedOperations::C8yFirmware;
use c8y_api::smartrest::smartrest_serializer::OperationStatusMessage;
use c8y_api::smartrest::smartrest_serializer::SmartRest;
use tedge_api::topic::get_child_id_from_child_topic;
use tedge_api::OperationStatus;
use tedge_mqtt_ext::MqttMessage;
use tedge_mqtt_ext::Topic;
Expand Down Expand Up @@ -98,11 +97,17 @@ impl TryFrom<&MqttMessage> for FirmwareOperationResponse {

fn try_from(message: &MqttMessage) -> Result<Self, Self::Error> {
let topic = &message.topic.name;
let child_id = get_child_id_from_child_topic(topic).ok_or(
FirmwareManagementError::InvalidTopicFromChildOperation {
topic: topic.into(),
},
)?;
let child_id = match topic.split('/').collect::<Vec<&str>>()[..] {
// This plugin is still listening to the deprecated `tedge` command topic
["tedge", child_id, "commands", "res", "firmware_update"] if !child_id.is_empty() => {
child_id.to_string()
}
_ => {
return Err(FirmwareManagementError::InvalidTopicFromChildOperation {
topic: topic.into(),
})
}
};
let request_payload: ResponsePayload = serde_json::from_str(message.payload_str()?)?;

Ok(Self {
Expand Down

0 comments on commit e80b0ce

Please sign in to comment.