thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
211 stars 55 forks source link

feat(workflow): support combining fixed strings with variable expansions #2847

Closed reubenmiller closed 3 weeks ago

reubenmiller commented 2 months ago

Is your feature improvement request related to a problem? Please describe.

The variable expansion supported by the tedge-agent workflow syntax is too restrictive and does not support combining fixed strings with a variable

For example the following script will not be expanded as the tedge-mapper-

script = "sudo systemctl restart tedge-mapper-${.payload.mapperType}"

Because of that, if the user wants to build a script argument by combining a fixed string with a variable reference, they would then need to create a wrapper script which will do the string interpolation.

For example the above would have to be write a wrapper script, e.g. /usr/bin/my_wrapper.sh:

#!/bin/sh
sudo systemctl restart "tedge-mapper-$1"

And then call the wrapper script from the workflow state:

script = "/usr/bin/my_wrapper.sh ${.payload.mapperType}"

Writing a wrapper script adds too much overhead and is harder to maintain as it is easy for the wrapper script to get out of sync with the workflow definition.

Describe the solution you'd like

Support expanding variable references (e.g. ${<dotnotation>}) even when a static prefix/suffix is provided (or even multiple variable references in the same argument?)

operation = "restart_mapper"

[init]
action = "proceed"
on_success = "executing"

[executing]
script = "sudo systemctl restart tedge-mapper-${.payload.mapperType}"
on_success = "successful"

[successful]
action = "cleanup"

[failed]
action = "cleanup"

Describe alternatives you've considered

Additional context

gligorisaev commented 4 weeks ago

Test Cases:

1. /tests/cumulocity/configuration/configuration_operation.robot

New or Changed Sections

Trigger config_snapshot operation from another operation

Trigger custom config_snapshot operation

Trigger config_update operation from another workflow

Trigger custom config_update operation

Customize config operations & Restore config operations

Customize Operation Workflows

The new and changed sections integrate well with the existing suite, ensuring thorough validation of both standard and custom configurations.

2. /tests/cumulocity/log/log_operation.robot

New or Changed Sections

Trigger log_upload operation from another operation

Trigger custom log_upload operation

Customize Operation Workflows

Restore log_upload operation