-
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: Extract operation implementation details from CumulocityConverter
#3260
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is Additional details and impacted files📢 Thoughts on this report? Let us know! |
BTreeMap
for Operations
storageCumulocityConverter
Using it multiple times will create operations with the same names, but its impossible to have multiple operation implementations for the same operation name Signed-off-by: Marcel Guzik <[email protected]>
Signed-off-by: Marcel Guzik <[email protected]>
51774d9
to
7efcbfc
Compare
Robot Results
|
Signed-off-by: Marcel Guzik <[email protected]>
7efcbfc
to
2f0c534
Compare
let prev_operation = current_operations.remove_operation(&operation.name); | ||
let prev_operation = current_operations.insert_operation(operation); |
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 change seems weird at first ... but is correct!
Previously any operation with the same name was removed before adding a new version of the same operation.
/// Required because when given an external id of the main device when creating an operation, we want to create it | ||
/// in a main directory, instead of a subdirectory. |
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.
Okay. It makes sense for this PR focus on code refactoring without any user-visible changes, but this asymmetry between the main device and the child devices makes things more complicated than they should.
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.
I don't fully get what you mean. Do you mean this PR specifically, or the codebase more generally?
One maybe unnecessary change that I did was instead of having "operations for the main device" in one field and "operations for child devices" in a hashmap, i put it all in a single hashmap, so that CumulocityConverter
only passes along the external id and doesn't have to care if a device is a child device or a main device. In retrospect the functions can still take an external id but the operations for the main device can be made a normal field instead of a hashmap entry, since "operations for the main device" is something that always exists and putting it in a hashmap where it can be removed introduces an extra failure mode.
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 point is in no case to disagree with this PR which is a real improvement reducing the accidental complexity of the c8y mapper.
My comment is coming from the fact that you (correctly) feel the need to add a comment on why we need the main device external id here (while we don't for the child devices).
EntityType::MainDevice => Ok(self.operations.filter_by_topic(topic, prefix)), | ||
EntityType::ChildDevice => { | ||
if let Some(operations) = self.children.get(device_xid) { | ||
Ok(operations.filter_by_topic(topic, prefix)) | ||
} else { | ||
Ok(Vec::new()) | ||
} | ||
} | ||
EntityType::MainDevice | EntityType::ChildDevice => Ok(self | ||
.supported_operations | ||
.get_operation_handlers(device_xid, topic, prefix)), |
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 is one of the benefit of this PR, pushing away the artificial difference that has been introduced between the main and the child devices (see also: #3260 (comment))
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.
Approved. This is nice clarification of the code base.
refactor: Extract operation implementation details from `CumulocityConverter`
TODO
Proposed changes
This PR introduces an
SupportedOperations
struct that is used byCumulocityConverter
to load and save operations.It achieves following things:
CumulocityConverter
into new operations module: The mainCumulocityConverter
doesn't create any files or symlinks, or doesn't need to create paths, the logic of mapping supported operations to the filesystem is contained in its own moduleCumulocityConverter
: instead of having separateoperations: Operations
andchildren: HashMap<Child, Operations>
,SupportedOperation
handles this distinction, the converter just passes an external idBTreeMap
for to have only one operation under a given name and to ensure consistent orderingTypes of changes
Paste Link to the issue
Operations
struct refactor #3256Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments