Overwrite data upon loading a tariff plan

80 views
Skip to first unread message

Dominik Schopf

unread,
Jun 23, 2021, 11:55:41 AM6/23/21
to CGRateS
Hello everyone,

I have a rather simple question about how to accomplish something with cgrates.

We currently implemented our system to properly generate a complete a tariff plan "package" whenever it's needed.
Then we simply forward that towards cgrates using the load_tp_from_folder command (or trigger it via API).

However I found that cgrates does not delete any elements that got deleted from the tariff plan upon the mentioned load_tp_from_folder.
So for example we have an attribute entry, which we simply remove when we do not need it anymore.
After we removed this attribute from the Attributes.csv files and reloaded the tariff plan, I can still find the attribute using the cgr-cli.

Is is somehow possible to just "throw" the whole tariff plan to cgrates, tell it to reload and forget about any data that is not present anymore?
We need to do this without restarting cgrates, since there could be ongoing calls and so on.

Thanks in advance

Jacek Konieczny

unread,
Jun 24, 2021, 3:28:44 AM6/24/21
to CGRateS
Hi,

I have also found this being a problem. My solution is to not load the tariff from filesystem, but build it from our control app via the API. The app first lists the objects in the current tariff (e.g. using APIerSv1.GetActionPlanIDs() to get currently installed action plans), then adds the objects needed (APIerSv1.SetActionPlan(), keep track of ids added) and in the end removes everything that is not needed any more.

The actual tariff (destination and rates) I load from CSV files into DataDB and then load from DataDB via API. I make sure all ids are unique here (e.g. destination id includes hash of actual prefixes), so lefover entries are either reused or won't hurt (I assume the inevitable 'memory leak' will be manageable).

Fortunately AttributeS profiles are quite static in my use case, so I don't have to fight with that much.

I agree that this should be probably easier, but not found a better way.

Jacek

Adrian Porosnicu

unread,
Jun 29, 2021, 8:04:21 AM6/29/21
to CGRateS
Hello,

The data management in CGRateS is like in any other database. 
Firstly, you can remove your attribute by using the removing attribute profile API: https://pkg.go.dev/github.com/cgrates/cgr...@v0.9.1-rc3.0.20210625161334-062644154e56/apier/v1#APIerSv1.RemoveAttributeProfile
Another way is to set your attribute by making overwrite, with the same Tenant and ID: https://pkg.go.dev/github.com/cgrates/cgr...@v0.9.1-rc3.0.20210625161334-062644154e56/apier/v1#APIerSv1.SetAttributeProfile
Last choice would be to use cgr-loader with the "remove" flag, but this will delete the whole data from the directory you loaded. For your case, you should have a directory which contains just your attribute. Here is an example with "-remove" flag:
https://github.com/cgrates/cgrates/blob/master/cmd/cgr-loader/cgr-loader_remove_it_test.go#L482 . Also you can use another two APIs for deleting, these 2 works by the same principle as the cgr-loader "-remove" flag: 

Adrian
Reply all
Reply to author
Forward
0 new messages