BroadbandForum / obuspa

OB-USP-AGENT is a system daemon providing a User Services Platform (USP) Agent. https://github.com/BroadbandForum/obuspa/wiki
BSD 3-Clause "New" or "Revised" License
93 stars 62 forks source link

DATA_MODEL_SetParameterInDatabase for BulkData.Profile.x.Enable not turning off #93

Closed CSalaza73 closed 1 year ago

CSalaza73 commented 1 year ago

We are implementing a feature to collect intermediate data as it comes in through a bulkdata push. We are able to set the enable to true using DATA_MODEL_SetParameterValue before calling an asynchronous command where it creates a separate thread. When the asynchronous call is at the end of the function to send an operation complete message, it uses a sync timer to call a callback which uses DATA_MODEL_SetParameterInDatabase to set BulkData.Profile.2.Enable to "false".

We see the value of Enable to false using the CLI but the bulkdata push is still happening. We did notice that Device.BulkData.Profile.2.X_ARRIS-COM_Status as "Enabled" when BulkData.Profile.2.Enable is "true" but also when BulkData.Profile.2.Enable is "false" after using. DATA_MODEL_SetParameterInDatabase.

Our question is why can we not stop the bulkdata push even after setting Enable to "false" using DATA_MODEL_SetParameterInDatabase in an asynchronous function.

holme-r commented 1 year ago

I verified that enable/disable works for bulkdata push using 'obuspa -c', so the problem is something to do with the code that you've added.

The changes you're making are using internal APIs, not the standard ones that are designed to be used (usp_api.h). Use of internal APIs is not recommended. Many internal functions do not work correctly unless they are called from the data model thread and do not have guards to prevent this (unlike the usp_api ones, which do have guards).

When I tried calling DATA_MODEL_SetParameterValue() from a sync_timer callback, I hit an assert because the set was not within a database transaction. Wrapping the set in calls to DM_TRANS_Start() and DM_TRANS_Commit() fixed the issue and the disable occurred correctly. Alternatively, calling USP_DM_SetParameterValue (instead of DATA_MODEL_SetParameterValue) includes the database transaction wrapping.

CSalaza73 commented 1 year ago

Thank you for your response. I think the actual question we have is how can we change the Enable feature of a bulkdata.profile by being outside the main data model thread? We are trying to do this in an asynchronous command. It seems as all the api functions and internal APIs do not allow this to happen. We thought we could use setParameterInDatabase() which not not required to be in the data model thread but as mentioned it has not worked.

We tried using the DM_TRANS_Start() and DM_TRANS_Commit() but this did not change the outcome.

holme-r commented 1 year ago

There is a PR which is currently undergoing review in the upstream BBF repo, which will allow you to initiate setting a parameter from another thread. It adds a function which posts a message on the data model’s queue containing a callback and arg pointer, which will get called when the data model thread processes that message. This is a generic callback which can call any function from within the data model thread e.g. USP_DM_SetParameterValue(). The code review cycle is about 2 weeks, but if you are BBF members you could pickup the PR earlier.

holme-r commented 1 year ago

The PR has been merged. Please use the function USP_PROCESS_DoWork() in latest commit (v7.0.4).