-
Notifications
You must be signed in to change notification settings - Fork 72
Files under directory /etc/tedge/operations/c8y are loaded many times on c8y-mapper startup #3160
Description
Describe the bug
The supported operation files under /etc/tedge/operations/c8y should be ideally loaded only once on c8y-mapper startup. However, it is actually loaded many times. This can be explained by tracing how get_operations() functions are called.
- init messages
let supported_operations_message = self.create_supported_operations( - constructing
CumulocityConverter
let operations = Operations::try_new(&*config.ops_dir)?; - registering a new command registration message (as many times as command registration messages received)
let need_cloud_update = self.update_operations(ops_dir.as_std_path())?;
My comments:
(2) is actually redundant. Since already operations get created during init, they should parse to CumulocityConverter.
(3) is most problematic. CumulocityConverter::register_operation() is called by receiving a command registration message. It means, if user has 5 command registration messages, the supported operation directory will be loaded 5 times. I have a doubt if mapper has to load the directory every time when a command registration message arrives.
To Reproduce
Easy check is to use validation for custom operation handler. If the contents of a custom handler is invalid, it logs a warning message. This validation is called inside the get_operations() function.
Prepare the version of #3144.
- Create a invalid custom operation handler file, e.g. /etc/tedge/operations/c8y/my_CustomOperation
[exec]
topic = "c8y/devicecontrol/notifications"
on_fragment = "com_cumulocity_model_WebCamDevice"
command_name = "/usr/bin/do_something.sh ${.payload.com_cumulocity_model_WebCamDevice.parameters}"- Restart c8y-mapper.
- See the output of the c8y-mapper. You'll find 7 times of the warning message.
WARN c8y_api::smartrest::operations: ''command' is missing in the JSON custom operation handler mapping 'my_CustomOperation'
Expected behavior
The operation files should be scanned as few times as possible.
Screenshots
Environment (please complete the following information):
- OS [incl. version]
- Hardware [incl. revision]
- System-Architecture [e.g. result of "uname -a"]
- thin-edge.io version [e.g. 1.3.0]:
1.3.1
Additional context
The directory will be loaded when file change is detected, however, this should be good.