aws-greengrass / aws-greengrass-shadow-manager

A GreengrassV2 Component that provides offline device shadow documents and optional synchronization to the IoT device shadow service.
Apache License 2.0
9 stars 6 forks source link

feat: store thing shadow sync configurations as a map #184

Closed ghost closed 1 year ago

ghost commented 1 year ago

Description of changes: The ThingShadowSyncConfiguration object represents the sync configuration of a thing shadow. Currently, all thing shadows parsed from the component configuration are stored as a set of ThingShadowSyncConfiguration. Different parts of the ShadowManager rely on the set properties, such as uniqueness of elements and the equality method of ThingShadowSyncConfiguration, to identify whether a specific (thing, shadow) pair exists in the configuration.

However, we plan to introduce more attributes to ThingShadowSyncConfiguration in the near future, which would make this approach less feasible since it's unclear how the equality operator should work in that case. For example, if a new attribute is added, the set.contains((thing, shadow)) approach that is currently used won't work anymore.

To address this issue, this commit changes the data structure that stores all the ThingShadowSyncConfigurations from a Set to a Map<ThingShadow, ThingShadowSyncConfiguration>. The ThingShadow object contains only the pair (thingName, shadowName), while the ThingShadowSyncConfiguration contains all the configurations of ThingShadowSyncConfiguration. This new approach will enable us to add more attributes to the ThingShadowSyncConfiguration in the future without affecting the way how ShadowManager checks if a pair of (thing, shadow) exists in the configuration.

Why is this change necessary: Because of the "add on interaction" feature that we want to introduce in the near future.

How was this change tested: Unit / integration tests.

Checklist:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.