-
Notifications
You must be signed in to change notification settings - Fork 55
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
refactor: Reorganise c8y_mapper_ext::operations module #3012
refactor: Reorganise c8y_mapper_ext::operations module #3012
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
|
Robot Results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory name implementation
can be improved since all codes in repo are a kind of "implementation". Maybe contexts
(as all files are inheriting OperationContext
) or commands
(as all files are specific operation type but the name operation
is already taken).
crates/extensions/c8y_mapper_ext/src/operations/implementation/config_update.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @rina23q already raised, I'm not quite happy with the module named implementation
either. How about calling that wrapper module handlers
since those modules are extensions of the common handler?
@@ -0,0 +1,43 @@ | |||
//! Operations' topic filters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite happy with this module with all the operation specific filters. I see that you wanted to separate the conversion aspects from the command handling aspects. In that case I get a feeling that we need two separate operation specific modules for each operation/command type: one with just the conversion aspects and other with the command processing aspects as done now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wanted to separate these because reacting to operation status changes and MQTT topics are really different concerns, and I went on a bit of an autopilot separating modules, but looking at these functions, they're completely superfluous, the implementation is the same, just with different arguments.
I get a feeling that we need two separate operation specific modules for each operation/command type: one with just the conversion aspects and other with the command processing aspects as done now.
I think that wrt. the conversion aspect, there are really two things here: the topic filters (topic_filter
module) and the conversions of incoming cumulocity messages that initiate thin-edge.io operations (convert
module).
On the topic fiilters:
I'm not sure if we need a conversion module per operation type. Topic filters are necessary to create an MQTT subscription, and in this case I think the pattern is more like:
OperationHandler
handles some set of operations- if
CumulocityConverter
gets an operation of type that can be handled byOperationHandler
, it should pass the message to the handler - so
OperationHandler
needs to expose the set of operations it supports, so thatCumulocityConverter
makes a proper MQTT subscription - but it doesn't have to be per operation type. I think what's preferable is that
OperationHandler
produces only one topic filter, that covers all the operations that are enabled by the current configuration.
Also this will hopefully clear up more once we've made OperationHandler
an actor: the topic filters will fit neatly into the message types of the new operations actor.
On the conversion functions in the convert
module:
These are impl blocks on CumulocityConverter
, which I've pulled under operations
module because other than converting between Cumulocity messages and thin-edge.io messages, they perform some side effects like querying the entity store or calling into c8y proxy to obtain a URL where the operation has to upload a file.
This auxiliary communication with C8y when we receive an operation is very much symmetric to auxiliary communication with C8y when we terminate the operation (support or failure), so the long term plan is definitely to move these side-effects into OperationHandler
, but right now it's very much coupled to CumulocityConverter
which uses it primarily to convert between MQTT messages, so I think refactoring this will be best left as a follow-up.
Conclusion
- as for the topic filters, instead of having different topic filters for different operation types, there should be
OperationHandler::topic_filter
that just creates a filter for all operation types the handler is interested in, andCumulocityConverter
should just call it and don't care about different operation types. - as for the
convert
module functions, I think this should be left as a follow-up.
How does that sound?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6c7d4ae
to
8c484d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments are not related to the main code, so I would approve now.
let capabilities = Capabilities { | ||
log_upload: true, | ||
config_snapshot: true, | ||
config_update: true, | ||
firmware_update: true, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is equal to Capapilities::default()
.
let operation_topics = OperationHandler::topic_filter(&capabilities) | ||
.into_iter() | ||
.map(|(e, c)| mqtt_schema.topics(e, c)) | ||
.collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice simplification!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
`operations` module was reorganised to better separate different concerns: - plain conversions of operations-related messages - spawning and joining of operation tasks - handling different types of operations Signed-off-by: Marcel Guzik <[email protected]>
53423f1
to
e419058
Compare
Proposed changes
No functional changes were made.
operations
module was reorganised into submodules to better separate different concerns:This prepares the
OperationHandler
to more neatly be converted into an actor, as the lower-level handling of different operation types should remain unaffected.Types of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments