Skip to content
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

tedge-mapper-c8y service restart is required after a change of supported operation file contents #1970

Merged
merged 2 commits into from
May 15, 2023

Conversation

PradeepKiruvale
Copy link
Contributor

Proposed changes

The issue is the custom operation was not updating the operations_by_trigger map when a custom operation is added.

  • Since adding a custom operation file and editing it will generate multiple file create/modification events.
  • When a file is just opened (using vi, nano, or any other editor), it will generate an event, that will be processed by the mapper and the operation will be added to the operations vector.
  • When the content is added to the operation file, one more event gets generated and this time it has to update the existing operation with operation content. But the operations_by_trigger map was not updated because there is no content in the operation file.
  • In the earlier case the map was updated only when the operation is added at the first time but not when the operation is updated.

The proposed solution is:

When the operation content is updated/modify event is triggered, the operations_by_trigger map has to be updated with template number as the key and the custom operation position index in the operation vector as data, as below

+            if let Some(detail) = operation.exec() {
+                if let Some(on_message) = &detail.on_message {
+                    self.operations_by_trigger.insert(on_message.clone(), index);
+                }
+            }

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#1705

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request May 15, 2023 13:48 — with GitHub Actions Inactive
@github-actions
Copy link
Contributor

github-actions bot commented May 15, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass %
198 0 5 198 100

Passed Tests

Name ⏱️ Duration Suite
Define Child device 1 ID 0.004 s C8Y Child Alarms Rpi
Normal case when the child device does not exist on c8y cloud 2.33 s C8Y Child Alarms Rpi
Normal case when the child device already exists 1.152 s C8Y Child Alarms Rpi
Reconciliation when the new alarm message arrives, restart the mapper 2.565 s C8Y Child Alarms Rpi
Reconciliation when the alarm that is cleared 5.865 s C8Y Child Alarms Rpi
Prerequisite Parent 17.556 s Child Conf Mgmt Plugin
Prerequisite Child 0.394 s Child Conf Mgmt Plugin
Child device bootstrapping 15.52 s Child Conf Mgmt Plugin
Snapshot from device 62.417 s Child Conf Mgmt Plugin
Child device config update 62.033 s Child Conf Mgmt Plugin
Configuration types should be detected on file change (without restarting service) 55.38 s Inotify Crate
Check lock file existence in default folder 1.405 s Lock File
Check PID number in lock file 1.437 s Lock File
Check PID number in lock file after restarting the services 2.9539999999999997 s Lock File
Check starting same service twice 1.7 s Lock File
Switch off lock file creation 4.73 s Lock File
Set configuration when file exists 55.438 s Configuration Operation
Set configuration when file does not exist 6.458 s Configuration Operation
Set configuration with broken url 6.224 s Configuration Operation
Get configuration 5.99 s Configuration Operation
Get non existent configuration file 5.535 s Configuration Operation
Get non existent configuration type 5.5280000000000005 s Configuration Operation
Update configuration plugin config via cloud 6.377 s Configuration Operation
Modify configuration plugin config via local filesystem modify inplace 3.1 s Configuration Operation
Modify configuration plugin config via local filesystem overwrite 5.398 s Configuration Operation
Update configuration plugin config via local filesystem copy 3.356 s Configuration Operation
Update configuration plugin config via local filesystem move (different directory) 5.286 s Configuration Operation
Update configuration plugin config via local filesystem move (same directory) 3.26 s Configuration Operation
Successful firmware operation 68.649 s Firmware Operation
Install with empty firmware name 57.801 s Firmware Operation
Prerequisite Parent 19.647 s Firmware Operation Child Device
Prerequisite Child 8.176 s Firmware Operation Child Device
Child device firmware update 6.402 s Firmware Operation Child Device
Child device firmware update with cache 5.912 s Firmware Operation Child Device
Firmware plugin supports restart via service manager #1932 5.836 s Firmware Operation Child Device Retry
Update Inventory data via inventory.json 1.516 s Inventory Update
Retrieve a JWT tokens 55.727 s Jwt Request
Check running collectd 1.603 s Monitor Device Collectd
Is collectd publishing MQTT messages? 3.164 s Monitor Device Collectd
Check thin-edge monitoring 4.345 s Monitor Device Collectd
Check grouping of measurements 9.04 s Monitor Device Collectd
Update the custom operation dynamically 48.797 s Dynamically Reload Operation
Main device registration 2.3 s Device Registration
Child device registration 2.52 s Device Registration
Supports restarting the device 66.662 s Restart Device
Update tedge version from previous using Cumulocity 105.988 s Tedge Self Update
Test if all c8y services are up 51.323 s Service Monitoring
Test if all c8y services are down 51.384 s Service Monitoring
Test if all c8y services are using configured service type 173.832 s Service Monitoring
Test if all c8y services using default service type when service type configured as empty 87.113 s Service Monitoring
Check health status of tedge-mapper-c8y service on broker stop start 25.975 s Service Monitoring
Check health status of tedge-mapper-c8y service on broker restart 27.455 s Service Monitoring
Check health status of child device service 24.16 s Service Monitoring
Successful shell command with output 4.164 s Shell Operation
Check Successful shell command with literal double quotes output 3.718 s Shell Operation
Execute multiline shell command 3.64 s Shell Operation
Failed shell command 3.593 s Shell Operation
Software list should be populated during startup 56.315 s Software
Install software via Cumulocity 72.71 s Software
Software list should only show currently installed software and not candidates 33.533 s Software
Child devices support sending simple measurements 1.692 s Child Device Telemetry
Child devices support sending custom measurements 1.45 s Child Device Telemetry
Child devices support sending custom events 1.248 s Child Device Telemetry
Child devices support sending custom events overriding the type 1.169 s Child Device Telemetry
Child devices support sending custom alarms #1699 1.217 s Child Device Telemetry
Child devices support sending inventory data via c8y topic 1.435 s Child Device Telemetry
Child device supports sending custom child device measurements directly to c8y 2.057 s Child Device Telemetry
Check retained alarms 52.308 s Raise Alarms
Thin-edge devices support sending simple measurements 1.7189999999999999 s Thin-Edge Device Telemetry
Thin-edge devices support sending simple measurements with custom type 1.446 s Thin-Edge Device Telemetry
Thin-edge devices support sending custom measurements 1.248 s Thin-Edge Device Telemetry
Thin-edge devices support sending custom events 1.031 s Thin-Edge Device Telemetry
Thin-edge devices support sending custom events overriding the type 1.3559999999999999 s Thin-Edge Device Telemetry
Thin-edge devices support sending custom alarms #1699 3.608 s Thin-Edge Device Telemetry
Thin-edge device supports sending custom Thin-edge device measurements directly to c8y 1.933 s Thin-Edge Device Telemetry
Thin-edge device support sending inventory data via c8y topic 1.44 s Thin-Edge Device Telemetry
Validate updated data path used by tedge-agent 0.729 s Data Path Config
Validate updated data path used by c8y-firmware-plugin 11.105 s Data Path Config
Stop tedge-agent service 0.256 s Log Path Config
Customize the log path 0.143 s Log Path Config
Initialize tedge-agent 0.108 s Log Path Config
Check created folders 0.122 s Log Path Config
Remove created custom folders 0.104 s Log Path Config
Install thin-edge via apt 53.58 s Install Apt
Install latest via script (from current branch) 31.196 s Install Tedge
Install specific version via script (from current branch) 26.865 s Install Tedge
Install latest tedge via script (from main branch) 23.352 s Install Tedge
Install then uninstall latest tedge via script (from main branch) 41.11 s Install Tedge
Support starting and stopping services 42.76 s Service-Control
Supports a reconnect 59.64 s Test-Commands
Supports disconnect then connect 42.791 s Test-Commands
Update unknown setting 44.758 s Test-Commands
Update known setting 26.793 s Test-Commands
Stop c8y-configuration-plugin 0.199 s Health C8Y-Configuration-Plugin
Update the service file 0.234 s Health C8Y-Configuration-Plugin
Reload systemd files 0.674 s Health C8Y-Configuration-Plugin
Start c8y-configuration-plugin 0.187 s Health C8Y-Configuration-Plugin
Start watchdog service 10.268 s Health C8Y-Configuration-Plugin
Check PID of c8y-configuration-plugin 0.087 s Health C8Y-Configuration-Plugin
Kill the PID 0.212 s Health C8Y-Configuration-Plugin
Recheck PID of c8y-configuration-plugin 6.377 s Health C8Y-Configuration-Plugin
Compare PID change 0.001 s Health C8Y-Configuration-Plugin
Stop watchdog service 0.153 s Health C8Y-Configuration-Plugin
Remove entry from service file 0.107 s Health C8Y-Configuration-Plugin
Stop c8y-log-plugin 0.276 s Health C8Y-Log-Plugin
Update the service file 0.223 s Health C8Y-Log-Plugin
Reload systemd files 0.347 s Health C8Y-Log-Plugin
Start c8y-log-plugin 0.249 s Health C8Y-Log-Plugin
Start watchdog service 10.27 s Health C8Y-Log-Plugin
Check PID of c8y-log-plugin 0.097 s Health C8Y-Log-Plugin
Kill the PID 0.244 s Health C8Y-Log-Plugin
Recheck PID of c8y-log-plugin 6.351 s Health C8Y-Log-Plugin
Compare PID change 0.001 s Health C8Y-Log-Plugin
Stop watchdog service 0.238 s Health C8Y-Log-Plugin
Remove entry from service file 0.149 s Health C8Y-Log-Plugin
Stop tedge-mapper 0.248 s Health Tedge Mapper C8Y
Update the service file 0.129 s Health Tedge Mapper C8Y
Reload systemd files 0.497 s Health Tedge Mapper C8Y
Start tedge-mapper 0.209 s Health Tedge Mapper C8Y
Start watchdog service 10.339 s Health Tedge Mapper C8Y
Check PID of tedge-mapper 0.094 s Health Tedge Mapper C8Y
Kill the PID 0.18 s Health Tedge Mapper C8Y
Recheck PID of tedge-mapper 6.401 s Health Tedge Mapper C8Y
Compare PID change 0.005 s Health Tedge Mapper C8Y
Stop watchdog service 0.237 s Health Tedge Mapper C8Y
Remove entry from service file 0.145 s Health Tedge Mapper C8Y
Stop tedge-agent 0.179 s Health Tedge-Agent
Update the service file 0.142 s Health Tedge-Agent
Reload systemd files 0.188 s Health Tedge-Agent
Start tedge-agent 0.223 s Health Tedge-Agent
Start watchdog service 10.196 s Health Tedge-Agent
Check PID of tedge-mapper 0.07 s Health Tedge-Agent
Kill the PID 0.155 s Health Tedge-Agent
Recheck PID of tedge-agent 6.36 s Health Tedge-Agent
Compare PID change 0.001 s Health Tedge-Agent
Stop watchdog service 0.323 s Health Tedge-Agent
Remove entry from service file 0.184 s Health Tedge-Agent
Stop tedge-mapper-az 0.185 s Health Tedge-Mapper-Az
Update the service file 0.19 s Health Tedge-Mapper-Az
Reload systemd files 0.488 s Health Tedge-Mapper-Az
Start tedge-mapper-az 0.17 s Health Tedge-Mapper-Az
Start watchdog service 10.207 s Health Tedge-Mapper-Az
Check PID of tedge-mapper-az 0.153 s Health Tedge-Mapper-Az
Kill the PID 0.543 s Health Tedge-Mapper-Az
Recheck PID of tedge-agent 6.756 s Health Tedge-Mapper-Az
Compare PID change 0.001 s Health Tedge-Mapper-Az
Stop watchdog service 0.392 s Health Tedge-Mapper-Az
Remove entry from service file 0.207 s Health Tedge-Mapper-Az
Stop tedge-mapper-collectd 0.323 s Health Tedge-Mapper-Collectd
Update the service file 0.162 s Health Tedge-Mapper-Collectd
Reload systemd files 0.558 s Health Tedge-Mapper-Collectd
Start tedge-mapper-collectd 0.153 s Health Tedge-Mapper-Collectd
Start watchdog service 10.262 s Health Tedge-Mapper-Collectd
Check PID of tedge-mapper-collectd 0.107 s Health Tedge-Mapper-Collectd
Kill the PID 0.386 s Health Tedge-Mapper-Collectd
Recheck PID of tedge-mapper-collectd 6.745 s Health Tedge-Mapper-Collectd
Compare PID change 0.001 s Health Tedge-Mapper-Collectd
Stop watchdog service 0.135 s Health Tedge-Mapper-Collectd
Remove entry from service file 0.195 s Health Tedge-Mapper-Collectd
tedge-collectd-mapper health status 6.15 s Health Tedge-Mapper-Collectd
c8y-log-plugin health status 5.932 s MQTT health endpoints
c8y-configuration-plugin health status 5.638 s MQTT health endpoints
Publish on a local insecure broker 0.529 s Basic Pub Sub
Publish on a local secure broker 3.828 s Basic Pub Sub
Publish on a local secure broker with client authentication 3.719 s Basic Pub Sub
Check remote mqtt broker #1773 2.496 s Remote Mqtt Broker
Wrong package name 0.072 s Improve Tedge Apt Plugin Error Messages
Wrong version 0.073 s Improve Tedge Apt Plugin Error Messages
Wrong type 0.201 s Improve Tedge Apt Plugin Error Messages
tedge_connect_test_positive 0.21 s Tedge Connect Test
tedge_connect_test_negative 0.695 s Tedge Connect Test
tedge_connect_test_sm_services 8.835 s Tedge Connect Test
tedge_disconnect_test_sm_services 2.094 s Tedge Connect Test
Install thin-edge.io 24.406 s Call Tedge
call tedge -V 0.097 s Call Tedge
call tedge -h 0.069 s Call Tedge
call tedge -h -V 0.093 s Call Tedge
call tedge help 0.084 s Call Tedge
tedge config list 0.18 s Call Tedge Config List
tedge config list --all 0.107 s Call Tedge Config List
set/unset device.type 0.401 s Call Tedge Config List
set/unset device.key.path 0.304 s Call Tedge Config List
set/unset device.cert.path 0.285 s Call Tedge Config List
set/unset c8y.root.cert.path 0.345 s Call Tedge Config List
set/unset c8y.smartrest.templates 0.424 s Call Tedge Config List
set/unset az.root.cert.path 0.511 s Call Tedge Config List
set/unset az.mapper.timestamp 0.581 s Call Tedge Config List
set/unset mqtt.bind_address 0.758 s Call Tedge Config List
set/unset mqtt.port 1.108 s Call Tedge Config List
set/unset tmp.path 0.877 s Call Tedge Config List
set/unset logs.path 0.673 s Call Tedge Config List
set/unset run.path 0.355 s Call Tedge Config List
Get Put Delete 2.527 s Http File Transfer Api
Set keys should return value on stdout 0.296 s Tedge Config Get
Unset keys should not return anything on stdout and warnings on stderr 0.378 s Tedge Config Get
Invalid keys should not return anything on stdout and warnings on stderr 0.504 s Tedge Config Get
Set configuration via environment variables 1.419 s Tedge Config Get
Set unknown configuration via environment variables 0.2 s Tedge Config Get

Comment on lines 72 to 77
if let Some(detail) = operation.exec() {
if let Some(on_message) = &detail.on_message {
self.operations_by_trigger.insert(on_message.clone(), index);
}
}
self.operations[index] = operation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this key piece of code is duplicated, it's better to introduce a private method to update the triggers.

Suggested change
if let Some(detail) = operation.exec() {
if let Some(on_message) = &detail.on_message {
self.operations_by_trigger.insert(on_message.clone(), index);
}
}
self.operations[index] = operation;
self.operations[index] = operation;
self.update_triggers(index, operation);

Signed-off-by: Pradeep Kumar K J <pradeepkumar.kj@softwareag.com>
@PradeepKiruvale PradeepKiruvale temporarily deployed to Test Pull Request May 15, 2023 14:21 — with GitHub Actions Inactive
Copy link
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@didier-wenzek didier-wenzek merged commit b245979 into thin-edge:main May 15, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants