thin-edge / thin-edge.io

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

Add a support of firmware_update to c8y-mapper #2453

Closed rina23q closed 10 months ago

rina23q commented 11 months ago

Is your feature improvement request related to a problem? Please describe. As a part of making all c8y-*-plugins generic, c8y-firmware-plugin's feature should be converted to mapper, agent, and operation workflow. This ticket focuses on c8y-mapper side's implementation.

Describe the solution you'd like c8y-mapper addresses:

Command Metadata

Topic: te/<identifier>/cmd/firmware_update Payload: can be {} empty JSON, or name, version, url (all fields are optional)

{
    "name": "firmware-foo-bar",
    "version": "0.1.0",
    "url": "http://example.com"
}

Upon receiving a message on the topic, c8y-mapper translates it to

New Command

  1. SmartREST message is received by c8y-mapper.
    # message ID, device XID, FW name, FW version, FW url
    515,DeviceSerial,myFirmware,1.0,http://www.my.url
  2. c8y-mapper creates a new command with init state. Topic: te/<identifier>/cmd/firmware_update/<cmd-id>
    {
    "status": "init",
    "remoteUrl": "http://www.my.url",
    "name": "myFirmware",
    "version": "1.0"
    }
  3. Downloading a file from remote will be done by tedge-agent. Firmware installation and rollback mechanism will be done by operation workflow.
  4. Upon receiving the executing state, c8y-mapper converts the message to SmartREST 501 (operation executing).
  5. Upon receiving the final state (failed or successful), c8y-mapper converts the message to SmartREST.
    • successful: SmartREST 503 (operation successful) and 115 (current firmware)
    • failed: SmartREST 502 (operation failed)

Describe alternatives you've considered

Additional context If user wants to use the old API by c8y-firmware-plugin,

rina23q commented 11 months ago

Resolved by #2464

To try the message conversion, one needs to enable firmware_update feature by tedge config, then restart tedge-mapper-c8y.

sudo tedge config set c8y.enable.firmware_update true
gligorisaev commented 11 months ago

QA has thoroughly checked the feature and here are the results: