fledge-iot / fledge-service-dispatcher

Dispatcher service is responsible for dispatching control messages between Fledge services.
0 stars 0 forks source link

Asset name not updated in "ingest" operation of filter in pipeline #51

Closed aklira closed 5 months ago

aklira commented 9 months ago

Fledge: dev_v2.2.0 We have a FLEDGE filter plugin which ingest some readings. When the reading's asset name is "opcua_operation", the reading content is modified and asset name is changed to "PivotCommand" as shown below:

            if (assetName == "opcua_operation") {
                opcua2pivot(reading);
                reading->setAssetName("PivotCommand");
            } else ...

This plugin is loaded in a pipeline which sources a NORTH plugin and broadcasts to SOUTH. When ingesting an expected reading, the dispatcher syslog shows that the content and asset name are correctly modified as show above:

Dec 13 16:39:55 ubuntu-vm Fledge dispatcher[108388]: DEBUG: Filtering control request for piepline 'pipe', {"asset_code":"opcua_operation","user_ts":"2023-12-13 15:39:55.631339+00:00","ts":"2023-12-13 15:39:55.631339+00:00","reading":{"co_id":"pivotDPC","co_type":"opcua_dpc","co_value":4,"co_test":0,"co_se":0,"co_ts":1702481995}}
(...)
Dec 13 16:39:55 ubuntu-vm Fledge dispatcher[108388]: DEBUG: Result of filtering control request is {"asset_code":"PivotCommand","user_ts":"2023-12-13 15:39:55.631339+00:00","ts":"2023-12-13 15:39:55.631339+00:00","reading":{"PIVOTTC":{"GTIC":{"Select":0, "ComingFrom":"opcua", "Identifier":"pivotDPC", "DPCTyp":{"t":{"SecondSinceEpoch":1702481995}, "q":{"test":0}, "ctlVal":4}}}}}

However, in the south plugin the received operation has only the content updated. The asset name update has been restored to original value

FlorentP42 commented 9 months ago

Additionnal information from https://github.com/fledge-iot/fledge/issues/1239

Describe the bug As explained in the documentation:

Mapping Rules

For a set point write the name of the asset will always be set to reading, the asset that is created will have a set of datapoints, one per each setpoint write operation that is to be executed. The name of the datapoint is the name of the set point to be written and the value of the datapoint is the value to to set.

For example, if a set point write wishes to set the Pump Speed set point to 80 and the Pump Running set point to True then the reading that would be created and passed to the filter would have the asset_code of reading and two data points, one called Pump Speed with a value of 80 and another called Pump Running with a value of True.

This reading can then be manipulated by a filter in the same way as in any other pipeline. For example the expression filter filter could be used to scale the pump speed. If the required was to multiply the pump speed by 10, then the expression defined would be Pump Speed * 10 .

In the case of an operation the mapping is very similar, except that the asset_code in the reading becomes the operation name and the data points are the parameters of the operation.

For example, if an operation Start Fan required a parameter of Fan Speed then a reading with an asset_code of Start Fan with a single datapoint called Fan Speed would be created and passed through the filter pipeline.

This works as intended when entering a control pipeline: operation name is converted into asset_code of the reading to process. But this is not respected when exiting the pipeline: here for consistency we expect the asset_code to be converted back into operation name as it may have changed during filtering, and this is not happening.

To Reproduce Steps to reproduce the behavior:

  1. Create a north service that can call an operation named "NorthOP".
  2. Create a south service that can receive an operation named "SouthOP".
  3. Create a control pipeline between those services.
  4. Add a filter to this pipeline that will change the asset_code of the readings being filtered from "NorthOP" to "SouthOP".
  5. Restart Fledge so that the pipeline becomes active.
  6. Call the operation "NorthOP" from the north plugin.
  7. Notice that the operation received in the south plugin is still called "NorthOP" when it should be "SouthOP".

Expected behavior Operation name is properly updated with the value from asset_code when exiting a control pipeline.

Additional context N/A

MarkRiddoch commented 8 months ago

The enhancement to allow operation names to be changed by filter pipelines is currently being tested and will be available in develop shortly

FlorentP42 commented 7 months ago

This seems to be fixed in Fledge 2.3.0-73